From cb67249b54af15f7e9dc2bf06e31470cebb4cdc5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 6 Apr 2016 12:03:34 +0300 Subject: [PATCH] New undo command Add Group. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 8 +- src/app/valentina/xml/vpattern.cpp | 6 +- src/app/valentina/xml/vpattern.h | 4 +- src/libs/ifc/xml/vabstractpattern.cpp | 121 +++++++++++++++--- src/libs/ifc/xml/vabstractpattern.h | 9 +- .../drawTools/toolcurve/vabstractspline.cpp | 7 + .../drawTools/toolcurve/vabstractspline.h | 1 + .../tooldoublepoint/vtooldoublepoint.cpp | 13 ++ .../tooldoublepoint/vtooldoublepoint.h | 1 + .../toolsinglepoint/vtoolsinglepoint.cpp | 7 + .../toolsinglepoint/vtoolsinglepoint.h | 1 + src/libs/vtools/tools/drawTools/vtoolline.cpp | 7 + src/libs/vtools/tools/drawTools/vtoolline.h | 1 + .../tools/nodeDetails/vabstractnode.cpp | 7 + .../vtools/tools/nodeDetails/vabstractnode.h | 2 + src/libs/vtools/tools/vdatatool.h | 11 +- src/libs/vtools/tools/vtooldetail.cpp | 7 + src/libs/vtools/tools/vtooldetail.h | 1 + src/libs/vtools/tools/vtooluniondetails.cpp | 7 + src/libs/vtools/tools/vtooluniondetails.h | 1 + src/libs/vtools/undocommands/addgroup.cpp | 104 +++++++++++++++ src/libs/vtools/undocommands/addgroup.h | 47 +++++++ src/libs/vtools/undocommands/undocommands.pri | 6 +- 23 files changed, 348 insertions(+), 31 deletions(-) create mode 100644 src/libs/vtools/undocommands/addgroup.cpp create mode 100644 src/libs/vtools/undocommands/addgroup.h diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index fad3d9e82..6e13b293c 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -54,6 +54,7 @@ #include "tools/vtooldetail.h" #include "tools/vtooluniondetails.h" #include "dialogs/dialogs.h" +#include "../vtools/undocommands/addgroup.h" #include #include @@ -1012,7 +1013,12 @@ void MainWindow::ClosedDialogGroup(int result) DialogGroup *dialog = qobject_cast(dialogTool); SCASSERT(dialog != nullptr); - doc->AddGroup(pattern->getNextId(), dialog->GetName(), dialog->GetGroup()); + const QDomElement group = doc->CreateGroup(pattern->getNextId(), dialog->GetName(), dialog->GetGroup()); + if (not group.isNull()) + { + AddGroup *addGroup = new AddGroup(group, doc); + qApp->getUndoStack()->push(addGroup); + } } ArrowTool(); } diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 6816d7e4e..f0485fd95 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -466,7 +466,7 @@ void VPattern::customEvent(QEvent *event) */ void VPattern::ParseDrawElement(const QDomNode &node, const Document &parse) { - QStringList tags = QStringList() << TagCalculation << TagModeling << TagDetails; + QStringList tags = QStringList() << TagCalculation << TagModeling << TagDetails << TagGroups; QDomNode domNode = node.firstChild(); while (domNode.isNull() == false) { @@ -490,6 +490,10 @@ void VPattern::ParseDrawElement(const QDomNode &node, const Document &parse) qCDebug(vXML, "Tag details."); ParseDetails(domElement, parse); break; + case 3: // TagGroups + qCDebug(vXML, "Tag groups."); + ParseGroups(domElement); + break; default: VException e(tr("Wrong tag name '%1'.").arg(domElement.tagName())); throw e; diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index c65ccb6d1..92c57cd13 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -112,9 +112,9 @@ private: 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 ParseDetailElement(const QDomElement &domElement, const Document &parse); void ParseDetails(const QDomElement &domElement, const Document &parse); + void ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse, const QString &type); void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index f7f50a77e..c532ce063 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -31,6 +31,8 @@ #include "exception/vexceptionemptyparameter.h" #include "vpatternconverter.h" #include "../qmuparser/qmutokenparser.h" +#include "../exception/vexceptionobjecterror.h" +#include "../vtools/tools/vdatatool.h" const QString VAbstractPattern::TagPattern = QStringLiteral("pattern"); const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation"); @@ -44,7 +46,8 @@ const QString VAbstractPattern::TagIncrements = QStringLiteral("increments"); const QString VAbstractPattern::TagIncrement = QStringLiteral("increment"); const QString VAbstractPattern::TagDraw = QStringLiteral("draw"); const QString VAbstractPattern::TagGroups = QStringLiteral("groups"); -const QString VAbstractPattern::TagItem = QStringLiteral("item"); +const QString VAbstractPattern::TagGroup = QStringLiteral("group"); +const QString VAbstractPattern::TagGroupItem = QStringLiteral("item"); const QString VAbstractPattern::TagPoint = QStringLiteral("point"); const QString VAbstractPattern::TagLine = QStringLiteral("line"); const QString VAbstractPattern::TagSpline = QStringLiteral("spline"); @@ -292,6 +295,54 @@ bool VAbstractPattern::GetActivNodeElement(const QString &name, QDomElement &ele return false; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::ParseGroups(const QDomElement &domElement) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + QMap itemTool; + QMap itemVisibility; + + QDomNode domNode = domElement.firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + if (domElement.tagName() == TagGroup) + { + const QPair > groupData = ParseItemElement(domElement); + const QMap group = groupData.second; + auto i = group.constBegin(); + while (i != group.constEnd()) + { + if (not itemTool.contains(i.key())) + { + itemTool.insert(i.key(), i.value()); + } + + const bool previous = itemVisibility.value(i.key(), true); + itemVisibility.insert(i.key(), previous || groupData.first); + } + } + } + } + domNode = domNode.nextSibling(); + } + + auto i = itemTool.constBegin(); + while (i != itemTool.constEnd()) + { + if (tools.contains(i.value())) + { + VDataTool* tool = tools.value(i.value()); + tool->GroupVisibility(i.key(), itemVisibility.value(i.key(), true)); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- int VAbstractPattern::CountPP() const { @@ -1325,6 +1376,44 @@ bool VAbstractPattern::IsFunction(const QString &token) const return false; } +//--------------------------------------------------------------------------------------------------------------------- +QPair > VAbstractPattern::ParseItemElement(const QDomElement &domElement) +{ + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + + try + { + const bool visible = GetParametrBool(domElement, AttrVisible, trueStr); + + QMap items; + + const QDomNodeList nodeList = domElement.childNodes(); + const qint32 num = nodeList.size(); + for (qint32 i = 0; i < num; ++i) + { + const QDomElement element = nodeList.at(i).toElement(); + if (not element.isNull() && element.tagName() == TagGroupItem) + { + const quint32 object = GetParametrUInt(element, AttrObject, NULL_ID_STR); + const quint32 tool = GetParametrUInt(element, AttrTool, NULL_ID_STR); + items.insert(object, tool); + } + } + + QPair > group; + group.first = visible; + group.second = items; + + return group; + } + catch (const VExceptionBadId &e) + { + VExceptionObjectError excep(tr("Error creating or updating group"), domElement); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief IsModified state of the document for cases that do not cover QUndoStack. @@ -1381,31 +1470,27 @@ QDomElement VAbstractPattern::CreateGroups() } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::AddGroup(quint32 id, const QString &name, const QMap &group) +QDomElement VAbstractPattern::CreateGroup(quint32 id, const QString &name, const QMap &groupData) { - if (id == NULL_ID || group.isEmpty()) + if (id == NULL_ID || groupData.isEmpty()) { - return; + return QDomElement(); } - QDomElement groups = CreateGroups(); + QDomElement group = createElement(TagGroup); + group.setAttribute(AttrId, id); + group.setAttribute(AttrName, name); + group.setAttribute(AttrVisible, trueStr); - if (groups.isNull()) + auto i = groupData.constBegin(); + while (i != groupData.constEnd()) { - return; - } - - groups.setAttribute(AttrId, id); - groups.setAttribute(AttrName, name); - groups.setAttribute(AttrVisible, trueStr); - - auto i = group.constBegin(); - while (i != group.constEnd()) - { - QDomElement item = createElement(TagItem); + QDomElement item = createElement(TagGroupItem); item.setAttribute(AttrObject, i.key()); item.setAttribute(AttrTool, i.value()); - groups.appendChild(item); + group.appendChild(item); ++i; } + + return group; } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 15321da9e..77ada5d8a 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -67,6 +67,8 @@ public: bool GetActivDrawElement(QDomElement &element) const; bool GetActivNodeElement(const QString& name, QDomElement& element) const; + void ParseGroups(const QDomElement &domElement); + quint32 getCursor() const; void setCursor(const quint32 &value); @@ -115,7 +117,7 @@ public: QDomElement GetDraw(const QString &name) const; QDomElement CreateGroups(); - void AddGroup(quint32 id, const QString &name, const QMap &group); + QDomElement CreateGroup(quint32 id, const QString &name, const QMap &groupData); static const QString TagPattern; static const QString TagCalculation; @@ -129,7 +131,8 @@ public: static const QString TagIncrement; static const QString TagDraw; static const QString TagGroups; - static const QString TagItem; + static const QString TagGroup; + static const QString TagGroupItem; static const QString TagPoint; static const QString TagLine; static const QString TagSpline; @@ -281,6 +284,8 @@ private: bool IsVariable(const QString& token) const; bool IsPostfixOperator(const QString& token) const; bool IsFunction(const QString& token) const; + + QPair > ParseItemElement(const QDomElement &domElement); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 042a3f640..7d7b5f03c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -334,3 +334,10 @@ QString VAbstractSpline::name() const { return ObjectName(id); } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + setVisible(visible); +} diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 140276363..89f2548f2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -53,6 +53,7 @@ public: QString name() const; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index b8eaf3359..8e7729788 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -92,6 +92,19 @@ void VToolDoublePoint::SetEnabled(bool enabled) SetToolEnabled(this, enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDoublePoint::GroupVisibility(quint32 object, bool visible) +{ + if (object == p1id) + { + firstPoint->setVisible(visible); + } + else if (object == p2id) + { + secondPoint->setVisible(visible); + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Label1ChangePosition(const QPointF &pos) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index c1cae4c8f..8612864e1 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -56,6 +56,7 @@ public: void SetEnabled(bool enabled); + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: void Label1ChangePosition(const QPointF &pos); void Label2ChangePosition(const QPointF &pos); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 3e4f79b2c..b41c53e4b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -96,6 +96,13 @@ void VToolSinglePoint::SetEnabled(bool enabled) SetToolEnabled(lineName, enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + setVisible(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NameChangePosition handle change posion point label. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 785ed98f9..9c0cf5710 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -53,6 +53,7 @@ public: void SetEnabled(bool enabled); + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: void NameChangePosition(const QPointF &pos); virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index 9e66ec18b..acadc4f00 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -470,6 +470,13 @@ void VToolLine::SetLineColor(const QString &value) SaveOption(obj); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + setVisible(visible); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLine::GetFirstPoint() const { diff --git a/src/libs/vtools/tools/drawTools/vtoolline.h b/src/libs/vtools/tools/drawTools/vtoolline.h index 084c92d80..a554c4248 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.h +++ b/src/libs/vtools/tools/drawTools/vtoolline.h @@ -63,6 +63,7 @@ public: virtual void SetTypeLine(const QString &value) Q_DECL_OVERRIDE; virtual void SetLineColor(const QString &value) Q_DECL_OVERRIDE; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index 2435b77f9..fc7662e9b 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -108,6 +108,13 @@ void VAbstractNode::SetParentType(const ParentType &value) parentType = value; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractNode::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + Q_UNUSED(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToModeling add tag to modeling tag current pattern peace. diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index 037eef068..9ebc987ce 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -54,6 +54,8 @@ public: ParentType GetParentType() const; void SetParentType(const ParentType &value); + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + protected: ParentType parentType; protected: diff --git a/src/libs/vtools/tools/vdatatool.h b/src/libs/vtools/tools/vdatatool.h index 6ebd29b38..3b939b07e 100644 --- a/src/libs/vtools/tools/vdatatool.h +++ b/src/libs/vtools/tools/vdatatool.h @@ -46,11 +46,12 @@ class VDataTool : public QObject public: explicit VDataTool(VContainer *data, QObject *parent = nullptr); virtual ~VDataTool() Q_DECL_OVERRIDE; - VContainer getData() const; - void setData(const VContainer *value); - virtual quint32 referens() const; - virtual void incrementReferens(); - virtual void decrementReferens(); + VContainer getData() const; + void setData(const VContainer *value); + virtual quint32 referens() const; + virtual void incrementReferens(); + virtual void decrementReferens(); + virtual void GroupVisibility(quint32 object, bool visible)=0; protected: /** @brief data container with data */ VContainer data; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index d876c9fef..62252cba3 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -628,6 +628,13 @@ void VToolDetail::ShowVisualization(bool show) Q_UNUSED(show) } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + Q_UNUSED(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 322b5fee9..c93769c1e 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -86,6 +86,7 @@ public: enum { Type = UserType + static_cast(Tool::Detail)}; virtual QString getTagName() const Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; virtual void FullUpdateFromGuiOk(int result); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index d895ed931..f0706e462 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -488,6 +488,13 @@ void VToolUnionDetails::decrementReferens() } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolUnionDetails::GroupVisibility(quint32 object, bool visible) +{ + Q_UNUSED(object); + Q_UNUSED(visible); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool from GUI. diff --git a/src/libs/vtools/tools/vtooluniondetails.h b/src/libs/vtools/tools/vtooluniondetails.h index 058d4ee79..af18419ac 100644 --- a/src/libs/vtools/tools/vtooluniondetails.h +++ b/src/libs/vtools/tools/vtooluniondetails.h @@ -84,6 +84,7 @@ public: virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; virtual void incrementReferens() Q_DECL_OVERRIDE; virtual void decrementReferens() Q_DECL_OVERRIDE; + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/libs/vtools/undocommands/addgroup.cpp b/src/libs/vtools/undocommands/addgroup.cpp new file mode 100644 index 000000000..b4b86ef90 --- /dev/null +++ b/src/libs/vtools/undocommands/addgroup.cpp @@ -0,0 +1,104 @@ +/************************************************************************ + ** + ** @file addgroup.cpp + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "addgroup.h" +#include "../vwidgets/vmaingraphicsscene.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../vmisc/vabstractapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +AddGroup::AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("add group")); + nodeId = doc->GetParametrId(xml); +} + +//--------------------------------------------------------------------------------------------------------------------- +AddGroup::~AddGroup() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddGroup::undo() +{ + qCDebug(vUndo, "Undo."); + + doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = doc->elementById(nodeId); + if (group.isElement()) + { + group.setAttribute(VAbstractPattern::AttrVisible, trueStr); + doc->ParseGroups(groups); + if (groups.removeChild(group).isNull()) + { + qCDebug(vUndo, "Can't delete group."); + return; + } + } + else + { + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); + return; + } + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddGroup::redo() +{ + qCDebug(vUndo, "Redo."); + + doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + groups.appendChild(xml); + doc->ParseGroups(groups); + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); +} diff --git a/src/libs/vtools/undocommands/addgroup.h b/src/libs/vtools/undocommands/addgroup.h new file mode 100644 index 000000000..ae3273253 --- /dev/null +++ b/src/libs/vtools/undocommands/addgroup.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file addgroup.h + ** @author Roman Telezhynskyi + ** @date 6 4, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef ADDGROUP_H +#define ADDGROUP_H + +#include "vundocommand.h" + +class AddGroup : public VUndoCommand +{ + Q_OBJECT +public: + AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); + virtual ~AddGroup(); + virtual void undo() Q_DECL_OVERRIDE; + virtual void redo() Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(AddGroup) + const QString nameActivDraw; +}; + +#endif // ADDGROUP_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 46d553b32..e4fed2b63 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -18,7 +18,8 @@ HEADERS += \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ $$PWD/movelabel.h \ - $$PWD/movedoublelabel.h + $$PWD/movedoublelabel.h \ + $$PWD/addgroup.h SOURCES += \ $$PWD/addtocalc.cpp \ @@ -37,4 +38,5 @@ SOURCES += \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ $$PWD/movelabel.cpp \ - $$PWD/movedoublelabel.cpp + $$PWD/movedoublelabel.cpp \ + $$PWD/addgroup.cpp