1 /************************************************************************
2 **
3 ** @file
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 20 9, 2017
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2017 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "operationshowlabel.h"
30
31 #include <QDomElement>
32
33 #include "../ifc/xml/vabstractpattern.h"
34 #include "../vwidgets/vmaingraphicsview.h"
35 #include "../vmisc/vabstractapplication.h"
36 #include "../vtools/tools/drawTools/vdrawtool.h"
37
38 //---------------------------------------------------------------------------------------------------------------------
OperationShowLabel(VAbstractPattern * doc,quint32 idTool,quint32 idPoint,bool visible,QUndoCommand * parent)39 OperationShowLabel::OperationShowLabel(VAbstractPattern *doc, quint32 idTool, quint32 idPoint, bool visible,
40 QUndoCommand *parent)
41 : VUndoCommand(QDomElement(), doc, parent),
42 m_visible(visible),
43 m_oldVisible(not visible),
44 m_scene(VAbstractValApplication::VApp()->getCurrentScene()),
45 m_idTool(idTool)
46 {
47 nodeId = idPoint;
48 qCDebug(vUndo, "Point id %u", nodeId);
49
50 setText(tr("toggle label"));
51
52 qCDebug(vUndo, "Tool id %u", m_idTool);
53
54 const QDomElement element = GetDestinationObject(m_idTool, nodeId);
55 if (element.isElement())
56 {
57 m_oldVisible = doc->GetParametrBool(element, AttrShowLabel, trueStr);
58 }
59 else
60 {
61 qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
62 }
63 }
64
65 //---------------------------------------------------------------------------------------------------------------------
undo()66 void OperationShowLabel::undo()
67 {
68 qCDebug(vUndo, "Undo.");
69
70 Do(m_oldVisible);
71 }
72
73 //---------------------------------------------------------------------------------------------------------------------
redo()74 void OperationShowLabel::redo()
75 {
76 qCDebug(vUndo, "Redo.");
77
78 Do(m_visible);
79 }
80
81 //---------------------------------------------------------------------------------------------------------------------
Do(bool visible)82 void OperationShowLabel::Do(bool visible)
83 {
84 QDomElement domElement = GetDestinationObject(m_idTool, nodeId);
85 if (not domElement.isNull() && domElement.isElement())
86 {
87 doc->SetAttribute<bool>(domElement, AttrShowLabel, visible);
88
89 if (VDrawTool *tool = qobject_cast<VDrawTool *>(VAbstractPattern::getTool(m_idTool)))
90 {
91 tool->SetLabelVisible(nodeId, visible);
92 }
93 VMainGraphicsView::NewSceneRect(m_scene, VAbstractValApplication::VApp()->getSceneView());
94 }
95 else
96 {
97 qCDebug(vUndo, "Can't find point with id = %u.", nodeId);
98 }
99 }
100
101