From 8466e84eefdb3dde45d9af5244f1833c38c6ff7c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 15 Aug 2017 10:44:00 +0300 Subject: [PATCH] Read/Write pattern label. --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 13 ++--- src/libs/ifc/ifcdef.h | 13 +++++ src/libs/ifc/xml/vabstractpattern.cpp | 32 +++++++++-- src/libs/ifc/xml/vabstractpattern.h | 4 ++ src/libs/ifc/xml/vdomdocument.cpp | 53 ++++++++++++++++++- src/libs/ifc/xml/vdomdocument.h | 9 ++++ src/libs/vformat/vlabeltemplate.cpp | 48 ++--------------- src/libs/vformat/vlabeltemplate.h | 19 ------- 8 files changed, 113 insertions(+), 78 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 3a444c1b3..3b428f707 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -602,9 +602,9 @@ void DialogPatternProperties::SaveTemplateData() { if (templateDataChanged) { - //doc->SetTemplate(templateLines); + doc->SetPatternLabelTemplate(templateLines); templateDataChanged = false; - //emit doc->patternChanged(false); + emit doc->patternChanged(false); } } @@ -884,14 +884,7 @@ void DialogPatternProperties::EditLabel() DialogEditLabel editor(doc); -// if (templateDataChanged) -// { -// editor.SetTemplate(templateLines); -// } -// else -// { -// editor.SetTemplate(doc->GetTemplate()); -// } + templateDataChanged ? editor.SetTemplate(templateLines) : editor.SetTemplate(doc->GetPatternLabelTemplate()); if (QDialog::Accepted == editor.exec()) { diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 9b0b8e565..21899c820 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -213,4 +213,17 @@ extern const QString currentSeamAllowance; extern const QStringList builInVariables; +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") + +struct VLabelTemplateLine +{ + QString line; + bool bold; + bool italic; + int alignment; +}; + +QT_WARNING_POP + #endif // IFCDEF_H diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index c1092679a..4ef4e0585 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -87,6 +87,7 @@ const QString VAbstractPattern::TagPatternName = QStringLiteral("patternNam const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); +const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel"); const QString VAbstractPattern::TagSize = QStringLiteral("size"); const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); const QString VAbstractPattern::TagShowMeasurements = QStringLiteral("showMeasurements"); @@ -1374,6 +1375,25 @@ void VAbstractPattern::SetMesurementsVisible(bool bVisible) emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetPatternLabelTemplate(const QVector &lines) +{ + QDomElement tag = CheckTagExists(TagPatternLabel); + RemoveAllChildren(tag); + SetLabelTemplate(tag, lines); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractPattern::GetPatternLabelTemplate() const +{ + const QDomNodeList list = elementsByTagName(TagPatternLabel); + if (list.isEmpty()) + { + return QVector(); + } + return GetLabelTemplate(list.at(0).toElement()); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1516,7 +1536,8 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagSize << TagShowDate << TagShowMeasurements; + << TagCustomerName << TagPatternLabel << TagSize << TagShowDate + << TagShowMeasurements; switch (tags.indexOf(tag)) { case 1: //TagImage @@ -1556,13 +1577,16 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) case 9: // TagCustomerName element = createElement(TagCustomerName); break; - case 10: // TagSize + case 10: // TagPatternLabel + element = createElement(TagPatternLabel); + break; + case 11: // TagSize element = createElement(TagSize); break; - case 11: // TagShowDate + case 12: // TagShowDate element = createElement(TagShowDate); break; - case 12: // TagShowMeasurements + case 13: // TagShowMeasurements element = createElement(TagShowMeasurements); break; case 0: //TagUnit (Mandatory tag) diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index b7b285052..bc81b2ea8 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -154,6 +154,9 @@ public: bool IsMeasurementsVisible() const; void SetMesurementsVisible(bool bVisible); + void SetPatternLabelTemplate(const QVector &lines); + QVector GetPatternLabelTemplate() const; + QString GetImage() const; QString GetImageExtension() const; void SetImage(const QString &text, const QString &extension); @@ -209,6 +212,7 @@ public: static const QString TagPatternNum; static const QString TagCompanyName; static const QString TagCustomerName; + static const QString TagPatternLabel; static const QString TagSize; static const QString TagShowDate; static const QString TagShowMeasurements; diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 7199346df..c2a5e1587 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -178,9 +178,15 @@ void MessageHandler::handleMessage(QtMsgType type, const QString &description, c Q_LOGGING_CATEGORY(vXML, "v.xml") -const QString VDomDocument::AttrId = QStringLiteral("id"); +const QString VDomDocument::AttrId = QStringLiteral("id"); +const QString VDomDocument::AttrText = QStringLiteral("text"); +const QString VDomDocument::AttrBold = QStringLiteral("bold"); +const QString VDomDocument::AttrItalic = QStringLiteral("italic"); +const QString VDomDocument::AttrAlignment = QStringLiteral("alignment"); + const QString VDomDocument::TagVersion = QStringLiteral("version"); const QString VDomDocument::TagUnit = QStringLiteral("unit"); +const QString VDomDocument::TagLine = QStringLiteral("line"); //--------------------------------------------------------------------------------------------------------------------- VDomDocument::VDomDocument() @@ -899,3 +905,48 @@ bool VDomDocument::SafeCopy(const QString &source, const QString &destination, Q return result; } + +//--------------------------------------------------------------------------------------------------------------------- +QVector VDomDocument::GetLabelTemplate(const QDomElement &element) const +{ + QVector lines; + + if (not element.isNull()) + { + QDomElement tagLine = element.firstChildElement(); + while (tagLine.isNull() == false) + { + if (tagLine.tagName() == TagLine) + { + VLabelTemplateLine line; + line.line = GetParametrString(tagLine, AttrText, tr("")); + line.bold = GetParametrBool(tagLine, AttrBold, falseStr); + line.italic = GetParametrBool(tagLine, AttrItalic, falseStr); + line.alignment = GetParametrUInt(tagLine, AttrAlignment, "0"); + lines.append(line); + } + tagLine = tagLine.nextSiblingElement(TagLine); + } + } + + return lines; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDomDocument::SetLabelTemplate(QDomElement &element, const QVector &lines) +{ + if (not element.isNull()) + { + for (int i=0; i < lines.size(); ++i) + { + QDomElement tagLine = createElement(TagLine); + + SetAttribute(tagLine, AttrText, lines.at(i).line); + SetAttribute(tagLine, AttrBold, lines.at(i).bold); + SetAttribute(tagLine, AttrItalic, lines.at(i).italic); + SetAttribute(tagLine, AttrAlignment, lines.at(i).alignment); + + element.appendChild(tagLine); + } + } +} diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index b2e0dafc5..58906bf13 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -83,8 +83,14 @@ class VDomDocument : public QDomDocument Q_DECLARE_TR_FUNCTIONS(VDomDocument) public: static const QString AttrId; + static const QString AttrText; + static const QString AttrBold; + static const QString AttrItalic; + static const QString AttrAlignment; + static const QString TagVersion; static const QString TagUnit; + static const QString TagLine; VDomDocument(); virtual ~VDomDocument() Q_DECL_EQ_DEFAULT; @@ -130,6 +136,9 @@ protected: void TestUniqueId() const; void CollectId(const QDomElement &node, QVector &vector)const; + QVector GetLabelTemplate(const QDomElement &element) const; + void SetLabelTemplate(QDomElement &element, const QVector &lines); + private: Q_DISABLE_COPY(VDomDocument) /** @brief Map used for finding element by id. */ diff --git a/src/libs/vformat/vlabeltemplate.cpp b/src/libs/vformat/vlabeltemplate.cpp index 942c88405..78f6ba385 100644 --- a/src/libs/vformat/vlabeltemplate.cpp +++ b/src/libs/vformat/vlabeltemplate.cpp @@ -31,12 +31,6 @@ const QString VLabelTemplate::TagTemplate = QStringLiteral("template"); const QString VLabelTemplate::TagLines = QStringLiteral("lines"); -const QString VLabelTemplate::TagLine = QStringLiteral("line"); - -const QString VLabelTemplate::AttrText = QStringLiteral("text"); -const QString VLabelTemplate::AttrBold = QStringLiteral("bold"); -const QString VLabelTemplate::AttrItalic = QStringLiteral("italic"); -const QString VLabelTemplate::AttrAlignment = QStringLiteral("alignment"); //--------------------------------------------------------------------------------------------------------------------- VLabelTemplate::VLabelTemplate() @@ -69,52 +63,18 @@ void VLabelTemplate::AddLines(const QVector &lines) return; } - QDomElement tagLines = listLines.at(0).toElement(); - if (not tagLines.isNull()) - { - for (int i=0; i < lines.size(); ++i) - { - QDomElement tagLine = createElement(TagLine); - - SetAttribute(tagLine, AttrText, lines.at(i).line); - SetAttribute(tagLine, AttrBold, lines.at(i).bold); - SetAttribute(tagLine, AttrItalic, lines.at(i).italic); - SetAttribute(tagLine, AttrAlignment, lines.at(i).alignment); - - tagLines.appendChild(tagLine); - } - } + QDomElement tag = listLines.at(0).toElement(); + VDomDocument::SetLabelTemplate(tag, lines); } //--------------------------------------------------------------------------------------------------------------------- QVector VLabelTemplate::ReadLines() const { - QVector lines; - const QDomNodeList listLines = elementsByTagName(TagLines); if (listLines.size() == 0) { - return lines; + return QVector(); } - QDomElement tagLines = listLines.at(0).toElement(); - if (not tagLines.isNull()) - { - QDomElement tagLine = tagLines.firstChildElement(); - while (tagLine.isNull() == false) - { - if (tagLine.tagName() == TagLine) - { - VLabelTemplateLine line; - line.line = GetParametrString(tagLine, AttrText, tr("")); - line.bold = GetParametrBool(tagLine, AttrBold, falseStr); - line.italic = GetParametrBool(tagLine, AttrItalic, falseStr); - line.alignment = GetParametrUInt(tagLine, AttrAlignment, "0"); - lines.append(line); - } - tagLine = tagLine.nextSiblingElement(TagLine); - } - } - - return lines; + return VDomDocument::GetLabelTemplate(listLines.at(0).toElement()); } diff --git a/src/libs/vformat/vlabeltemplate.h b/src/libs/vformat/vlabeltemplate.h index c79960390..dd091479e 100644 --- a/src/libs/vformat/vlabeltemplate.h +++ b/src/libs/vformat/vlabeltemplate.h @@ -31,19 +31,6 @@ #include "../ifc/xml/vdomdocument.h" -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Weffc++") - -struct VLabelTemplateLine -{ - QString line; - bool bold; - bool italic; - int alignment; -}; - -QT_WARNING_POP - class VLabelTemplate : public VDomDocument { public: @@ -52,12 +39,6 @@ public: static const QString TagTemplate; static const QString TagLines; - static const QString TagLine; - - static const QString AttrText; - static const QString AttrBold; - static const QString AttrItalic; - static const QString AttrAlignment; void CreateEmptyTemplate();