Seamly2D
Code documentation
togglepieceinlayout.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file togglepieceinlayout.cpp
3  ** @author Douglas S Caskey
4  ** @date Jan 2, 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 toggledetailinlayout.cpp
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 25 6, 2016
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) 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 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 "togglepieceinlayout.h"
54 
55 #include <QDomElement>
56 #include <QHash>
57 #include <QMessageLogger>
58 #include <QtDebug>
59 
60 #include "vundocommand.h"
61 #include "../ifc/ifcdef.h"
62 #include "../ifc/xml/vabstractpattern.h"
63 #include "../vmisc/vabstractapplication.h"
64 #include "../vmisc/def.h"
65 #include "../vmisc/logging.h"
66 #include "../vpatterndb/vcontainer.h"
67 #include "../vpatterndb/vpiece.h"
68 #include "../vwidgets/vabstractmainwindow.h"
69 
70 //---------------------------------------------------------------------------------------------------------------------
72  QUndoCommand *parent)
73  : VUndoCommand(QDomElement(), doc, parent)
74  , m_id(id)
75  , m_data(data)
76  , m_oldState(!state)
77  , m_newState(state)
78 {
79  setText(tr("Piece in Layout List"));
80 }
81 
82 //---------------------------------------------------------------------------------------------------------------------
84 {
85 }
86 
87 //---------------------------------------------------------------------------------------------------------------------
89 {
90  qCDebug(vUndo, "TogglePieceInLayout::undo().");
91 
92  if (m_newState != m_oldState)
93  {
95  }
96 }
97 
98 //---------------------------------------------------------------------------------------------------------------------
100 {
101  qCDebug(vUndo, "TogglePieceInLayout::redo().");
102 
103  if (m_newState != m_oldState)
104  {
105  doCmd(m_newState);
106  }
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {
112  return static_cast<int>(UndoCommand::TogglePieceInLayout);
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
117 {
118  return m_id;
119 }
120 
121 //---------------------------------------------------------------------------------------------------------------------
123 {
124  return m_newState;
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
129 {
130  QDomElement element = doc->elementById(m_id, VAbstractPattern::TagPiece);
131  if (element.isElement())
132  {
133  doc->SetAttribute(element, AttrInLayout, state);
134 
135  VPiece piece = m_data->DataPieces()->value(m_id);
136  piece.SetInLayout(state);
137  m_data->UpdatePiece(m_id, piece);
138  emit updateList(m_id);
139 
140  VAbstractMainWindow *window = qobject_cast<VAbstractMainWindow *>(qApp->getMainWindow());
141  SCASSERT(window != nullptr)
142  window->ShowToolTip(tr("Include piece in layout changed: ") + (state ? tr("Include") : tr("Exclude")));
143  }
144  else
145  {
146  qDebug("Can't get piece by id = %u.", m_id);
147  return;
148  }
149 }
TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc, QUndoCommand *parent=nullptr)
virtual void undo() Q_DECL_OVERRIDE
virtual void redo() Q_DECL_OVERRIDE
virtual int id() const Q_DECL_OVERRIDE
void updateList(quint32 m_id)
virtual void ShowToolTip(const QString &toolTip)=0
static const QString TagPiece
The VContainer class container of all variables.
Definition: vcontainer.h:141
const QHash< quint32, VPiece > * DataPieces() const
Definition: vcontainer.cpp:712
void UpdatePiece(quint32 id, const VPiece &piece)
Definition: vcontainer.cpp:510
QDomElement elementById(quint32 id, const QString &tagName=QString())
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
Definition: vpiece.h:88
void SetInLayout(bool inLayout)
Definition: vpiece.cpp:382
VAbstractPattern * doc
Definition: vundocommand.h:106
#define SCASSERT(cond)
Definition: def.h:317
const QString AttrInLayout
Definition: ifcdef.cpp:149
#define qApp
Definition: vapplication.h:67