From 8b6df4aaa5c2ad0e7fae2ddf3189e9df93545cb3 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 3 Jun 2020 07:25:09 +0200 Subject: [PATCH] Fixed saveState() and restoreState() version handling to work like the function from QMainWindow --- src/DockManager.cpp | 20 +++++++++++++++++++- src/DockManager.h | 9 +++++++-- src/ads_globals.h | 7 ------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 3cda957..1b8162f 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -72,6 +72,16 @@ static void initResource() namespace ads { +/** + * Internal file version in case the sturture changes interbally + */ +enum eStateFileVersion +{ + InitialVersion = 0, //!< InitialVersion + Version1 = 1, //!< Version1 + CurrentVersion = Version1//!< CurrentVersion +}; + static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig; /** @@ -240,6 +250,13 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi return false; } + ADS_PRINT(s.attributes().value("UserVersion")); + v = s.attributes().value("UserVersion").toInt(&ok); + if (!ok || v != version) + { + return false; + } + s.setFileVersion(v); bool Result = true; #ifdef ADS_DEBUG_PRINT @@ -528,7 +545,8 @@ QByteArray CDockManager::saveState(int version) const s.setAutoFormatting(ConfigFlags.testFlag(XmlAutoFormattingEnabled)); s.writeStartDocument(); s.writeStartElement("QtAdvancedDockingSystem"); - s.writeAttribute("Version", QString::number(version)); + s.writeAttribute("Version", QString::number(CurrentVersion)); + s.writeAttribute("UserVersion", QString::number(version)); s.writeAttribute("Containers", QString::number(d->Containers.count())); for (auto Container : d->Containers) { diff --git a/src/DockManager.h b/src/DockManager.h index 5daf893..a074249 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -308,8 +308,12 @@ public: * If auto formatting is enabled, the output is intended and line wrapped. * The XmlMode XmlAutoFormattingDisabled is better if you would like to have * a more compact XML output - i.e. for storage in ini files. + * The version number is stored as part of the data. + * To restore the saved state, pass the return value and version number + * to restoreState(). + * \see restoreState() */ - QByteArray saveState(int version = Version1) const; + QByteArray saveState(int version = 0) const; /** * Restores the state of this dockmanagers dockwidgets. @@ -317,8 +321,9 @@ public: * not match, the dockmanager's state is left unchanged, and this function * returns false; otherwise, the state is restored, and this function * returns true. + * \see saveState() */ - bool restoreState(const QByteArray &state, int version = Version1); + bool restoreState(const QByteArray &state, int version = 0); /** * Saves the current perspective to the internal list of perspectives. diff --git a/src/ads_globals.h b/src/ads_globals.h index 407bde3..ef6bf4a 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -64,13 +64,6 @@ QT_FORWARD_DECLARE_CLASS(QSplitter) namespace ads { -enum eStateFileVersion -{ - InitialVersion = 0, - Version1 = 1, - CurrentVersion = Version1 -}; - class CDockSplitter; enum DockWidgetArea