From bf3c0fc6332ab9d955fb6bc5647a648260d2b616 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Wed, 7 Oct 2026 07:05:12 +1300 Subject: [PATCH] Toolbars settings: only update windows that took them applyToAll() restyled every QMainWindow, including the terminal strip editor and the print window, which never read the settings when they open: they changed on OK and went back to defaults when reopened. applyTo() now marks the window, and applyToAll() only updates marked windows, so the page covers the folio, element and title block editors as described. Co-Authored-By: Claude Opus 5.5 --- sources/toolbarsettings.cpp | 13 ++++++++++--- tests/qttest/tst_toolbarsettings.cpp | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sources/toolbarsettings.cpp b/sources/toolbarsettings.cpp index 04d59ee11..bd0379e35 100644 --- a/sources/toolbarsettings.cpp +++ b/sources/toolbarsettings.cpp @@ -26,6 +26,8 @@ namespace { const QString ICON_SIZE = QStringLiteral("toolbars/icon_size"); const QString BUTTON_STYLE = QStringLiteral("toolbars/button_style"); const QString LOCKED = QStringLiteral("toolbars/locked"); + //Set on a window by applyTo() + const char *const APPLIED = "qetToolbarSettings"; } int ToolbarSettings::iconSize() @@ -69,13 +71,15 @@ void ToolbarSettings::save(int icon_size, Qt::ToolButtonStyle style, bool locked @brief ToolbarSettings::applyTo Apply the settings to \a window and its toolbars. The window passes its icon size and button style on to every toolbar that has none of - its own; an invalid size gives the style's default back. + its own; an invalid size gives the style's default back. The window + is marked, so applyToAll() updates it again later. */ void ToolbarSettings::applyTo(QMainWindow *window) { if (!window) { return; } + window->setProperty(APPLIED, true); const int size = iconSize(); window->setIconSize(size > 0 ? QSize(size, size) : QSize()); window->setToolButtonStyle(buttonStyle()); @@ -90,12 +94,15 @@ void ToolbarSettings::applyTo(QMainWindow *window) /** @brief ToolbarSettings::applyToAll - Apply the settings to every open window, after they change. + Apply the settings again to every open window that took them with + applyTo(), after they change. Other windows are left alone: they + would lose the settings the next time they open. */ void ToolbarSettings::applyToAll() { for (QWidget *widget : QApplication::topLevelWidgets()) { - if (auto *window = qobject_cast(widget)) { + auto *window = qobject_cast(widget); + if (window && window->property(APPLIED).toBool()) { applyTo(window); } } diff --git a/tests/qttest/tst_toolbarsettings.cpp b/tests/qttest/tst_toolbarsettings.cpp index 1b77c01a3..184b773d1 100644 --- a/tests/qttest/tst_toolbarsettings.cpp +++ b/tests/qttest/tst_toolbarsettings.cpp @@ -29,8 +29,8 @@ /** ToolbarSettings and its configuration page: defaults change nothing, - saved values reach every open window's toolbars, and a toolbar inside - a panel is left alone. + saved values reach every open window that took them, and a toolbar + inside a panel or a window that never took them is left alone. */ class tst_toolbarsettings : public QObject { @@ -40,6 +40,8 @@ class tst_toolbarsettings : public QObject QToolBar *m_top = nullptr; QToolBar *m_left = nullptr; QToolBar *m_in_dock = nullptr; + QMainWindow *m_other = nullptr; + QToolBar *m_other_bar = nullptr; QSize m_default_size; private slots: @@ -60,11 +62,18 @@ private slots: dock->setWidget(m_in_dock); m_window->addDockWidget(Qt::LeftDockWidgetArea, dock); m_window->show(); + + //A window that never takes the settings, like the print window + m_other = new QMainWindow(); + m_other_bar = new QToolBar(QStringLiteral("other"), m_other); + m_other->addToolBar(Qt::TopToolBarArea, m_other_bar); + m_other->show(); } void cleanupTestCase() { delete m_window; + delete m_other; } void defaultsChangeNothing() @@ -102,6 +111,10 @@ private slots: QVERIFY(!m_left->isMovable()); //A toolbar inside a panel is not one of the window's toolbars QVERIFY(m_in_dock->isMovable()); + //Nor is a window that did not take the settings when it opened + QCOMPARE(m_other_bar->iconSize(), m_default_size); + QCOMPARE(m_other_bar->toolButtonStyle(), Qt::ToolButtonIconOnly); + QVERIFY(m_other_bar->isMovable()); //A page opened now shows what was saved ToolbarsConfigPage page;