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.
This commit is contained in:
Martin Kleusberg
2013-09-07 12:15:56 +02:00
parent bc2511434e
commit c01a890992

View File

@@ -349,18 +349,21 @@ void MainWindow::addRecord()
void MainWindow::deleteRecord()
{
if(ui->dataTable->currentIndex().isValid())
if(ui->dataTable->selectionModel()->hasSelection())
{
int row = ui->dataTable->currentIndex().row();
if(m_browseTableModel->removeRow(row))
int old_row = ui->dataTable->currentIndex().row();
while(ui->dataTable->selectionModel()->hasSelection())
{
populateTable(ui->comboBrowseTable->currentText());
if(row > m_browseTableModel->totalRowCount())
row = m_browseTableModel->totalRowCount();
selectTableLine(row);
} else {
QMessageBox::warning( this, QApplication::applicationName(), tr("Error deleting record:\n") + db.lastErrorMessage);
if(!m_browseTableModel->removeRow(ui->dataTable->selectionModel()->selectedIndexes().first().row()))
{
QMessageBox::warning(this, QApplication::applicationName(), tr("Error deleting record:\n%1").arg(db.lastErrorMessage));
break;
}
}
populateTable(ui->comboBrowseTable->currentText());
if(old_row > m_browseTableModel->totalRowCount())
old_row = m_browseTableModel->totalRowCount();
selectTableLine(old_row);
} else {
QMessageBox::information( this, QApplication::applicationName(), tr("Please select a record first"));
}