From 777088fc8003511e27554fdea8d60902fc7c8aba Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 14 Aug 2016 16:37:00 +0200 Subject: [PATCH] Improve code for deleting table rows Actually handle the case that deleting rows might fail in the SqliteTableModel. That's where this sort of check belongs. This allows us to get rid of the full refresh of the table view after deleting a row in the Browse Data tab. Thanks to @innermous for pointing this out! --- src/MainWindow.cpp | 2 +- src/sqlitetablemodel.cpp | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index de9a104b..c97414fc 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -595,7 +595,7 @@ void MainWindow::deleteRecord() break; } } - populateTable(ui->comboBrowseTable->currentText()); + if(old_row > m_browseTableModel->totalRowCount()) old_row = m_browseTableModel->totalRowCount(); selectTableLine(old_row); diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index 012f936a..80b2993d 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -394,16 +394,21 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent) { beginRemoveRows(parent, row, row + count - 1); + bool ok = true; + for(int i=count-1;i>=0;i--) { - m_db->deleteRecord(m_sTable, m_data.at(row + i).at(0)); - m_data.removeAt(row + i); + if(m_db->deleteRecord(m_sTable, m_data.at(row + i).at(0))) + { + m_data.removeAt(row + i); + --m_rowCount; + } else { + ok = false; + } } - m_rowCount -= count; - endRemoveRows(); - return true; + return ok; } QModelIndex SqliteTableModel::dittoRecord(int old_row)