Skip to content

Commit c01a890

Browse files
committed
MainWindow: Support deleting multiple rows at once
When multiple rows are selected in the Browse Data tab of the main window and the delete record button is clicked delete all selected rows and not just one of them.
1 parent bc25114 commit c01a890

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/MainWindow.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,21 @@ void MainWindow::addRecord()
349349

350350
void MainWindow::deleteRecord()
351351
{
352-
if(ui->dataTable->currentIndex().isValid())
352+
if(ui->dataTable->selectionModel()->hasSelection())
353353
{
354-
int row = ui->dataTable->currentIndex().row();
355-
if(m_browseTableModel->removeRow(row))
354+
int old_row = ui->dataTable->currentIndex().row();
355+
while(ui->dataTable->selectionModel()->hasSelection())
356356
{
357-
populateTable(ui->comboBrowseTable->currentText());
358-
if(row > m_browseTableModel->totalRowCount())
359-
row = m_browseTableModel->totalRowCount();
360-
selectTableLine(row);
361-
} else {
362-
QMessageBox::warning( this, QApplication::applicationName(), tr("Error deleting record:\n") + db.lastErrorMessage);
357+
if(!m_browseTableModel->removeRow(ui->dataTable->selectionModel()->selectedIndexes().first().row()))
358+
{
359+
QMessageBox::warning(this, QApplication::applicationName(), tr("Error deleting record:\n%1").arg(db.lastErrorMessage));
360+
break;
361+
}
363362
}
363+
populateTable(ui->comboBrowseTable->currentText());
364+
if(old_row > m_browseTableModel->totalRowCount())
365+
old_row = m_browseTableModel->totalRowCount();
366+
selectTableLine(old_row);
364367
} else {
365368
QMessageBox::information( this, QApplication::applicationName(), tr("Please select a record first"));
366369
}

0 commit comments

Comments
 (0)