Seamly2D
Code documentation
adddetnode.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 adddetnode.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 15 6, 2014
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) 2013-2015 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 "adddetnode.h"
53 
54 #include <QByteArray>
55 #include <QDomNode>
56 
57 #include "../vmisc/logging.h"
58 #include "../ifc/xml/vabstractpattern.h"
59 #include "vundocommand.h"
60 
61 //---------------------------------------------------------------------------------------------------------------------
62 AddDetNode::AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &blockName, QUndoCommand *parent)
63  : VUndoCommand(xml, doc, parent), m_blockName(blockName)
64 {
65  setText(QObject::tr("add node"));
67 }
68 
69 //---------------------------------------------------------------------------------------------------------------------
71 {}
72 
73 //---------------------------------------------------------------------------------------------------------------------
75 {
76  qCDebug(vUndo, "Undo.");
77 
78  QDomElement modeling = GetModelingSection();
79  if (not modeling.isNull())
80  {
81  QDomElement domElement = doc->elementById(nodeId);
82  if (domElement.isElement())
83  {
84  if (modeling.removeChild(domElement).isNull())
85  {
86  qCDebug(vUndo, "Can't delete node.");
87  return;
88  }
89  }
90  else
91  {
92  qCDebug(vUndo, "Can't get node by id = %u.", nodeId);
93  return;
94  }
95  }
96  else
97  {
98  qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling));
99  return;
100  }
101 }
102 
103 //---------------------------------------------------------------------------------------------------------------------
105 {
106  qCDebug(vUndo, "Redo.");
107 
108  QDomElement modeling = GetModelingSection();
109  if (not modeling.isNull())
110  {
111  modeling.appendChild(xml);
112  }
113  else
114  {
115  qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagModeling));
116  return;
117  }
118 }
119 
120 //---------------------------------------------------------------------------------------------------------------------
122 {
123  QDomElement modeling;
124  if (m_blockName.isEmpty())
125  {
127  }
128  else
129  {
130  modeling = doc->getDraftBlockElement(m_blockName).firstChildElement(VAbstractPattern::TagModeling);
131  }
132  return modeling;
133 }
virtual void redo() Q_DECL_OVERRIDE
Definition: adddetnode.cpp:104
AddDetNode(const QDomElement &xml, VAbstractPattern *doc, const QString &blockName, QUndoCommand *parent=nullptr)
Definition: adddetnode.cpp:62
QString m_blockName
Definition: adddetnode.h:75
virtual ~AddDetNode() Q_DECL_OVERRIDE
Definition: adddetnode.cpp:70
QDomElement GetModelingSection() const
Definition: adddetnode.cpp:121
virtual void undo() Q_DECL_OVERRIDE
Definition: adddetnode.cpp:74
static const QString TagModeling
QDomElement getDraftBlockElement(const QString &name)
bool getActiveNodeElement(const QString &name, QDomElement &element) const
getActiveNodeElement find element in current draft block by name.
QDomElement elementById(quint32 id, const QString &tagName=QString())
static quint32 getParameterId(const QDomElement &domElement)
getParameterId return value id attribute.
QDomElement xml
Definition: vundocommand.h:105
VAbstractPattern * doc
Definition: vundocommand.h:106
quint32 nodeId
Definition: vundocommand.h:107