Serialization/deserialization for class VLayoutPiece.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-07-01 11:02:09 +03:00
parent 89f786d98a
commit 0330869796
16 changed files with 547 additions and 82 deletions

View File

@ -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

View File

@ -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

View File

@ -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 \

View File

@ -0,0 +1,154 @@
/************************************************************************
**
** @file vgeometrydef.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vgeometrydef.h"
#include "../vmisc/vdatastreamenum.h"
#include "../ifc/exception/vexception.h"
#include <QCoreApplication>
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;
}

View File

@ -68,17 +68,17 @@ typedef QVector<QPolygonF> 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)
@ -88,6 +88,12 @@ struct VLayoutPassmark
PassmarkLineType type{PassmarkLineType::OneLine};
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)

View File

@ -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<VLayoutPassmark> 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<QPoin
const TextLine& tl = tm.GetSourceLine(i);
QFont fnt = tm.GetFont();
fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize);
fnt.setBold(tl.bold);
fnt.setItalic(tl.italic);
fnt.setBold(tl.m_bold);
fnt.setItalic(tl.m_italic);
QFontMetrics fm(fnt);

View File

@ -153,6 +153,9 @@ public:
qreal BiggestEdge() const;
friend QDataStream& operator<< (QDataStream& dataStream, const VLayoutPiece& piece);
friend QDataStream& operator>> (QDataStream& dataStream, VLayoutPiece& piece);
private:
QSharedDataPointer<VLayoutPieceData> d;

View File

@ -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<QPointF> 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

View File

@ -32,6 +32,24 @@
#include <QPainterPath>
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)

View File

@ -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<VLayoutPiecePathData> d;
};

View File

@ -34,6 +34,8 @@
#include <QVector>
#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<QPointF> 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

View File

@ -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<TextLine> VTextManager::m_patternLabelLines = QList<TextLine>();
// 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<TextLine> VTextManager::m_patternLabelLines = QVector<TextLine>();
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<QString, QString> 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<QString, QString> 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<QString, QString> &placeholders, QString
}
//---------------------------------------------------------------------------------------------------------------------
QList<TextLine> PrepareLines(const QVector<VLabelTemplateLine> &lines)
QVector<TextLine> PrepareLines(const QVector<VLabelTemplateLine> &lines)
{
QList<TextLine> textLines;
QVector<TextLine> textLines;
for (auto &line : lines)
{
@ -188,8 +291,8 @@ QList<TextLine> PrepareLines(const QVector<VLabelTemplateLine> &lines)
tl.m_qsText = line.line;
tl.m_eAlign = static_cast<Qt::Alignment>(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<TextLine> VTextManager::GetAllSourceLines() const
QVector<TextLine> 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

View File

@ -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<TextLine> GetAllSourceLines() const;
QVector<TextLine> GetAllSourceLines() const;
int GetSourceLinesCount() const;
const TextLine& GetSourceLine(int i) const;
void Update(const QString& qsName, const VPieceLabelData& data);
void Update(VAbstractPattern* pDoc);
friend QDataStream& operator<<(QDataStream& dataStream, const VTextManager& data);
friend QDataStream& operator>>(QDataStream& dataStream, VTextManager& data);
private:
QFont m_font;
QList<TextLine> m_liLines;
QVector<TextLine> m_liLines;
static QList<TextLine> m_patternLabelLines;
static QVector<TextLine> m_patternLabelLines;
static const quint32 streamHeader;
static const quint16 classVersion;
};
#endif // VTEXTMANAGER_H

View File

@ -70,7 +70,7 @@ VPieceNode::~VPieceNode()
//---------------------------------------------------------------------------------------------------------------------
QDataStream &operator<<(QDataStream &out, const VPieceNode &p)
{
out << p.d;
out << *p.d;
return out;
}

View File

@ -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);

View File

@ -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