mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-13 10:04:13 +02:00
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 "<project>[*] - 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
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -98,6 +98,7 @@ class QETDiagramEditor : public QETMainWindow
|
||||
ProjectView *findProject(const QString &) const;
|
||||
QMdiSubWindow *subWindowForWidget(QWidget *) const;
|
||||
void updateUsageTrackersActiveState();
|
||||
void updateWindowModifiedState();
|
||||
|
||||
signals:
|
||||
void syncElementsPanel();
|
||||
|
||||
Reference in New Issue
Block a user