From 195b34c0ca4f97d83a613d6a50ec8ee2fcf2e976 Mon Sep 17 00:00:00 2001 From: mfreiholz Date: Mon, 4 Apr 2016 08:51:38 +0200 Subject: [PATCH] Serialize SectionIndexData on storeSate(). --- .../include/ads/ContainerWidget.h | 4 +++ .../include/ads/Serialization.h | 2 ++ AdvancedDockingSystem/src/ContainerWidget.cpp | 34 +++++++++++++++++-- AdvancedDockingSystem/src/Serialization.cpp | 4 +++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/AdvancedDockingSystem/include/ads/ContainerWidget.h b/AdvancedDockingSystem/include/ads/ContainerWidget.h index 16c6c52..61e5096 100644 --- a/AdvancedDockingSystem/include/ads/ContainerWidget.h +++ b/AdvancedDockingSystem/include/ads/ContainerWidget.h @@ -14,6 +14,7 @@ class QGridLayout; #include "ads/Internal.h" #include "ads/SectionContent.h" #include "ads/FloatingWidget.h" +#include "ads/Serialization.h" ADS_NAMESPACE_BEGIN class SectionWidget; @@ -129,6 +130,9 @@ private: QByteArray saveHierarchy() const; void saveFloatingWidgets(QDataStream& out) const; void saveSectionWidgets(QDataStream& out, QWidget* widget) const; + + bool saveSectionIndex(ADS_NS_SER::SectionIndexData &sid) const; + bool restoreHierarchy(const QByteArray& data); bool restoreFloatingWidgets(QDataStream& in, int version, QList& floatings); bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList& sections, QList& contentsToHide); diff --git a/AdvancedDockingSystem/include/ads/Serialization.h b/AdvancedDockingSystem/include/ads/Serialization.h index 7f7ec03..8e50e8d 100644 --- a/AdvancedDockingSystem/include/ads/Serialization.h +++ b/AdvancedDockingSystem/include/ads/Serialization.h @@ -65,6 +65,8 @@ class ADS_EXPORT_API SectionEntity { public: SectionEntity(); + qint32 x; + qint32 y; qint32 width; qint32 height; qint32 currentIndex; diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index a9de1d2..16f04b2 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -369,10 +369,10 @@ QByteArray ContainerWidget::saveState() const } // SectionIndex data. - const QByteArray sectionIndexData; - if (!sectionIndexData.isEmpty()) + ADS_NS_SER::SectionIndexData sid; + if (saveSectionIndex(sid)) { - writer.write(ADS_NS_SER::ET_SectionIndex, sectionIndexData); + writer.write(sid); } if (writer.offsetsCount() == 0) @@ -844,6 +844,34 @@ void ContainerWidget::saveSectionWidgets(QDataStream& out, QWidget* widget) cons } } +bool ContainerWidget::saveSectionIndex(ADS_NS_SER::SectionIndexData& sid) const +{ + if (_sections.count() <= 0) + return false; + + sid.sectionsCount = _sections.count(); + for (int i = 0; i < _sections.count(); ++i) + { + ADS_NS_SER::SectionEntity se; + se.x = _sections[i]->geometry().x(); + se.y = _sections[i]->geometry().y(); + se.width = _sections[i]->geometry().width(); + se.height = _sections[i]->geometry().height(); + se.currentIndex = _sections[i]->currentIndex(); + se.sectionContentsCount = _sections[i]->contents().count(); + foreach (const SectionContent::RefPtr& sc, _sections[i]->contents()) + { + ADS_NS_SER::SectionContentEntity sce; + sce.uniqueName = sc->uniqueName(); + sce.visible = true; + sce.preferredIndex = _sections[i]->indexOfContent(sc); + se.sectionContents.append(sce); // std::move()? + } + sid.sections.append(se); // std::move()? + } + return true; +} + bool ContainerWidget::restoreHierarchy(const QByteArray& data) { QDataStream in(data); diff --git a/AdvancedDockingSystem/src/Serialization.cpp b/AdvancedDockingSystem/src/Serialization.cpp index 5efc620..e7df053 100644 --- a/AdvancedDockingSystem/src/Serialization.cpp +++ b/AdvancedDockingSystem/src/Serialization.cpp @@ -147,6 +147,8 @@ SectionEntity::SectionEntity() : QDataStream& operator<<(QDataStream& out, const SectionEntity& data) { + out << data.x; + out << data.y; out << data.width; out << data.height; out << data.currentIndex; @@ -160,6 +162,8 @@ QDataStream& operator<<(QDataStream& out, const SectionEntity& data) QDataStream& operator>>(QDataStream& in, SectionEntity& data) { + in >> data.x; + in >> data.y; in >> data.width; in >> data.height; in >> data.currentIndex;