Skip to content

Commit 1e4a88d

Browse files
committed
Warn user to apply or discard unsaved changes in cell editor
Additionally disable the entire widget when not associated to any valid index. See issue #2488
1 parent af84e89 commit 1e4a88d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/EditDialog.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,31 @@ EditDialog::~EditDialog()
112112

113113
void EditDialog::setCurrentIndex(const QModelIndex& idx)
114114
{
115+
if (m_currentIndex != QPersistentModelIndex(idx) && ui->buttonApply->isEnabled() &&
116+
(sciEdit->isModified() || ui->qtEdit->document()->isModified() || hexEdit->isModified())) {
117+
118+
QMessageBox::StandardButton reply = QMessageBox::question(
119+
this,
120+
tr("Unsaved data in the cell editor"),
121+
tr("The cell editor contains data not yet applied to the database.\n"
122+
"Do you want to apply the edited data?"),
123+
QMessageBox::Apply | QMessageBox::Discard);
124+
125+
if (reply == QMessageBox::Apply)
126+
accept();
127+
}
128+
129+
setDisabled(!idx.isValid());
130+
115131
m_currentIndex = QPersistentModelIndex(idx);
116132

117133
QByteArray bArrData = idx.data(Qt::EditRole).toByteArray();
118134
loadData(bArrData);
119135
updateCellInfoAndMode(bArrData);
120136

121137
ui->buttonApply->setDisabled(true);
138+
sciEdit->setModified(false);
139+
ui->qtEdit->document()->setModified(false);
122140
}
123141

124142
void EditDialog::showEvent(QShowEvent*)

0 commit comments

Comments
 (0)