Mercurial > hg > svgui
comparison widgets/ModelDataTableDialog.cpp @ 1536:5a215033b853
Fix #1951 Selecting row in data editor with multiple items having same frame always selects the first
author | Chris Cannam |
---|---|
date | Tue, 15 Oct 2019 09:32:24 +0100 |
parents | 873ff035364c |
children | 0ca4ca37809e |
comparison
equal
deleted
inserted
replaced
1535:873ff035364c | 1536:5a215033b853 |
---|---|
33 #include <QScreen> | 33 #include <QScreen> |
34 #include <QAction> | 34 #include <QAction> |
35 #include <QToolBar> | 35 #include <QToolBar> |
36 | 36 |
37 #include <iostream> | 37 #include <iostream> |
38 | |
39 //#define DEBUG_MODEL_DATA_TABLE_DIALOG 1 | |
38 | 40 |
39 ModelDataTableDialog::ModelDataTableDialog(ModelId tabularModelId, | 41 ModelDataTableDialog::ModelDataTableDialog(ModelId tabularModelId, |
40 QString title, QWidget *parent) : | 42 QString title, QWidget *parent) : |
41 QMainWindow(parent), | 43 QMainWindow(parent), |
42 m_currentRow(0), | 44 m_currentRow(0), |
160 } | 162 } |
161 | 163 |
162 void | 164 void |
163 ModelDataTableDialog::userScrolledToFrame(sv_frame_t frame) | 165 ModelDataTableDialog::userScrolledToFrame(sv_frame_t frame) |
164 { | 166 { |
167 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG | |
168 SVDEBUG << "ModelDataTableDialog::userScrolledToFrame " << frame << endl; | |
169 #endif | |
170 | |
171 // The table may contain more than one row with the same frame. If | |
172 // our current row has the same frame as the one passed in, we | |
173 // should do nothing - this avoids e.g. the situation where the | |
174 // user clicks on the second of two equal-framed rows, we fire | |
175 // scrollToFrame() from viewClicked(), that calls back here, and | |
176 // we end up switching the selection to the first of the two rows | |
177 // instead of the one the user clicked on. | |
178 | |
179 if (m_table->getFrameForModelIndex(m_table->index(m_currentRow, 0)) == | |
180 frame) { | |
181 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG | |
182 SVDEBUG << "ModelDataTableDialog::userScrolledToFrame: Already have this frame current; calling makeCurrent" << endl; | |
183 #endif | |
184 return; | |
185 } | |
186 | |
165 QModelIndex index = m_table->getModelIndexForFrame(frame); | 187 QModelIndex index = m_table->getModelIndexForFrame(frame); |
166 makeCurrent(index.row()); | 188 makeCurrent(index.row()); |
167 } | 189 } |
168 | 190 |
169 void | 191 void |
239 } | 261 } |
240 | 262 |
241 void | 263 void |
242 ModelDataTableDialog::viewClicked(const QModelIndex &index) | 264 ModelDataTableDialog::viewClicked(const QModelIndex &index) |
243 { | 265 { |
244 // SVDEBUG << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << endl; | 266 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG |
267 SVDEBUG << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << endl; | |
268 #endif | |
269 | |
245 emit scrollToFrame(m_table->getFrameForModelIndex(index)); | 270 emit scrollToFrame(m_table->getFrameForModelIndex(index)); |
246 } | 271 } |
247 | 272 |
248 void | 273 void |
249 ModelDataTableDialog::viewPressed(const QModelIndex &) | 274 ModelDataTableDialog::viewPressed(const QModelIndex &) |
250 { | 275 { |
251 // SVDEBUG << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << endl; | 276 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG |
277 SVDEBUG << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << endl; | |
278 #endif | |
252 } | 279 } |
253 | 280 |
254 void | 281 void |
255 ModelDataTableDialog::currentChanged(const QModelIndex ¤t, | 282 ModelDataTableDialog::currentChanged(const QModelIndex ¤t, |
256 const QModelIndex &previous) | 283 const QModelIndex &previous) |
257 { | 284 { |
285 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG | |
258 SVDEBUG << "ModelDataTableDialog::currentChanged: from " | 286 SVDEBUG << "ModelDataTableDialog::currentChanged: from " |
259 << previous.row() << ", " << previous.column() | 287 << previous.row() << ", " << previous.column() |
260 << " to " << current.row() << ", " << current.column() | 288 << " to " << current.row() << ", " << current.column() |
261 << endl; | 289 << endl; |
290 #endif | |
262 m_currentRow = current.row(); | 291 m_currentRow = current.row(); |
263 m_table->setCurrentRow(m_currentRow); | 292 m_table->setCurrentRow(m_currentRow); |
264 } | 293 } |
265 | 294 |
266 void | 295 void |
279 } | 308 } |
280 } | 309 } |
281 // Remove rows in reverse order, so as not to pull the rug from | 310 // Remove rows in reverse order, so as not to pull the rug from |
282 // under our own feet | 311 // under our own feet |
283 for (auto ri = selectedRows.rbegin(); ri != selectedRows.rend(); ++ri) { | 312 for (auto ri = selectedRows.rbegin(); ri != selectedRows.rend(); ++ri) { |
313 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG | |
284 SVDEBUG << "ModelDataTableDialog: removing row " << *ri << endl; | 314 SVDEBUG << "ModelDataTableDialog: removing row " << *ri << endl; |
315 #endif | |
285 m_table->removeRow(*ri); | 316 m_table->removeRow(*ri); |
286 } | 317 } |
287 } | 318 } |
288 | 319 |
289 void | 320 void |
304 } | 335 } |
305 | 336 |
306 void | 337 void |
307 ModelDataTableDialog::currentChangedThroughResort(const QModelIndex &index) | 338 ModelDataTableDialog::currentChangedThroughResort(const QModelIndex &index) |
308 { | 339 { |
309 // SVDEBUG << "ModelDataTableDialog::currentChangedThroughResort: row = " << index.row() << endl; | 340 #ifdef DEBUG_MODEL_DATA_TABLE_DIALOG |
310 // m_tableView->scrollTo(index); | 341 SVDEBUG << "ModelDataTableDialog::currentChangedThroughResort: row = " << index.row() << endl; |
342 #endif | |
311 makeCurrent(index.row()); | 343 makeCurrent(index.row()); |
312 } | 344 } |
313 | 345 |
314 void | 346 void |
315 ModelDataTableDialog::modelRemoved() | 347 ModelDataTableDialog::modelRemoved() |