Skip to content

Commit 8b6df4a

Browse files
Fixed saveState() and restoreState() version handling to work like the function from QMainWindow
1 parent ccf8ea9 commit 8b6df4a

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/DockManager.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ static void initResource()
7272

7373
namespace ads
7474
{
75+
/**
76+
* Internal file version in case the sturture changes interbally
77+
*/
78+
enum eStateFileVersion
79+
{
80+
InitialVersion = 0, //!< InitialVersion
81+
Version1 = 1, //!< Version1
82+
CurrentVersion = Version1//!< CurrentVersion
83+
};
84+
7585
static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig;
7686

7787
/**
@@ -240,6 +250,13 @@ bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int versi
240250
return false;
241251
}
242252

253+
ADS_PRINT(s.attributes().value("UserVersion"));
254+
v = s.attributes().value("UserVersion").toInt(&ok);
255+
if (!ok || v != version)
256+
{
257+
return false;
258+
}
259+
243260
s.setFileVersion(v);
244261
bool Result = true;
245262
#ifdef ADS_DEBUG_PRINT
@@ -528,7 +545,8 @@ QByteArray CDockManager::saveState(int version) const
528545
s.setAutoFormatting(ConfigFlags.testFlag(XmlAutoFormattingEnabled));
529546
s.writeStartDocument();
530547
s.writeStartElement("QtAdvancedDockingSystem");
531-
s.writeAttribute("Version", QString::number(version));
548+
s.writeAttribute("Version", QString::number(CurrentVersion));
549+
s.writeAttribute("UserVersion", QString::number(version));
532550
s.writeAttribute("Containers", QString::number(d->Containers.count()));
533551
for (auto Container : d->Containers)
534552
{

src/DockManager.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,22 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
308308
* If auto formatting is enabled, the output is intended and line wrapped.
309309
* The XmlMode XmlAutoFormattingDisabled is better if you would like to have
310310
* a more compact XML output - i.e. for storage in ini files.
311+
* The version number is stored as part of the data.
312+
* To restore the saved state, pass the return value and version number
313+
* to restoreState().
314+
* \see restoreState()
311315
*/
312-
QByteArray saveState(int version = Version1) const;
316+
QByteArray saveState(int version = 0) const;
313317

314318
/**
315319
* Restores the state of this dockmanagers dockwidgets.
316320
* The version number is compared with that stored in state. If they do
317321
* not match, the dockmanager's state is left unchanged, and this function
318322
* returns false; otherwise, the state is restored, and this function
319323
* returns true.
324+
* \see saveState()
320325
*/
321-
bool restoreState(const QByteArray &state, int version = Version1);
326+
bool restoreState(const QByteArray &state, int version = 0);
322327

323328
/**
324329
* Saves the current perspective to the internal list of perspectives.

src/ads_globals.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ QT_FORWARD_DECLARE_CLASS(QSplitter)
6464

6565
namespace ads
6666
{
67-
enum eStateFileVersion
68-
{
69-
InitialVersion = 0,
70-
Version1 = 1,
71-
CurrentVersion = Version1
72-
};
73-
7467
class CDockSplitter;
7568

7669
enum DockWidgetArea

0 commit comments

Comments
 (0)