Mercurial > hg > svgui
changeset 1272:0ded54e94332
Delete rows in reverse order for safety
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 16:06:27 +0100 |
parents | d967e21fe995 |
children | 61418c112281 |
files | widgets/ModelDataTableDialog.cpp widgets/ModelDataTableDialog.h |
diffstat | 2 files changed, 18 insertions(+), 11 deletions(-) [+] |
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); } }
--- 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 <QMainWindow>