Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/widgets/ModelDataTableDialog.cpp Mon Apr 23 16:04:51 2018 +0100 +++ b/widgets/ModelDataTableDialog.cpp Mon Apr 23 16:06:27 2018 +0100 @@ -261,12 +261,12 @@ void ModelDataTableDialog::currentChanged(const QModelIndex ¤t, - const QModelIndex &) + const QModelIndex &previous) { -// SVDEBUG << "ModelDataTableDialog::currentChanged: from " -// << previous.row() << ", " << previous.column() -// << " to " << current.row() << ", " << current.column() -// << endl; + SVDEBUG << "ModelDataTableDialog::currentChanged: from " + << previous.row() << ", " << previous.column() + << " to " << current.row() << ", " << current.column() + << endl; m_currentRow = current.row(); m_table->setCurrentRow(m_currentRow); } @@ -280,10 +280,17 @@ void ModelDataTableDialog::deleteRows() { - // not efficient - while (m_tableView->selectionModel()->hasSelection()) { - m_table->removeRow - (m_tableView->selectionModel()->selection().indexes().begin()->row()); + std::set<int> selectedRows; + if (m_tableView->selectionModel()->hasSelection()) { + for (const auto &ix: m_tableView->selectionModel()->selectedIndexes()) { + selectedRows.insert(ix.row()); + } + } + // Remove rows in reverse order, so as not to pull the rug from + // under our own feet + for (auto ri = selectedRows.rbegin(); ri != selectedRows.rend(); ++ri) { + SVDEBUG << "ModelDataTableDialog: removing row " << *ri << endl; + m_table->removeRow(*ri); } }