Seamly2D
Code documentation
addpiece.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file addpiece.cpp
3  ** @author Douglas S Caskey
4  ** @date Dec 11, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25  /************************************************************************
26  **
27  ** @file
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 6 11, 2016
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentine project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2016 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more pieces.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #include "addpiece.h"
54 #include "../vpatterndb/vpiecenode.h"
55 #include "../vpatterndb/vpiecepath.h"
56 
57 //---------------------------------------------------------------------------------------------------------------------
58 AddPiece::AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &piece, const QString &blockName,
59  QUndoCommand *parent)
60  : VUndoCommand(xml, doc, parent)
61  , m_piece(piece)
62  , m_blockName(blockName)
63 {
64  setText(tr("add piece"));
66 }
67 
68 //---------------------------------------------------------------------------------------------------------------------
70 {}
71 
72 //---------------------------------------------------------------------------------------------------------------------
74 {
75  qCDebug(vUndo, "Undo.");
76 
77  QDomElement pieces = getPiecesElement();
78  if (not pieces.isNull())
79  {
80  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPiece);
81  if (domElement.isElement())
82  {
83  if (pieces.removeChild(domElement).isNull())
84  {
85  qCDebug(vUndo, "Can't delete node");
86  return;
87  }
88 
93  }
94  else
95  {
96  qCDebug(vUndo, "Can't get node by id = %u.", nodeId);
97  return;
98  }
99  }
100  else
101  {
102  qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagPieces));
103  return;
104  }
105  emit NeedFullParsing();
106 }
107 
108 //---------------------------------------------------------------------------------------------------------------------
110 {
111  qCDebug(vUndo, "Redo.");
112 
113  QDomElement pieces = getPiecesElement();
114  if (not pieces.isNull())
115  {
116  pieces.appendChild(xml);
117  }
118  else
119  {
120  qCDebug(vUndo, "Can't find tag %s.", qUtf8Printable(VAbstractPattern::TagPieces));
121  return;
122  }
123  RedoFullParsing();
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
127 QDomElement AddPiece::getPiecesElement() const
128 {
129  QDomElement pieces;
130  if (m_blockName.isEmpty())
131  {
133  }
134  else
135  {
136  pieces = doc->getDraftBlockElement(m_blockName).firstChildElement(VAbstractPattern::TagPieces);
137  }
138  return pieces;
139 }
virtual void undo() Q_DECL_OVERRIDE
Definition: addpiece.cpp:73
QDomElement getPiecesElement() const
Definition: addpiece.cpp:127
VPiece m_piece
Definition: addpiece.h:80
virtual ~AddPiece()
Definition: addpiece.cpp:69
virtual void redo() Q_DECL_OVERRIDE
Definition: addpiece.cpp:109
QString m_blockName
Definition: addpiece.h:81
AddPiece(const QDomElement &xml, VAbstractPattern *doc, const VPiece &piece, const QString &blockName=QString(), QUndoCommand *parent=nullptr)
Definition: addpiece.cpp:58
static const QString TagPieces
QDomElement getDraftBlockElement(const QString &name)
bool getActiveNodeElement(const QString &name, QDomElement &element) const
getActiveNodeElement find element in current draft block by name.
static const QString TagPiece
QDomElement elementById(quint32 id, const QString &tagName=QString())
static quint32 getParameterId(const QDomElement &domElement)
getParameterId return value id attribute.
QVector< VPieceNode > GetNodes() const
Definition: vpiecepath.cpp:227
Definition: vpiece.h:88
QVector< CustomSARecord > GetCustomSARecords() const
Definition: vpiece.cpp:444
QVector< quint32 > GetInternalPaths() const
Definition: vpiece.cpp:426
QVector< quint32 > getAnchors() const
Definition: vpiece.cpp:462
VPiecePath GetPath() const
Definition: vpiece.cpp:156
void NeedFullParsing()
virtual void RedoFullParsing()
void DecrementReferences(const QVector< quint32 > &nodes) const
QDomElement xml
Definition: vundocommand.h:105
VAbstractPattern * doc
Definition: vundocommand.h:106
quint32 nodeId
Definition: vundocommand.h:107