From 76fda3f0e6796c3b5c4852de58f1895a2b4176c5 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sun, 2 Aug 2026 07:30:14 +1200 Subject: [PATCH] Reflect unsaved-changes state in the main window title On macOS in particular there's currently no way to tell from the window chrome alone whether the active project has unsaved changes. The main window's title is set once in the constructor to a static string and never updated afterward, and QET never sets Qt's windowModified property anywhere -- so the native "document modified" indicator (the dot in the close button on macOS; an asterisk in the title on platforms that render it as text) never appears. Add QETDiagramEditor::updateWindowModifiedState(), which sets the window title to "[*] - QElectroTech" (the "[*]" is Qt's own placeholder convention for this) and calls setWindowModified() with the active project's own modified flag. Call it from two places: - subWindowActivated(), the single existing choke point already used whenever the visible MDI tab changes, so switching projects immediately reflects the newly active one's own state. - A new per-project connection to QETProject::projectModified, added in addProject() alongside the existing undo-stack registration, filtered to only act when the modified project is the currently active one. With no project open, the title and modified flag both revert to the original static, unmodified state. Implements https://github.com/qelectrotech/qelectrotech-source-mirror/discussions/596 --- sources/qetdiagrameditor.cpp | 33 +++++++++++++++++++++++++++++++++ sources/qetdiagrameditor.h | 1 + 2 files changed, 34 insertions(+) diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 5b2ba6779..7f9a2d4c7 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1283,6 +1283,12 @@ bool QETDiagramEditor::addProject(QETProject *project, bool update_panel) undo_group.addStack(project -> undoStack()); + connect(project, &QETProject::projectModified, this, [this](QETProject *modified_project, bool) { + if (modified_project == currentProject()) { + updateWindowModifiedState(); + } + }); + m_element_collection_widget->addProject(project); // met a jour le panel d'elements @@ -2553,6 +2559,7 @@ void QETDiagramEditor::subWindowActivated(QMdiSubWindow *subWindows) slot_updateWindowsMenu(); emit syncElementsPanel(); updateUsageTrackersActiveState(); + updateWindowModifiedState(); } /** @@ -2578,6 +2585,32 @@ void QETDiagramEditor::updateUsageTrackersActiveState() } } +/** + @brief QETDiagramEditor::updateWindowModifiedState + Reflect the currently active project's unsaved-changes state in the + main window's title and native "document modified" indicator (e.g. + the dot in the close button on macOS). Called whenever the active + project changes, or whenever the active project's own modified state + changes. + + The window title's "[*]" placeholder is Qt's own convention: combined + with setWindowModified(), it lets each platform render the modified + indicator its own way (or not at all, on platforms without one) + without QET having to draw anything itself. +*/ +void QETDiagramEditor::updateWindowModifiedState() +{ + if (QETProject *project = currentProject()) { + setWindowTitle(QString("%1[*] - %2").arg( + project->pathNameTitle(), + tr("QElectroTech", "window title"))); + setWindowModified(project->projectOptionsWereModified()); + } else { + setWindowTitle(tr("QElectroTech", "window title")); + setWindowModified(false); + } +} + /** @brief QETDiagramEditor::selectionChanged This slot is called when a diagram selection was changed. diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 0114a186e..1d54899e8 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -98,6 +98,7 @@ class QETDiagramEditor : public QETMainWindow ProjectView *findProject(const QString &) const; QMdiSubWindow *subWindowForWidget(QWidget *) const; void updateUsageTrackersActiveState(); + void updateWindowModifiedState(); signals: void syncElementsPanel();