Add Valentina version info inside each file before saving.

Many misunderstand purpose of tag "version" and think that this tag contains
information about the Valentina version. More info in the comment should help.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-05-29 16:33:36 +03:00
parent 39a7fcd743
commit 9287acf90e
6 changed files with 50 additions and 8 deletions

View File

@ -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<quint32> 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"))
{

View File

@ -62,7 +62,7 @@ public:
QVector<quint32> 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;

View File

@ -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())
{

View File

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

View File

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

View File

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