Implemented XML serialization and loading of docking state

This commit is contained in:
Uwe Kindler 2017-12-29 18:18:16 +01:00
parent 8a014a6c2d
commit dae852d9f9
11 changed files with 245 additions and 159 deletions

View File

@ -2,7 +2,7 @@
<project> <project>
<configuration id="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795" name="Default"> <configuration id="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795" name="Default">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-633788812842026300" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD -std=c++14 &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-1519829723851667984" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD -std=c++14 &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@ -105,7 +105,7 @@ void MainWindow::createContent()
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget); m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu)); m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); /*m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu)); auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
DockWidget = createCalendarDockWidget(ViewMenu); DockWidget = createCalendarDockWidget(ViewMenu);
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false)); DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
@ -116,7 +116,7 @@ void MainWindow::createContent()
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/
} }

View File

@ -39,6 +39,7 @@
#include <QDebug> #include <QDebug>
#include <QMenu> #include <QMenu>
#include <QSplitter> #include <QSplitter>
#include <QXmlStreamWriter>
#include "DockContainerWidget.h" #include "DockContainerWidget.h"
@ -706,15 +707,18 @@ void CDockAreaWidget::updateDockArea()
//============================================================================ //============================================================================
void CDockAreaWidget::saveState(QDataStream& stream) const void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
{ {
stream << d->ContentsLayout->count() << d->ContentsLayout->currentIndex(); s.writeStartElement("DockAreaWidget");
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
s.writeAttribute("CurrentIndex", QString::number(d->ContentsLayout->currentIndex()));
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count() qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
<< " CurrentIndex: " << d->ContentsLayout->currentIndex(); << " CurrentIndex: " << d->ContentsLayout->currentIndex();
for (int i = 0; i < d->ContentsLayout->count(); ++i) for (int i = 0; i < d->ContentsLayout->count(); ++i)
{ {
dockWidget(i)->saveState(stream); dockWidget(i)->saveState(s);
} }
s.writeEndElement();
} }
} // namespace ads } // namespace ads

View File

@ -32,6 +32,8 @@
//============================================================================ //============================================================================
#include <QFrame> #include <QFrame>
class QXmlStreamWriter;
namespace ads namespace ads
{ {
struct DockAreaWidgetPrivate; struct DockAreaWidgetPrivate;
@ -164,7 +166,7 @@ public:
/** /**
* Saves the state into the given stream * Saves the state into the given stream
*/ */
void saveState(QDataStream& Stream) const; void saveState(QXmlStreamWriter& Stream) const;
public slots: public slots:
/** /**

View File

@ -30,12 +30,15 @@
//============================================================================ //============================================================================
#include "DockContainerWidget.h" #include "DockContainerWidget.h"
#include <iostream>
#include <QEvent> #include <QEvent>
#include <QList> #include <QList>
#include <QGridLayout> #include <QGridLayout>
#include <QPointer> #include <QPointer>
#include <QVariant> #include <QVariant>
#include <QDebug> #include <QDebug>
#include <QXmlStreamWriter>
#include "DockManager.h" #include "DockManager.h"
#include "DockAreaWidget.h" #include "DockAreaWidget.h"
@ -120,7 +123,7 @@ struct DockContainerWidgetPrivate
/** /**
* Save state of child nodes * Save state of child nodes
*/ */
void saveChildNodesState(QDataStream& Stream, QWidget* Widget); void saveChildNodesState(QXmlStreamWriter& Stream, QWidget* Widget);
/** /**
* Restore state of child nodes. * Restore state of child nodes.
@ -130,21 +133,21 @@ struct DockContainerWidgetPrivate
* \param[in] Testing If Testing is true, only the stream data is * \param[in] Testing If Testing is true, only the stream data is
* parsed without modifiying anything. * parsed without modifiying anything.
*/ */
bool restoreChildNodes(QDataStream& Stream, QWidget*& CreatedWidget, bool restoreChildNodes(QXmlStreamReader& Stream, QWidget*& CreatedWidget,
bool Testing); bool Testing);
/** /**
* Restores a splitter. * Restores a splitter.
* \see restoreChildNodes() for details * \see restoreChildNodes() for details
*/ */
bool restoreSplitter(QDataStream& Stream, QWidget*& CreatedWidget, bool restoreSplitter(QXmlStreamReader& Stream, QWidget*& CreatedWidget,
bool Testing); bool Testing);
/** /**
* Restores a dock area. * Restores a dock area.
* \see restoreChildNodes() for details * \see restoreChildNodes() for details
*/ */
bool restoreDockArea(QDataStream& Stream, QWidget*& CreatedWidget, bool restoreDockArea(QXmlStreamReader& Stream, QWidget*& CreatedWidget,
bool Testing); bool Testing);
/** /**
@ -314,39 +317,56 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
//============================================================================ //============================================================================
void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidget* Widget) void DockContainerWidgetPrivate::saveChildNodesState(QXmlStreamWriter& s, QWidget* Widget)
{ {
QSplitter* Splitter = dynamic_cast<QSplitter*>(Widget); QSplitter* Splitter = dynamic_cast<QSplitter*>(Widget);
if (Splitter) if (Splitter)
{ {
stream << internal::SplitterMarker << Splitter->orientation() << Splitter->count(); s.writeStartElement("Splitter");
s.writeAttribute("Orientation", QString::number(Splitter->orientation()));
s.writeAttribute("Count", QString::number(Splitter->count()));
qDebug() << "NodeSplitter orient: " << Splitter->orientation() qDebug() << "NodeSplitter orient: " << Splitter->orientation()
<< " WidgetCont: " << Splitter->count(); << " WidgetCont: " << Splitter->count();
for (int i = 0; i < Splitter->count(); ++i) for (int i = 0; i < Splitter->count(); ++i)
{ {
saveChildNodesState(stream, Splitter->widget(i)); saveChildNodesState(s, Splitter->widget(i));
} }
stream << Splitter->sizes();
s.writeStartElement("Sizes");
for (auto Size : Splitter->sizes())
{
s.writeCharacters(QString::number(Size) + " ");
}
s.writeEndElement();
s.writeEndElement();
} }
else else
{ {
stream << internal::DockAreaMarker;
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(Widget); CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(Widget);
if (DockArea) if (DockArea)
{ {
DockArea->saveState(stream); DockArea->saveState(s);
} }
} }
} }
//============================================================================ //============================================================================
bool DockContainerWidgetPrivate::restoreSplitter(QDataStream& stream, bool DockContainerWidgetPrivate::restoreSplitter(QXmlStreamReader& s,
QWidget*& CreatedWidget, bool Testing) QWidget*& CreatedWidget, bool Testing)
{ {
int Orientation; bool Ok;
int WidgetCount; int Orientation = s.attributes().value("Orientation").toInt(&Ok);
stream >> Orientation >> WidgetCount; if (!Ok)
{
return false;
}
int WidgetCount = s.attributes().value("Count").toInt(&Ok);
if (!Ok)
{
return false;
}
qDebug() << "Restore NodeSplitter Orientation: " << Orientation << qDebug() << "Restore NodeSplitter Orientation: " << Orientation <<
" WidgetCount: " << WidgetCount; " WidgetCount: " << WidgetCount;
QSplitter* Splitter = nullptr; QSplitter* Splitter = nullptr;
@ -355,15 +375,42 @@ bool DockContainerWidgetPrivate::restoreSplitter(QDataStream& stream,
Splitter = internal::newSplitter((Qt::Orientation)Orientation); Splitter = internal::newSplitter((Qt::Orientation)Orientation);
} }
bool Visible = false; bool Visible = false;
for (int i = 0; i < WidgetCount; ++i) QList<int> Sizes;
while (s.readNextStartElement())
{ {
QWidget* ChildNode; QWidget* ChildNode = nullptr;
if (!restoreChildNodes(stream, ChildNode, Testing)) bool Result = true;
if (s.name() == "Splitter")
{
Result = restoreSplitter(s, ChildNode, Testing);
}
else if (s.name() == "DockAreaWidget")
{
Result = restoreDockArea(s, ChildNode, Testing);
}
else if (s.name() == "Sizes")
{
QString sSizes = s.readElementText().trimmed();
qDebug() << "Sizes: " << sSizes;
QTextStream TextStream(&sSizes);
while (!TextStream.atEnd())
{
int value;
TextStream >> value;
Sizes.append(value);
}
}
else
{
s.skipCurrentElement();
}
if (!Result)
{ {
return false; return false;
} }
if (Testing) if (Testing || !ChildNode)
{ {
continue; continue;
} }
@ -374,8 +421,11 @@ bool DockContainerWidgetPrivate::restoreSplitter(QDataStream& stream,
Visible |= ChildNode->isVisibleTo(Splitter); Visible |= ChildNode->isVisibleTo(Splitter);
} }
QList<int> Sizes; if (Sizes.count() != WidgetCount)
stream >> Sizes; {
return false;
}
if (!Testing) if (!Testing)
{ {
if (!Splitter->count()) if (!Splitter->count())
@ -394,17 +444,27 @@ bool DockContainerWidgetPrivate::restoreSplitter(QDataStream& stream,
{ {
CreatedWidget = nullptr; CreatedWidget = nullptr;
} }
return true; return true;
} }
//============================================================================ //============================================================================
bool DockContainerWidgetPrivate::restoreDockArea(QDataStream& stream, bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
QWidget*& CreatedWidget, bool Testing) QWidget*& CreatedWidget, bool Testing)
{ {
int Tabs; bool Ok;
int CurrentIndex; int Tabs = s.attributes().value("Tabs").toInt(&Ok);
stream >> Tabs >> CurrentIndex; if (!Ok)
{
return false;
}
int CurrentIndex = s.attributes().value("CurrentIndex").toInt(&Ok);
if (!Ok)
{
return false;
}
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: " qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
<< CurrentIndex; << CurrentIndex;
@ -414,21 +474,27 @@ bool DockContainerWidgetPrivate::restoreDockArea(QDataStream& stream,
DockArea = new CDockAreaWidget(DockManager, _this); DockArea = new CDockAreaWidget(DockManager, _this);
} }
for (int i = 0; i < Tabs; ++i) while (s.readNextStartElement())
{ {
int Marker; if (s.name() != "DockWidget")
stream >> Marker; {
if (Marker != internal::DockWidgetMarker) continue;
}
auto ObjectName = s.attributes().value("ObjectName");
if (ObjectName.isEmpty())
{ {
return false; return false;
} }
QString ObjectName; bool Closed = s.attributes().value("Closed").toInt(&Ok);
bool Closed; if (!Ok)
stream >> ObjectName >> Closed; {
qDebug() << "Restore DockWidget " << ObjectName << " Closed: " << Closed; return false;
}
CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName); s.skipCurrentElement();
CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName.toString());
if (!DockWidget || Testing) if (!DockWidget || Testing)
{ {
continue; continue;
@ -464,23 +530,30 @@ bool DockContainerWidgetPrivate::restoreDockArea(QDataStream& stream,
//============================================================================ //============================================================================
bool DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream, bool DockContainerWidgetPrivate::restoreChildNodes(QXmlStreamReader& s,
QWidget*& CreatedWidget, bool Testing) QWidget*& CreatedWidget, bool Testing)
{ {
int Marker; bool Result = true;
stream >> Marker; while (s.readNextStartElement())
if (internal::SplitterMarker == Marker)
{ {
return restoreSplitter(stream, CreatedWidget, Testing); if (s.name() == "Splitter")
{
Result = restoreSplitter(s, CreatedWidget, Testing);
qDebug() << "Splitter";
} }
else if (internal::DockAreaMarker == Marker) else if (s.name() == "DockAreaWidget")
{ {
return restoreDockArea(stream, CreatedWidget, Testing); Result = restoreDockArea(s, CreatedWidget, Testing);
qDebug() << "DockAreaWidget";
} }
else else
{ {
return false; s.skipCurrentElement();
qDebug() << "Unknown element";
} }
}
return Result;
} }
@ -879,37 +952,31 @@ QList<CDockAreaWidget*> CDockContainerWidget::openedDockAreas() const
//============================================================================ //============================================================================
void CDockContainerWidget::saveState(QDataStream& stream) const void CDockContainerWidget::saveState(QXmlStreamWriter& s) const
{ {
qDebug() << "CDockContainerWidget::saveState isFloating " qDebug() << "CDockContainerWidget::saveState isFloating "
<< isFloating(); << isFloating();
stream << internal::ContainerMarker;
stream << isFloating(); s.writeStartElement("DockContainerWidget");
s.writeAttribute("Floating", QString::number(isFloating() ? 1 : 0));
if (isFloating()) if (isFloating())
{ {
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this); CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
stream << FloatingWidget->saveGeometry(); QByteArray Geometry = FloatingWidget->saveGeometry();
s.writeTextElement("Geometry", Geometry.toHex(' '));
} }
d->saveChildNodesState(s, d->RootSplitter);
d->saveChildNodesState(stream, d->RootSplitter); s.writeEndElement();
} }
//============================================================================ //============================================================================
bool CDockContainerWidget::restoreState(QDataStream& stream, bool Testing) bool CDockContainerWidget::restoreState(QXmlStreamReader& s, bool Testing)
{ {
bool IsFloating; bool IsFloating = s.attributes().value("Floating").toInt();
int Marker;
stream >> Marker;
if (Marker != internal::ContainerMarker)
{
return false;
}
stream >> IsFloating;
qDebug() << "Restore CDockContainerWidget Floating" << IsFloating; qDebug() << "Restore CDockContainerWidget Floating" << IsFloating;
QWidget* NewRootSplitter; QWidget*NewRootSplitter {};
if (!Testing) if (!Testing)
{ {
d->DockAreas.clear(); d->DockAreas.clear();
@ -918,8 +985,19 @@ bool CDockContainerWidget::restoreState(QDataStream& stream, bool Testing)
if (IsFloating) if (IsFloating)
{ {
qDebug() << "Restore floating widget"; qDebug() << "Restore floating widget";
QByteArray Geometry; if (!s.readNextStartElement() || s.name() != "Geometry")
stream >> Geometry; {
return false;
}
QByteArray GeometryString = s.readElementText(QXmlStreamReader::ErrorOnUnexpectedElement).toLocal8Bit();
QByteArray Geometry = QByteArray::fromHex(GeometryString);
std::cout << "Geometry: " << Geometry.toHex(' ').toStdString() << std::endl;
if (Geometry.isEmpty())
{
return false;
}
if (!Testing) if (!Testing)
{ {
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this); CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
@ -928,7 +1006,7 @@ bool CDockContainerWidget::restoreState(QDataStream& stream, bool Testing)
} }
} }
if (!d->restoreChildNodes(stream, NewRootSplitter, Testing)) if (!d->restoreChildNodes(s, NewRootSplitter, Testing))
{ {
return false; return false;
} }

View File

@ -34,6 +34,9 @@
#include "ads_globals.h" #include "ads_globals.h"
class QXmlStreamWriter;
class QXmlStreamReader;
namespace ads namespace ads
{ {
struct DockContainerWidgetPrivate; struct DockContainerWidgetPrivate;
@ -147,7 +150,7 @@ public:
/** /**
* Saves the state into the given stream * Saves the state into the given stream
*/ */
void saveState(QDataStream& Stream) const; void saveState(QXmlStreamWriter& Stream) const;
/** /**
* Restores the state from given stream. * Restores the state from given stream.
@ -155,7 +158,7 @@ public:
* stream but does not restore anything. You can use this check for * stream but does not restore anything. You can use this check for
* faulty files before you start restoring the state * faulty files before you start restoring the state
*/ */
bool restoreState(QDataStream& Stream, bool Testing); bool restoreState(QXmlStreamReader& Stream, bool Testing);
/** /**
* Dumps the layout for debugging purposes * Dumps the layout for debugging purposes

View File

@ -30,6 +30,8 @@
//============================================================================ //============================================================================
#include "DockManager.h" #include "DockManager.h"
#include <iostream>
#include <QMainWindow> #include <QMainWindow>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
@ -38,6 +40,8 @@
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
#include <QAction> #include <QAction>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include "FloatingDockContainer.h" #include "FloatingDockContainer.h"
#include "DockOverlay.h" #include "DockOverlay.h"
@ -76,12 +80,12 @@ struct DockManagerPrivate
/** /**
* Restores the state * Restores the state
*/ */
bool restoreState(const QByteArray &state, int version); bool restoreState(const QByteArray &state, int version, bool Testing = internal::Restore);
/** /**
* Restores the container with the given index * Restores the container with the given index
*/ */
bool restoreContainer(int Index, QDataStream& stream, bool Testing); bool restoreContainer(int Index, QXmlStreamReader& stream, bool Testing);
/** /**
* Loads the stylesheet * Loads the stylesheet
@ -112,45 +116,13 @@ void DockManagerPrivate::loadStylesheet()
//============================================================================ //============================================================================
bool DockManagerPrivate::checkFormat(const QByteArray &state, int version) bool DockManagerPrivate::restoreContainer(int Index, QXmlStreamReader& stream, bool Testing)
{ {
if (state.isEmpty()) if (Testing)
{ {
return false; Index = 0;
}
QByteArray sd = state;
QDataStream stream(&sd, QIODevice::ReadOnly);
int marker;
int v;
stream >> marker;
stream >> v;
if (stream.status() != QDataStream::Ok || marker != internal::VersionMarker || v != version)
{
return false;
} }
int Result = true;
int ContainerCount;
stream >> ContainerCount;
int i;
for (i = 0; i < ContainerCount; ++i)
{
if (!Containers[0]->restoreState(stream, internal::RestoreTesting))
{
Result = false;
break;
}
}
return Result;
}
//============================================================================
bool DockManagerPrivate::restoreContainer(int Index, QDataStream& stream, bool Testing)
{
if (Index >= Containers.count()) if (Index >= Containers.count())
{ {
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this); CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this);
@ -165,46 +137,61 @@ bool DockManagerPrivate::restoreContainer(int Index, QDataStream& stream, bool T
//============================================================================ //============================================================================
bool DockManagerPrivate::restoreState(const QByteArray &state, int version) bool DockManagerPrivate::checkFormat(const QByteArray &state, int version)
{
return restoreState(state, version, internal::RestoreTesting);
}
//============================================================================
bool DockManagerPrivate::restoreState(const QByteArray &state, int version,
bool Testing)
{ {
if (state.isEmpty()) if (state.isEmpty())
{ {
return false; return false;
} }
QByteArray sd = state; QXmlStreamReader s(state);
QDataStream stream(&sd, QIODevice::ReadOnly); s.readNextStartElement();
if (s.name() != "QtAdvancedDockingSystem")
int marker; {
int v; return false;
stream >> marker; }
stream >> v; qDebug() << s.attributes().value("Version");
bool ok;
if (stream.status() != QDataStream::Ok || marker != internal::VersionMarker || v != version) int v = s.attributes().value("Version").toInt(&ok);
if (!ok || v != version)
{ {
return false; return false;
} }
int Result = true; bool Result = true;
int ContainerCount; int DockContainers = s.attributes().value("DockContainers").toInt();
stream >> ContainerCount; qDebug() << DockContainers;
qDebug() << "ContainerCount " << ContainerCount; int DockContainerCount = 0;
int i; while (s.readNextStartElement())
for (i = 0; i < ContainerCount; ++i)
{ {
Result = restoreContainer(i, stream, internal::Restore); if (s.name() == "DockContainerWidget")
{
Result = restoreContainer(DockContainerCount, s, Testing);
if (!Result) if (!Result)
{ {
break; break;
} }
DockContainerCount++;
}
} }
if (!Testing)
{
// Delete remaining empty floating widgets // Delete remaining empty floating widgets
int FloatingWidgetIndex = i - 1; int FloatingWidgetIndex = DockContainerCount - 1;
int DeleteCount = FloatingWidgets.count() - FloatingWidgetIndex; int DeleteCount = FloatingWidgets.count() - FloatingWidgetIndex;
for (int i = 0; i < DeleteCount; ++i) for (int i = 0; i < DeleteCount; ++i)
{ {
FloatingWidgets[FloatingWidgetIndex + i]->deleteLater(); FloatingWidgets[FloatingWidgetIndex + i]->deleteLater();
} }
}
return Result; return Result;
} }
@ -309,17 +296,23 @@ unsigned int CDockManager::zOrderIndex() const
//============================================================================ //============================================================================
QByteArray CDockManager::saveState(int version) const QByteArray CDockManager::saveState(int version) const
{ {
QByteArray data; QByteArray xmldata;
QDataStream stream(&data, QIODevice::WriteOnly); QXmlStreamWriter s(&xmldata);
stream << internal::VersionMarker; s.setAutoFormatting(true);
stream << version; s.writeStartDocument();
s.writeStartElement("QtAdvancedDockingSystem");
stream << d->Containers.count(); s.writeAttribute("Version", QString::number(version));
s.writeAttribute("DockContainers", QString::number(d->Containers.count()));
for (auto Container : d->Containers) for (auto Container : d->Containers)
{ {
Container->saveState(stream); Container->saveState(s);
} }
return data;
s.writeEndElement();
s.writeEndDocument();
std::cout << xmldata.toStdString() << std::endl;
return xmldata;
} }

View File

@ -38,6 +38,7 @@
#include <QPointer> #include <QPointer>
#include <QEvent> #include <QEvent>
#include <QDebug> #include <QDebug>
#include <QXmlStreamWriter>
#include "DockWidgetTitleBar.h" #include "DockWidgetTitleBar.h"
#include "DockContainerWidget.h" #include "DockContainerWidget.h"
@ -361,11 +362,12 @@ void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
//============================================================================ //============================================================================
void CDockWidget::saveState(QDataStream& stream) const void CDockWidget::saveState(QXmlStreamWriter& s) const
{ {
stream << internal::DockWidgetMarker; s.writeStartElement("DockWidget");
qDebug() << "CDockWidget::saveState " << objectName() << " closed " << d->Closed; s.writeAttribute("ObjectName", objectName());
stream << objectName() << d->Closed; s.writeAttribute("Closed", QString::number(d->Closed ? 1 : 0));
s.writeEndElement();
} }

View File

@ -32,6 +32,8 @@
//============================================================================ //============================================================================
#include <QFrame> #include <QFrame>
class QXmlStreamWriter;
namespace ads namespace ads
{ {
struct DockWidgetPrivate; struct DockWidgetPrivate;
@ -81,7 +83,7 @@ protected:
/** /**
* Saves the state into the given stream * Saves the state into the given stream
*/ */
void saveState(QDataStream& Stream) const; void saveState(QXmlStreamWriter& Stream) const;
/** /**
* This is a helper function for the dock manager to flag this widget * This is a helper function for the dock manager to flag this widget

View File

@ -439,7 +439,7 @@ void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
//============================================================================ //============================================================================
bool CFloatingDockContainer::restoreState(QDataStream& Stream, bool Testing) bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing)
{ {
if (!d->DockContainer->restoreState(Stream, Testing)) if (!d->DockContainer->restoreState(Stream, Testing))
{ {

View File

@ -31,6 +31,8 @@
//============================================================================ //============================================================================
#include <QWidget> #include <QWidget>
class QXmlStreamReader;
namespace ads namespace ads
{ {
struct FloatingDockContainerPrivate; struct FloatingDockContainerPrivate;
@ -110,7 +112,7 @@ public:
* stream but does not restore anything. You can use this check for * stream but does not restore anything. You can use this check for
* faulty files before you start restoring the state * faulty files before you start restoring the state
*/ */
bool restoreState(QDataStream& Stream, bool Testing); bool restoreState(QXmlStreamReader& Stream, bool Testing);
}; // class FloatingDockContainer }; // class FloatingDockContainer
} }
// namespace ads // namespace ads