Seamly2D
Code documentation
showdoublepointname.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * @file showdoublepointname.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 "showdoublepointname.h"
26 
27 #include <QDomElement>
28 
29 #include "../ifc/xml/vabstractpattern.h"
30 #include "../vwidgets/vmaingraphicsview.h"
31 #include "../vmisc/vabstractapplication.h"
32 #include "../vtools/tools/drawTools/vdrawtool.h"
33 
34 //---------------------------------------------------------------------------------------------------------------------
35 ShowDoublePointName::ShowDoublePointName(VAbstractPattern *doc, quint32 toolId, quint32 pointId, bool visible,
36  ShowDoublePoint type, QUndoCommand *parent)
37  : VUndoCommand(QDomElement(), doc, parent)
38  , m_visible(visible)
39  , m_oldVisible(not visible)
40  , m_scene(qApp->getCurrentScene())
41  , m_type(type)
42  , m_idTool(toolId)
43 {
44  nodeId = pointId;
45  qCDebug(vUndo, "Point id %u", nodeId);
46 
47  if (type == ShowDoublePoint::FirstPoint)
48  {
49  setText(tr("toggle the first dart visibility"));
50  }
51  else
52  {
53  setText(tr("toggle the second dart visibility"));
54  }
55 
56  const QDomElement domElement = doc->elementById(m_idTool, VAbstractPattern::TagPoint);
57  if (domElement.isElement())
58  {
59  if (type == ShowDoublePoint::FirstPoint)
60  {
62  }
63  else
64  {
66  }
67  }
68  else
69  {
70  qCDebug(vUndo, "Can't find point with id = %u.", m_idTool);
71  }
72 }
73 
74 //---------------------------------------------------------------------------------------------------------------------
76 {
77  qCDebug(vUndo, "Undo.");
78 
80 }
81 
82 //---------------------------------------------------------------------------------------------------------------------
84 {
85  qCDebug(vUndo, "Redo.");
86 
88 }
89 
90 //---------------------------------------------------------------------------------------------------------------------
92 {
93  QDomElement domElement = doc->elementById(m_idTool, VAbstractPattern::TagPoint);
94  if (domElement.isElement())
95  {
97  {
98  doc->SetAttribute<bool>(domElement, AttrShowPointName1, visible);
99  }
100  else
101  {
102  doc->SetAttribute<bool>(domElement, AttrShowPointName2, visible);
103  }
104 
105  if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
106  {
107  tool->setPointNameVisiblity(nodeId, visible);
108  }
109  VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
110  }
111  else
112  {
113  qCDebug(vUndo, "Can't find point with id = %u.", m_idTool);
114  }
115 }
virtual void undo() override
ShowDoublePoint m_type
void setVisibility(bool visible)
ShowDoublePointName(VAbstractPattern *doc, quint32 toolId, quint32 pointId, bool visible, ShowDoublePoint type, QUndoCommand *parent=nullptr)
virtual void redo() override
QGraphicsScene * m_scene
static VDataTool * getTool(quint32 id)
getTool return tool from tool list.
static const QString TagPoint
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
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
quint32 nodeId
Definition: vundocommand.h:107
const QString trueStr
Definition: def.cpp:197
const QString AttrShowPointName2
Definition: ifcdef.cpp:155
const QString AttrShowPointName1
Definition: ifcdef.cpp:154
ShowDoublePoint
#define qApp
Definition: vapplication.h:67