Seamly2D
Code documentation
set_piece_color.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file set_piece_color.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 elements.
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 #include "set_piece_color.h"
26 
27 #include <QDomElement>
28 #include <QHash>
29 #include <QMessageLogger>
30 #include <QtDebug>
31 
32 #include "vundocommand.h"
33 #include "../ifc/ifcdef.h"
34 #include "../ifc/xml/vabstractpattern.h"
35 #include "../vmisc/vabstractapplication.h"
36 #include "../vmisc/def.h"
37 #include "../vmisc/logging.h"
38 #include "../vpatterndb/vcontainer.h"
39 #include "../vpatterndb/vpiece.h"
40 #include "../vwidgets/vabstractmainwindow.h"
41 
42 //---------------------------------------------------------------------------------------------------------------------
43 SetPieceColor::SetPieceColor(quint32 id, QString color, VContainer *data, VAbstractPattern *doc, QUndoCommand *parent)
44  : VUndoCommand(QDomElement(), doc, parent)
45  , m_id(id)
46  , m_data(data)
47  , m_oldColor(m_data->DataPieces()->value(m_id).getColor())
48  , m_newColor(color)
49 {
50  setText(tr("Change piece color"));
51 }
52 
53 //---------------------------------------------------------------------------------------------------------------------
55 {
56 }
57 
58 //---------------------------------------------------------------------------------------------------------------------
60 {
61  if (m_newColor != m_oldColor)
62  {
64  }
65 }
66 
67 //---------------------------------------------------------------------------------------------------------------------
69 {
70  if (m_newColor != m_oldColor)
71  {
73  }
74 }
75 
76 //---------------------------------------------------------------------------------------------------------------------
77 int SetPieceColor::id() const
78 {
79  return static_cast<int>(UndoCommand::SetPieceColor);
80 }
81 
82 //---------------------------------------------------------------------------------------------------------------------
84 {
85  return m_id;
86 }
87 
88 //---------------------------------------------------------------------------------------------------------------------
89 QString SetPieceColor::getColor() const
90 {
91  return m_newColor;
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
95 void SetPieceColor::doCmd(QString color)
96 {
97  QDomElement element = doc->elementById(m_id, VAbstractPattern::TagPiece);
98  if (element.isElement())
99  {
100  doc->SetAttribute(element, QStringLiteral("color"), color);
101 
102  VPiece piece = m_data->DataPieces()->value(m_id);
103  piece.setColor(color);
104  m_data->UpdatePiece(m_id, piece);
105 
106  emit updateList(m_id);
107 
108  VAbstractMainWindow *window = qobject_cast<VAbstractMainWindow *>(qApp->getMainWindow());
109  SCASSERT(window != nullptr)
110  window->ShowToolTip(tr("Piece color changed: ") + color);
111  }
112  else
113  {
114  return;
115  }
116 }
QString m_oldColor
virtual int id() const Q_DECL_OVERRIDE
void updateList(quint32 m_id)
virtual void undo() Q_DECL_OVERRIDE
QString m_newColor
VContainer * m_data
QString getColor() const
virtual ~SetPieceColor()
quint32 getpieceId() const
virtual void redo() Q_DECL_OVERRIDE
SetPieceColor(quint32 id, QString color, VContainer *data, VAbstractPattern *doc, QUndoCommand *parent=nullptr)
void doCmd(QString color)
virtual void ShowToolTip(const QString &toolTip)=0
static const QString TagPiece
void setColor(const QString &value)
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
VAbstractPattern * doc
Definition: vundocommand.h:106
#define SCASSERT(cond)
Definition: def.h:317
#define qApp
Definition: vapplication.h:67