mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-07 20:34:14 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<QMainWindow *>(widget)) {
|
||||
auto *window = qobject_cast<QMainWindow *>(widget);
|
||||
if (window && window->property(APPLIED).toBool()) {
|
||||
applyTo(window);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user