Seamly2D
Code documentation
savetooloptions.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 savetooloptions.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 11 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 "savetooloptions.h"
53 
54 #include <QDomNode>
55 
56 #include "../vmisc/def.h"
57 #include "../vmisc/logging.h"
58 #include "../ifc/xml/vabstractpattern.h"
59 #include "vundocommand.h"
60 
61 //---------------------------------------------------------------------------------------------------------------------
62 SaveToolOptions::SaveToolOptions(const QDomElement &oldXml, const QDomElement &newXml, VAbstractPattern *doc,
63  const quint32 &id, QUndoCommand *parent)
64  : VUndoCommand(QDomElement(), doc, parent), oldXml(oldXml), newXml(newXml)
65 {
66  setText(tr("save tool option"));
67  nodeId = id;
68 }
69 
70 //---------------------------------------------------------------------------------------------------------------------
72 {}
73 
74 //---------------------------------------------------------------------------------------------------------------------
76 {
77  qCDebug(vUndo, "Undo.");
78 
79  QDomElement domElement = doc->elementById(nodeId);
80  if (domElement.isElement())
81  {
82  domElement.parentNode().replaceChild(oldXml, domElement);
83 
85  }
86  else
87  {
88  qCDebug(vUndo, "Can't find tool with id = %u.", nodeId);
89  return;
90  }
91 }
92 
93 //---------------------------------------------------------------------------------------------------------------------
95 {
96  qCDebug(vUndo, "Redo.");
97 
98  QDomElement domElement = doc->elementById(nodeId);
99  if (domElement.isElement())
100  {
101  domElement.parentNode().replaceChild(newXml, domElement);
102 
104  }
105  else
106  {
107  qCDebug(vUndo, "Can't find tool with id = %u.", nodeId);
108  return;
109  }
110 }
111 
112 //---------------------------------------------------------------------------------------------------------------------
113 bool SaveToolOptions::mergeWith(const QUndoCommand *command)
114 {
115  const SaveToolOptions *saveCommand = static_cast<const SaveToolOptions *>(command);
116  SCASSERT(saveCommand != nullptr)
117  const quint32 id = saveCommand->getToolId();
118 
119  if (id != nodeId)
120  {
121  return false;
122  }
123 
124  newXml = saveCommand->getNewXml();
125  return true;
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
130 {
131  return static_cast<int>(UndoCommand::SaveToolOptions);
132 }
virtual int id() const Q_DECL_OVERRIDE
virtual void undo() Q_DECL_OVERRIDE
virtual ~SaveToolOptions() Q_DECL_OVERRIDE
const QDomElement oldXml
SaveToolOptions(const QDomElement &oldXml, const QDomElement &newXml, VAbstractPattern *doc, const quint32 &id, QUndoCommand *parent=nullptr)
virtual void redo() Q_DECL_OVERRIDE
QDomElement newXml
QDomElement getNewXml() const
quint32 getToolId() const
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE
QDomElement elementById(quint32 id, const QString &tagName=QString())
VAbstractPattern * doc
Definition: vundocommand.h:106
void NeedLiteParsing(const Document &parse)
quint32 nodeId
Definition: vundocommand.h:107
#define SCASSERT(cond)
Definition: def.h:317