diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 2baf87b64..9058970f3 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -42,6 +42,7 @@ #include "../vmisc/undoevent.h" #include "../vmisc/vsettings.h" #include "../vmisc/vmath.h" +#include "../vmisc/projectversion.h" #include "../qmuparser/qmuparsererror.h" #include "../vgeometry/varc.h" #include "../vgeometry/vellipticalarc.h" @@ -65,6 +66,15 @@ const QString VPattern::AttrReadOnly = QStringLiteral("readOnly"); +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +QString FileComment() +{ + return QString("Pattern created with Valentina v%1 (http://www.valentina-project.org/).").arg(APP_VERSION_STR); +} +} + //--------------------------------------------------------------------------------------------------------------------- VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, QObject *parent) @@ -83,8 +93,7 @@ void VPattern::CreateEmptyFile() this->clear(); QDomElement patternElement = this->createElement(TagPattern); - patternElement.appendChild( - createComment(QStringLiteral("Pattern created with Valentina (http://www.valentina-project.org/)."))); + patternElement.appendChild(createComment(FileComment())); QDomElement version = createElement(TagVersion); QDomText newNodeText = createTextNode(VPatternConverter::PatternMaxVerStr); @@ -378,7 +387,7 @@ QVector VPattern::GetActivePPPieces() const } //--------------------------------------------------------------------------------------------------------------------- -bool VPattern::SaveDocument(const QString &fileName, QString &error) const +bool VPattern::SaveDocument(const QString &fileName, QString &error) { try { @@ -391,6 +400,14 @@ bool VPattern::SaveDocument(const QString &fileName, QString &error) const return false; } + // Update comment with Valentina version + QDomNode commentNode = documentElement().firstChild(); + if (commentNode.isComment()) + { + QDomComment comment = commentNode.toComment(); + comment.setData(FileComment()); + } + const bool saved = VAbstractPattern::SaveDocument(fileName, error); if (saved && QFileInfo(fileName).suffix() != QLatin1String("autosave")) { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 7ad603a47..9dc6cab3f 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -62,7 +62,7 @@ public: QVector GetActivePPPieces() const; virtual void setXMLContent(const QString &fileName) Q_DECL_OVERRIDE; - virtual bool SaveDocument(const QString &fileName, QString &error) const Q_DECL_OVERRIDE; + virtual bool SaveDocument(const QString &fileName, QString &error) Q_DECL_OVERRIDE; QRectF ActiveDrawBoundingRect() const; diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 9f25ac7d2..732e83ca6 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -728,7 +728,7 @@ QString VDomDocument::UnitsHelpString() } //--------------------------------------------------------------------------------------------------------------------- -bool VDomDocument::SaveDocument(const QString &fileName, QString &error) const +bool VDomDocument::SaveDocument(const QString &fileName, QString &error) { if (fileName.isEmpty()) { diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 0aaac1f92..a1638e256 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -116,7 +116,7 @@ public: static QString UnitsToStr(const Unit &unit, const bool translate = false); static QString UnitsHelpString(); - virtual bool SaveDocument(const QString &fileName, QString &error) const; + virtual bool SaveDocument(const QString &fileName, QString &error); QString Major() const; QString Minor() const; QString Patch() const; diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index cd1ac02d0..0a0003cf6 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -52,6 +52,7 @@ #include "../vpatterndb/calculator.h" #include "../vpatterndb/variables/vmeasurement.h" #include "../vpatterndb/vcontainer.h" +#include "../vmisc/projectversion.h" const QString VMeasurements::TagVST = QStringLiteral("vst"); const QString VMeasurements::TagVIT = QStringLiteral("vit"); @@ -83,6 +84,15 @@ const QString VMeasurements::GenderUnknown = QStringLiteral("unknown"); const QString defBirthDate = QStringLiteral("1800-01-01"); +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +QString FileComment() +{ + return QString("Measurements created with Valentina v%1 (http://www.valentina-project.org/).").arg(APP_VERSION_STR); +} +} + //--------------------------------------------------------------------------------------------------------------------- VMeasurements::VMeasurements(VContainer *data) :VDomDocument(), @@ -121,6 +131,20 @@ void VMeasurements::setXMLContent(const QString &fileName) type = ReadType(); } +//--------------------------------------------------------------------------------------------------------------------- +bool VMeasurements::SaveDocument(const QString &fileName, QString &error) +{ + // Update comment with Valentina version + QDomNode commentNode = documentElement().firstChild(); + if (commentNode.isComment()) + { + QDomComment comment = commentNode.toComment(); + comment.setData(FileComment()); + } + + return VDomDocument::SaveDocument(fileName, error); +} + //--------------------------------------------------------------------------------------------------------------------- void VMeasurements::AddEmpty(const QString &name, const QString &formula) { @@ -676,7 +700,7 @@ void VMeasurements::CreateEmptyStandardFile(Unit unit, int baseSize, int baseHei this->clear(); QDomElement mElement = this->createElement(TagVST); - mElement.appendChild(createComment("Measurements created with Valentina (http://www.valentina-project.org/).")); + mElement.appendChild(createComment(FileComment())); QDomElement version = createElement(TagVersion); const QDomText newNodeText = createTextNode(VVSTConverter::MeasurementMaxVerStr); @@ -719,7 +743,7 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit) this->clear(); QDomElement mElement = this->createElement(TagVIT); - mElement.appendChild(createComment("Measurements created with Valentina (http://www.valentina-project.org/).")); + mElement.appendChild(createComment(FileComment())); QDomElement version = createElement(TagVersion); const QDomText newNodeText = createTextNode(VVITConverter::MeasurementMaxVerStr); diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 5c9ce24b2..da3c57978 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -52,6 +52,7 @@ public: virtual ~VMeasurements() Q_DECL_EQ_DEFAULT; virtual void setXMLContent(const QString &fileName) Q_DECL_OVERRIDE; + virtual bool SaveDocument(const QString &fileName, QString &error) Q_DECL_OVERRIDE; void AddEmpty(const QString &name, const QString &formula = QString()); void AddEmptyAfter(const QString &after, const QString &name, const QString &formula = QString());