# HG changeset patch # User Chris Cannam # Date 1524495987 -3600 # Node ID 0ded54e94332eb4b356552f868570ba836055a0a # Parent d967e21fe99582d2ca2507471b73f1e8224bd6f1 Delete rows in reverse order for safety diff -r d967e21fe995 -r 0ded54e94332 widgets/ModelDataTableDialog.cpp --- 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 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); } } diff -r d967e21fe995 -r 0ded54e94332 widgets/ModelDataTableDialog.h --- a/widgets/ModelDataTableDialog.h Mon Apr 23 16:04:51 2018 +0100 +++ b/widgets/ModelDataTableDialog.h Mon Apr 23 16:06:27 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _MODEL_DATA_TABLE_DIALOG_H_ -#define _MODEL_DATA_TABLE_DIALOG_H_ +#ifndef SV_MODEL_DATA_TABLE_DIALOG_H +#define SV_MODEL_DATA_TABLE_DIALOG_H #include