Debugger: Fix saving (legacy) state

Since dd9f9c799b we not only save the dock
widget state as the state of Perspectives, but the whole FancyMainwindow
state, so other properties from FancyMainWindow like the side bar state
is saved too.

The conversion from "legacy" to "new" state information was only done
when saving the state of perspectives when switching them (and for the
active Perspective at shutdown). The code that serialized that into
settings was expecting "new" state information, which was not true and
lead to soft asserts.

Do the conversion directly when reading settings instead.

Change-Id: I588fcf49bb7195100030266e5752358b7e734113
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2023-12-15 11:44:11 +01:00
parent 3771eb196b
commit b2199ec59d
2 changed files with 11 additions and 7 deletions

View File

@@ -1078,15 +1078,13 @@ const char *PerspectiveState::savesHeaderKey()
bool PerspectiveState::hasWindowState() const bool PerspectiveState::hasWindowState() const
{ {
return !mainWindowState.isEmpty() || !mainWindowStateLegacy.isEmpty(); return !mainWindowState.isEmpty();
} }
bool PerspectiveState::restoreWindowState(FancyMainWindow * mainWindow) bool PerspectiveState::restoreWindowState(FancyMainWindow * mainWindow)
{ {
if (!mainWindowState.isEmpty()) if (!mainWindowState.isEmpty())
return mainWindow->restoreSettings(mainWindowState); return mainWindow->restoreSettings(mainWindowState);
if (!mainWindowStateLegacy.isEmpty())
return mainWindow->restoreFancyState(mainWindowStateLegacy);
return false; return false;
} }

View File

@@ -45,19 +45,25 @@ public:
Store mainWindowState; Store mainWindowState;
QVariantHash headerViewStates; QVariantHash headerViewStates;
QByteArray mainWindowStateLegacy; // legacy for up to QtC 12
Store toSettings() const; Store toSettings() const;
static PerspectiveState fromSettings(const Store &settings); static PerspectiveState fromSettings(const Store &settings);
// legacy for up to QtC 12, operators for direct QVariant conversion // legacy for up to QtC 12, operators for direct QVariant conversion
friend QDataStream &operator>>(QDataStream &ds, PerspectiveState &state) friend QDataStream &operator>>(QDataStream &ds, PerspectiveState &state)
{ {
return ds >> state.mainWindowStateLegacy >> state.headerViewStates; QByteArray mainWindowStateLegacy;
ds >> mainWindowStateLegacy >> state.headerViewStates;
// the "legacy" state is just the QMainWindow::saveState(), which is
// saved under "State" in the FancyMainWindow state
state.mainWindowState.clear();
state.mainWindowState.insert("State", mainWindowStateLegacy);
return ds;
} }
friend QDataStream &operator<<(QDataStream &ds, const PerspectiveState &state) friend QDataStream &operator<<(QDataStream &ds, const PerspectiveState &state)
{ {
return ds << state.mainWindowStateLegacy << state.headerViewStates; // the "legacy" state is just the QMainWindow::saveState(), which is
// saved under "State" in the FancyMainWindow state
return ds << state.mainWindowState.value("State") << state.headerViewStates;
} }
}; };