diff --git a/src/libs/ifc/xml/vabstractmconverter.cpp b/src/libs/ifc/xml/vabstractmconverter.cpp index e43892fba..e1c22fe0d 100644 --- a/src/libs/ifc/xml/vabstractmconverter.cpp +++ b/src/libs/ifc/xml/vabstractmconverter.cpp @@ -40,7 +40,7 @@ VAbstractMConverter::~VAbstractMConverter() } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractMConverter::AddRootCommentV0_3_0() +void VAbstractMConverter::AddRootComment() { const QString rootComment = QStringLiteral("Measurements created with Valentina (http://www.valentina-project.org/)."); diff --git a/src/libs/ifc/xml/vabstractmconverter.h b/src/libs/ifc/xml/vabstractmconverter.h index a4f94902e..c31ff71a5 100644 --- a/src/libs/ifc/xml/vabstractmconverter.h +++ b/src/libs/ifc/xml/vabstractmconverter.h @@ -38,7 +38,7 @@ public: virtual ~VAbstractMConverter() Q_DECL_OVERRIDE; protected: - void AddRootCommentV0_3_0(); + void AddRootComment(); static QMultiMap OldNamesToNewNames_InV0_3_0(); private: diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp index caabccab3..6775fe3e6 100644 --- a/src/libs/ifc/xml/vvitconverter.cpp +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -219,7 +219,7 @@ QDomElement VVITConverter::AddMV0_3_0(const QString &name, qreal value) //--------------------------------------------------------------------------------------------------------------------- void VVITConverter::ToV0_3_0() { - AddRootCommentV0_3_0(); + AddRootComment(); SetVersion(QStringLiteral("0.3.0")); AddNewTagsForV0_3_0(); ConvertMeasurementsToV0_3_0(); diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp index 84a2cb5c3..6e0668590 100644 --- a/src/libs/ifc/xml/vvstconverter.cpp +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -137,9 +137,120 @@ void VVSTConverter::ApplyPatches() } } +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::AddNewTagsForV0_4_0() +{ + QDomElement rootElement = this->documentElement(); + QDomNode refChild = rootElement.firstChildElement("version"); + + { + QDomElement ro = createElement(QStringLiteral("read-only")); + const QDomText roNodeText = createTextNode("false"); + ro.appendChild(roNodeText); + refChild = rootElement.insertAfter(ro, refChild); + } + + { + QDomElement notes = createElement(QStringLiteral("notes")); + const QDomText nodeText = createTextNode(UniqueTagText(QStringLiteral("description"))); + notes.appendChild(nodeText); + rootElement.insertAfter(notes, refChild); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::RemoveTagsForV0_4_0() +{ + QDomElement rootElement = this->documentElement(); + + { + const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("description")); + if (not nodeList.isEmpty()) + { + rootElement.removeChild(nodeList.at(0)); + } + } + + { + const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("id")); + if (not nodeList.isEmpty()) + { + rootElement.removeChild(nodeList.at(0)); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::ConvertMeasurementsToV0_4_0() +{ + const QString tagBM = QStringLiteral("body-measurements"); + + QDomElement bm = createElement(tagBM); + + QMultiMap names = OldNamesToNewNames_InV0_3_0(); + + QMutableMapIterator iter( names ); + while( iter.hasNext() ) + { + iter.next(); + + qreal resValue = 0; + qreal resSizeIncrease = 0; + qreal resHeightIncrease = 0; + + // This has the same effect as a .values(), just isn't as elegant + const QList list = names.values( iter.key() ); + foreach(const QString &val, list ) + { + const QDomNodeList nodeList = this->elementsByTagName(val); + if (nodeList.isEmpty()) + { + continue; + } + + QDomElement m = nodeList.at(0).toElement(); + const qreal value = GetParametrDouble(m, QStringLiteral("value"), "0.0"); + const qreal size_increase = GetParametrDouble(m, QStringLiteral("size_increase"), "0.0"); + const qreal height_increase = GetParametrDouble(m, QStringLiteral("height_increase"), "0.0"); + + if (not qFuzzyIsNull(value)) + { + resValue = value; + resSizeIncrease = size_increase; + resHeightIncrease = height_increase; + } + } + + bm.appendChild(AddMV0_4_0(iter.key(), resValue, resSizeIncrease, resHeightIncrease)); + } + + QDomElement rootElement = this->documentElement(); + const QDomNodeList listBM = elementsByTagName(tagBM); + rootElement.replaceChild(bm, listBM.at(0)); +} + +//--------------------------------------------------------------------------------------------------------------------- +QDomElement VVSTConverter::AddMV0_4_0(const QString &name, qreal value, qreal sizeIncrease, qreal heightIncrease) +{ + QDomElement element = createElement(QStringLiteral("m")); + + SetAttribute(element, QStringLiteral("name"), name); + SetAttribute(element, QStringLiteral("base"), QString().setNum(value)); + SetAttribute(element, QStringLiteral("size_increase"), QString().setNum(sizeIncrease)); + SetAttribute(element, QStringLiteral("height_increase"), QString().setNum(heightIncrease)); + SetAttribute(element, QStringLiteral("description"), QString("")); + SetAttribute(element, QStringLiteral("full_name"), QString("")); + + return element; +} + //--------------------------------------------------------------------------------------------------------------------- void VVSTConverter::ToV0_4_0() { + AddRootComment(); SetVersion(QStringLiteral("0.4.0")); + AddNewTagsForV0_4_0(); + RemoveTagsForV0_4_0(); + ConvertMeasurementsToV0_4_0(); Save(); } diff --git a/src/libs/ifc/xml/vvstconverter.h b/src/libs/ifc/xml/vvstconverter.h index f360ce6eb..5ed54f0f1 100644 --- a/src/libs/ifc/xml/vvstconverter.h +++ b/src/libs/ifc/xml/vvstconverter.h @@ -55,6 +55,11 @@ private: Q_DISABLE_COPY(VVSTConverter) static const QString MeasurementMinVerStr; + void AddNewTagsForV0_4_0(); + void RemoveTagsForV0_4_0(); + void ConvertMeasurementsToV0_4_0(); + QDomElement AddMV0_4_0(const QString &name, qreal value, qreal sizeIncrease, qreal heightIncrease); + void ToV0_4_0(); };