From 033086979640c277b198296cc74deca7bcd4e07d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 1 Jul 2019 11:02:09 +0300 Subject: [PATCH] Serialization/deserialization for class VLayoutPiece. --HG-- branch : develop --- src/app/tape/tape.pro | 18 +-- src/app/valentina/valentina.pro | 18 +-- src/libs/vgeometry/vgeometry.pri | 1 + src/libs/vgeometry/vgeometrydef.cpp | 154 +++++++++++++++++++++++ src/libs/vgeometry/vgeometrydef.h | 30 +++-- src/libs/vlayout/vlayoutpiece.cpp | 22 +++- src/libs/vlayout/vlayoutpiece.h | 3 + src/libs/vlayout/vlayoutpiece_p.h | 90 ++++++++++++- src/libs/vlayout/vlayoutpiecepath.cpp | 18 +++ src/libs/vlayout/vlayoutpiecepath.h | 3 + src/libs/vlayout/vlayoutpiecepath_p.h | 62 +++++++++ src/libs/vlayout/vtextmanager.cpp | 151 ++++++++++++++++++---- src/libs/vlayout/vtextmanager.h | 35 ++++-- src/libs/vpatterndb/vpiecenode.cpp | 2 +- src/libs/vwidgets/vtextgraphicsitem.cpp | 4 +- src/test/ValentinaTest/ValentinaTest.pro | 18 +-- 16 files changed, 547 insertions(+), 82 deletions(-) create mode 100644 src/libs/vgeometry/vgeometrydef.cpp diff --git a/src/app/tape/tape.pro b/src/app/tape/tape.pro index e1fc4eabf..7fa078bfe 100644 --- a/src/app/tape/tape.pro +++ b/src/app/tape/tape.pro @@ -396,6 +396,15 @@ DEPENDPATH += $$PWD/../../libs/vmisc win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/vmisc.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/libvmisc.a +# VLayout static library (depend on VGeometry) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout + +INCLUDEPATH += $$PWD/../../libs/vlayout +DEPENDPATH += $$PWD/../../libs/vlayout + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a + # VGeometry static library (depend on ifc) unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/ -lvgeometry @@ -405,15 +414,6 @@ DEPENDPATH += $$PWD/../../libs/vgeometry win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a -# VLayout static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout - -INCLUDEPATH += $$PWD/../../libs/vlayout -DEPENDPATH += $$PWD/../../libs/vlayout - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a - # QMuParser library win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 diff --git a/src/app/valentina/valentina.pro b/src/app/valentina/valentina.pro index 9ea225410..b59ec387f 100644 --- a/src/app/valentina/valentina.pro +++ b/src/app/valentina/valentina.pro @@ -553,6 +553,15 @@ DEPENDPATH += $$PWD/../../libs/vpatterndb win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/vpatterndb.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/libvpatterndb.a +# VLayout static library (depend on IFC, VGeometry) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout + +INCLUDEPATH += $$PWD/../../libs/vlayout +DEPENDPATH += $$PWD/../../libs/vlayout + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a + # VGeometry static library (depend on ifc) unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/ -lvgeometry @@ -571,15 +580,6 @@ DEPENDPATH += $$PWD/../../libs/fervor win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/fervor/$${DESTDIR}/fervor.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/fervor/$${DESTDIR}/libfervor.a -# VLayout static library (depend on IFC) -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout - -INCLUDEPATH += $$PWD/../../libs/vlayout -DEPENDPATH += $$PWD/../../libs/vlayout - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a - # IFC static library (depend on QMuParser, VMisc) unix|win32: LIBS += -L$$OUT_PWD/../../libs/ifc/$${DESTDIR}/ -lifc diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index d010aabe0..4c2248b78 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -2,6 +2,7 @@ # This need for corect working file translations.pro SOURCES += \ + $$PWD/vgeometrydef.cpp \ $$PWD/vgobject.cpp \ $$PWD/vabstractcurve.cpp \ $$PWD/varc.cpp \ diff --git a/src/libs/vgeometry/vgeometrydef.cpp b/src/libs/vgeometry/vgeometrydef.cpp new file mode 100644 index 000000000..0d8aac1f0 --- /dev/null +++ b/src/libs/vgeometry/vgeometrydef.cpp @@ -0,0 +1,154 @@ +/************************************************************************ + ** + ** @file vgeometrydef.cpp + ** @author Roman Telezhynskyi + ** @date 1 7, 2019 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2019 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vgeometrydef.h" + +#include "../vmisc/vdatastreamenum.h" +#include "../ifc/exception/vexception.h" + +#include + +const quint32 VLayoutPassmark::streamHeader = 0x943E2759; // CRC-32Q string "VLayoutPassmark" +const quint16 VLayoutPassmark::classVersion = 1; + +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream &operator<<(QDataStream &dataStream, const VLayoutPassmark &data) +{ + dataStream << VLayoutPassmark::streamHeader << VLayoutPassmark::classVersion; + + // Added in classVersion = 1 + dataStream << data.lines; + dataStream << data.type; + dataStream << data.baseLine; + dataStream << data.isBuiltIn; + + // Added in classVersion = 2 + + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream &operator>>(QDataStream &dataStream, VLayoutPassmark &data) +{ + quint32 actualStreamHeader = 0; + dataStream >> actualStreamHeader; + + if (actualStreamHeader != VLayoutPassmark::streamHeader) + { + QString message = QCoreApplication::tr("VLayoutPassmark prefix mismatch error: actualStreamHeader = 0x%1 and " + "streamHeader = 0x%2") + .arg(actualStreamHeader, 8, 0x10, QChar('0')) + .arg(VLayoutPassmark::streamHeader, 8, 0x10, QChar('0')); + throw VException(message); + } + + quint16 actualClassVersion = 0; + dataStream >> actualClassVersion; + + if (actualClassVersion > VLayoutPassmark::classVersion) + { + QString message = QCoreApplication::tr("VLayoutPassmark compatibility error: actualClassVersion = %1 and " + "classVersion = %2") + .arg(actualClassVersion).arg(VLayoutPassmark::classVersion); + throw VException(message); + } + + dataStream >> data.lines; + dataStream >> data.type; + dataStream >> data.baseLine; + dataStream >> data.isBuiltIn; + +// if (actualClassVersion >= 2) +// { + +// } + + return dataStream; +} + +const quint32 VLayoutPlaceLabel::streamHeader = 0xB282E284; // CRC-32Q string "VLayoutPlaceLabel" +const quint16 VLayoutPlaceLabel::classVersion = 1; + +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator<<(QDataStream &dataStream, const VLayoutPlaceLabel &data) +{ + dataStream << VLayoutPlaceLabel::streamHeader << VLayoutPlaceLabel::classVersion; + + // Added in classVersion = 1 + dataStream << data.center; + dataStream << data.type; + dataStream << data.shape; + dataStream << data.rotationMatrix; + dataStream << data.box; + + // Added in classVersion = 2 + + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator>>(QDataStream &dataStream, VLayoutPlaceLabel &data) +{ + quint32 actualStreamHeader = 0; + dataStream >> actualStreamHeader; + + if (actualStreamHeader != VLayoutPlaceLabel::streamHeader) + { + QString message = QCoreApplication::tr("VLayoutPlaceLabel prefix mismatch error: actualStreamHeader = 0x%1 and " + "streamHeader = 0x%2") + .arg(actualStreamHeader, 8, 0x10, QChar('0')) + .arg(VLayoutPlaceLabel::streamHeader, 8, 0x10, QChar('0')); + throw VException(message); + } + + quint16 actualClassVersion = 0; + dataStream >> actualClassVersion; + + if (actualClassVersion > VLayoutPlaceLabel::classVersion) + { + QString message = QCoreApplication::tr("VLayoutPlaceLabel compatibility error: actualClassVersion = %1 and " + "classVersion = %2") + .arg(actualClassVersion).arg(VLayoutPlaceLabel::classVersion); + throw VException(message); + } + + dataStream >> data.center; + dataStream >> data.type; + dataStream >> data.shape; + dataStream >> data.rotationMatrix; + dataStream >> data.box; + +// if (actualClassVersion >= 2) +// { + +// } + + return dataStream; +} diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index edc97e51b..670214621 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -68,26 +68,32 @@ typedef QVector PlaceLabelImg; struct VLayoutPlaceLabel { - VLayoutPlaceLabel() - : center(), - type(PlaceLabelType::Button), - shape() - {} - - QPointF center; - PlaceLabelType type; - PlaceLabelImg shape; + QPointF center{}; + PlaceLabelType type{PlaceLabelType::Button}; + PlaceLabelImg shape{}; QTransform rotationMatrix{}; QRectF box{}; + + friend QDataStream& operator<<(QDataStream& dataStream, const VLayoutPlaceLabel& data); + friend QDataStream& operator>>(QDataStream& dataStream, VLayoutPlaceLabel& data); +private: + static const quint32 streamHeader; + static const quint16 classVersion; }; Q_DECLARE_METATYPE(VLayoutPlaceLabel) struct VLayoutPassmark { - QVector lines{}; + QVector lines{}; PassmarkLineType type{PassmarkLineType::OneLine}; - QLineF baseLine{}; - bool isBuiltIn{false}; + QLineF baseLine{}; + bool isBuiltIn{false}; + + friend QDataStream& operator<<(QDataStream& dataStream, const VLayoutPassmark& data); + friend QDataStream& operator>>(QDataStream& dataStream, VLayoutPassmark& data); +private: + static const quint32 streamHeader; + static const quint16 classVersion; }; Q_DECLARE_METATYPE(VLayoutPassmark) diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 7baa5cabc..9535b786b 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -59,6 +59,9 @@ #include "vtextmanager.h" #include "vgraphicsfillitem.h" +const quint32 VLayoutPieceData::streamHeader = 0x80D7D009; // CRC-32Q string "VLayoutPieceData" +const quint16 VLayoutPieceData::classVersion = 1; + namespace { //--------------------------------------------------------------------------------------------------------------------- @@ -356,6 +359,21 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer } } +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream &operator<<(QDataStream &dataStream, const VLayoutPiece &piece) +{ + dataStream << *piece.d; + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream &operator>>(QDataStream &dataStream, VLayoutPiece &piece) +{ + dataStream >> *piece.d; + return dataStream; +} + //--------------------------------------------------------------------------------------------------------------------- VLayoutPiece::VLayoutPiece() :VAbstractPiece(), d(new VLayoutPieceData) @@ -1127,8 +1145,8 @@ void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector> (QDataStream& dataStream, VLayoutPiece& piece); + private: QSharedDataPointer d; diff --git a/src/libs/vlayout/vlayoutpiece_p.h b/src/libs/vlayout/vlayoutpiece_p.h index 192ffdde8..28a668d7b 100644 --- a/src/libs/vlayout/vlayoutpiece_p.h +++ b/src/libs/vlayout/vlayoutpiece_p.h @@ -38,9 +38,11 @@ #include "../vpatterndb/floatItemData/vpatternlabeldata.h" #include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vmisc/diagnostic.h" +#include "../vmisc/vdatastreamenum.h" #include "vlayoutpiecepath.h" #include "../vgeometry/vgeometrydef.h" #include "vtextmanager.h" +#include "../ifc/exception/vexception.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -91,7 +93,10 @@ public: m_square(detail.m_square) {} - ~VLayoutPieceData() {} + ~VLayoutPieceData() Q_DECL_EQ_DEFAULT; + + friend QDataStream& operator<<(QDataStream& dataStream, const VLayoutPieceData& piece); + friend QDataStream& operator>>(QDataStream& dataStream, VLayoutPieceData& piece); /** @brief contour list of contour points. */ QVector contour; @@ -142,8 +147,91 @@ public: private: VLayoutPieceData &operator=(const VLayoutPieceData &) Q_DECL_EQ_DELETE; + + static const quint32 streamHeader; + static const quint16 classVersion; }; +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +inline QDataStream &operator<<(QDataStream &dataStream, const VLayoutPieceData &piece) +{ + dataStream << VLayoutPieceData::streamHeader << VLayoutPieceData::classVersion; + + // Added in classVersion = 1 + dataStream << piece.contour; + dataStream << piece.seamAllowance; + dataStream << piece.layoutAllowance; + dataStream << piece.passmarks; + dataStream << piece.m_internalPaths; + dataStream << piece.matrix; + dataStream << piece.layoutWidth; + dataStream << piece.mirror; + dataStream << piece.detailLabel; + dataStream << piece.patternInfo; + dataStream << piece.grainlinePoints; + dataStream << piece.grainlineArrowType; + dataStream << piece.grainlineAngle; + dataStream << piece.grainlineEnabled; + dataStream << piece.m_placeLabels; + dataStream << piece.m_square; + + // Added in classVersion = 2 + + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QDataStream &operator>>(QDataStream &dataStream, VLayoutPieceData &piece) +{ + quint32 actualStreamHeader = 0; + dataStream >> actualStreamHeader; + + if (actualStreamHeader != VLayoutPieceData::streamHeader) + { + QString message = QCoreApplication::tr("VRawLayoutData prefix mismatch error: actualStreamHeader = 0x%1 and " + "streamHeader = 0x%2") + .arg(actualStreamHeader, 8, 0x10, QChar('0')) + .arg(VLayoutPieceData::streamHeader, 8, 0x10, QChar('0')); + throw VException(message); + } + + quint16 actualClassVersion = 0; + dataStream >> actualClassVersion; + + if (actualClassVersion > VLayoutPieceData::classVersion) + { + QString message = QCoreApplication::tr("VRawLayoutData compatibility error: actualClassVersion = %1 and " + "classVersion = %2") + .arg(actualClassVersion).arg(VLayoutPieceData::classVersion); + throw VException(message); + } + + dataStream >> piece.contour; + dataStream >> piece.seamAllowance; + dataStream >> piece.layoutAllowance; + dataStream >> piece.passmarks; + dataStream >> piece.m_internalPaths; + dataStream >> piece.matrix; + dataStream >> piece.layoutWidth; + dataStream >> piece.mirror; + dataStream >> piece.detailLabel; + dataStream >> piece.patternInfo; + dataStream >> piece.grainlinePoints; + dataStream >> piece.grainlineArrowType; + dataStream >> piece.grainlineAngle; + dataStream >> piece.grainlineEnabled; + dataStream >> piece.m_placeLabels; + dataStream >> piece.m_square; + +// if (actualClassVersion >= 2) +// { + +// } + + return dataStream; +} + QT_WARNING_POP #endif // VLAYOUTDETAIL_P_H diff --git a/src/libs/vlayout/vlayoutpiecepath.cpp b/src/libs/vlayout/vlayoutpiecepath.cpp index 4b3bfbf9d..af9d41e6d 100644 --- a/src/libs/vlayout/vlayoutpiecepath.cpp +++ b/src/libs/vlayout/vlayoutpiecepath.cpp @@ -32,6 +32,24 @@ #include +const quint32 VLayoutPiecePathData::streamHeader = 0xA53F0225; // CRC-32Q string "VLayoutPiecePathData" +const quint16 VLayoutPiecePathData::classVersion = 1; + +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream &operator<<(QDataStream &dataStream, const VLayoutPiecePath &path) +{ + dataStream << *path.d; + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream &operator>>(QDataStream &dataStream, VLayoutPiecePath &path) +{ + dataStream >> *path.d; + return dataStream; +} + //--------------------------------------------------------------------------------------------------------------------- VLayoutPiecePath::VLayoutPiecePath() : d(new VLayoutPiecePathData) diff --git a/src/libs/vlayout/vlayoutpiecepath.h b/src/libs/vlayout/vlayoutpiecepath.h index 1e38e3847..f6f69ba95 100644 --- a/src/libs/vlayout/vlayoutpiecepath.h +++ b/src/libs/vlayout/vlayoutpiecepath.h @@ -64,6 +64,9 @@ public: bool IsCutPath() const; void SetCutPath(bool cut); + friend QDataStream& operator<< (QDataStream& dataStream, const VLayoutPiecePath& path); + friend QDataStream& operator>> (QDataStream& dataStream, VLayoutPiecePath& path); + private: QSharedDataPointer d; }; diff --git a/src/libs/vlayout/vlayoutpiecepath_p.h b/src/libs/vlayout/vlayoutpiecepath_p.h index 2197260d1..39eabfcf0 100644 --- a/src/libs/vlayout/vlayoutpiecepath_p.h +++ b/src/libs/vlayout/vlayoutpiecepath_p.h @@ -34,6 +34,8 @@ #include #include "../vmisc/diagnostic.h" +#include "../vmisc/vdatastreamenum.h" +#include "../ifc/exception/vexception.h" QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -58,6 +60,9 @@ public: ~VLayoutPiecePathData() Q_DECL_EQ_DEFAULT; + friend QDataStream& operator<<(QDataStream& dataStream, const VLayoutPiecePathData& path); + friend QDataStream& operator>>(QDataStream& dataStream, VLayoutPiecePathData& path); + /** @brief m_points list of path points. */ QVector m_points{}; @@ -68,9 +73,66 @@ public: private: VLayoutPiecePathData &operator=(const VLayoutPiecePathData &) Q_DECL_EQ_DELETE; + + static const quint32 streamHeader; + static const quint16 classVersion; }; QT_WARNING_POP +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator<<(QDataStream &dataStream, const VLayoutPiecePathData &path) +{ + dataStream << VLayoutPiecePathData::streamHeader << VLayoutPiecePathData::classVersion; + + // Added in classVersion = 1 + dataStream << path.m_points; + dataStream << path.m_penStyle; + dataStream << path.m_cut; + + // Added in classVersion = 2 + + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator>>(QDataStream &dataStream, VLayoutPiecePathData &path) +{ + quint32 actualStreamHeader = 0; + dataStream >> actualStreamHeader; + + if (actualStreamHeader != VLayoutPiecePathData::streamHeader) + { + QString message = QCoreApplication::tr("VLayoutPiecePathData prefix mismatch error: actualStreamHeader = 0x%1 " + "and streamHeader = 0x%2") + .arg(actualStreamHeader, 8, 0x10, QChar('0')) + .arg(VLayoutPiecePathData::streamHeader, 8, 0x10, QChar('0')); + throw VException(message); + } + + quint16 actualClassVersion = 0; + dataStream >> actualClassVersion; + + if (actualClassVersion > VLayoutPiecePathData::classVersion) + { + QString message = QCoreApplication::tr("VLayoutPiecePathData compatibility error: actualClassVersion = %1 and " + "classVersion = %2") + .arg(actualClassVersion).arg(VLayoutPiecePathData::classVersion); + throw VException(message); + } + + dataStream >> path.m_points; + dataStream >> path.m_penStyle; + dataStream >> path.m_cut; + +// if (actualClassVersion >= 2) +// { + +// } + + return dataStream; +} + #endif // VLAYOUTPIECEPATH_P_H diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index e65124ecf..674c6b19f 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -41,19 +41,122 @@ #include "../vpatterndb/vcontainer.h" #include "vtextmanager.h" -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief TextLine::TextLine default constructor - */ -TextLine::TextLine() - : m_qsText(), - m_iFontSize(MIN_FONT_SIZE), - bold(false), - italic(false), - m_eAlign(Qt::AlignCenter) -{} +const quint32 TextLine::streamHeader = 0xA3881E49; // CRC-32Q string "TextLine" +const quint16 TextLine::classVersion = 1; -QList VTextManager::m_patternLabelLines = QList(); +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator<<(QDataStream &dataStream, const TextLine &data) +{ + dataStream << TextLine::streamHeader << TextLine::classVersion; + + // Added in classVersion = 1 + dataStream << data.m_qsText; + dataStream << data.m_iFontSize; + dataStream << data.m_bold; + dataStream << data.m_italic; + dataStream << data.m_eAlign; + + // Added in classVersion = 2 + + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator>>(QDataStream &dataStream, TextLine &data) +{ + quint32 actualStreamHeader = 0; + dataStream >> actualStreamHeader; + + if (actualStreamHeader != TextLine::streamHeader) + { + QString message = QCoreApplication::tr("TextLine prefix mismatch error: actualStreamHeader = 0x%1 and " + "streamHeader = 0x%2") + .arg(actualStreamHeader, 8, 0x10, QChar('0')) + .arg(TextLine::streamHeader, 8, 0x10, QChar('0')); + throw VException(message); + } + + quint16 actualClassVersion = 0; + dataStream >> actualClassVersion; + + if (actualClassVersion > TextLine::classVersion) + { + QString message = QCoreApplication::tr("TextLine compatibility error: actualClassVersion = %1 and " + "classVersion = %2") + .arg(actualClassVersion).arg(TextLine::classVersion); + throw VException(message); + } + + dataStream >> data.m_qsText; + dataStream >> data.m_iFontSize; + dataStream >> data.m_bold; + dataStream >> data.m_italic; + dataStream >> data.m_eAlign; + +// if (actualClassVersion >= 2) +// { + +// } + + return dataStream; +} + +QVector VTextManager::m_patternLabelLines = QVector(); +const quint32 VTextManager::streamHeader = 0x47E6A9EE; // CRC-32Q string "VTextManager" +const quint16 VTextManager::classVersion = 1; + +// Friend functions +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator<<(QDataStream &dataStream, const VTextManager &data) +{ + dataStream << VTextManager::streamHeader << VTextManager::classVersion; + + // Added in classVersion = 1 + dataStream << data.m_font; + dataStream << data.m_liLines; + + // Added in classVersion = 2 + + return dataStream; +} + +//--------------------------------------------------------------------------------------------------------------------- +QDataStream& operator>>(QDataStream &dataStream, VTextManager &data) +{ + quint32 actualStreamHeader = 0; + dataStream >> actualStreamHeader; + + if (actualStreamHeader != VTextManager::streamHeader) + { + QString message = QCoreApplication::tr("VTextManager prefix mismatch error: actualStreamHeader = 0x%1 and " + "streamHeader = 0x%2") + .arg(actualStreamHeader, 8, 0x10, QChar('0')) + .arg(VTextManager::streamHeader, 8, 0x10, QChar('0')); + throw VException(message); + } + + quint16 actualClassVersion = 0; + dataStream >> actualClassVersion; + + if (actualClassVersion > VTextManager::classVersion) + { + QString message = QCoreApplication::tr("VTextManager compatibility error: actualClassVersion = %1 and " + "classVersion = %2") + .arg(actualClassVersion).arg(VTextManager::classVersion); + throw VException(message); + } + + dataStream >> data.m_font; + dataStream >> data.m_liLines; + +// if (actualClassVersion >= 2) +// { + +// } + + return dataStream; +} namespace { @@ -87,7 +190,7 @@ QMap PreparePlaceholders(const VAbstractPattern *doc) placeholders.insert(pl_customer, doc->GetCustomerName()); } - placeholders.insert(pl_pExt, QString("val")); + placeholders.insert(pl_pExt, QStringLiteral("val")); placeholders.insert(pl_pFileName, QFileInfo(qApp->GetPatternPath()).baseName()); placeholders.insert(pl_mFileName, QFileInfo(doc->MPath()).baseName()); @@ -98,13 +201,13 @@ QMap PreparePlaceholders(const VAbstractPattern *doc) { curSize = QString::number(VContainer::size(valentinaNamespace)); curHeight = QString::number(VContainer::height(valentinaNamespace)); - mExt = "vst"; + mExt = QStringLiteral("vst"); } else if (qApp->patternType() == MeasurementsType::Individual) { curSize = QString::number(VContainer::size(valentinaNamespace)); curHeight = QString::number(VContainer::height(valentinaNamespace)); - mExt = "vit"; + mExt = QStringLiteral("vit"); } placeholders.insert(pl_size, curSize); @@ -176,9 +279,9 @@ QString ReplacePlaceholders(const QMap &placeholders, QString } //--------------------------------------------------------------------------------------------------------------------- -QList PrepareLines(const QVector &lines) +QVector PrepareLines(const QVector &lines) { - QList textLines; + QVector textLines; for (auto &line : lines) { @@ -188,8 +291,8 @@ QList PrepareLines(const QVector &lines) tl.m_qsText = line.line; tl.m_eAlign = static_cast(line.alignment); tl.m_iFontSize = line.fontSizeIncrement; - tl.bold = line.bold; - tl.italic = line.italic; + tl.m_bold = line.bold; + tl.m_italic = line.italic; textLines << tl; } @@ -265,7 +368,7 @@ void VTextManager::SetFontSize(int iFS) } //--------------------------------------------------------------------------------------------------------------------- -QList VTextManager::GetAllSourceLines() const +QVector VTextManager::GetAllSourceLines() const { return m_liLines; } @@ -323,8 +426,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) const TextLine& tl = GetSourceLine(i); fnt = m_font; fnt.setPixelSize(iFS + tl.m_iFontSize); - fnt.setBold(tl.bold); - fnt.setItalic(tl.italic); + fnt.setBold(tl.m_bold); + fnt.setItalic(tl.m_italic); QFontMetrics fm(fnt); const int iTW = fm.width(tl.m_qsText); if (iTW > iMaxLen) @@ -336,8 +439,8 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) if (iMaxLen > fW) { QFont fnt = m_font; - fnt.setBold(maxLine.bold); - fnt.setItalic(maxLine.italic); + fnt.setBold(maxLine.m_bold); + fnt.setItalic(maxLine.m_italic); int lineLength = 0; do diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 0b212e3ec..c81d984da 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -49,13 +49,17 @@ class VAbstractPattern; */ struct TextLine { - QString m_qsText; - int m_iFontSize; // 0 means default - bool bold; - bool italic; - Qt::Alignment m_eAlign; + QString m_qsText{}; + int m_iFontSize{MIN_FONT_SIZE}; // 0 means default + bool m_bold{false}; + bool m_italic{false}; + Qt::Alignment m_eAlign{Qt::AlignCenter}; - TextLine(); + friend QDataStream& operator<<(QDataStream& dataStream, const TextLine& data); + friend QDataStream& operator>>(QDataStream& dataStream, TextLine& data); +private: + static const quint32 streamHeader; + static const quint16 classVersion; }; /** @@ -79,18 +83,23 @@ public: void SetFontSize(int iFS); void FitFontSize(qreal fW, qreal fH); - QList GetAllSourceLines() const; - int GetSourceLinesCount() const; - const TextLine& GetSourceLine(int i) const; + QVector GetAllSourceLines() const; + int GetSourceLinesCount() const; + const TextLine& GetSourceLine(int i) const; void Update(const QString& qsName, const VPieceLabelData& data); void Update(VAbstractPattern* pDoc); -private: - QFont m_font; - QList m_liLines; + friend QDataStream& operator<<(QDataStream& dataStream, const VTextManager& data); + friend QDataStream& operator>>(QDataStream& dataStream, VTextManager& data); - static QList m_patternLabelLines; +private: + QFont m_font; + QVector m_liLines; + + static QVector m_patternLabelLines; + static const quint32 streamHeader; + static const quint16 classVersion; }; #endif // VTEXTMANAGER_H diff --git a/src/libs/vpatterndb/vpiecenode.cpp b/src/libs/vpatterndb/vpiecenode.cpp index eaa47ac25..fbda85c74 100644 --- a/src/libs/vpatterndb/vpiecenode.cpp +++ b/src/libs/vpatterndb/vpiecenode.cpp @@ -70,7 +70,7 @@ VPieceNode::~VPieceNode() //--------------------------------------------------------------------------------------------------------------------- QDataStream &operator<<(QDataStream &out, const VPieceNode &p) { - out << p.d; + out << *p.d; return out; } diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index f3e636a7d..9deb7c707 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -164,8 +164,8 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem const TextLine& tl = m_tm.GetSourceLine(i); fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize); - fnt.setBold(tl.bold); - fnt.setItalic(tl.italic); + fnt.setBold(tl.m_bold); + fnt.setItalic(tl.m_italic); QString qsText = tl.m_qsText; QFontMetrics fm(fnt); diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 27d7c8afa..cbfbc7631 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -191,6 +191,15 @@ DEPENDPATH += $$PWD/../../libs/vmisc win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/vmisc.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/libvmisc.a +# VLayout static library (depend on ifc, VGeometry) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR} -lvlayout + +INCLUDEPATH += $$PWD/../../libs/vlayout +DEPENDPATH += $$PWD/../../libs/vlayout + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a + # VGeometry static library (depend on ifc) unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR} -lvgeometry @@ -200,15 +209,6 @@ DEPENDPATH += $$PWD/../../libs/vgeometry win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a -# VLayout static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR} -lvlayout - -INCLUDEPATH += $$PWD/../../libs/vlayout -DEPENDPATH += $$PWD/../../libs/vlayout - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a - # QMuParser library win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2