From 9869ae249f8bbb4d2941de579bc2aed9042f6393 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 18 Mar 2020 14:37:30 +0200 Subject: [PATCH] Refactoring. Move all related to the visibility group undo command classes in one file. --- src/app/valentina/dialogs/vwidgetgroups.cpp | 4 +- src/app/valentina/mainwindow.cpp | 2 +- src/libs/vtools/tools/drawTools/vdrawtool.h | 4 +- src/libs/vtools/undocommands/addgroup.cpp | 121 ---- src/libs/vtools/undocommands/addgroup.h | 56 -- .../vtools/undocommands/additemtogroup.cpp | 122 ---- src/libs/vtools/undocommands/additemtogroup.h | 58 -- .../undocommands/changegroupvisibility.cpp | 95 ---- .../undocommands/changegroupvisibility.h | 55 -- .../changemultiplegroupsvisibility.cpp | 131 ----- .../changemultiplegroupsvisibility.h | 55 -- src/libs/vtools/undocommands/delgroup.cpp | 124 ---- src/libs/vtools/undocommands/delgroup.h | 55 -- .../undocommands/removeitemfromgroup.cpp | 123 ---- .../vtools/undocommands/removeitemfromgroup.h | 58 -- src/libs/vtools/undocommands/undocommands.pri | 18 +- src/libs/vtools/undocommands/undogroup.cpp | 532 ++++++++++++++++++ src/libs/vtools/undocommands/undogroup.h | 149 +++++ 18 files changed, 688 insertions(+), 1074 deletions(-) delete mode 100644 src/libs/vtools/undocommands/addgroup.cpp delete mode 100644 src/libs/vtools/undocommands/addgroup.h delete mode 100644 src/libs/vtools/undocommands/additemtogroup.cpp delete mode 100644 src/libs/vtools/undocommands/additemtogroup.h delete mode 100644 src/libs/vtools/undocommands/changegroupvisibility.cpp delete mode 100644 src/libs/vtools/undocommands/changegroupvisibility.h delete mode 100644 src/libs/vtools/undocommands/changemultiplegroupsvisibility.cpp delete mode 100644 src/libs/vtools/undocommands/changemultiplegroupsvisibility.h delete mode 100644 src/libs/vtools/undocommands/delgroup.cpp delete mode 100644 src/libs/vtools/undocommands/delgroup.h delete mode 100644 src/libs/vtools/undocommands/removeitemfromgroup.cpp delete mode 100644 src/libs/vtools/undocommands/removeitemfromgroup.h create mode 100644 src/libs/vtools/undocommands/undogroup.cpp create mode 100644 src/libs/vtools/undocommands/undogroup.h diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index 02e19b6a5..1c8daff83 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -29,9 +29,7 @@ #include "vwidgetgroups.h" #include "ui_vwidgetgroups.h" #include "../vtools/dialogs/tools/dialoggroup.h" -#include "../vtools/undocommands/delgroup.h" -#include "../vtools/undocommands/changegroupvisibility.h" -#include "../vtools/undocommands/changemultiplegroupsvisibility.h" +#include "../vtools/undocommands/undogroup.h" #include "../vpatterndb/vcontainer.h" #include diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 427681cb6..00eca97a4 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -58,7 +58,7 @@ #include "tools/vtooluniondetails.h" #include "dialogs/dialogs.h" #include "dialogs/vwidgetgroups.h" -#include "../vtools/undocommands/addgroup.h" +#include "../vtools/undocommands/undogroup.h" #include "dialogs/vwidgetdetails.h" #include "../vpatterndb/vpiecepath.h" #include "../qmuparser/qmuparsererror.h" diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 396401400..58333342a 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -51,9 +51,7 @@ #include "../vwidgets/vabstractmainwindow.h" #include "../vdatatool.h" #include "../vgeometry/vpointf.h" -#include "../vtools/undocommands/addgroup.h" -#include "../vtools/undocommands/additemtogroup.h" -#include "../vtools/undocommands/removeitemfromgroup.h" +#include "../vtools/undocommands/undogroup.h" /** * @brief The VDrawTool abstract class for all draw tool. diff --git a/src/libs/vtools/undocommands/addgroup.cpp b/src/libs/vtools/undocommands/addgroup.cpp deleted file mode 100644 index c0eab5ff0..000000000 --- a/src/libs/vtools/undocommands/addgroup.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/************************************************************************ - ** - ** @file addgroup.cpp - ** @author Roman Telezhynskyi - ** @date 6 4, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 -#include - -#include "../vmisc/vabstractapplication.h" -#include "../vmisc/def.h" -#include "../vwidgets/vmaingraphicsview.h" -#include "../ifc/xml/vabstractpattern.h" -#include "vundocommand.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, VAbstractPattern::TagGroup); - if (group.isElement()) - { - group.setAttribute(VAbstractPattern::AttrVisible, trueStr); - doc->ParseGroups(groups); - if (groups.removeChild(group).isNull()) - { - qCDebug(vUndo, "Can't delete group."); - return; - } - emit UpdateGroups(); - } - else - { - if (groups.childNodes().isEmpty()) - { - QDomNode parent = groups.parentNode(); - parent.removeChild(groups); - } - - 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()); - if (qApp->GetDrawMode() == Draw::Calculation) - { - emit 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); - emit UpdateGroups(); - } - 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 deleted file mode 100644 index 0c8b21267..000000000 --- a/src/libs/vtools/undocommands/addgroup.h +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************ - ** - ** @file addgroup.h - ** @author Roman Telezhynskyi - ** @date 6 4, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 -#include -#include -#include -#include -#include - -#include "vundocommand.h" - -class AddGroup : public VUndoCommand -{ - Q_OBJECT -public: - AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); - virtual ~AddGroup(); - virtual void undo() override; - virtual void redo() override; -signals: - void UpdateGroups(); -private: - Q_DISABLE_COPY(AddGroup) - const QString nameActivDraw; -}; - -#endif // ADDGROUP_H diff --git a/src/libs/vtools/undocommands/additemtogroup.cpp b/src/libs/vtools/undocommands/additemtogroup.cpp deleted file mode 100644 index 2c5af9d5e..000000000 --- a/src/libs/vtools/undocommands/additemtogroup.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************ - ** - ** @file addgroup.h - ** @author Ronan Le Tiec - ** @date 31 3, 2018 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 "additemtogroup.h" - -#include -#include - -#include "../vmisc/vabstractapplication.h" -#include "../vmisc/def.h" -#include "../vwidgets/vmaingraphicsview.h" -#include "../ifc/xml/vabstractpattern.h" -#include "../vtools/tools/vdatatool.h" -#include "vundocommand.h" - -//--------------------------------------------------------------------------------------------------------------------- -AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent) - : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) -{ - setText(tr("Add item to group")); - nodeId = groupId; -} - -//--------------------------------------------------------------------------------------------------------------------- -void AddItemToGroup::undo() -{ - qCDebug(vUndo, "Undo the add item to group"); - performUndoRedo(true); -} - -//--------------------------------------------------------------------------------------------------------------------- -void AddItemToGroup::redo() -{ - qCDebug(vUndo, "Redo the add item to group"); - performUndoRedo(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void AddItemToGroup::performUndoRedo(bool isUndo) -{ - doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change - - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - if(isUndo) - { - if (group.removeChild(xml).isNull()) - { - qCDebug(vUndo, "Can't delete item."); - return; - } - - // set the item visible. Because if the undo is done when unvisible and it's not in any group after the - // undo, it stays unvisible until the entire drawing is completly rerendered. - quint32 objectId = doc->GetParametrUInt(xml, QStringLiteral("object"), NULL_ID_STR); - quint32 toolId = doc->GetParametrUInt(xml, QStringLiteral("tool"), NULL_ID_STR); - VDataTool* tool = VAbstractPattern::getTool(toolId); - tool->GroupVisibility(objectId,true); - } - else // is redo - { - - if (group.appendChild(xml).isNull()) - { - qCDebug(vUndo, "Can't add item."); - return; - } - } - - doc->SetModified(true); - emit qApp->getCurrentDocument()->patternChanged(false); - - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } else - { - qCDebug(vUndo, "Can't get tag Groups."); - return; - } - - emit UpdateGroups(); - } - else - { - qCDebug(vUndo, "Can't get group by id = %u.", nodeId); - return; - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - if (qApp->GetDrawMode() == Draw::Calculation) - { - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo - } -} diff --git a/src/libs/vtools/undocommands/additemtogroup.h b/src/libs/vtools/undocommands/additemtogroup.h deleted file mode 100644 index 3f8d9c7b8..000000000 --- a/src/libs/vtools/undocommands/additemtogroup.h +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************ - ** - ** @file addgroup.h - ** @author Ronan Le Tiec - ** @date 31 3, 2018 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 ADDITEMTOGROUP_H -#define ADDITEMTOGROUP_H - -#include -#include -#include -#include -#include -#include - -#include "vundocommand.h" - -class AddItemToGroup : public VUndoCommand -{ - Q_OBJECT -public: - AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); - virtual ~AddItemToGroup()=default; - virtual void undo() override; - virtual void redo() override; -signals: - void UpdateGroups(); -protected: - void performUndoRedo(bool isUndo); -private: - Q_DISABLE_COPY(AddItemToGroup) - const QString nameActivDraw; -}; - -#endif // ADDITEMTOGROUP_H diff --git a/src/libs/vtools/undocommands/changegroupvisibility.cpp b/src/libs/vtools/undocommands/changegroupvisibility.cpp deleted file mode 100644 index ef511f084..000000000 --- a/src/libs/vtools/undocommands/changegroupvisibility.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************************************ - ** - ** @file changegroupVisibility.cpp - ** @author Roman Telezhynskyi - ** @date 14 7, 2019 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2019 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 "changegroupvisibility.h" -#include "../vmisc/vabstractapplication.h" -#include "../vwidgets/vmaingraphicsview.h" - -//--------------------------------------------------------------------------------------------------------------------- -ChangeGroupVisibility::ChangeGroupVisibility(VAbstractPattern *doc, vidtype id, bool visible, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), - m_newVisibility(visible), - m_nameActivDraw(doc->GetNameActivPP()) -{ - setText(tr("change group visibility")); - nodeId = id; - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - m_oldVisibility = doc->GetParametrBool(group, VAbstractPattern::AttrVisible, trueStr); - } - else - { - qDebug("Can't get group by id = %u.", id); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -ChangeGroupVisibility::~ChangeGroupVisibility() -{} - -//--------------------------------------------------------------------------------------------------------------------- -void ChangeGroupVisibility::undo() -{ - qCDebug(vUndo, "Undo."); - - Do(m_oldVisibility); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ChangeGroupVisibility::redo() -{ - qCDebug(vUndo, "Redo."); - - Do(m_newVisibility); -} - -//--------------------------------------------------------------------------------------------------------------------- -void ChangeGroupVisibility::Do(bool visible) -{ - doc->ChangeActivPP(m_nameActivDraw);//Without this user will not see this change - - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - doc->SetAttribute(group, VAbstractPattern::AttrVisible, visible); - - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } - - emit UpdateGroup(nodeId, visible); - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - } - else - { - qDebug("Can't get group by id = %u.", nodeId); - } -} diff --git a/src/libs/vtools/undocommands/changegroupvisibility.h b/src/libs/vtools/undocommands/changegroupvisibility.h deleted file mode 100644 index f126718e4..000000000 --- a/src/libs/vtools/undocommands/changegroupvisibility.h +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************ - ** - ** @file changegroupVisibility.h - ** @author Roman Telezhynskyi - ** @date 14 7, 2019 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2019 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 CHANGEGROUPVISIBILITY_H -#define CHANGEGROUPVISIBILITY_H - -#include "vundocommand.h" - -class ChangeGroupVisibility : public VUndoCommand -{ - Q_OBJECT -public: - ChangeGroupVisibility(VAbstractPattern *doc, vidtype id, bool visible, QUndoCommand *parent = nullptr); - virtual ~ChangeGroupVisibility(); - virtual void undo() override; - virtual void redo() override; - -signals: - void UpdateGroup(vidtype id, bool visible); - -private: - Q_DISABLE_COPY(ChangeGroupVisibility) - - bool m_oldVisibility{true}; - bool m_newVisibility{true}; - const QString m_nameActivDraw{}; - - void Do(bool visible); -}; - -#endif // CHANGEGROUPVISIBILITY_H diff --git a/src/libs/vtools/undocommands/changemultiplegroupsvisibility.cpp b/src/libs/vtools/undocommands/changemultiplegroupsvisibility.cpp deleted file mode 100644 index 47e16355c..000000000 --- a/src/libs/vtools/undocommands/changemultiplegroupsvisibility.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/************************************************************************ - ** - ** @file changemultiplegroupsVisibility.cpp - ** @author Roman Telezhynskyi - ** @date 15 7, 2019 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2019 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 "changemultiplegroupsvisibility.h" -#include "../vmisc/vabstractapplication.h" -#include "../vwidgets/vmaingraphicsview.h" - -//--------------------------------------------------------------------------------------------------------------------- -ChangeMultipleGroupsVisibility::ChangeMultipleGroupsVisibility(VAbstractPattern *doc, const QVector &groups, - bool visible, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), - m_groups(groups), - m_newVisibility(visible), - m_nameActivDraw(doc->GetNameActivPP()) -{ - setText(tr("change multiple groups visibility")); - - for(auto & groupId : m_groups) - { - QDomElement group = doc->elementById(groupId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - m_oldVisibility.insert(groupId, doc->GetParametrBool(group, VAbstractPattern::AttrVisible, trueStr)); - } - else - { - qDebug("Can't get group by id = %u.", groupId); - } - } - -} - -//--------------------------------------------------------------------------------------------------------------------- -void ChangeMultipleGroupsVisibility::undo() -{ - qCDebug(vUndo, "Undo."); - - doc->ChangeActivPP(m_nameActivDraw);//Without this user will not see this change - - QMap groupsState; - - QMap::const_iterator i = m_oldVisibility.constBegin(); - while (i != m_oldVisibility.constEnd()) - { - QDomElement group = doc->elementById(i.key(), VAbstractPattern::TagGroup); - if (group.isElement()) - { - doc->SetAttribute(group, VAbstractPattern::AttrVisible, i.value()); - groupsState.insert(i.key(), i.value()); - } - else - { - qDebug("Can't get group by id = %u.", i.key()); - } - ++i; - } - - if (not groupsState.isEmpty()) - { - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - - emit UpdateMultipleGroups(groupsState); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void ChangeMultipleGroupsVisibility::redo() -{ - qCDebug(vUndo, "ChangeMultipleGroupsVisibility::redo"); - - doc->ChangeActivPP(m_nameActivDraw);//Without this user will not see this change - - QMap groupsState; - - for (auto& groupId : m_groups) - { - QDomElement group = doc->elementById(groupId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - doc->SetAttribute(group, VAbstractPattern::AttrVisible, m_newVisibility); - groupsState.insert(groupId, m_newVisibility); - } - else - { - qDebug("Can't get group by id = %u.", groupId); - } - } - - if (not groupsState.isEmpty()) - { - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - - emit UpdateMultipleGroups(groupsState); - } -} diff --git a/src/libs/vtools/undocommands/changemultiplegroupsvisibility.h b/src/libs/vtools/undocommands/changemultiplegroupsvisibility.h deleted file mode 100644 index 4a70c65c8..000000000 --- a/src/libs/vtools/undocommands/changemultiplegroupsvisibility.h +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************ - ** - ** @file changemultiplegroupsVisibility.h - ** @author Roman Telezhynskyi - ** @date 15 7, 2019 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2019 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 CHANGEMULTIPLEGROUPSVISIBILITY_H -#define CHANGEMULTIPLEGROUPSVISIBILITY_H - -#include "vundocommand.h" - -class ChangeMultipleGroupsVisibility : public VUndoCommand -{ - Q_OBJECT -public: - ChangeMultipleGroupsVisibility(VAbstractPattern *doc, const QVector &groups, bool visible, - QUndoCommand *parent = nullptr); - virtual ~ChangeMultipleGroupsVisibility() =default; - virtual void undo() override; - virtual void redo() override; - -signals: - void UpdateMultipleGroups(const QMap &groups); - -private: - Q_DISABLE_COPY(ChangeMultipleGroupsVisibility) - - QVector m_groups; - bool m_newVisibility{true}; - QMap m_oldVisibility{}; - const QString m_nameActivDraw{}; -}; - -#endif // CHANGEMULTIPLEGROUPSVISIBILITY_H diff --git a/src/libs/vtools/undocommands/delgroup.cpp b/src/libs/vtools/undocommands/delgroup.cpp deleted file mode 100644 index 87e818c25..000000000 --- a/src/libs/vtools/undocommands/delgroup.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************************************ - ** - ** @file delgroup.cpp - ** @author Roman Telezhynskyi - ** @date 6 4, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 "delgroup.h" - -#include -#include -#include - -#include "../vmisc/vabstractapplication.h" -#include "../vmisc/def.h" -#include "../vwidgets/vmaingraphicsview.h" -#include "../ifc/xml/vabstractpattern.h" -#include "vundocommand.h" - -//--------------------------------------------------------------------------------------------------------------------- -DelGroup::DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), nameActivDraw(doc->GetNameActivPP()) -{ - setText(tr("delete group")); - nodeId = id; - xml = doc->CloneNodeById(nodeId); -} - -//--------------------------------------------------------------------------------------------------------------------- -DelGroup::~DelGroup() -{ -} - -//--------------------------------------------------------------------------------------------------------------------- -void DelGroup::undo() -{ - qCDebug(vUndo, "Undo."); - - if (qApp->GetDrawMode() == Draw::Calculation) - { - emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change - } - - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - groups.appendChild(xml); - doc->ParseGroups(groups); - emit UpdateGroups(); - } - else - { - qCDebug(vUndo, "Can't get tag Groups."); - return; - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DelGroup::redo() -{ - qCDebug(vUndo, "Redo."); - - if (qApp->GetDrawMode() == Draw::Calculation) - {//Keep first! - emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change - } - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - group.setAttribute(VAbstractPattern::AttrVisible, trueStr); - doc->ParseGroups(groups); - if (groups.removeChild(group).isNull()) - { - qCDebug(vUndo, "Can't delete group."); - return; - } - emit UpdateGroups(); - - if (groups.childNodes().isEmpty()) - { - QDomNode parent = groups.parentNode(); - parent.removeChild(groups); - } - } - 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()); -} diff --git a/src/libs/vtools/undocommands/delgroup.h b/src/libs/vtools/undocommands/delgroup.h deleted file mode 100644 index bdd5120f1..000000000 --- a/src/libs/vtools/undocommands/delgroup.h +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************ - ** - ** @file delgroup.h - ** @author Roman Telezhynskyi - ** @date 6 4, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 DELGROUP_H -#define DELGROUP_H - -#include -#include -#include -#include -#include - -#include "vundocommand.h" - -class DelGroup : public VUndoCommand -{ - Q_OBJECT -public: - DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent = nullptr); - virtual ~DelGroup(); - virtual void undo() override; - virtual void redo() override; -signals: - void UpdateGroups(); -private: - Q_DISABLE_COPY(DelGroup) - const QString nameActivDraw; -}; - -#endif // DELGROUP_H diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.cpp b/src/libs/vtools/undocommands/removeitemfromgroup.cpp deleted file mode 100644 index 27b905ebe..000000000 --- a/src/libs/vtools/undocommands/removeitemfromgroup.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************************************ - ** - ** @file removeitemfromgroup.cpp - ** @author Ronan Le Tiec - ** @date 1 4, 2018 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 "removeitemfromgroup.h" - -#include -#include - -#include "../vmisc/vabstractapplication.h" -#include "../vmisc/def.h" -#include "../vwidgets/vmaingraphicsview.h" -#include "../ifc/xml/vabstractpattern.h" -#include "../vtools/tools/vdatatool.h" -#include "vundocommand.h" - -//--------------------------------------------------------------------------------------------------------------------- - -RemoveItemFromGroup::RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent) - : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) -{ - setText(tr("Remove item from group")); - nodeId = groupId; -} - -//--------------------------------------------------------------------------------------------------------------------- -void RemoveItemFromGroup::undo() -{ - qCDebug(vUndo, "Undo the remove item from group"); - performUndoRedo(true); -} - -//--------------------------------------------------------------------------------------------------------------------- -void RemoveItemFromGroup::redo() -{ - qCDebug(vUndo, "Redo the add item to group"); - performUndoRedo(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void RemoveItemFromGroup::performUndoRedo(bool isUndo) -{ - doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change - - QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); - if (group.isElement()) - { - if(isUndo) - { - if (group.appendChild(xml).isNull()) - { - qCDebug(vUndo, "Can't add the item."); - return; - } - } - else // is redo - { - if (group.removeChild(xml).isNull()) - { - qCDebug(vUndo, "Can't delete item."); - return; - } - - // set the item visible. Because if the undo is done when unvisibile and it's not in any group after the - // undo, it stays unvisible until the entire drawing is completly rerendered. - quint32 objectId = doc->GetParametrUInt(xml, QStringLiteral("object"), NULL_ID_STR); - quint32 toolId = doc->GetParametrUInt(xml, QStringLiteral("tool"), NULL_ID_STR); - VDataTool* tool = VAbstractPattern::getTool(toolId); - tool->GroupVisibility(objectId,true); - } - - doc->SetModified(true); - emit qApp->getCurrentDocument()->patternChanged(false); - - QDomElement groups = doc->CreateGroups(); - if (not groups.isNull()) - { - doc->ParseGroups(groups); - } else - { - qCDebug(vUndo, "Can't get tag Groups."); - return; - } - - emit UpdateGroups(); - } - else - { - qCDebug(vUndo, "Can't get group by id = %u.", nodeId); - return; - } - - VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); - - if (qApp->GetDrawMode() == Draw::Calculation) - { - emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo - } -} diff --git a/src/libs/vtools/undocommands/removeitemfromgroup.h b/src/libs/vtools/undocommands/removeitemfromgroup.h deleted file mode 100644 index e19873476..000000000 --- a/src/libs/vtools/undocommands/removeitemfromgroup.h +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************ - ** - ** @file removeitemfromgroup.h - ** @author Ronan Le Tiec - ** @date 31 3, 2018 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentina 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 REMOVEITEMFROMGROUP_H -#define REMOVEITEMFROMGROUP_H - -#include -#include -#include -#include -#include -#include - -#include "vundocommand.h" - -class RemoveItemFromGroup : public VUndoCommand -{ - Q_OBJECT -public: - RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); - virtual ~RemoveItemFromGroup()=default; - virtual void undo() override; - virtual void redo() override; -signals: - void UpdateGroups(); -protected: - void performUndoRedo(bool isUndo); -private: - Q_DISABLE_COPY(RemoveItemFromGroup) - const QString nameActivDraw; -}; - -#endif // REMOVEITEMFROMGROUP_H diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 310cb557c..37d8a34b6 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -4,20 +4,17 @@ HEADERS += \ $$PWD/addtocalc.h \ $$PWD/addpatternpiece.h \ - $$PWD/changegroupvisibility.h \ - $$PWD/changemultiplegroupsvisibility.h \ $$PWD/movespoint.h \ $$PWD/movespline.h \ $$PWD/movesplinepath.h \ $$PWD/savetooloptions.h \ $$PWD/deltool.h \ $$PWD/deletepatternpiece.h \ + $$PWD/undogroup.h \ $$PWD/vundocommand.h \ $$PWD/renamepp.h \ $$PWD/label/movelabel.h \ $$PWD/label/movedoublelabel.h \ - $$PWD/addgroup.h \ - $$PWD/delgroup.h \ $$PWD/label/moveabstractlabel.h \ $$PWD/label/operationmovelabel.h \ $$PWD/addpiece.h \ @@ -29,27 +26,22 @@ HEADERS += \ $$PWD/label/showdoublelabel.h \ $$PWD/label/operationshowlabel.h \ $$PWD/saveplacelabeloptions.h \ - $$PWD/togglepiecestate.h \ - $$PWD/additemtogroup.h \ - $$PWD/removeitemfromgroup.h + $$PWD/togglepiecestate.h SOURCES += \ $$PWD/addtocalc.cpp \ $$PWD/addpatternpiece.cpp \ - $$PWD/changegroupvisibility.cpp \ - $$PWD/changemultiplegroupsvisibility.cpp \ $$PWD/movespoint.cpp \ $$PWD/movespline.cpp \ $$PWD/movesplinepath.cpp \ $$PWD/savetooloptions.cpp \ $$PWD/deltool.cpp \ $$PWD/deletepatternpiece.cpp \ + $$PWD/undogroup.cpp \ $$PWD/vundocommand.cpp \ $$PWD/renamepp.cpp \ $$PWD/label/movelabel.cpp \ $$PWD/label/movedoublelabel.cpp \ - $$PWD/addgroup.cpp \ - $$PWD/delgroup.cpp \ $$PWD/label/moveabstractlabel.cpp \ $$PWD/label/operationmovelabel.cpp \ $$PWD/addpiece.cpp \ @@ -61,6 +53,4 @@ SOURCES += \ $$PWD/label/showdoublelabel.cpp \ $$PWD/label/operationshowlabel.cpp \ $$PWD/saveplacelabeloptions.cpp \ - $$PWD/togglepiecestate.cpp \ - $$PWD/additemtogroup.cpp \ - $$PWD/removeitemfromgroup.cpp + $$PWD/togglepiecestate.cpp diff --git a/src/libs/vtools/undocommands/undogroup.cpp b/src/libs/vtools/undocommands/undogroup.cpp new file mode 100644 index 000000000..a64ff98af --- /dev/null +++ b/src/libs/vtools/undocommands/undogroup.cpp @@ -0,0 +1,532 @@ +/************************************************************************ + ** + ** @file undogroup.cpp + ** @author Roman Telezhynskyi + ** @date 18 3, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 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 "undogroup.h" + +#include +#include + +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/def.h" +#include "../vwidgets/vmaingraphicsview.h" +#include "../ifc/xml/vabstractpattern.h" +#include "vundocommand.h" +#include "../vtools/tools/vdatatool.h" + +//AddGroup +//--------------------------------------------------------------------------------------------------------------------- +AddGroup::AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("add group")); + nodeId = doc->GetParametrId(xml); +} + +//--------------------------------------------------------------------------------------------------------------------- +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, VAbstractPattern::TagGroup); + if (group.isElement()) + { + group.setAttribute(VAbstractPattern::AttrVisible, trueStr); + doc->ParseGroups(groups); + if (groups.removeChild(group).isNull()) + { + qCDebug(vUndo, "Can't delete group."); + return; + } + emit UpdateGroups(); + } + else + { + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + + 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()); + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit 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); + emit UpdateGroups(); + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); +} + +//AddItemToGroup +//--------------------------------------------------------------------------------------------------------------------- +AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("Add item to group")); + nodeId = groupId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddItemToGroup::undo() +{ + qCDebug(vUndo, "Undo the add item to group"); + performUndoRedo(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddItemToGroup::redo() +{ + qCDebug(vUndo, "Redo the add item to group"); + performUndoRedo(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void AddItemToGroup::performUndoRedo(bool isUndo) +{ + doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change + + QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + if(isUndo) + { + if (group.removeChild(xml).isNull()) + { + qCDebug(vUndo, "Can't delete item."); + return; + } + + // set the item visible. Because if the undo is done when unvisible and it's not in any group after the + // undo, it stays unvisible until the entire drawing is completly rerendered. + quint32 objectId = doc->GetParametrUInt(xml, QStringLiteral("object"), NULL_ID_STR); + quint32 toolId = doc->GetParametrUInt(xml, QStringLiteral("tool"), NULL_ID_STR); + VDataTool* tool = VAbstractPattern::getTool(toolId); + tool->GroupVisibility(objectId,true); + } + else // is redo + { + + if (group.appendChild(xml).isNull()) + { + qCDebug(vUndo, "Can't add item."); + return; + } + } + + doc->SetModified(true); + emit qApp->getCurrentDocument()->patternChanged(false); + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + doc->ParseGroups(groups); + } else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + emit UpdateGroups(); + } + else + { + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } +} + +//RemoveItemFromGroup +//--------------------------------------------------------------------------------------------------------------------- +RemoveItemFromGroup::RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, + QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("Remove item from group")); + nodeId = groupId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void RemoveItemFromGroup::undo() +{ + qCDebug(vUndo, "Undo the remove item from group"); + performUndoRedo(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void RemoveItemFromGroup::redo() +{ + qCDebug(vUndo, "Redo the add item to group"); + performUndoRedo(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void RemoveItemFromGroup::performUndoRedo(bool isUndo) +{ + doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change + + QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + if(isUndo) + { + if (group.appendChild(xml).isNull()) + { + qCDebug(vUndo, "Can't add the item."); + return; + } + } + else // is redo + { + if (group.removeChild(xml).isNull()) + { + qCDebug(vUndo, "Can't delete item."); + return; + } + + // set the item visible. Because if the undo is done when unvisibile and it's not in any group after the + // undo, it stays unvisible until the entire drawing is completly rerendered. + quint32 objectId = doc->GetParametrUInt(xml, QStringLiteral("object"), NULL_ID_STR); + quint32 toolId = doc->GetParametrUInt(xml, QStringLiteral("tool"), NULL_ID_STR); + VDataTool* tool = VAbstractPattern::getTool(toolId); + tool->GroupVisibility(objectId,true); + } + + doc->SetModified(true); + emit qApp->getCurrentDocument()->patternChanged(false); + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + doc->ParseGroups(groups); + } else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + emit UpdateGroups(); + } + else + { + qCDebug(vUndo, "Can't get group by id = %u.", nodeId); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo + } +} + +//ChangeGroupVisibility +//--------------------------------------------------------------------------------------------------------------------- +ChangeGroupVisibility::ChangeGroupVisibility(VAbstractPattern *doc, vidtype id, bool visible, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + m_newVisibility(visible), + m_nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("change group visibility")); + nodeId = id; + QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + m_oldVisibility = doc->GetParametrBool(group, VAbstractPattern::AttrVisible, trueStr); + } + else + { + qDebug("Can't get group by id = %u.", id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void ChangeGroupVisibility::undo() +{ + qCDebug(vUndo, "Undo."); + + Do(m_oldVisibility); +} + +//--------------------------------------------------------------------------------------------------------------------- +void ChangeGroupVisibility::redo() +{ + qCDebug(vUndo, "Redo."); + + Do(m_newVisibility); +} + +//--------------------------------------------------------------------------------------------------------------------- +void ChangeGroupVisibility::Do(bool visible) +{ + doc->ChangeActivPP(m_nameActivDraw);//Without this user will not see this change + + QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + doc->SetAttribute(group, VAbstractPattern::AttrVisible, visible); + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + doc->ParseGroups(groups); + } + + emit UpdateGroup(nodeId, visible); + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + } + else + { + qDebug("Can't get group by id = %u.", nodeId); + } +} + +//ChangeMultipleGroupsVisibility +//--------------------------------------------------------------------------------------------------------------------- +ChangeMultipleGroupsVisibility::ChangeMultipleGroupsVisibility(VAbstractPattern *doc, const QVector &groups, + bool visible, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), + m_groups(groups), + m_newVisibility(visible), + m_nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("change multiple groups visibility")); + + for(auto & groupId : m_groups) + { + QDomElement group = doc->elementById(groupId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + m_oldVisibility.insert(groupId, doc->GetParametrBool(group, VAbstractPattern::AttrVisible, trueStr)); + } + else + { + qDebug("Can't get group by id = %u.", groupId); + } + } + +} + +//--------------------------------------------------------------------------------------------------------------------- +void ChangeMultipleGroupsVisibility::undo() +{ + qCDebug(vUndo, "Undo."); + + doc->ChangeActivPP(m_nameActivDraw);//Without this user will not see this change + + QMap groupsState; + + QMap::const_iterator i = m_oldVisibility.constBegin(); + while (i != m_oldVisibility.constEnd()) + { + QDomElement group = doc->elementById(i.key(), VAbstractPattern::TagGroup); + if (group.isElement()) + { + doc->SetAttribute(group, VAbstractPattern::AttrVisible, i.value()); + groupsState.insert(i.key(), i.value()); + } + else + { + qDebug("Can't get group by id = %u.", i.key()); + } + ++i; + } + + if (not groupsState.isEmpty()) + { + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + doc->ParseGroups(groups); + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + + emit UpdateMultipleGroups(groupsState); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void ChangeMultipleGroupsVisibility::redo() +{ + qCDebug(vUndo, "ChangeMultipleGroupsVisibility::redo"); + + doc->ChangeActivPP(m_nameActivDraw);//Without this user will not see this change + + QMap groupsState; + + for (auto& groupId : m_groups) + { + QDomElement group = doc->elementById(groupId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + doc->SetAttribute(group, VAbstractPattern::AttrVisible, m_newVisibility); + groupsState.insert(groupId, m_newVisibility); + } + else + { + qDebug("Can't get group by id = %u.", groupId); + } + } + + if (not groupsState.isEmpty()) + { + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + doc->ParseGroups(groups); + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + + emit UpdateMultipleGroups(groupsState); + } +} + +//DelGroup +//--------------------------------------------------------------------------------------------------------------------- +DelGroup::DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), nameActivDraw(doc->GetNameActivPP()) +{ + setText(tr("delete group")); + nodeId = id; + xml = doc->CloneNodeById(nodeId); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DelGroup::undo() +{ + qCDebug(vUndo, "Undo."); + + if (qApp->GetDrawMode() == Draw::Calculation) + { + emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + } + + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + groups.appendChild(xml); + doc->ParseGroups(groups); + emit UpdateGroups(); + } + else + { + qCDebug(vUndo, "Can't get tag Groups."); + return; + } + + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DelGroup::redo() +{ + qCDebug(vUndo, "Redo."); + + if (qApp->GetDrawMode() == Draw::Calculation) + {//Keep first! + emit doc->SetCurrentPP(nameActivDraw);//Without this user will not see this change + } + QDomElement groups = doc->CreateGroups(); + if (not groups.isNull()) + { + QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); + if (group.isElement()) + { + group.setAttribute(VAbstractPattern::AttrVisible, trueStr); + doc->ParseGroups(groups); + if (groups.removeChild(group).isNull()) + { + qCDebug(vUndo, "Can't delete group."); + return; + } + emit UpdateGroups(); + + if (groups.childNodes().isEmpty()) + { + QDomNode parent = groups.parentNode(); + parent.removeChild(groups); + } + } + 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()); +} diff --git a/src/libs/vtools/undocommands/undogroup.h b/src/libs/vtools/undocommands/undogroup.h new file mode 100644 index 000000000..2a08f276e --- /dev/null +++ b/src/libs/vtools/undocommands/undogroup.h @@ -0,0 +1,149 @@ +/************************************************************************ + ** + ** @file undogroup.h + ** @author Roman Telezhynskyi + ** @date 18 3, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 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 UNDOGROUP_H +#define UNDOGROUP_H + + +#include +#include +#include +#include +#include +#include + +#include "vundocommand.h" + +class AddGroup : public VUndoCommand +{ + Q_OBJECT +public: + AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = nullptr); + virtual ~AddGroup()=default; + virtual void undo() override; + virtual void redo() override; +signals: + void UpdateGroups(); +private: + Q_DISABLE_COPY(AddGroup) + const QString nameActivDraw; +}; + +class AddItemToGroup : public VUndoCommand +{ + Q_OBJECT +public: + AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); + virtual ~AddItemToGroup()=default; + virtual void undo() override; + virtual void redo() override; +signals: + void UpdateGroups(); +protected: + void performUndoRedo(bool isUndo); +private: + Q_DISABLE_COPY(AddItemToGroup) + const QString nameActivDraw; +}; + +class RemoveItemFromGroup : public VUndoCommand +{ + Q_OBJECT +public: + RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); + virtual ~RemoveItemFromGroup()=default; + virtual void undo() override; + virtual void redo() override; +signals: + void UpdateGroups(); +protected: + void performUndoRedo(bool isUndo); +private: + Q_DISABLE_COPY(RemoveItemFromGroup) + const QString nameActivDraw; +}; + +class ChangeGroupVisibility : public VUndoCommand +{ + Q_OBJECT +public: + ChangeGroupVisibility(VAbstractPattern *doc, vidtype id, bool visible, QUndoCommand *parent = nullptr); + virtual ~ChangeGroupVisibility()=default; + virtual void undo() override; + virtual void redo() override; + +signals: + void UpdateGroup(vidtype id, bool visible); + +private: + Q_DISABLE_COPY(ChangeGroupVisibility) + + bool m_oldVisibility{true}; + bool m_newVisibility{true}; + const QString m_nameActivDraw{}; + + void Do(bool visible); +}; + +class ChangeMultipleGroupsVisibility : public VUndoCommand +{ + Q_OBJECT +public: + ChangeMultipleGroupsVisibility(VAbstractPattern *doc, const QVector &groups, bool visible, + QUndoCommand *parent = nullptr); + virtual ~ChangeMultipleGroupsVisibility() =default; + virtual void undo() override; + virtual void redo() override; + +signals: + void UpdateMultipleGroups(const QMap &groups); + +private: + Q_DISABLE_COPY(ChangeMultipleGroupsVisibility) + + QVector m_groups; + bool m_newVisibility{true}; + QMap m_oldVisibility{}; + const QString m_nameActivDraw{}; +}; + +class DelGroup : public VUndoCommand +{ + Q_OBJECT +public: + DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent = nullptr); + virtual ~DelGroup()=default; + virtual void undo() override; + virtual void redo() override; +signals: + void UpdateGroups(); +private: + Q_DISABLE_COPY(DelGroup) + const QString nameActivDraw; +}; + +#endif // UNDOGROUP_H