Seamly2D
Code documentation
showoperationpointname.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * @file showoperationpointname.cpp *
3  * *
4  * Copyright (C) 2017 Seamly, LLC *
5  * *
6  * https://github.com/fashionfreedom/seamly2d *
7  * *
8  ***************************************************************************
9  **
10  ** Seamly2D is free software: you can redistribute it and/or modify
11  ** it under the terms of the GNU General Public License as published by
12  ** the Free Software Foundation, either version 3 of the License, or
13  ** (at your option) any later version.
14  **
15  ** Seamly2D is distributed in the hope that it will be useful,
16  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  ** GNU General Public License for more details.
19  **
20  ** You should have received a copy of the GNU General Public License
21  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
22  **
23  **************************************************************************/
24 
25  #include "showoperationpointname.h"
26 
27  #include <QDomElement>
28 
29  #include "../ifc/xml/vabstractpattern.h"
30  #include "../vmisc/logging.h"
31  #include "../vwidgets/vmaingraphicsview.h"
32  #include "../vmisc/vabstractapplication.h"
33  #include "../vtools/tools/drawTools/vdrawtool.h"
34 
35  //---------------------------------------------------------------------------------------------------------------------
36  ShowOperationPointName::ShowOperationPointName(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible,
37  QUndoCommand *parent)
38  : VUndoCommand(QDomElement(), doc, parent)
39  , m_visible(visible)
40  , m_oldVisible(not visible)
41  , m_scene(qApp->getCurrentScene())
42  , m_idTool(idTool)
43  {
44  nodeId = idPoint;
45  setText(tr("toggle point visibility"));
46 
47  const QDomElement element = getDestinationObject(m_idTool, nodeId);
48  if (element.isElement())
49  {
51  }
52  else
53  {
54  qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
55  }
56  }
57 
58  //---------------------------------------------------------------------------------------------------------------------
60  {
61  qCDebug(vUndo, "Undo.");
62 
64  }
65 
66  //---------------------------------------------------------------------------------------------------------------------
68  {
69  qCDebug(vUndo, "Redo.");
70 
71  Do(m_visible);
72  }
73 
74  //---------------------------------------------------------------------------------------------------------------------
75  void ShowOperationPointName::Do(bool visible)
76  {
77  QDomElement domElement = getDestinationObject(m_idTool, nodeId);
78  if (not domElement.isNull() && domElement.isElement())
79  {
80  doc->SetAttribute<bool>(domElement, AttrShowPointName, visible);
81 
82  if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
83  {
84  tool->setPointNameVisiblity(nodeId, visible);
85  }
87  }
88  else
89  {
90  qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
91  }
92  }
ShowOperationPointName(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible, QUndoCommand *parent=nullptr)
virtual void redo() Q_DECL_OVERRIDE
virtual void undo() Q_DECL_OVERRIDE
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
static bool getParameterBool(const QDomElement &domElement, const QString &name, const QString &defValue)
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
SetAttribute set attribute in pattern file. Replace "," by ".".
Definition: vdomdocument.h:185
The VDrawTool abstract class for all draw tool.
Definition: vdrawtool.h:68
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item=nullptr)
NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view.
VAbstractPattern * doc
Definition: vundocommand.h:106
QDomElement getDestinationObject(quint32 idTool, quint32 idPoint) const
quint32 nodeId
Definition: vundocommand.h:107
const QString trueStr
Definition: def.cpp:197
const QString AttrShowPointName
Definition: ifcdef.cpp:153
#define qApp
Definition: vapplication.h:67