mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 21:25:44 +08:00
Refactor: Add *Entity to all serialization entities to omit name collisions
This commit is contained in:
parent
34891e746e
commit
2a1bc4c43b
@ -21,76 +21,76 @@ enum EntryType
|
|||||||
ET_Custom = 0x0000ffff
|
ET_Custom = 0x0000ffff
|
||||||
};
|
};
|
||||||
|
|
||||||
class ADS_EXPORT_API Header
|
class ADS_EXPORT_API HeaderEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static qint32 MAGIC;
|
static qint32 MAGIC;
|
||||||
static qint32 MAJOR_VERSION;
|
static qint32 MAJOR_VERSION;
|
||||||
static qint32 MINOR_VERSION;
|
static qint32 MINOR_VERSION;
|
||||||
|
|
||||||
Header();
|
HeaderEntity();
|
||||||
qint32 magic;
|
qint32 magic;
|
||||||
qint32 majorVersion;
|
qint32 majorVersion;
|
||||||
qint32 minorVersion;
|
qint32 minorVersion;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const Header& data);
|
QDataStream& operator<<(QDataStream& out, const HeaderEntity& data);
|
||||||
QDataStream& operator>>(QDataStream& in, Header& data);
|
QDataStream& operator>>(QDataStream& in, HeaderEntity& data);
|
||||||
|
|
||||||
|
|
||||||
class ADS_EXPORT_API OffsetsHeader
|
class ADS_EXPORT_API OffsetsHeaderEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OffsetsHeader();
|
OffsetsHeaderEntity();
|
||||||
|
|
||||||
qint64 entriesCount;
|
qint64 entriesCount;
|
||||||
QList<class OffsetsHeaderEntry> entries;
|
QList<class OffsetsHeaderEntryEntity> entries;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const OffsetsHeader& data);
|
QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntity& data);
|
||||||
QDataStream& operator>>(QDataStream& in, OffsetsHeader& data);
|
QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntity& data);
|
||||||
|
|
||||||
|
|
||||||
class ADS_EXPORT_API OffsetsHeaderEntry
|
class ADS_EXPORT_API OffsetsHeaderEntryEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OffsetsHeaderEntry();
|
OffsetsHeaderEntryEntity();
|
||||||
qint32 type;
|
qint32 type;
|
||||||
qint64 offset;
|
qint64 offset;
|
||||||
qint64 contentSize;
|
qint64 contentSize;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntry& data);
|
QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntryEntity& data);
|
||||||
QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntry& data);
|
QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntryEntity& data);
|
||||||
|
|
||||||
|
|
||||||
class ADS_EXPORT_API Section
|
class ADS_EXPORT_API SectionEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Section();
|
SectionEntity();
|
||||||
qint32 width;
|
qint32 width;
|
||||||
qint32 height;
|
qint32 height;
|
||||||
qint32 currentIndex;
|
qint32 currentIndex;
|
||||||
qint32 sectionContentsCount;
|
qint32 sectionContentsCount;
|
||||||
QList<class SectionContent> sectionContents;
|
QList<class SectionContentEntity> sectionContents;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const Section& data);
|
QDataStream& operator<<(QDataStream& out, const SectionEntity& data);
|
||||||
QDataStream& operator>>(QDataStream& in, Section& data);
|
QDataStream& operator>>(QDataStream& in, SectionEntity& data);
|
||||||
|
|
||||||
|
|
||||||
class ADS_EXPORT_API SectionContent
|
class ADS_EXPORT_API SectionContentEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SectionContent();
|
SectionContentEntity();
|
||||||
QString uniqueName;
|
QString uniqueName;
|
||||||
bool visible;
|
bool visible;
|
||||||
qint32 preferredIndex;
|
qint32 preferredIndex;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const SectionContent& data);
|
QDataStream& operator<<(QDataStream& out, const SectionContentEntity& data);
|
||||||
QDataStream& operator>>(QDataStream& in, SectionContent& data);
|
QDataStream& operator>>(QDataStream& in, SectionContentEntity& data);
|
||||||
|
|
||||||
|
|
||||||
class ADS_EXPORT_API FloatingContent
|
class ADS_EXPORT_API FloatingContentEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FloatingContent();
|
FloatingContentEntity();
|
||||||
QString uniqueName;
|
QString uniqueName;
|
||||||
qint32 xpos;
|
qint32 xpos;
|
||||||
qint32 ypos;
|
qint32 ypos;
|
||||||
@ -98,8 +98,8 @@ public:
|
|||||||
qint32 height;
|
qint32 height;
|
||||||
bool visible;
|
bool visible;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const FloatingContent& data);
|
QDataStream& operator<<(QDataStream& out, const FloatingContentEntity& data);
|
||||||
QDataStream& operator>>(QDataStream& in, FloatingContent& data);
|
QDataStream& operator>>(QDataStream& in, FloatingContentEntity& data);
|
||||||
|
|
||||||
|
|
||||||
// Type: OffsetHeaderEntry::Hierarchy
|
// Type: OffsetHeaderEntry::Hierarchy
|
||||||
@ -119,7 +119,7 @@ class ADS_EXPORT_API SectionIndexData
|
|||||||
public:
|
public:
|
||||||
SectionIndexData();
|
SectionIndexData();
|
||||||
qint32 sectionsCount;
|
qint32 sectionsCount;
|
||||||
QList<Section> sections;
|
QList<SectionEntity> sections;
|
||||||
};
|
};
|
||||||
QDataStream& operator<<(QDataStream& out, const SectionIndexData& data);
|
QDataStream& operator<<(QDataStream& out, const SectionIndexData& data);
|
||||||
QDataStream& operator>>(QDataStream& in, SectionIndexData& data);
|
QDataStream& operator>>(QDataStream& in, SectionIndexData& data);
|
||||||
@ -139,7 +139,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QBuffer _contentBuffer;
|
QBuffer _contentBuffer;
|
||||||
OffsetsHeader _offsetsHeader;
|
OffsetsHeaderEntity _offsetsHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -155,7 +155,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray _data;
|
QByteArray _data;
|
||||||
OffsetsHeader _offsetsHeader;
|
OffsetsHeaderEntity _offsetsHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
ADS_NAMESPACE_SER_END
|
ADS_NAMESPACE_SER_END
|
||||||
|
@ -61,16 +61,16 @@ ADS_NAMESPACE_SER_BEGIN
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
qint32 Header::MAGIC = 0x00001337;
|
qint32 HeaderEntity::MAGIC = 0x00001337;
|
||||||
qint32 Header::MAJOR_VERSION = 2;
|
qint32 HeaderEntity::MAJOR_VERSION = 2;
|
||||||
qint32 Header::MINOR_VERSION = 0;
|
qint32 HeaderEntity::MINOR_VERSION = 0;
|
||||||
|
|
||||||
Header::Header() :
|
HeaderEntity::HeaderEntity() :
|
||||||
magic(0), majorVersion(0), minorVersion(0)
|
magic(0), majorVersion(0), minorVersion(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const Header& data)
|
QDataStream& operator<<(QDataStream& out, const HeaderEntity& data)
|
||||||
{
|
{
|
||||||
out << data.magic;
|
out << data.magic;
|
||||||
out << data.majorVersion;
|
out << data.majorVersion;
|
||||||
@ -78,7 +78,7 @@ QDataStream& operator<<(QDataStream& out, const Header& data)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& in, Header& data)
|
QDataStream& operator>>(QDataStream& in, HeaderEntity& data)
|
||||||
{
|
{
|
||||||
in >> data.magic;
|
in >> data.magic;
|
||||||
in >> data.majorVersion;
|
in >> data.majorVersion;
|
||||||
@ -88,12 +88,12 @@ QDataStream& operator>>(QDataStream& in, Header& data)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
OffsetsHeader::OffsetsHeader() :
|
OffsetsHeaderEntity::OffsetsHeaderEntity() :
|
||||||
entriesCount(0)
|
entriesCount(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const OffsetsHeader& data)
|
QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntity& data)
|
||||||
{
|
{
|
||||||
out << data.entriesCount;
|
out << data.entriesCount;
|
||||||
for (int i = 0; i < data.entriesCount; ++i)
|
for (int i = 0; i < data.entriesCount; ++i)
|
||||||
@ -103,12 +103,12 @@ QDataStream& operator<<(QDataStream& out, const OffsetsHeader& data)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& in, OffsetsHeader& data)
|
QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntity& data)
|
||||||
{
|
{
|
||||||
in >> data.entriesCount;
|
in >> data.entriesCount;
|
||||||
for (int i = 0; i < data.entriesCount; ++i)
|
for (int i = 0; i < data.entriesCount; ++i)
|
||||||
{
|
{
|
||||||
OffsetsHeaderEntry entry;
|
OffsetsHeaderEntryEntity entry;
|
||||||
in >> entry;
|
in >> entry;
|
||||||
data.entries.append(entry);
|
data.entries.append(entry);
|
||||||
}
|
}
|
||||||
@ -117,12 +117,12 @@ QDataStream& operator>>(QDataStream& in, OffsetsHeader& data)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
OffsetsHeaderEntry::OffsetsHeaderEntry() :
|
OffsetsHeaderEntryEntity::OffsetsHeaderEntryEntity() :
|
||||||
type(ET_Unknown), offset(0), contentSize(0)
|
type(ET_Unknown), offset(0), contentSize(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntry& data)
|
QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntryEntity& data)
|
||||||
{
|
{
|
||||||
out << data.type;
|
out << data.type;
|
||||||
out << data.offset;
|
out << data.offset;
|
||||||
@ -130,7 +130,7 @@ QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntry& data)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntry& data)
|
QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntryEntity& data)
|
||||||
{
|
{
|
||||||
in >> data.type;
|
in >> data.type;
|
||||||
in >> data.offset;
|
in >> data.offset;
|
||||||
@ -140,12 +140,12 @@ QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntry& data)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Section::Section() :
|
SectionEntity::SectionEntity() :
|
||||||
width(0), height(0), currentIndex(0), sectionContentsCount(0)
|
width(0), height(0), currentIndex(0), sectionContentsCount(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const Section& data)
|
QDataStream& operator<<(QDataStream& out, const SectionEntity& data)
|
||||||
{
|
{
|
||||||
out << data.width;
|
out << data.width;
|
||||||
out << data.height;
|
out << data.height;
|
||||||
@ -158,7 +158,7 @@ QDataStream& operator<<(QDataStream& out, const Section& data)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& in, Section& data)
|
QDataStream& operator>>(QDataStream& in, SectionEntity& data)
|
||||||
{
|
{
|
||||||
in >> data.width;
|
in >> data.width;
|
||||||
in >> data.height;
|
in >> data.height;
|
||||||
@ -166,7 +166,7 @@ QDataStream& operator>>(QDataStream& in, Section& data)
|
|||||||
in >> data.sectionContentsCount;
|
in >> data.sectionContentsCount;
|
||||||
for (int i = 0; i < data.sectionContentsCount; ++i)
|
for (int i = 0; i < data.sectionContentsCount; ++i)
|
||||||
{
|
{
|
||||||
SectionContent sc;
|
SectionContentEntity sc;
|
||||||
in >> sc;
|
in >> sc;
|
||||||
data.sectionContents.append(sc);
|
data.sectionContents.append(sc);
|
||||||
}
|
}
|
||||||
@ -175,12 +175,12 @@ QDataStream& operator>>(QDataStream& in, Section& data)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SectionContent::SectionContent() :
|
SectionContentEntity::SectionContentEntity() :
|
||||||
visible(false), preferredIndex(0)
|
visible(false), preferredIndex(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const SectionContent& data)
|
QDataStream& operator<<(QDataStream& out, const SectionContentEntity& data)
|
||||||
{
|
{
|
||||||
out << data.uniqueName;
|
out << data.uniqueName;
|
||||||
out << data.visible;
|
out << data.visible;
|
||||||
@ -188,7 +188,7 @@ QDataStream& operator<<(QDataStream& out, const SectionContent& data)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& in, SectionContent& data)
|
QDataStream& operator>>(QDataStream& in, SectionContentEntity& data)
|
||||||
{
|
{
|
||||||
in >> data.uniqueName;
|
in >> data.uniqueName;
|
||||||
in >> data.visible;
|
in >> data.visible;
|
||||||
@ -198,12 +198,12 @@ QDataStream& operator>>(QDataStream& in, SectionContent& data)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
FloatingContent::FloatingContent() :
|
FloatingContentEntity::FloatingContentEntity() :
|
||||||
xpos(0), ypos(0), width(0), height(0), visible(false)
|
xpos(0), ypos(0), width(0), height(0), visible(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const FloatingContent& data)
|
QDataStream& operator<<(QDataStream& out, const FloatingContentEntity& data)
|
||||||
{
|
{
|
||||||
out << data.uniqueName;
|
out << data.uniqueName;
|
||||||
out << data.xpos;
|
out << data.xpos;
|
||||||
@ -214,7 +214,7 @@ QDataStream& operator<<(QDataStream& out, const FloatingContent& data)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream& operator>>(QDataStream& in, FloatingContent& data)
|
QDataStream& operator>>(QDataStream& in, FloatingContentEntity& data)
|
||||||
{
|
{
|
||||||
in >> data.uniqueName;
|
in >> data.uniqueName;
|
||||||
in >> data.xpos;
|
in >> data.xpos;
|
||||||
@ -265,7 +265,7 @@ QDataStream& operator>>(QDataStream& in, SectionIndexData& data)
|
|||||||
in >> data.sectionsCount;
|
in >> data.sectionsCount;
|
||||||
for (int i = 0; i < data.sectionsCount; ++i)
|
for (int i = 0; i < data.sectionsCount; ++i)
|
||||||
{
|
{
|
||||||
Section s;
|
SectionEntity s;
|
||||||
in >> s;
|
in >> s;
|
||||||
data.sections.append(s);
|
data.sections.append(s);
|
||||||
}
|
}
|
||||||
@ -281,7 +281,7 @@ InMemoryWriter::InMemoryWriter()
|
|||||||
|
|
||||||
bool InMemoryWriter::write(qint32 entryType, const QByteArray& data)
|
bool InMemoryWriter::write(qint32 entryType, const QByteArray& data)
|
||||||
{
|
{
|
||||||
OffsetsHeaderEntry entry;
|
OffsetsHeaderEntryEntity entry;
|
||||||
entry.type = entryType;
|
entry.type = entryType;
|
||||||
entry.offset = _contentBuffer.pos(); // Relative offset!
|
entry.offset = _contentBuffer.pos(); // Relative offset!
|
||||||
entry.contentSize = data.size();
|
entry.contentSize = data.size();
|
||||||
@ -296,7 +296,7 @@ bool InMemoryWriter::write(qint32 entryType, const QByteArray& data)
|
|||||||
|
|
||||||
bool InMemoryWriter::write(const SectionIndexData& data)
|
bool InMemoryWriter::write(const SectionIndexData& data)
|
||||||
{
|
{
|
||||||
OffsetsHeaderEntry entry;
|
OffsetsHeaderEntryEntity entry;
|
||||||
entry.type = ET_SectionIndex;
|
entry.type = ET_SectionIndex;
|
||||||
entry.offset = _contentBuffer.pos(); // Relative offset!
|
entry.offset = _contentBuffer.pos(); // Relative offset!
|
||||||
|
|
||||||
@ -319,10 +319,10 @@ QByteArray InMemoryWriter::toByteArray() const
|
|||||||
out.setVersion(QDataStream::Qt_4_5);
|
out.setVersion(QDataStream::Qt_4_5);
|
||||||
|
|
||||||
// Basic format header.
|
// Basic format header.
|
||||||
Header header;
|
HeaderEntity header;
|
||||||
header.magic = Header::MAGIC;
|
header.magic = HeaderEntity::MAGIC;
|
||||||
header.majorVersion = Header::MAJOR_VERSION;
|
header.majorVersion = HeaderEntity::MAJOR_VERSION;
|
||||||
header.minorVersion = Header::MINOR_VERSION;
|
header.minorVersion = HeaderEntity::MINOR_VERSION;
|
||||||
out << header;
|
out << header;
|
||||||
|
|
||||||
// Offsets-Header
|
// Offsets-Header
|
||||||
@ -332,7 +332,7 @@ QByteArray InMemoryWriter::toByteArray() const
|
|||||||
// - Seek back to begin-pos and write OffsetsHeader again.
|
// - Seek back to begin-pos and write OffsetsHeader again.
|
||||||
// Use a copy of OffsetsHeader to keep the _offsetsHeader relative.
|
// Use a copy of OffsetsHeader to keep the _offsetsHeader relative.
|
||||||
const qint64 posOffsetHeaders = out.device()->pos();
|
const qint64 posOffsetHeaders = out.device()->pos();
|
||||||
OffsetsHeader offsetsHeader = _offsetsHeader;
|
OffsetsHeaderEntity offsetsHeader = _offsetsHeader;
|
||||||
out << offsetsHeader;
|
out << offsetsHeader;
|
||||||
|
|
||||||
// Now we know the size of the entire header.
|
// Now we know the size of the entire header.
|
||||||
@ -367,14 +367,14 @@ bool InMemoryReader::initReadHeader()
|
|||||||
in.setVersion(QDataStream::Qt_4_5);
|
in.setVersion(QDataStream::Qt_4_5);
|
||||||
|
|
||||||
// Basic format header.
|
// Basic format header.
|
||||||
Header header;
|
HeaderEntity header;
|
||||||
in >> header;
|
in >> header;
|
||||||
if (header.magic != Header::MAGIC)
|
if (header.magic != HeaderEntity::MAGIC)
|
||||||
{
|
{
|
||||||
qWarning() << QString("invalid format (magic=%1)").arg(header.magic);
|
qWarning() << QString("invalid format (magic=%1)").arg(header.magic);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (header.majorVersion > Header::MAJOR_VERSION)
|
if (header.majorVersion > HeaderEntity::MAJOR_VERSION)
|
||||||
{
|
{
|
||||||
qWarning() << QString("format is too new (major=%1; minor=%2)")
|
qWarning() << QString("format is too new (major=%1; minor=%2)")
|
||||||
.arg(header.majorVersion).arg(header.minorVersion);
|
.arg(header.majorVersion).arg(header.minorVersion);
|
||||||
@ -404,7 +404,7 @@ bool InMemoryReader::read(qint32 entryType, QByteArray& data)
|
|||||||
else if (_offsetsHeader.entries.at(index).offset == 0)
|
else if (_offsetsHeader.entries.at(index).offset == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const OffsetsHeaderEntry& entry = _offsetsHeader.entries.at(index);
|
const OffsetsHeaderEntryEntity& entry = _offsetsHeader.entries.at(index);
|
||||||
|
|
||||||
QDataStream in(_data);
|
QDataStream in(_data);
|
||||||
in.setVersion(QDataStream::Qt_4_5);
|
in.setVersion(QDataStream::Qt_4_5);
|
||||||
|
Loading…
Reference in New Issue
Block a user