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();