#28 Use a hash of toolbar and dockwidget names as crosscheck of window geometry format

This commit is contained in:
Mat Sutcliffe
2020-06-28 00:03:56 +01:00
parent 372e9876db
commit f68b1e1a88
2 changed files with 20 additions and 2 deletions

View File

@@ -59,6 +59,7 @@
#include <QStringBuilder>
#include <QStyle>
#include <QSysInfo>
#include <QToolBar>
#include <QUrl>
#include <QWidget>
#include <QWindow>
@@ -411,12 +412,26 @@ namespace BlackGui
return filename;
}
int CGuiApplication::hashForStateSettingsSchema(const QMainWindow *window)
{
unsigned int hash = 0;
for (auto obj : window->findChildren<QToolBar *>(QString(), Qt::FindDirectChildrenOnly))
{
hash ^= qHash(obj->objectName());
}
for (auto obj : window->findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly))
{
hash ^= qHash(obj->objectName());
}
return static_cast<int>((hash & 0xffff) ^ (hash >> 16));
}
bool CGuiApplication::saveWindowGeometryAndState(const QMainWindow *window) const
{
if (!window) { return false; }
QSettings settings(fileForWindowGeometryAndStateSettings(), QSettings::IniFormat);
settings.setValue("geometry", window->saveGeometry());
settings.setValue("windowState", window->saveState());
settings.setValue("windowState", window->saveState(hashForStateSettingsSchema(window)));
return true;
}
@@ -466,7 +481,7 @@ namespace BlackGui
logSub.changeSubscription(pattern);
window->restoreGeometry(g);
window->restoreState(s);
window->restoreState(s, hashForStateSettingsSchema(window));
}
return true;
}

View File

@@ -399,6 +399,9 @@ namespace BlackGui
//! Settings ini filename
static const QString &fileForWindowGeometryAndStateSettings();
//! Hash of names of toolbars and dockwidgets
static int hashForStateSettingsSchema(const QMainWindow *window);
};
} // ns