From 9c63c4f794416a249ea0136ae8bf247a59565944 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 6 Apr 2016 12:36:33 +0300 Subject: [PATCH] The method SetGroupName. --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 32 +++++++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.h | 1 + src/libs/vtools/undocommands/addgroup.cpp | 6 +++++ 3 files changed, 39 insertions(+) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index c532ce063..d723c0365 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1494,3 +1494,35 @@ QDomElement VAbstractPattern::CreateGroup(quint32 id, const QString &name, const return group; } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetGroupName(quint32 id, const QString &name) +{ + QDomElement groups = CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = elementById(id); + if (group.isElement()) + { + group.setAttribute(AttrName, name); + modified = true; + emit patternChanged(false); + } + else + { + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + + qDebug("Can't get group by id = %u.", id); + return; + } + } + else + { + qDebug("Can't get tag Groups."); + return; + } +} diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 77ada5d8a..90e8c1b3c 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -118,6 +118,7 @@ public: QDomElement CreateGroups(); QDomElement CreateGroup(quint32 id, const QString &name, const QMap &groupData); + void SetGroupName(quint32 id, const QString &name); static const QString TagPattern; static const QString TagCalculation; diff --git a/src/libs/vtools/undocommands/addgroup.cpp b/src/libs/vtools/undocommands/addgroup.cpp index b4b86ef90..2a5bdf65b 100644 --- a/src/libs/vtools/undocommands/addgroup.cpp +++ b/src/libs/vtools/undocommands/addgroup.cpp @@ -67,6 +67,12 @@ void AddGroup::undo() } else { + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); return; }