Fixed saveState() and restoreState() version handling to work like the function from QMainWindow

This commit is contained in:
Uwe Kindler 2020-06-03 07:25:09 +02:00
parent ccf8ea9d1e
commit 8b6df4aaa5
3 changed files with 26 additions and 10 deletions

View File

@ -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)
{

View File

@ -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.

View File

@ -64,13 +64,6 @@ QT_FORWARD_DECLARE_CLASS(QSplitter)
namespace ads
{
enum eStateFileVersion
{
InitialVersion = 0,
Version1 = 1,
CurrentVersion = Version1
};
class CDockSplitter;
enum DockWidgetArea