Mercurial > hg > svgui
comparison widgets/ModelDataTableDialog.cpp @ 1324:13d9b422f7fe zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:31 +0100 |
parents | 0ded54e94332 |
children | d39db4673676 |
comparison
equal
deleted
inserted
replaced
1183:57d192e26331 | 1324:13d9b422f7fe |
---|---|
59 connect(action, SIGNAL(triggered()), this, SLOT(togglePlayTracking())); | 59 connect(action, SIGNAL(triggered()), this, SLOT(togglePlayTracking())); |
60 toolbar->addAction(action); | 60 toolbar->addAction(action); |
61 | 61 |
62 toolbar = addToolBar(tr("Edit Toolbar")); | 62 toolbar = addToolBar(tr("Edit Toolbar")); |
63 | 63 |
64 action = new QAction(il.load("datainsert"), tr("Insert New Item"), this); | 64 action = new QAction(il.load("draw"), tr("Insert New Item"), this); |
65 action->setShortcut(tr("Insert")); | 65 action->setShortcut(tr("Insert")); |
66 action->setStatusTip(tr("Insert a new item")); | 66 action->setStatusTip(tr("Insert a new item")); |
67 connect(action, SIGNAL(triggered()), this, SLOT(insertRow())); | 67 connect(action, SIGNAL(triggered()), this, SLOT(insertRow())); |
68 toolbar->addAction(action); | 68 toolbar->addAction(action); |
69 | 69 |
206 } | 206 } |
207 | 207 |
208 void | 208 void |
209 ModelDataTableDialog::makeCurrent(int row) | 209 ModelDataTableDialog::makeCurrent(int row) |
210 { | 210 { |
211 if (m_table->rowCount() == 0 || | |
212 row >= m_table->rowCount() || | |
213 row < 0) { | |
214 return; | |
215 } | |
216 | |
211 int rh = m_tableView->height() / m_tableView->rowHeight(0); | 217 int rh = m_tableView->height() / m_tableView->rowHeight(0); |
212 int topRow = row - rh/4; | 218 int topRow = row - rh/4; |
213 if (topRow < 0) topRow = 0; | 219 if (topRow < 0) topRow = 0; |
214 | 220 |
215 // should only scroll if the desired row is not currently visible | 221 // should only scroll if the desired row is not currently visible |
253 // SVDEBUG << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << endl; | 259 // SVDEBUG << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << endl; |
254 } | 260 } |
255 | 261 |
256 void | 262 void |
257 ModelDataTableDialog::currentChanged(const QModelIndex ¤t, | 263 ModelDataTableDialog::currentChanged(const QModelIndex ¤t, |
258 const QModelIndex &) | 264 const QModelIndex &previous) |
259 { | 265 { |
260 // SVDEBUG << "ModelDataTableDialog::currentChanged: from " | 266 SVDEBUG << "ModelDataTableDialog::currentChanged: from " |
261 // << previous.row() << ", " << previous.column() | 267 << previous.row() << ", " << previous.column() |
262 // << " to " << current.row() << ", " << current.column() | 268 << " to " << current.row() << ", " << current.column() |
263 // << endl; | 269 << endl; |
264 m_currentRow = current.row(); | 270 m_currentRow = current.row(); |
265 m_table->setCurrentRow(m_currentRow); | 271 m_table->setCurrentRow(m_currentRow); |
266 } | 272 } |
267 | 273 |
268 void | 274 void |
272 } | 278 } |
273 | 279 |
274 void | 280 void |
275 ModelDataTableDialog::deleteRows() | 281 ModelDataTableDialog::deleteRows() |
276 { | 282 { |
277 // not efficient | 283 std::set<int> selectedRows; |
278 while (m_tableView->selectionModel()->hasSelection()) { | 284 if (m_tableView->selectionModel()->hasSelection()) { |
279 m_table->removeRow | 285 for (const auto &ix: m_tableView->selectionModel()->selectedIndexes()) { |
280 (m_tableView->selectionModel()->selection().indexes().begin()->row()); | 286 selectedRows.insert(ix.row()); |
287 } | |
288 } | |
289 // Remove rows in reverse order, so as not to pull the rug from | |
290 // under our own feet | |
291 for (auto ri = selectedRows.rbegin(); ri != selectedRows.rend(); ++ri) { | |
292 SVDEBUG << "ModelDataTableDialog: removing row " << *ri << endl; | |
293 m_table->removeRow(*ri); | |
281 } | 294 } |
282 } | 295 } |
283 | 296 |
284 void | 297 void |
285 ModelDataTableDialog::editRow() | 298 ModelDataTableDialog::editRow() |