Seamly2D
Code documentation
showpointname.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * @file showpointname.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 "showpointname.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/vabstracttool.h"
34 
35 //---------------------------------------------------------------------------------------------------------------------
36 ShowPointName::ShowPointName(VAbstractPattern *doc, quint32 id, bool visible, QUndoCommand *parent)
37  : VUndoCommand(QDomElement(), doc, parent)
38  , m_visible(visible)
39  , m_oldVisible(true)
40  , m_scene(qApp->getCurrentScene())
41 {
42  setText(tr("toggle point visibility"));
43 
44  nodeId = id;
45 
46  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint);
47  if (domElement.isElement())
48  {
50  }
51  else
52  {
53  qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
54  }
55 }
56 
57 //---------------------------------------------------------------------------------------------------------------------
59 {
60  qCDebug(vUndo, "Undo.");
61 
63 }
64 
65 //---------------------------------------------------------------------------------------------------------------------
67 {
68  qCDebug(vUndo, "Redo.");
69 
71 }
72 
73 //---------------------------------------------------------------------------------------------------------------------
74 void ShowPointName::setVisibility(bool visible)
75 {
76  QDomElement domElement = doc->elementById(nodeId, VAbstractPattern::TagPoint);
77  if (domElement.isElement())
78  {
79  doc->SetAttribute<bool>(domElement, AttrShowPointName, visible);
80 
81  if (VAbstractTool *tool = qobject_cast<VAbstractTool *>(VAbstractPattern::getTool(nodeId)))
82  {
83  tool->setPointNameVisiblity(nodeId, visible);
84  }
85  }
86  else
87  {
88  qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
89  }
90 }
void setVisibility(bool visible)
ShowPointName(VAbstractPattern *doc, quint32 id, bool visible, QUndoCommand *parent=nullptr)
virtual void redo() override
virtual void undo() override
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
static const QString TagPoint
The VAbstractTool abstract class for all tools.
Definition: vabstracttool.h:80
QDomElement elementById(quint32 id, const QString &tagName=QString())
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
VAbstractPattern * doc
Definition: vundocommand.h:106
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