Seamly2D
Code documentation
toggle_piecelock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file toggle_piecelock.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 "toggle_piecelock.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 TogglePieceLock::TogglePieceLock(quint32 id, bool lock, VContainer *data, VAbstractPattern *doc, QUndoCommand *parent)
44  : VUndoCommand(QDomElement(), doc, parent)
45  , m_id(id)
46  , m_data(data)
47  , m_oldLock(!lock)
48  , m_newLock(lock)
49 {
50  setText(tr("Pattern piece lock"));
51 }
52 
53 //---------------------------------------------------------------------------------------------------------------------
55 {
56 }
57 
58 //---------------------------------------------------------------------------------------------------------------------
60 {
61  if (m_newLock != m_oldLock)
62  {
64  }
65 }
66 
67 //---------------------------------------------------------------------------------------------------------------------
69 {
70  if (m_newLock != m_oldLock)
71  {
73  }
74 }
75 
76 //---------------------------------------------------------------------------------------------------------------------
78 {
79  return static_cast<int>(UndoCommand::TogglePieceLock);
80 }
81 
82 //---------------------------------------------------------------------------------------------------------------------
84 {
85  return m_id;
86 }
87 
88 //---------------------------------------------------------------------------------------------------------------------
90 {
91  return m_newLock;
92 }
93 
94 //---------------------------------------------------------------------------------------------------------------------
95 void TogglePieceLock::doCmd(bool lock)
96 {
97  QDomElement element = doc->elementById(m_id, VAbstractPattern::TagPiece);
98  if (element.isElement())
99  {
100  doc->SetAttribute(element, AttrPieceLocked, lock);
101 
102  VPiece piece = m_data->DataPieces()->value(m_id);
103  piece.setIsLocked(lock);
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 lock changed: ") + (lock ? tr("Locked") : tr("Unlocked")));
111  }
112  else
113  {
114  return;
115  }
116 }
TogglePieceLock(quint32 id, bool lock, VContainer *data, VAbstractPattern *doc, QUndoCommand *parent=nullptr)
virtual int id() const Q_DECL_OVERRIDE
virtual void undo() Q_DECL_OVERRIDE
quint32 getpieceId() const
void updateList(quint32 m_id)
bool getNewLock() const
void doCmd(bool lock)
VContainer * m_data
virtual void redo() Q_DECL_OVERRIDE
virtual ~TogglePieceLock()
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 setIsLocked(bool isLocked)
Definition: vpiece.cpp:394
VAbstractPattern * doc
Definition: vundocommand.h:106
#define SCASSERT(cond)
Definition: def.h:317
const QString AttrPieceLocked
Definition: ifcdef.cpp:150
#define qApp
Definition: vapplication.h:67