From b3f3f03cc30af348d2a19187d16b89cac5d16a7c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 29 Nov 2016 14:58:00 +0200 Subject: [PATCH] Added custom increment and decrement methods for tool VToolPiecePath. --HG-- branch : feature --- .../tools/nodeDetails/vtoolpiecepath.cpp | 69 +++++++++++++++++++ .../vtools/tools/nodeDetails/vtoolpiecepath.h | 6 ++ 2 files changed, 75 insertions(+) diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index d4c54609a..48c804129 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -98,6 +98,55 @@ QString VToolPiecePath::getTagName() const return VAbstractPattern::TagPath; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::incrementReferens() +{ + ++_referens; + if (_referens == 1) + { + if (idTool != NULL_ID) + { + doc->IncrementReferens(idTool); + } + else + { + IncrementNodes(VAbstractTool::data.GetPiecePath(id)); + } + ShowNode(); + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::decrementReferens() +{ + if (_referens > 0) + { + --_referens; + } + if (_referens == 0) + { + if (idTool != NULL_ID) + { + doc->DecrementReferens(idTool); + } + else + { + DecrementNodes(VAbstractTool::data.GetPiecePath(id)); + } + HideNode(); + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolPiecePath::AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node) { @@ -241,3 +290,23 @@ void VToolPiecePath::RefreshGeometry() this->setPath(p); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::IncrementNodes(const VPiecePath &path) const +{ + for (int i = 0; i < path.CountNodes(); ++i) + { + const QSharedPointer node = VAbstractTool::data.GetGObject(path.at(i).GetId()); + doc->IncrementReferens(node->getIdTool()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::DecrementNodes(const VPiecePath &path) const +{ + for (int i = 0; i < path.CountNodes(); ++i) + { + const QSharedPointer node = VAbstractTool::data.GetGObject(path.at(i).GetId()); + doc->DecrementReferens(node->getIdTool()); + } +} diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h index 18f4e236d..edc8e2273 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h @@ -50,6 +50,9 @@ public: enum { Type = UserType + static_cast(Tool::PiecePath)}; virtual QString getTagName() const Q_DECL_OVERRIDE; + virtual void incrementReferens() Q_DECL_OVERRIDE; + virtual void decrementReferens() Q_DECL_OVERRIDE; + static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node); static void AddNodes(VAbstractPattern *doc, QDomElement &domElement, const VPiecePath &path); static void AddAttributes(VAbstractPattern *doc, QDomElement &domElement, quint32 id, const VPiecePath &path); @@ -72,6 +75,9 @@ private: QGraphicsItem * parent = nullptr ); void RefreshGeometry(); + + void IncrementNodes(const VPiecePath &path) const; + void DecrementNodes(const VPiecePath &path) const; }; #endif // VTOOLPIECEPATH_H