comparison widgets/ModelDataTableDialog.cpp @ 1272:0ded54e94332

Delete rows in reverse order for safety
author Chris Cannam
date Mon, 23 Apr 2018 16:06:27 +0100
parents d967e21fe995
children d39db4673676
comparison
equal deleted inserted replaced
1271:d967e21fe995 1272:0ded54e94332
259 // SVDEBUG << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << endl; 259 // SVDEBUG << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << endl;
260 } 260 }
261 261
262 void 262 void
263 ModelDataTableDialog::currentChanged(const QModelIndex &current, 263 ModelDataTableDialog::currentChanged(const QModelIndex &current,
264 const QModelIndex &) 264 const QModelIndex &previous)
265 { 265 {
266 // SVDEBUG << "ModelDataTableDialog::currentChanged: from " 266 SVDEBUG << "ModelDataTableDialog::currentChanged: from "
267 // << previous.row() << ", " << previous.column() 267 << previous.row() << ", " << previous.column()
268 // << " to " << current.row() << ", " << current.column() 268 << " to " << current.row() << ", " << current.column()
269 // << endl; 269 << endl;
270 m_currentRow = current.row(); 270 m_currentRow = current.row();
271 m_table->setCurrentRow(m_currentRow); 271 m_table->setCurrentRow(m_currentRow);
272 } 272 }
273 273
274 void 274 void
278 } 278 }
279 279
280 void 280 void
281 ModelDataTableDialog::deleteRows() 281 ModelDataTableDialog::deleteRows()
282 { 282 {
283 // not efficient 283 std::set<int> selectedRows;
284 while (m_tableView->selectionModel()->hasSelection()) { 284 if (m_tableView->selectionModel()->hasSelection()) {
285 m_table->removeRow 285 for (const auto &ix: m_tableView->selectionModel()->selectedIndexes()) {
286 (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);
287 } 294 }
288 } 295 }
289 296
290 void 297 void
291 ModelDataTableDialog::editRow() 298 ModelDataTableDialog::editRow()