Skip to content

Commit

Permalink
Do not ignore error when inserting rows in 'Duplicate record'
Browse files Browse the repository at this point in the history
That avoids overwriting existing record as reported in issue #1255.

This doesn't improve the underlying situation, that is inserting empty rows
before duplicating the content. But it is safer to not ignore the error in
the initial row insertion.
  • Loading branch information
mgrojo committed Dec 10, 2017
1 parent 5807c0b commit 7ed1b1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void MainWindow::init()
connect(dittoRecordShortcut, &QShortcut::activated, [this]() {
int currentRow = ui->dataTable->currentIndex().row();
auto row = m_browseTableModel->dittoRecord(currentRow);
ui->dataTable->setCurrentIndex(row);
duplicateRecord(currentRow);
});

// Add menu item for log dock
Expand Down Expand Up @@ -2450,7 +2450,7 @@ void MainWindow::showRecordPopupMenu(const QPoint& pos)
popupRecordMenu.addAction(action);

connect(action, &QAction::triggered, [&]() {
m_browseTableModel->dittoRecord(row);
duplicateRecord(row);
});

popupRecordMenu.exec(ui->dataTable->verticalHeader()->mapToGlobal(pos));
Expand Down Expand Up @@ -2767,3 +2767,12 @@ void MainWindow::saveFilterAsView()
else
QMessageBox::information(this, qApp->applicationName(), tr("There is no filter set for this table. View will not be created."));
}

void MainWindow::duplicateRecord(int currentRow)
{
auto row = m_browseTableModel->dittoRecord(currentRow);
if (row.isValid())
ui->dataTable->setCurrentIndex(row);
else
QMessageBox::warning(this, qApp->applicationName(), db.lastError());
}
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class MainWindow : public QMainWindow
void enableEditing(bool enable_edit, bool enable_insertdelete);
void loadExtensionsFromSettings();
void saveAsView(QString query);
void duplicateRecord(int currentRow);

sqlb::ObjectIdentifier currentlyBrowsedTableName() const;

Expand Down
4 changes: 3 additions & 1 deletion src/sqlitetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,9 @@ QModelIndex SqliteTableModel::dittoRecord(int old_row)
if(!isEditable())
return QModelIndex();

insertRow(rowCount());
if (!insertRow(rowCount()))
return QModelIndex();

int firstEditedColumn = 0;
int new_row = rowCount() - 1;

Expand Down

0 comments on commit 7ed1b1d

Please sign in to comment.