Added custom increment and decrement methods for tool VToolPiecePath.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-29 14:58:00 +02:00
parent 14962270f6
commit b3f3f03cc3
2 changed files with 75 additions and 0 deletions

View File

@ -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<VGObject> 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<VGObject> node = VAbstractTool::data.GetGObject(path.at(i).GetId());
doc->DecrementReferens(node->getIdTool());
}
}

View File

@ -50,6 +50,9 @@ public:
enum { Type = UserType + static_cast<int>(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