Merge pull request #925 from arummler/fix-undo-stack

Fix issues with undo stack
This commit is contained in:
Laurent Trinques
2026-09-18 18:54:11 +02:00
committed by GitHub
4 changed files with 28 additions and 4 deletions
+4 -1
View File
@@ -726,7 +726,10 @@ QETResult ProjectView::doSave()
// write to file
QETResult result = m_project -> write();
updateWindowTitle();
project()->undoStack()->clear();
// This marks the stack's current index as the new "saved" point (so isClean()/cleanChanged() correctly
// resume tracking unsaved changes from here) without discarding the undo history. Edits made before this save
// stay undoable for the rest of the session.
project()->undoStack()->setClean();
return(result);
}
+1 -1
View File
@@ -2840,7 +2840,7 @@ void QETDiagramEditor::updateWindowModifiedState()
setWindowTitle(QString("%1[*] - %2").arg(
project->pathNameTitle(),
tr("QElectroTech", "window title")));
setWindowModified(project->projectOptionsWereModified());
setWindowModified(project->projectWasModified());
} else {
setWindowTitle(tr("QElectroTech", "window title"));
setWindowModified(false);
+3 -1
View File
@@ -534,7 +534,9 @@ QString QETProject::pathNameTitle() const
)
).arg(final_title);
}
if (m_modified) {
// Same condition as projectWasModified(): project-options changeg (m_modified) OR the undo stack sitting away from
// its clean index.
if (m_modified || !m_undo_stack->isClean()) {
final_title = QString(
tr(
"%1 [modifié]",
+20 -1
View File
@@ -252,7 +252,26 @@ class QETProject : public QObject
void updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
void removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &);
void usedTitleBlockTemplateChanged(const QString &);
void undoStackChanged (bool a) {if (!a) setModified(true);}
/* Deliberately does NOT touch m_modified: m_modified /
* setModified() track project-OPTIONS changes only (see
* projectOptionsWereModified()), which have no undo
* entry and so must stay set until an explicit write().
* Diagram-content changes are tracked by the undo
* stack's own clean index instead, and projectWasModified()
* already ORs the two together -- that combined value is
* what actually answers "does this project have unsaved
* changes", so re-derive and broadcast it here on every
* clean/dirty transition (covering, in particular, an
* Undo that walks the stack back to its clean index).
* Latching m_modified itself to the undo stack's dirty
* state, the way this slot did before, is a one-way trap:
* cleanChanged(true) would never come back through here
* to un-set it, so a plain content edit stayed marked as
* unsaved even after being fully undone. */
void undoStackChanged (bool /*a*/) {
emit projectModified(this, projectWasModified());
emit projectInformationsChanged(this);
}
private:
void readProjectXml(QDomDocument &xml_project);