Seamly2D
Code documentation
delgroup.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file delgroup.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 6 4, 2016
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2016 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "delgroup.h"
53 
54 #include <QDomElement>
55 #include <QDomNode>
56 #include <QDomNodeList>
57 
58 #include "../vmisc/logging.h"
59 #include "../vmisc/vabstractapplication.h"
60 #include "../vmisc/def.h"
61 #include "../vwidgets/vmaingraphicsview.h"
62 #include "../ifc/xml/vabstractpattern.h"
63 #include "vundocommand.h"
64 
65 //---------------------------------------------------------------------------------------------------------------------
66 DelGroup::DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent)
67  : VUndoCommand(QDomElement(), doc, parent), activeBlockName(doc->getActiveDraftBlockName())
68 {
69  setText(tr("delete group"));
70  nodeId = id;
72 }
73 
74 //---------------------------------------------------------------------------------------------------------------------
76 {
77 }
78 
79 //---------------------------------------------------------------------------------------------------------------------
81 {
82  qCDebug(vUndo, "Undo.");
83 
84  doc->setCurrentDraftBlock(activeBlockName);//Without this user will not see this change
85 
86  QDomElement groups = doc->createGroups();
87  if (not groups.isNull())
88  {
89  groups.appendChild(xml);
90  doc->parseGroups(groups);
91  emit updateGroups();
92  }
93  else
94  {
95  qCDebug(vUndo, "Can't get tag Groups.");
96  return;
97  }
98 
99  VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
100 }
101 
102 //---------------------------------------------------------------------------------------------------------------------
104 {
105  qCDebug(vUndo, "Redo.");
106 
107  //Keep first!
108  doc->setCurrentDraftBlock(activeBlockName);//Without this user will not see this change
109  QDomElement groups = doc->createGroups();
110  if (not groups.isNull())
111  {
112  QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
113  if (group.isElement())
114  {
115  group.setAttribute(VAbstractPattern::AttrVisible, trueStr);
116  doc->parseGroups(groups);
117  if (groups.removeChild(group).isNull())
118  {
119  qCDebug(vUndo, "Can't delete group.");
120  return;
121  }
122  emit updateGroups();
123 
124  if (groups.childNodes().isEmpty())
125  {
126  QDomNode parent = groups.parentNode();
127  parent.removeChild(groups);
128  }
129  }
130  else
131  {
132  qCDebug(vUndo, "Can't get group by id = %u.", nodeId);
133  return;
134  }
135  }
136  else
137  {
138  qCDebug(vUndo, "Can't get tag Groups.");
139  return;
140  }
141 
142  VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
143 }
DelGroup(VAbstractPattern *doc, quint32 id, QUndoCommand *parent=nullptr)
Definition: delgroup.cpp:66
virtual void undo() Q_DECL_OVERRIDE
Definition: delgroup.cpp:80
virtual void redo() Q_DECL_OVERRIDE
Definition: delgroup.cpp:103
void updateGroups()
virtual ~DelGroup()
Definition: delgroup.cpp:75
const QString activeBlockName
Definition: delgroup.h:75
QDomElement createGroups()
static const QString TagGroup
void parseGroups(const QDomElement &domElement)
void setCurrentDraftBlock(const QString &patterPiece)
static const QString AttrVisible
QDomElement elementById(quint32 id, const QString &tagName=QString())
QDomElement CloneNodeById(const quint32 &nodeId)
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item=nullptr)
NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
QDomElement xml
Definition: vundocommand.h:105
VAbstractPattern * doc
Definition: vundocommand.h:106
quint32 nodeId
Definition: vundocommand.h:107
const QString trueStr
Definition: def.cpp:197
#define qApp
Definition: vapplication.h:67