Preparation for new changes in pattern format.
--HG-- branch : feature
This commit is contained in:
parent
9621904b97
commit
ad96323e29
|
@ -514,16 +514,6 @@ void VPattern::DecrementReferens(quint32 id) const
|
|||
tool->decrementReferens();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief TestUniqueId test exist unique id in pattern file. Each id must be unique.
|
||||
*/
|
||||
void VPattern::TestUniqueId() const
|
||||
{
|
||||
QVector<quint32> vector;
|
||||
CollectId(documentElement(), vector);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief SPointActiveDraw return id base point current pattern peace.
|
||||
|
@ -717,7 +707,7 @@ MeasurementsType VPattern::MType() const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VPattern::SaveDocument(const QString &fileName, QString &error)
|
||||
bool VPattern::SaveDocument(const QString &fileName, QString &error) const
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -2075,36 +2065,6 @@ void VPattern::ParseIncrementsElement(const QDomNode &node)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief GetParametrId return value id attribute.
|
||||
* @param domElement tag in xml tree.
|
||||
* @return id value.
|
||||
*/
|
||||
quint32 VPattern::GetParametrId(const QDomElement &domElement) const
|
||||
{
|
||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||
|
||||
quint32 id = 0;
|
||||
|
||||
QString message = tr("Got wrong parameter id. Need only id > 0.");
|
||||
try
|
||||
{
|
||||
id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR);
|
||||
if (id <= 0)
|
||||
{
|
||||
throw VExceptionWrongId(message, domElement);
|
||||
}
|
||||
}
|
||||
catch (const VExceptionConversionError &e)
|
||||
{
|
||||
VExceptionWrongId excep(message, domElement);
|
||||
excep.AddMoreInformation(e.ErrorMessage());
|
||||
throw excep;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<GHeights, bool> VPattern::GetGradationHeights() const
|
||||
{
|
||||
|
@ -2507,34 +2467,6 @@ QString VPattern::GenerateLabel(const LabelType &type) const
|
|||
return QString();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique.
|
||||
* @param node tag in xml tree.
|
||||
* @param vector list with ids.
|
||||
*/
|
||||
void VPattern::CollectId(const QDomElement &node, QVector<quint32> &vector) const
|
||||
{
|
||||
if (node.hasAttribute(VDomDocument::AttrId))
|
||||
{
|
||||
const quint32 id = GetParametrId(node);
|
||||
if (vector.contains(id))
|
||||
{
|
||||
throw VExceptionWrongId(tr("This id is not unique."), node);
|
||||
}
|
||||
vector.append(id);
|
||||
}
|
||||
|
||||
for (qint32 i=0; i<node.childNodes().length(); ++i)
|
||||
{
|
||||
const QDomNode n = node.childNodes().at(i);
|
||||
if (n.isElement())
|
||||
{
|
||||
CollectId(n.toElement(), vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPattern::PrepareForParse(const Document &parse)
|
||||
{
|
||||
|
|
|
@ -71,7 +71,6 @@ public:
|
|||
void UpdateToolData(const quint32 &id, VContainer *data);
|
||||
void IncrementReferens(quint32 id) const;
|
||||
void DecrementReferens(quint32 id) const;
|
||||
void TestUniqueId() const;
|
||||
quint32 SPointActiveDraw();
|
||||
bool isPatternModified() const;
|
||||
void setPatternModified(bool value);
|
||||
|
@ -150,10 +149,9 @@ public:
|
|||
static const QString IncrementKgrowth;
|
||||
static const QString IncrementDescription;
|
||||
|
||||
virtual bool SaveDocument(const QString &fileName, QString &error);
|
||||
virtual bool SaveDocument(const QString &fileName, QString &error) const;
|
||||
QStringList getPatternPieces() const;
|
||||
QRectF ActiveDrawBoundingRect() const;
|
||||
quint32 GetParametrId(const QDomElement& domElement) const;
|
||||
|
||||
QMap<GHeights, bool> GetGradationHeights() const;
|
||||
void SetGradationHeights(const QMap<GHeights, bool> &options);
|
||||
|
@ -265,7 +263,6 @@ private:
|
|||
void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement,
|
||||
const Document &parse, const QString& type);
|
||||
void ParseIncrementsElement(const QDomNode& node);
|
||||
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
|
||||
void PrepareForParse(const Document &parse);
|
||||
void UpdateMeasurements();
|
||||
void ToolsCommonAttributes(const QDomElement &domElement, quint32 &id);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "vabstractconverter.h"
|
||||
#include "exception/vexception.h"
|
||||
#include "exception/vexceptionwrongid.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
|
@ -45,7 +46,7 @@ VAbstractConverter::~VAbstractConverter()
|
|||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::Convert() const
|
||||
void VAbstractConverter::Convert()
|
||||
{
|
||||
if (ver == MaxVer())
|
||||
{
|
||||
|
@ -158,3 +159,40 @@ void VAbstractConverter::CheckVersion(int ver) const
|
|||
throw VException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VAbstractConverter::SaveDocument(const QString &fileName, QString &error) const
|
||||
{
|
||||
try
|
||||
{
|
||||
TestUniqueId();
|
||||
}
|
||||
catch (const VExceptionWrongId &e)
|
||||
{
|
||||
error = tr("Error no unique id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return VDomDocument::SaveDocument(fileName, error);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::Save() const
|
||||
{
|
||||
QString error;
|
||||
if (SaveDocument(fileName, error) == false)
|
||||
{
|
||||
VException e(error);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VAbstractConverter::SetVersion(const QString &version)
|
||||
{
|
||||
if (setTagText(TagVersion, version) == false)
|
||||
{
|
||||
VException e(tr("Could not change version."));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ public:
|
|||
VAbstractConverter(const QString &fileName);
|
||||
virtual ~VAbstractConverter();
|
||||
|
||||
void Convert() const;
|
||||
void Convert();
|
||||
virtual bool SaveDocument(const QString &fileName, QString &error) const;
|
||||
|
||||
protected:
|
||||
int ver;
|
||||
|
@ -46,6 +47,8 @@ protected:
|
|||
|
||||
int GetVersion(const QString &version) const;
|
||||
void CheckVersion(int ver) const;
|
||||
void Save() const;
|
||||
void SetVersion(const QString &version);
|
||||
|
||||
virtual int MinVer() const =0;
|
||||
virtual int MaxVer() const =0;
|
||||
|
@ -54,7 +57,7 @@ protected:
|
|||
virtual QString MaxVerStr() const =0;
|
||||
|
||||
virtual QString XSDSchema(int ver) const =0;
|
||||
virtual void ApplyPatches() const =0;
|
||||
virtual void ApplyPatches() =0;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VAbstractConverter)
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "exception/vexceptionconversionerror.h"
|
||||
#include "exception/vexceptionemptyparameter.h"
|
||||
#include "exception/vexceptionbadid.h"
|
||||
#include "exception/vexceptionwrongid.h"
|
||||
|
||||
#include <QAbstractMessageHandler>
|
||||
#include <QXmlSchema>
|
||||
|
@ -323,6 +324,36 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
|
|||
return param;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief GetParametrId return value id attribute.
|
||||
* @param domElement tag in xml tree.
|
||||
* @return id value.
|
||||
*/
|
||||
quint32 VDomDocument::GetParametrId(const QDomElement &domElement) const
|
||||
{
|
||||
Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null");
|
||||
|
||||
quint32 id = 0;
|
||||
|
||||
QString message = tr("Got wrong parameter id. Need only id > 0.");
|
||||
try
|
||||
{
|
||||
id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR);
|
||||
if (id <= 0)
|
||||
{
|
||||
throw VExceptionWrongId(message, domElement);
|
||||
}
|
||||
}
|
||||
catch (const VExceptionConversionError &e)
|
||||
{
|
||||
VExceptionWrongId excep(message, domElement);
|
||||
excep.AddMoreInformation(e.ErrorMessage());
|
||||
throw excep;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVal) const
|
||||
{
|
||||
|
@ -346,6 +377,39 @@ QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVa
|
|||
return defVal;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief TestUniqueId test exist unique id in pattern file. Each id must be unique.
|
||||
*/
|
||||
void VDomDocument::TestUniqueId() const
|
||||
{
|
||||
QVector<quint32> vector;
|
||||
CollectId(documentElement(), vector);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VDomDocument::CollectId(const QDomElement &node, QVector<quint32> &vector) const
|
||||
{
|
||||
if (node.hasAttribute(VDomDocument::AttrId))
|
||||
{
|
||||
const quint32 id = GetParametrId(node);
|
||||
if (vector.contains(id))
|
||||
{
|
||||
throw VExceptionWrongId(tr("This id is not unique."), node);
|
||||
}
|
||||
vector.append(id);
|
||||
}
|
||||
|
||||
for (qint32 i=0; i<node.childNodes().length(); ++i)
|
||||
{
|
||||
const QDomNode n = node.childNodes().at(i);
|
||||
if (n.isElement())
|
||||
{
|
||||
CollectId(n.toElement(), vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief ValidateXML validate xml file by xsd schema.
|
||||
|
@ -514,7 +578,7 @@ QString VDomDocument::UnitsToStr(const Unit &unit, const bool translate)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
|
||||
bool VDomDocument::SaveDocument(const QString &fileName, QString &error) const
|
||||
{
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
|
@ -565,13 +629,12 @@ QString VDomDocument::Patch() const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VDomDocument::setTagText(const QString &tag, const QString &text)
|
||||
bool VDomDocument::setTagText(const QString &tag, const QString &text)
|
||||
{
|
||||
const QDomNodeList nodeList = this->elementsByTagName(tag);
|
||||
if (nodeList.isEmpty())
|
||||
{
|
||||
qDebug()<<"Can't save tag "<<tag<<Q_FUNC_INFO;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -587,10 +650,11 @@ void VDomDocument::setTagText(const QString &tag, const QString &text)
|
|||
newTag.appendChild(newTagText);
|
||||
|
||||
parent.replaceChild(newTag, domElement);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -38,11 +38,6 @@
|
|||
|
||||
Q_DECLARE_LOGGING_CATEGORY(vXML)
|
||||
|
||||
/*
|
||||
can be used like #if (V_FORMAT_VERSION >= V_FORMAT_VERSION_CHECK(4, 4, 0))
|
||||
*/
|
||||
#define V_FORMAT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
|
||||
|
||||
#ifdef Q_CC_GNU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
|
@ -104,12 +99,13 @@ public:
|
|||
QString GetParametrString(const QDomElement& domElement, const QString &name,
|
||||
const QString &defValue = QString()) const;
|
||||
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
|
||||
quint32 GetParametrId(const QDomElement& domElement) const;
|
||||
|
||||
static void ValidateXML(const QString &schema, const QString &fileName);
|
||||
void setXMLContent(const QString &fileName);
|
||||
static Unit StrToUnits(const QString &unit);
|
||||
static QString UnitsToStr(const Unit &unit, const bool translate = false);
|
||||
virtual bool SaveDocument(const QString &fileName, QString &error);
|
||||
virtual bool SaveDocument(const QString &fileName, QString &error) const;
|
||||
QString Major() const;
|
||||
QString Minor() const;
|
||||
QString Patch() const;
|
||||
|
@ -118,12 +114,16 @@ public:
|
|||
QDomNode ParentNodeById(const quint32 &nodeId);
|
||||
QDomElement CloneNodeById(const quint32 &nodeId);
|
||||
QDomElement NodeById(const quint32 &nodeId);
|
||||
|
||||
static bool SafeCopy(const QString &source, const QString &destination, QString &error);
|
||||
|
||||
protected:
|
||||
void setTagText(const QString &tag, const QString &text);
|
||||
bool setTagText(const QString &tag, const QString &text);
|
||||
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
|
||||
|
||||
void TestUniqueId() const;
|
||||
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VDomDocument)
|
||||
/** @brief Map used for finding element by id. */
|
||||
|
|
|
@ -87,6 +87,8 @@ QString VPatternConverter::XSDSchema(int ver) const
|
|||
switch(ver)
|
||||
{
|
||||
case (0x000101):
|
||||
// return QStringLiteral("://schema/pattern/v0.1.2.xsd");
|
||||
// case (0x000102):
|
||||
return CurrentSchema;
|
||||
default:
|
||||
{
|
||||
|
@ -98,13 +100,20 @@ QString VPatternConverter::XSDSchema(int ver) const
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPatternConverter::ApplyPatches() const
|
||||
void VPatternConverter::ApplyPatches()
|
||||
{
|
||||
try
|
||||
{
|
||||
switch(ver)
|
||||
{
|
||||
case (0x000101):
|
||||
// {
|
||||
// ToV0_1_2();
|
||||
// const QString schema = XSDSchema(0x000102);
|
||||
// ValidateXML(schema, fileName);
|
||||
// break;
|
||||
// }
|
||||
// case (0x000102):
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -128,3 +137,10 @@ void VPatternConverter::ApplyPatches() const
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
//void VPatternConverter::ToV0_1_2()
|
||||
//{
|
||||
// SetVersion("0.1.2");
|
||||
// Save();
|
||||
//}
|
||||
|
|
|
@ -48,11 +48,13 @@ protected:
|
|||
virtual QString MaxVerStr() const;
|
||||
|
||||
QString XSDSchema(int ver) const;
|
||||
virtual void ApplyPatches() const;
|
||||
virtual void ApplyPatches();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VPatternConverter)
|
||||
static const QString PatternMinVerStr;
|
||||
|
||||
// void ToV0_1_2();
|
||||
};
|
||||
|
||||
#endif // VPATTERNCONVERTER_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user