OpendTect-6_4  6.4
i_qtreeview.h
Go to the documentation of this file.
1 #ifndef i_qtreeview_h
2 #define i_qtreeview_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H. Lammertink
9  Date: 31/01/2002
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "uitreeview.h"
16 
17 #include <QObject>
18 #include <QTreeWidget>
19 
20 
22 
26 QT_BEGIN_NAMESPACE
27 
28 class i_treeVwMessenger : public QObject
29 {
30  Q_OBJECT
31  friend class uiTreeViewBody;
32 
33 protected:
34 
35 i_treeVwMessenger( QTreeWidget& sndr, uiTreeView& receiver )
36  : sender_(sndr)
37  , receiver_(receiver)
38 {
39  connect( &sndr, SIGNAL(itemSelectionChanged()),
40  this, SLOT(itemSelectionChanged()) );
41 
42  connect( &sndr, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
43  this, SLOT(itemChanged(QTreeWidgetItem*,int)) );
44 
45  connect( &sndr,
46  SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
47  this,
48  SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)) );
49 
50  connect( &sndr, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
51  this, SLOT(itemClicked(QTreeWidgetItem*,int)) );
52 
53  connect( &sndr, SIGNAL(itemPressed(QTreeWidgetItem*,int)),
54  this, SLOT(itemPressed(QTreeWidgetItem*,int)) );
55 
56  connect( &sndr, SIGNAL(customContextMenuRequested(const QPoint &)),
57  this, SLOT(customContextMenuRequested(const QPoint &)) );
58 
59  connect( &sndr, SIGNAL(itemExpanded(QTreeWidgetItem*)),
60  this, SLOT(itemExpanded(QTreeWidgetItem*)) );
61 
62  connect( &sndr, SIGNAL(itemCollapsed(QTreeWidgetItem*)),
63  this, SLOT(itemCollapsed(QTreeWidgetItem*)) );
64 
65  connect( &sndr, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
66  this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)) );
67 
68  connect( &sndr, SIGNAL(itemEntered(QTreeWidgetItem*,int)),
69  this, SLOT(itemEntered(QTreeWidgetItem*,int)) );
70 }
71 
72 private:
73 
74 void setNotifiedItem( QTreeWidgetItem* item )
75 { receiver_.setNotifiedItem(item); }
76 
77 void setNotifiedColumn( int col )
78 { receiver_.setNotifiedColumn( col ); }
79 
81 QTreeWidget& sender_;
82 
83 
84 #define mTriggerBody( notifier, triggerstatement1, triggerstatement2 ) \
85 { \
86  BufferString msg = #notifier; \
87  const int refnr = receiver_.beginCmdRecEvent( msg ); \
88  triggerstatement1; \
89  triggerstatement2; \
90  receiver_.endCmdRecEvent( refnr, msg ); \
91 }
92 
93 #define mNoTrigger( notifier ) \
94  mTriggerBody( notifier, , )
95 
96 #define mTrigger( notifier ) \
97  mTriggerBody( notifier, receiver_.notifier.trigger(receiver_), )
98 
99 #define mTriggerExtra( notifier, extranotifier ) \
100  mTriggerBody( notifier, receiver_.notifier.trigger(receiver_), \
101  receiver_.extranotifier.trigger(receiver_) )
102 
103 private slots:
104 
106 {
107  QList<QTreeWidgetItem*> items = sender_.selectedItems();
108  setNotifiedItem( items.size()>0 ? items[0] : 0 );
109  mTrigger( selectionChanged );
110 }
111 
112 void itemChanged( QTreeWidgetItem* item, int column )
113 {
114  setNotifiedItem( item );
115  setNotifiedColumn( column );
117 }
118 
119 void currentItemChanged( QTreeWidgetItem* item, QTreeWidgetItem* )
120 {
121  setNotifiedItem( item );
122  mTrigger( currentChanged );
123 }
124 
125 void itemClicked( QTreeWidgetItem* item, int col )
126 {
127  setNotifiedItem( item );
128  setNotifiedColumn( col );
129  if ( receiver_.buttonstate_ == OD::RightButton )
130  mTriggerExtra( rightButtonClicked, mouseButtonClicked )
131  else if ( receiver_.buttonstate_ == OD::LeftButton )
132  mTriggerExtra( leftButtonClicked, mouseButtonClicked )
133  else
134  mTrigger( mouseButtonClicked );
135 }
136 
137 void itemPressed( QTreeWidgetItem* item, int col )
138 {
139  setNotifiedItem( item );
140  setNotifiedColumn( col );
141  if ( receiver_.buttonstate_ == OD::RightButton )
142  mTriggerExtra( rightButtonPressed, mouseButtonPressed )
143  else if ( receiver_.buttonstate_ == OD::LeftButton )
144  mTriggerExtra( leftButtonPressed, mouseButtonPressed )
145  else
146  mTrigger( mouseButtonPressed );
147 }
148 
149 void customContextMenuRequested( const QPoint& qpoint )
150 {
151  setNotifiedItem( sender_.itemAt(qpoint) );
152  receiver_.setNotifiedColumn( sender_.columnAt(qpoint.x()) );
153  mTrigger( contextMenuRequested );
154 }
155 
156 void itemExpanded( QTreeWidgetItem* item )
157 {
158  setNotifiedItem( item );
159  mTrigger( expanded );
160 }
161 
162 void itemCollapsed( QTreeWidgetItem* item )
163 {
164  setNotifiedItem( item );
165  mTrigger( collapsed );
166 }
167 
168 void itemDoubleClicked( QTreeWidgetItem* item, int col )
169 {
170  if ( !receiver_.allowDoubleClick() )
171  return;
172 
173  setNotifiedItem( item );
174  setNotifiedColumn( col );
175  mTrigger( doubleClicked );
176 }
177 
178 void itemEntered( QTreeWidgetItem* item, int col )
179 {
180  setNotifiedItem( item );
181  setNotifiedColumn( col );
183 }
184 
185 #undef mTriggerBody
186 #undef mNoTrigger
187 #undef mTrigger
188 #undef mTriggerExtra
189 
190 };
191 
192 QT_END_NAMESPACE
193 
194 #endif
void setNotifiedItem(QTreeWidgetItem *item)
Definition: i_qtreeview.h:74
uiTreeView & receiver_
Definition: i_qtreeview.h:80
void itemDoubleClicked(QTreeWidgetItem *item, int col)
Definition: i_qtreeview.h:168
void currentItemChanged(QTreeWidgetItem *item, QTreeWidgetItem *)
Definition: i_qtreeview.h:119
void setNotifiedItem(mQtclass(QTreeWidgetItem *))
QTreeWidget & sender_
Definition: i_qtreeview.h:81
#define mNoTrigger(notifier)
Definition: i_qtreeview.h:93
void itemSelectionChanged()
Definition: i_qtreeview.h:105
i_treeVwMessenger(QTreeWidget &sndr, uiTreeView &receiver)
Definition: i_qtreeview.h:35
Definition: keyenum.h:23
void itemEntered(QTreeWidgetItem *item, int col)
Definition: i_qtreeview.h:178
OD::ButtonState buttonstate_
Definition: uitreeview.h:161
friend class uiTreeViewBody
Definition: i_qtreeview.h:31
#define mTrigger(notifier)
Definition: i_qtreeview.h:96
void itemChanged(QTreeWidgetItem *item, int column)
Definition: i_qtreeview.h:112
void setNotifiedColumn(int col)
Definition: i_qtreeview.h:77
Definition: uitreeview.h:33
void itemCollapsed(QTreeWidgetItem *item)
Definition: i_qtreeview.h:162
void customContextMenuRequested(const QPoint &qpoint)
Definition: i_qtreeview.h:149
#define mTriggerExtra(notifier, extranotifier)
Definition: i_qtreeview.h:99
brief Helper class for uiTreeView to relay Qt&#39;s messages.
Definition: i_qtreeview.h:28
bool allowDoubleClick() const
void setNotifiedColumn(int col)
Definition: uitreeview.h:136
void itemPressed(QTreeWidgetItem *item, int col)
Definition: i_qtreeview.h:137
void itemExpanded(QTreeWidgetItem *item)
Definition: i_qtreeview.h:156
Definition: keyenum.h:24
void itemClicked(QTreeWidgetItem *item, int col)
Definition: i_qtreeview.h:125

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019