OpendTect-6_4  6.4
i_qtable.h
Go to the documentation of this file.
1 #ifndef i_qtable_h
2 #define i_qtable_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Nanne Hemstra
9  Date: January 2008
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "uitable.h"
16 
17 #include <QHeaderView>
18 #include <QObject>
19 #include <QTableWidget>
20 #include <QTableWidgetItem>
21 #include <QWidget>
22 
23 
25 
29 QT_BEGIN_NAMESPACE
30 
31 class i_tableMessenger : public QObject
32 {
33  Q_OBJECT
34  friend class uiTableBody;
35 
36 protected:
37 i_tableMessenger( QTableWidget* sndr, uiTable* receiver )
38  : sender_(sndr)
39  , receiver_(receiver)
41 {
42  connect( sndr, SIGNAL(cellChanged(int,int)),
43  this, SLOT(valueChanged(int,int)) );
44 
45  connect( sndr, SIGNAL(cellClicked(int,int)),
46  this, SLOT(clicked(int,int)) );
47 
48  connect( sndr, SIGNAL(cellPressed(int,int)),
49  this, SLOT(cellPressed(int,int)) );
50 
51  connect( sndr, SIGNAL(cellDoubleClicked(int,int)),
52  this, SLOT(doubleClicked(int,int)) );
53 
54  connect( sndr, SIGNAL(itemSelectionChanged()),
55  this, SLOT(itemSelectionChanged()) );
56 
57  connect( sndr, SIGNAL(cellEntered(int,int)),
58  this, SLOT(cellEntered(int,int)) );
59 
60  connect( sndr->verticalHeader(), SIGNAL(sectionClicked(int)),
61  this, SLOT(rowClicked(int)) );
62  connect( sndr->horizontalHeader(), SIGNAL(sectionClicked(int)),
63  this, SLOT(columnClicked(int)) );
64 
65  connect( sndr->verticalHeader(), SIGNAL(sectionPressed(int)),
66  this, SLOT(rowPressed(int)) );
67  connect( sndr->horizontalHeader(), SIGNAL(sectionPressed(int)),
68  this, SLOT(columnPressed(int)) );
69 
70  connect( sndr->verticalHeader(), SIGNAL(sectionDoubleClicked(int)),
71  this, SLOT(rowDoubleClicked(int)) );
72  connect( sndr->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)),
73  this, SLOT(columnDoubleClicked(int)) );
74 }
75 
76  virtual ~i_tableMessenger() {}
77 
78 private:
79 
81  QTableWidget* sender_;
83 
84 private slots:
85 
86 #define mTriggerBody( notifier, row, col, triggerstatement ) \
87 { \
88  BufferString msg = #notifier; \
89  msg += " "; msg += row; \
90  msg += " "; msg += col; \
91  const int refnr = receiver_->beginCmdRecEvent( msg ); \
92  triggerstatement; \
93  receiver_->endCmdRecEvent( refnr, msg ); \
94 }
95 
96 #define mNoTrigger( notifier, row, col ) \
97  mTriggerBody( notifier, row, col, )
98 
99 #define mTrigger( notifier, row, col ) \
100  mTriggerBody( notifier, row, col, receiver_->notifier.trigger(*receiver_) )
101 
102 #define mHeaderTriggerBody( notifier, idx, vertical, triggerstatement ) \
103  mTriggerBody( notifier, (vertical ? idx : -1), (vertical ? -1 : idx), \
104  triggerstatement )
105 
106 #define mNoHeaderTrigger( notifier, idx, vertical ) \
107  mHeaderTriggerBody( notifier, idx, vertical, )
108 
109 #define mHeaderTrigger( notifier, idx, vertical ) \
110  mHeaderTriggerBody( notifier, idx, vertical, \
111  receiver_->notifier.trigger(idx, *receiver_ ) )
112 
113 
114 void valueChanged( int row, int col )
115 {
116  receiver_->notifcell_ = RowCol(row,col);
117  mTrigger( valueChanged, row, col );
118 }
119 
120 
121 void clicked( int row, int col )
122 {
123  receiver_->notifcell_ = RowCol(row,col);
124  if ( receiver_->buttonstate_ == OD::RightButton )
125  mTrigger( rightClicked, row, col )
126  else if ( receiver_->buttonstate_ == OD::LeftButton )
127  mTrigger( leftClicked, row, col );
128 }
129 
130 
131 void doubleClicked( int row, int col )
132 {
133  receiver_->notifcell_ = RowCol(row,col);
134  mTrigger( doubleClicked, row, col );
135 }
136 
137 
139 { mTrigger( selectionChanged, -1, -1 ); }
140 
141 
142 void cellPressed( int row, int col )
143 {
144  receiver_->notifcell_ = RowCol(row,col);
145  mNoTrigger( cellPressed, row, col );
146 }
147 
148 
149 void cellEntered( int row, int col )
150 { mNoTrigger( cellEntered, row, col ); }
151 
152 
153 void rowClicked( int idx )
154 {
155  // Trigger is conditional to repair Qt inconsistency. Unlike tables and
156  // and lists, the header signals a final click after mouse dragging.
157  if ( idx == lastpressedheaderidx_ )
158  mHeaderTrigger( rowClicked, idx, true );
159 }
160 
161 
162 void columnClicked( int idx )
163 {
164  // Trigger is conditional to repair Qt inconsistency. Unlike tables and
165  // and lists, the header signals a final click after mouse dragging.
166  if ( idx == lastpressedheaderidx_ )
167  mHeaderTrigger( columnClicked, idx, false );
168 }
169 
170 
171 void rowPressed( int idx )
172 {
173  lastpressedheaderidx_ = idx;
174  mNoHeaderTrigger( rowPressed, idx, true );
175 }
176 
177 
178 void columnPressed( int idx )
179 {
180  lastpressedheaderidx_ = idx;
181  mNoHeaderTrigger( columnPressed, idx, false );
182 }
183 
184 
185 void rowDoubleClicked( int idx )
186 { mNoHeaderTrigger( rowDoubleClicked, idx, true ); }
187 
188 
189 void columnDoubleClicked( int idx )
190 { mNoHeaderTrigger( columnDoubleClicked, idx, false ); }
191 
192 #undef mNoTrigger
193 #undef mTrigger
194 #undef mTriggerBody
195 #undef mHeaderTriggerBody
196 #undef mNoHeaderTrigger
197 #undef mHeaderTrigger
198 
199 };
200 
201 QT_END_NAMESPACE
202 
203 #endif
friend class uiTableBody
Definition: i_qtable.h:34
void cellEntered(int row, int col)
Definition: i_qtable.h:149
void clicked(int row, int col)
Definition: i_qtable.h:121
virtual ~i_tableMessenger()
Definition: i_qtable.h:76
Definition: uitable.h:30
void itemSelectionChanged()
Definition: i_qtable.h:138
#define mNoHeaderTrigger(notifier, idx, vertical)
Definition: i_qtable.h:106
int lastpressedheaderidx_
Definition: i_qtable.h:82
void rowClicked(int idx)
Definition: i_qtable.h:153
void rowDoubleClicked(int idx)
Definition: i_qtable.h:185
Definition: keyenum.h:23
QTableWidget * sender_
Definition: i_qtable.h:81
void columnDoubleClicked(int idx)
Definition: i_qtable.h:189
void rowPressed(int idx)
Definition: i_qtable.h:171
void valueChanged(int row, int col)
Definition: i_qtable.h:114
#define mHeaderTrigger(notifier, idx, vertical)
Definition: i_qtable.h:109
OD::ButtonState buttonstate_
Definition: uitable.h:347
#define mTrigger(notifier, row, col)
Definition: i_qtable.h:99
Helper class for uiTable to relay Qt&#39;s &#39;activated&#39; messages to uiAction.
Definition: i_qtable.h:31
IdxPair used for its row() and col().
Definition: rowcol.h:25
#define mNoTrigger(notifier, row, col)
Definition: i_qtable.h:96
void columnPressed(int idx)
Definition: i_qtable.h:178
RowCol notifcell_
Definition: uitable.h:337
void cellPressed(int row, int col)
Definition: i_qtable.h:142
i_tableMessenger(QTableWidget *sndr, uiTable *receiver)
Definition: i_qtable.h:37
void doubleClicked(int row, int col)
Definition: i_qtable.h:131
uiTable * receiver_
Definition: i_qtable.h:80
void columnClicked(int idx)
Definition: i_qtable.h:162
Definition: keyenum.h:24

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