Seamly2D
Code documentation
rename_draftblock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file rename_draftblock.cpp
3  ** @author Douglas S Caskey
4  ** @date Jan 1, 2023
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2023 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 renamepp.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 17 7, 2014
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2013-2014 Valentina project
36  ** <https://github.com/fashionfreedom/seamly2d> 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 details.
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 "rename_draftblock.h"
54 
55 #include <QComboBox>
56 #include <QDomElement>
57 
58 #include "../vmisc/def.h"
59 #include "../vmisc/logging.h"
60 #include "../ifc/xml/vabstractpattern.h"
61 #include "vundocommand.h"
62 
63 //---------------------------------------------------------------------------------------------------------------------
64 RenameDraftBlock::RenameDraftBlock(VAbstractPattern *doc, const QString &newBlockName, QComboBox *combo, QUndoCommand *parent)
65  : VUndoCommand(QDomElement(), doc, parent)
66  , m_combo(combo)
67  , m_newBlockName(newBlockName)
68  , m_oldBlockName(QString())
69 {
70  setText(tr("rename pattern piece"));
71  SCASSERT(m_combo != nullptr)
73 }
74 
75 //---------------------------------------------------------------------------------------------------------------------
77 {}
78 
79 //---------------------------------------------------------------------------------------------------------------------
81 {
82  qCDebug(vUndo, "Undo.");
83 
85 }
86 
87 //---------------------------------------------------------------------------------------------------------------------
89 {
90  qCDebug(vUndo, "Redo.");
91 
93 }
94 
95 //---------------------------------------------------------------------------------------------------------------------
96 bool RenameDraftBlock::mergeWith(const QUndoCommand *command)
97 {
98  const RenameDraftBlock *renameCommand = static_cast<const RenameDraftBlock *>(command);
99  SCASSERT(renameCommand != nullptr)
100 
101  const QString oldName = renameCommand->getOldName();
102  if (m_newBlockName != oldName)
103  {
104  return false;
105  }
106 
107  m_newBlockName = renameCommand->getNewName();
108  return true;
109 }
110 
111 //---------------------------------------------------------------------------------------------------------------------
113 {
114  return static_cast<int>(UndoCommand::RenameDraftBlock);
115 }
116 
117 //---------------------------------------------------------------------------------------------------------------------
118 void RenameDraftBlock::changeName(const QString &oldName, const QString &newName)
119 {
120  if (doc->renameDraftBlock(oldName, newName))
121  {
122  m_combo->setItemText(m_combo->findText(oldName), newName);
123  }
124  else
125  {
126  qCWarning(vUndo, "Can't change pattern piece name");
127  }
128 }
RenameDraftBlock(VAbstractPattern *doc, const QString &newBlockName, QComboBox *combo, QUndoCommand *parent=nullptr)
virtual int id() const Q_DECL_OVERRIDE
void changeName(const QString &oldName, const QString &newName)
virtual ~RenameDraftBlock() Q_DECL_OVERRIDE
QString getNewName() const
virtual bool mergeWith(const QUndoCommand *command) Q_DECL_OVERRIDE
virtual void undo() Q_DECL_OVERRIDE
virtual void redo() Q_DECL_OVERRIDE
QString getOldName() const
bool renameDraftBlock(const QString &oldName, const QString &newName)
renameDraftBlock change draft block name.
QString getActiveDraftBlockName() const
getActiveDraftBlockName return current draft block name.
VAbstractPattern * doc
Definition: vundocommand.h:106
#define SCASSERT(cond)
Definition: def.h:317