From 5442eb40b923ec2f768197b155878adc3e92979a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 16 Jan 2017 11:59:02 +0200 Subject: [PATCH] Move methods to class VAbstractPattern to be able to use them for tool Unite Details. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 63 +------------------------ src/app/valentina/xml/vpattern.h | 2 - src/libs/ifc/xml/vabstractpattern.cpp | 66 ++++++++++++++++++++++++++- src/libs/ifc/xml/vabstractpattern.h | 7 ++- src/libs/ifc/xml/vdomdocument.cpp | 22 ++++----- src/libs/ifc/xml/vdomdocument.h | 16 +++---- 6 files changed, 91 insertions(+), 85 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 155705c29..1c5d0b82b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -562,53 +562,6 @@ VNodeDetail VPattern::ParseDetailNode(const QDomElement &domElement) const return VNodeDetail(id, tool, nodeType, mx, my, reverse); } -//--------------------------------------------------------------------------------------------------------------------- -VPieceNode VPattern::ParseSANode(const QDomElement &domElement) const -{ - const quint32 id = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); - const bool reverse = GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0"); - const qreal saBefore = GetParametrDouble(domElement, VAbstractPattern::AttrSABefore, "-1"); - const qreal saAfter = GetParametrDouble(domElement, VAbstractPattern::AttrSAAfter, "-1"); - const PieceNodeAngle angle = static_cast(GetParametrUInt(domElement, AttrAngle, "0")); - - const QString t = GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint); - Tool tool; - - const QStringList types = QStringList() << VAbstractPattern::NodePoint - << VAbstractPattern::NodeArc - << VAbstractPattern::NodeSpline - << VAbstractPattern::NodeSplinePath - << VAbstractPattern::NodeElArc; - - switch (types.indexOf(t)) - { - case 0: // VAbstractPattern::NodePoint - tool = Tool::NodePoint; - break; - case 1: // VAbstractPattern::NodeArc - tool = Tool::NodeArc; - break; - case 2: // VAbstractPattern::NodeSpline - tool = Tool::NodeSpline; - break; - case 3: // VAbstractPattern::NodeSplinePath - tool = Tool::NodeSplinePath; - break; - case 4: // NodeElArc - tool = Tool::NodeElArc; - break; - default: - VException e(tr("Wrong tag name '%1'.").arg(t)); - throw e; - } - VPieceNode node(id, tool, reverse); - node.SetSABefore(saBefore); - node.SetSAAfter(saAfter); - node.SetAngleType(angle); - - return node; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseDrawElement parse draw tag. @@ -782,7 +735,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } else { - ParsePieceNodes(element, detail); + detail.SetPath(ParsePieceNodes(element)); } break; case 1:// TagData @@ -832,20 +785,6 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, b detail.GetPath().SetNodes(VNodeDetail::Convert(data, oldNodes, detail.GetSAWidth(), closed)); } -//--------------------------------------------------------------------------------------------------------------------- -void VPattern::ParsePieceNodes(const QDomElement &domElement, VPiece &detail) const -{ - const QDomNodeList nodeList = domElement.childNodes(); - for (qint32 i = 0; i < nodeList.size(); ++i) - { - const QDomElement element = nodeList.at(i).toElement(); - if (not element.isNull()) - { - detail.GetPath().Append(ParseSANode(element)); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePieceCSARecords(const QDomElement &domElement, VPiece &detail) const { diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 8b444e36e..49da3ab46 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -115,13 +115,11 @@ private: VMainGraphicsScene *sceneDetail; VNodeDetail ParseDetailNode(const QDomElement &domElement) const; - VPieceNode ParseSANode(const QDomElement &domElement) const; void ParseDrawElement(const QDomNode& node, const Document &parse); void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); void ParseDetailElement(const QDomElement &domElement, const Document &parse); void ParseDetailNodes(const QDomElement &domElement, VPiece &detail, bool closed) const; - void ParsePieceNodes(const QDomElement &domElement, VPiece &detail) const; void ParsePieceCSARecords(const QDomElement &domElement, VPiece &detail) const; void ParsePieceInternalPaths(const QDomElement &domElement, VPiece &detail) const; void ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index c30ee0164..5f04dfa3e 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -45,6 +45,7 @@ #include "../ifc/exception/vexceptionbadid.h" #include "../ifc/ifcdef.h" #include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vpiecenode.h" #include "../vtools/tools/vdatatool.h" #include "vpatternconverter.h" #include "vdomdocument.h" @@ -555,7 +556,70 @@ void VAbstractPattern::AddTool(const quint32 &id, VDataTool *tool) { Q_ASSERT_X(id != 0, Q_FUNC_INFO, "id == 0"); SCASSERT(tool != nullptr) - tools.insert(id, tool); + tools.insert(id, tool); +} + +//--------------------------------------------------------------------------------------------------------------------- +VPiecePath VAbstractPattern::ParsePieceNodes(const QDomElement &domElement) +{ + VPiecePath path; + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (not element.isNull()) + { + path.Append(ParseSANode(element)); + } + } + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPieceNode VAbstractPattern::ParseSANode(const QDomElement &domElement) +{ + const quint32 id = VDomDocument::GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); + const bool reverse = VDomDocument::GetParametrUInt(domElement, VAbstractPattern::AttrNodeReverse, "0"); + const qreal saBefore = VDomDocument::GetParametrDouble(domElement, VAbstractPattern::AttrSABefore, "-1"); + const qreal saAfter = VDomDocument::GetParametrDouble(domElement, VAbstractPattern::AttrSAAfter, "-1"); + const PieceNodeAngle angle = static_cast(VDomDocument::GetParametrUInt(domElement, AttrAngle, "0")); + + const QString t = VDomDocument::GetParametrString(domElement, AttrType, VAbstractPattern::NodePoint); + Tool tool; + + const QStringList types = QStringList() << VAbstractPattern::NodePoint + << VAbstractPattern::NodeArc + << VAbstractPattern::NodeSpline + << VAbstractPattern::NodeSplinePath + << VAbstractPattern::NodeElArc; + + switch (types.indexOf(t)) + { + case 0: // VAbstractPattern::NodePoint + tool = Tool::NodePoint; + break; + case 1: // VAbstractPattern::NodeArc + tool = Tool::NodeArc; + break; + case 2: // VAbstractPattern::NodeSpline + tool = Tool::NodeSpline; + break; + case 3: // VAbstractPattern::NodeSplinePath + tool = Tool::NodeSplinePath; + break; + case 4: // NodeElArc + tool = Tool::NodeElArc; + break; + default: + VException e(QObject::tr("Wrong tag name '%1'.").arg(t)); + throw e; + } + VPieceNode node(id, tool, reverse); + node.SetSABefore(saBefore); + node.SetSAAfter(saAfter); + node.SetAngleType(angle); + + return node; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 1e2c8e34c..a8d6052e6 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -45,6 +45,8 @@ #include "vtoolrecord.h" class QDomElement; +class VPiecePath; +class VPieceNode; enum class Document : char { LiteParse, LitePPParse, FullParse }; enum class LabelType : char {NewPatternPiece, NewLabel}; @@ -93,6 +95,8 @@ public: static VDataTool* getTool(const quint32 &id); static void AddTool(const quint32 &id, VDataTool *tool); + static VPiecePath ParsePieceNodes(const QDomElement &domElement); + void AddToolOnRemove(VDataTool *tool); QVector *getHistory(); @@ -344,7 +348,8 @@ protected: /** @brief tools list with pointer on tools. */ static QHash tools; - static void ToolExists(const quint32 &id); + static void ToolExists(const quint32 &id); + static VPieceNode ParseSANode(const QDomElement &domElement); void SetActivPP(const QString& name); diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 307ffeb16..f8efed3e9 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -203,7 +203,7 @@ bool VDomDocument::find(const QDomElement &node, const QString& id) * @param name attribute name * @return long long value */ -quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue) const +quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QString &name, const QString &defValue) { Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); //-V591 @@ -212,7 +212,7 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri QString parametr; quint32 id = 0; - QString message = tr("Can't convert toUInt parameter"); + const QString message = QObject::tr("Can't convert toUInt parameter"); try { parametr = GetParametrString(domElement, name, defValue); @@ -233,7 +233,7 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri } //--------------------------------------------------------------------------------------------------------------------- -bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue) const +bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue) { Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); @@ -241,7 +241,7 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString QString parametr; bool val = true; - QString message = tr("Can't convert toBool parameter"); + const QString message = QObject::tr("Can't convert toBool parameter"); try { parametr = GetParametrString(domElement, name, defValue); @@ -280,7 +280,7 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString } //--------------------------------------------------------------------------------------------------------------------- -NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name) const +NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name) { const bool value = GetParametrBool(domElement, name, trueStr); if (value) @@ -315,7 +315,7 @@ void VDomDocument::SetParametrUsage(QDomElement &domElement, const QString &name * @throw VExceptionEmptyParameter when attribute is empty */ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name, - const QString &defValue) const + const QString &defValue) { Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); @@ -324,7 +324,7 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt { if (defValue.isEmpty()) { - throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement); + throw VExceptionEmptyParameter(QObject::tr("Got empty parameter"), name, domElement); } else { @@ -341,7 +341,7 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt * @param name attribute name * @return double value */ -qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue) const +qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name, const QString &defValue) { Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); @@ -349,7 +349,7 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri bool ok = false; qreal param = 0; - QString message = tr("Can't convert toDouble parameter"); + const QString message = QObject::tr("Can't convert toDouble parameter"); try { QString parametr = GetParametrString(domElement, name, defValue); @@ -374,13 +374,13 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri * @param domElement tag in xml tree. * @return id value. */ -quint32 VDomDocument::GetParametrId(const QDomElement &domElement) const +quint32 VDomDocument::GetParametrId(const QDomElement &domElement) { Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); quint32 id = NULL_ID; - const QString message = tr("Got wrong parameter id. Need only id > 0."); + const QString message = QObject::tr("Got wrong parameter id. Need only id > 0."); try { id = GetParametrUInt(domElement, VDomDocument::AttrId, NULL_ID_STR); diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 1d1ed589b..540be9aea 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -96,16 +96,16 @@ public: template void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const; - quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const; - bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const; + static quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue); + static bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue); - NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name) const; - void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value); + static NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name); + static void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value); - 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 QString GetParametrString(const QDomElement& domElement, const QString &name, + const QString &defValue = QString()); + static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue); + static quint32 GetParametrId(const QDomElement& domElement); static void ValidateXML(const QString &schema, const QString &fileName); virtual void setXMLContent(const QString &fileName);