From 8c84cff91dbe81bd2826bb642558925cfbb074c3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 26 Sep 2017 12:54:52 +0300 Subject: [PATCH] Read/write list of final measurements. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 26 +- src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.6.4.xsd | 985 +++++++++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 84 ++- src/libs/ifc/xml/vabstractpattern.h | 20 +- src/libs/ifc/xml/vpatternconverter.cpp | 22 +- src/libs/ifc/xml/vpatternconverter.h | 3 +- 7 files changed, 1117 insertions(+), 24 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.6.4.xsd diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 57a7c6509..9149dc0c1 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -152,7 +152,8 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagPatternLabel << TagPatternMaterials << TagPreviewCalculations; + << TagPatternLabel << TagPatternMaterials << TagPreviewCalculations + << TagFinalMeasurements; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -231,6 +232,9 @@ void VPattern::Parse(const Document &parse) qCDebug(vXML, "Tag prewiew calculations."); ParseIncrementsElement(domElement); break; + case 16: // TagFinalMeasurements + qCDebug(vXML, "Tag final measurements."); + break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; @@ -3128,9 +3132,9 @@ qreal VPattern::EvalFormula(VContainer *data, const QString &formula, bool *ok) QDomElement VPattern::MakeEmptyIncrement(const QString &name) { QDomElement element = createElement(TagIncrement); - SetAttribute(element, IncrementName, name); - SetAttribute(element, IncrementFormula, QString("0")); - SetAttribute(element, IncrementDescription, QString("")); + SetAttribute(element, AttrName, name); + SetAttribute(element, AttrFormula, QString("0")); + SetAttribute(element, AttrDescription, QString("")); return element; } @@ -3144,7 +3148,7 @@ QDomElement VPattern::FindIncrement(const QString &name) const const QDomElement domElement = list.at(i).toElement(); if (domElement.isNull() == false) { - const QString parameter = domElement.attribute(IncrementName); + const QString parameter = domElement.attribute(AttrName); if (parameter == name) { return domElement; @@ -3573,19 +3577,19 @@ void VPattern::ParseIncrementsElement(const QDomNode &node) { if (domElement.tagName() == TagIncrement) { - const QString name = GetParametrString(domElement, IncrementName, ""); + const QString name = GetParametrString(domElement, AttrName, ""); QString desc; try { - desc = GetParametrString(domElement, IncrementDescription); + desc = GetParametrString(domElement, AttrDescription); } catch (VExceptionEmptyParameter &e) { Q_UNUSED(e) } - const QString formula = GetParametrString(domElement, IncrementFormula, "0"); + const QString formula = GetParametrString(domElement, AttrFormula, "0"); bool ok = false; const qreal value = EvalFormula(data, formula, &ok); @@ -3664,19 +3668,19 @@ void VPattern::MoveDownPreviewCalculation(const QString &name) //--------------------------------------------------------------------------------------------------------------------- void VPattern::SetIncrementName(const QString &name, const QString &text) { - SetIncrementAttribute(name, IncrementName, text); + SetIncrementAttribute(name, AttrName, text); } //--------------------------------------------------------------------------------------------------------------------- void VPattern::SetIncrementFormula(const QString &name, const QString &text) { - SetIncrementAttribute(name, IncrementFormula, text); + SetIncrementAttribute(name, AttrFormula, text); } //--------------------------------------------------------------------------------------------------------------------- void VPattern::SetIncrementDescription(const QString &name, const QString &text) { - SetIncrementAttribute(name, IncrementDescription, text); + SetIncrementAttribute(name, AttrDescription, text); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index a07196c68..c6f701026 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -38,6 +38,7 @@ schema/pattern/v0.6.1.xsd schema/pattern/v0.6.2.xsd schema/pattern/v0.6.3.xsd + schema/pattern/v0.6.4.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.6.4.xsd b/src/libs/ifc/schema/pattern/v0.6.4.xsd new file mode 100644 index 000000000..ad9dc1934 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.6.4.xsd @@ -0,0 +1,985 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 1e442e673..5c26c377b 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -88,7 +88,9 @@ const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer") const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel"); const QString VAbstractPattern::TagPatternMaterials = QStringLiteral("patternMaterials"); +const QString VAbstractPattern::TagFinalMeasurements= QStringLiteral("finalMeasurements"); const QString VAbstractPattern::TagMaterial = QStringLiteral("material"); +const QString VAbstractPattern::TagFMeasurement = QStringLiteral("finalMeasurment"); const QString VAbstractPattern::TagGrainline = QStringLiteral("grainline"); const QString VAbstractPattern::TagPath = QStringLiteral("path"); const QString VAbstractPattern::TagNodes = QStringLiteral("nodes"); @@ -187,9 +189,8 @@ const QString VAbstractPattern::AttrDefHeight = QStringLiteral("defHeight" const QString VAbstractPattern::AttrDefSize = QStringLiteral("defSize"); const QString VAbstractPattern::AttrExtension = QStringLiteral("extension"); -const QString VAbstractPattern::IncrementName = QStringLiteral("name"); -const QString VAbstractPattern::IncrementFormula = QStringLiteral("formula"); -const QString VAbstractPattern::IncrementDescription = QStringLiteral("description"); +const QString VAbstractPattern::AttrFormula = QStringLiteral("formula"); +const QString VAbstractPattern::AttrDescription = QStringLiteral("description"); const QString VAbstractPattern::NodeArc = QStringLiteral("NodeArc"); const QString VAbstractPattern::NodeElArc = QStringLiteral("NodeElArc"); @@ -1444,6 +1445,28 @@ QMap VAbstractPattern::GetPatternMaterials() const return patternMaterials; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractPattern::GetFinalMeasurements() const +{ + const QDomNodeList list = elementsByTagName(TagFinalMeasurements); + if (list.isEmpty() || list.at(0).childNodes().count() == 0) + { + return QVector(); + } + + return GetFMeasurements(list.at(0).toElement()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetFinalMeasurements(const QVector &measurements) +{ + QDomElement tag = CheckTagExists(TagFinalMeasurements); + RemoveAllChildren(tag); + SetFMeasurements(tag, measurements); + modified = true; + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetPatternWasChanged(bool changed) { @@ -1598,7 +1621,8 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagPatternLabel << TagPatternMaterials; + << TagCustomerName << TagPatternLabel << TagPatternMaterials + << TagFinalMeasurements; switch (tags.indexOf(tag)) { case 1: //TagImage @@ -1641,6 +1665,9 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) case 10: // TagPatternMaterials element = createElement(TagPatternMaterials); break; + case 11: // TagFinalMeasurements + element = createElement(TagFinalMeasurements); + break; case 0: //TagUnit (Mandatory tag) default: return QDomElement(); @@ -1703,7 +1730,7 @@ QStringList VAbstractPattern::ListIncrements() const try { - increments.append(GetParametrString(dom, IncrementName)); + increments.append(GetParametrString(dom, AttrName)); } catch (VExceptionEmptyParameter &e) { @@ -1853,7 +1880,7 @@ QVector VAbstractPattern::ListIncrementExpressions() const { const QDomElement dom = list.at(i).toElement(); - ReadExpressionAttribute(expressions, dom, IncrementFormula); + ReadExpressionAttribute(expressions, dom, AttrFormula); } return expressions; @@ -2103,6 +2130,51 @@ void VAbstractPattern::SetMaterials(QDomElement &element, const QMap VAbstractPattern::GetFMeasurements(const QDomElement &element) const +{ + QVector measurements; + + if (not element.isNull()) + { + QDomElement tagFMeasurement = element.firstChildElement(); + while (not tagFMeasurement.isNull()) + { + if (tagFMeasurement.tagName() == TagFMeasurement) + { + VFinalMeasurement m; + + m.name = GetParametrString(tagFMeasurement, AttrName, tr("measurement")); + m.formula = GetParametrString(tagFMeasurement, AttrFormula, "0"); + m.description = GetParametrEmptyString(tagFMeasurement, AttrDescription); + + measurements.append(m); + } + tagFMeasurement = tagFMeasurement.nextSiblingElement(TagFMeasurement); + } + } + + return measurements; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetFMeasurements(QDomElement &element, const QVector &measurements) +{ + if (not element.isNull()) + { + for (int i=0; i < measurements.size(); ++i) + { + QDomElement tagFMeasurement = createElement(TagFMeasurement); + + SetAttribute(tagFMeasurement, AttrName, measurements.at(i).name); + SetAttribute(tagFMeasurement, AttrFormula, measurements.at(i).formula); + SetAttribute(tagFMeasurement, AttrDescription, measurements.at(i).description); + + element.appendChild(tagFMeasurement); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief IsModified state of the document for cases that do not cover QUndoStack. diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 6b5ae7b76..b10b39391 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -70,6 +70,13 @@ struct VFormulaField QString attribute; }; +struct VFinalMeasurement +{ + QString name; + QString formula; + QString description; +}; + QT_WARNING_POP class VAbstractPattern : public QObject, public VDomDocument @@ -163,6 +170,9 @@ public: void SetPatternMaterials(const QMap &materials); QMap GetPatternMaterials() const; + QVector GetFinalMeasurements() const; + void SetFinalMeasurements(const QVector &measurements); + void SetPatternWasChanged(bool changed); bool GetPatternWasChanged() const; @@ -221,7 +231,9 @@ public: static const QString TagCustomerName; static const QString TagPatternLabel; static const QString TagPatternMaterials; + static const QString TagFinalMeasurements; static const QString TagMaterial; + static const QString TagFMeasurement; static const QString TagGrainline; static const QString TagPath; static const QString TagNodes; @@ -320,9 +332,8 @@ public: static const QString AttrDefSize; static const QString AttrExtension; - static const QString IncrementName; - static const QString IncrementFormula; - static const QString IncrementDescription; + static const QString AttrFormula; + static const QString AttrDescription; static const QString NodeArc; static const QString NodeElArc; @@ -444,6 +455,9 @@ private: QMap GetMaterials(const QDomElement &element) const; void SetMaterials(QDomElement &element, const QMap &materials); + + QVector GetFMeasurements(const QDomElement &element) const; + void SetFMeasurements(QDomElement &element, const QVector &measurements); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index beca47c34..ae7fa52fa 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.6.3"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.6.3.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.6.4"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.6.4.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -250,6 +250,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000602): return QStringLiteral("://schema/pattern/v0.6.2.xsd"); case (0x000603): + return QStringLiteral("://schema/pattern/v0.6.3.xsd"); + case (0x000604): return CurrentSchema; default: InvalidVersion(ver); @@ -412,6 +414,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000603), m_convertedFileName); V_FALLTHROUGH case (0x000603): + ToV0_6_4(); + ValidateXML(XSDSchema(0x000604), m_convertedFileName); + V_FALLTHROUGH + case (0x000604): break; default: InvalidVersion(m_ver); @@ -430,7 +436,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 6, 3), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 6, 4), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -864,6 +870,16 @@ void VPatternConverter::ToV0_6_3() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_6_4() +{ + // TODO. Delete if minimal supported version is 0.6.4 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 6, 4), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.6.4")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 441cbd584..e6b83b7dc 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 6, 3); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 6, 4); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -109,6 +109,7 @@ private: void ToV0_6_1(); void ToV0_6_2(); void ToV0_6_3(); + void ToV0_6_4(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0();