Serialize SectionIndexData on storeSate().

This commit is contained in:
mfreiholz 2016-04-04 08:51:38 +02:00
parent ac80242545
commit 195b34c0ca
4 changed files with 41 additions and 3 deletions

View File

@ -14,6 +14,7 @@ class QGridLayout;
#include "ads/Internal.h" #include "ads/Internal.h"
#include "ads/SectionContent.h" #include "ads/SectionContent.h"
#include "ads/FloatingWidget.h" #include "ads/FloatingWidget.h"
#include "ads/Serialization.h"
ADS_NAMESPACE_BEGIN ADS_NAMESPACE_BEGIN
class SectionWidget; class SectionWidget;
@ -129,6 +130,9 @@ private:
QByteArray saveHierarchy() const; QByteArray saveHierarchy() const;
void saveFloatingWidgets(QDataStream& out) const; void saveFloatingWidgets(QDataStream& out) const;
void saveSectionWidgets(QDataStream& out, QWidget* widget) const; void saveSectionWidgets(QDataStream& out, QWidget* widget) const;
bool saveSectionIndex(ADS_NS_SER::SectionIndexData &sid) const;
bool restoreHierarchy(const QByteArray& data); bool restoreHierarchy(const QByteArray& data);
bool restoreFloatingWidgets(QDataStream& in, int version, QList<FloatingWidget*>& floatings); bool restoreFloatingWidgets(QDataStream& in, int version, QList<FloatingWidget*>& floatings);
bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList<SectionWidget*>& sections, QList<SectionContent::RefPtr>& contentsToHide); bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList<SectionWidget*>& sections, QList<SectionContent::RefPtr>& contentsToHide);

View File

@ -65,6 +65,8 @@ class ADS_EXPORT_API SectionEntity
{ {
public: public:
SectionEntity(); SectionEntity();
qint32 x;
qint32 y;
qint32 width; qint32 width;
qint32 height; qint32 height;
qint32 currentIndex; qint32 currentIndex;

View File

@ -369,10 +369,10 @@ QByteArray ContainerWidget::saveState() const
} }
// SectionIndex data. // SectionIndex data.
const QByteArray sectionIndexData; ADS_NS_SER::SectionIndexData sid;
if (!sectionIndexData.isEmpty()) if (saveSectionIndex(sid))
{ {
writer.write(ADS_NS_SER::ET_SectionIndex, sectionIndexData); writer.write(sid);
} }
if (writer.offsetsCount() == 0) 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) bool ContainerWidget::restoreHierarchy(const QByteArray& data)
{ {
QDataStream in(data); QDataStream in(data);

View File

@ -147,6 +147,8 @@ SectionEntity::SectionEntity() :
QDataStream& operator<<(QDataStream& out, const SectionEntity& data) QDataStream& operator<<(QDataStream& out, const SectionEntity& data)
{ {
out << data.x;
out << data.y;
out << data.width; out << data.width;
out << data.height; out << data.height;
out << data.currentIndex; out << data.currentIndex;
@ -160,6 +162,8 @@ QDataStream& operator<<(QDataStream& out, const SectionEntity& data)
QDataStream& operator>>(QDataStream& in, SectionEntity& data) QDataStream& operator>>(QDataStream& in, SectionEntity& data)
{ {
in >> data.x;
in >> data.y;
in >> data.width; in >> data.width;
in >> data.height; in >> data.height;
in >> data.currentIndex; in >> data.currentIndex;