Seamly2D
Code documentation
addgroup.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 addgroup.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 Valentina project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2016 Valentina project
35  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
36  **
37  ** Valentina 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  ** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "addgroup.h"
53 
54 #include <QDomNode>
55 #include <QDomNodeList>
56 
57 #include "../vmisc/logging.h"
58 #include "../vmisc/vabstractapplication.h"
59 #include "../vmisc/def.h"
60 #include "../vwidgets/vmaingraphicsview.h"
61 #include "../ifc/xml/vabstractpattern.h"
62 #include "vundocommand.h"
63 
64 //---------------------------------------------------------------------------------------------------------------------
65 AddGroup::AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent)
66  : VUndoCommand(xml, doc, parent)
67  , activeBlockName(doc->getActiveDraftBlockName())
68 {
69  setText(tr("add group"));
71 }
72 
73 //---------------------------------------------------------------------------------------------------------------------
75 {
76 }
77 
78 //---------------------------------------------------------------------------------------------------------------------
80 {
81  qCDebug(vUndo, "Undo.");
82 
83  doc->changeActiveDraftBlock(activeBlockName);//Without this user will not see this change
84 
85  QDomElement groups = doc->createGroups();
86  if (!groups.isNull())
87  {
88  QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
89  if (group.isElement())
90  {
91  group.setAttribute(VAbstractPattern::AttrVisible, trueStr);
92  doc->parseGroups(groups);
93  if (groups.removeChild(group).isNull())
94  {
95  qCDebug(vUndo, "Can't delete group.");
96  return;
97  }
98  emit updateGroups();
99  }
100  else
101  {
102  if (groups.childNodes().isEmpty())
103  {
104  QDomNode parent = groups.parentNode();
105  parent.removeChild(groups);
106  }
107 
108  qCDebug(vUndo, "Can't get group by id = %u.", nodeId);
109  return;
110  }
111  }
112  else
113  {
114  qCDebug(vUndo, "Can't get tag Groups.");
115  return;
116  }
117 
118  VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
119  doc->setCurrentDraftBlock(activeBlockName);//Return current pattern piece after undo
120 }
121 
122 //---------------------------------------------------------------------------------------------------------------------
124 {
125  qCDebug(vUndo, "Redo.");
126 
127  doc->changeActiveDraftBlock(activeBlockName);//Without this user will not see this change
128 
129  QDomElement groups = doc->createGroups();
130  if (!groups.isNull())
131  {
132  groups.appendChild(xml);
133  doc->parseGroups(groups);
134  emit updateGroups();
135  }
136  else
137  {
138  qCDebug(vUndo, "Can't get tag Groups.");
139  return;
140  }
141 
142  VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
143 }
const QString activeBlockName
Definition: addgroup.h:76
virtual void redo() Q_DECL_OVERRIDE
Definition: addgroup.cpp:123
AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent=nullptr)
Definition: addgroup.cpp:65
void updateGroups()
virtual ~AddGroup()
Definition: addgroup.cpp:74
virtual void undo() Q_DECL_OVERRIDE
Definition: addgroup.cpp:79
QDomElement createGroups()
static const QString TagGroup
void parseGroups(const QDomElement &domElement)
void setCurrentDraftBlock(const QString &patterPiece)
static const QString AttrVisible
void changeActiveDraftBlock(const QString &name, const Document &parse=Document::FullParse)
changeActiveDraftBlock set new active draft block name.
QDomElement elementById(quint32 id, const QString &tagName=QString())
static quint32 getParameterId(const QDomElement &domElement)
getParameterId return value id attribute.
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