From cb98e29a7c21996d951edc5bd8c0809d556f7a75 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Fri, 5 Jan 2018 20:51:36 +0100 Subject: [PATCH] Allow deleting and duplicating a selection of rows Before bbac655499d5f4d2334bb7068c47f120be2e9225 it was possible to delete a set of selected rows. This makes it possible again by only selecting the row if it is not already inside the selected rows. See issue #1283. Additionally and for coherence, the "Duplicate record" from the context menu is also made to apply to the list of selected rows. See issue #1090 --- src/MainWindow.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 8fd01c0b..d824ac20 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2447,16 +2447,32 @@ void MainWindow::showRecordPopupMenu(const QPoint& pos) if (row == -1) return; - ui->dataTable->selectRow(row); + // Select the row if it is not already in the selection. + QModelIndexList rowList = ui->dataTable->selectionModel()->selectedRows(); + bool found = false; + for (QModelIndex index : rowList) { + if (row == index.row()) { + found = true; + break; + } + } + if (!found) + ui->dataTable->selectRow(row); + + rowList = ui->dataTable->selectionModel()->selectedRows(); + + QString duplicateText = rowList.count() > 1 ? tr("Duplicate records") : tr("Duplicate record"); QMenu popupRecordMenu(this); - QAction* action = new QAction("Duplicate record", &popupRecordMenu); + QAction* action = new QAction(duplicateText, &popupRecordMenu); // Set shortcut for documentation purposes (the actual functional shortcut is not set here) action->setShortcut(QKeySequence(tr("Ctrl+\""))); popupRecordMenu.addAction(action); connect(action, &QAction::triggered, [&]() { - duplicateRecord(row); + for (QModelIndex index : rowList) { + duplicateRecord(index.row()); + } }); QAction* deleteRecordAction = new QAction(ui->buttonDeleteRecord->text(), &popupRecordMenu);