diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 4f718991..f80033b6 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -28,7 +28,7 @@ using json = nlohmann::json; EditDialog::EditDialog(QWidget* parent) : QDialog(parent), ui(new Ui::EditDialog), - currentIndex(QModelIndex()), + m_currentIndex(QModelIndex()), dataSource(SciBuffer), dataType(Null), isReadOnly(true) @@ -85,7 +85,7 @@ EditDialog::~EditDialog() void EditDialog::setCurrentIndex(const QModelIndex& idx) { - currentIndex = QPersistentModelIndex(idx); + m_currentIndex = QPersistentModelIndex(idx); QByteArray bArrData = idx.data(Qt::EditRole).toByteArray(); loadData(bArrData); @@ -500,11 +500,11 @@ bool EditDialog::promptInvalidData(const QString& data_type, const QString& erro void EditDialog::accept() { - if(!currentIndex.isValid()) + if(!m_currentIndex.isValid()) return; if (dataType == Null) { - emit recordTextUpdated(currentIndex, hexEdit->data(), true); + emit recordTextUpdated(m_currentIndex, hexEdit->data(), true); return; } @@ -524,7 +524,7 @@ void EditDialog::accept() { sciEdit->clearErrorIndicators(); - QString oldData = currentIndex.data(Qt::EditRole).toString(); + QString oldData = m_currentIndex.data(Qt::EditRole).toString(); QString newData; bool proceed = true; @@ -551,12 +551,12 @@ void EditDialog::accept() if (proceed) // The data is different, so commit it back to the database - emit recordTextUpdated(currentIndex, newData.toUtf8(), false); + emit recordTextUpdated(m_currentIndex, newData.toUtf8(), false); } break; case DockTextEdit::XML: { - QString oldData = currentIndex.data(Qt::EditRole).toString(); + QString oldData = m_currentIndex.data(Qt::EditRole).toString(); QString newData; QDomDocument xmlDoc; @@ -581,27 +581,27 @@ void EditDialog::accept() } if (proceed) // The data is different, so commit it back to the database - emit recordTextUpdated(currentIndex, newData.toUtf8(), false); + emit recordTextUpdated(m_currentIndex, newData.toUtf8(), false); } break; } break; case HexBuffer: // The data source is the hex widget buffer, thus binary data - QByteArray oldData = currentIndex.data(Qt::EditRole).toByteArray(); + QByteArray oldData = m_currentIndex.data(Qt::EditRole).toByteArray(); QByteArray newData = hexEdit->data(); if (newData != oldData) - emit recordTextUpdated(currentIndex, newData, true); + emit recordTextUpdated(m_currentIndex, newData, true); break; } if (!newTextData.isEmpty()) { - QString oldData = currentIndex.data(Qt::EditRole).toString(); + QString oldData = m_currentIndex.data(Qt::EditRole).toString(); // Check first for null case, otherwise empty strings cannot overwrite NULL values - if ((currentIndex.data(Qt::EditRole).isNull() && dataType != Null) || oldData != newTextData) + if ((m_currentIndex.data(Qt::EditRole).isNull() && dataType != Null) || oldData != newTextData) // The data is different, so commit it back to the database - emit recordTextUpdated(currentIndex, removedBom + newTextData.toUtf8(), false); + emit recordTextUpdated(m_currentIndex, removedBom + newTextData.toUtf8(), false); } } @@ -841,7 +841,7 @@ void EditDialog::setMustIndentAndCompact(bool enable) if (ui->buttonApply->isEnabled()) { setDataInBuffer(sciEdit->text().toUtf8(), SciBuffer); } else - setCurrentIndex(currentIndex); + setCurrentIndex(m_currentIndex); } // Determine the type of data in the cell diff --git a/src/EditDialog.h b/src/EditDialog.h index ca88b591..50a0f2d4 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -20,6 +20,7 @@ public: ~EditDialog() override; void setCurrentIndex(const QModelIndex& idx); + QPersistentModelIndex currentIndex() { return m_currentIndex; }; public slots: void setFocus(); @@ -55,7 +56,7 @@ private: Ui::EditDialog* ui; QHexEdit* hexEdit; DockTextEdit* sciEdit; - QPersistentModelIndex currentIndex; + QPersistentModelIndex m_currentIndex; int dataSource; int dataType; bool isReadOnly; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d0247059..dcf8ac3f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -923,8 +923,11 @@ void MainWindow::toggleEditDock(bool visible) // Update main window ui->tableBrowser->setFocus(); } else { - // fill edit dock with actual data - editDock->setCurrentIndex(ui->tableBrowser->currentIndex()); + // fill edit dock with actual data, when the current index has changed while the dock was invisible. + // (note that this signal is also emitted when the widget is docked or undocked, so we have to avoid + // reloading data when the user is editing and (un)docks the editor). + if (editDock->currentIndex() != ui->tableBrowser->currentIndex()) + editDock->setCurrentIndex(ui->tableBrowser->currentIndex()); } }