Seamly2D
Code documentation
addgroup.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* *
3
* Copyright (C) 2017 Seamly, LLC *
4
* *
5
* https://github.com/fashionfreedom/seamly2d *
6
* *
7
***************************************************************************
8
**
9
** Seamly2D is free software: you can redistribute it and/or modify
10
** it under the terms of the GNU General Public License as published by
11
** the Free Software Foundation, either version 3 of the License, or
12
** (at your option) any later version.
13
**
14
** Seamly2D is distributed in the hope that it will be useful,
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
** GNU General Public License for more details.
18
**
19
** You should have received a copy of the GNU General Public License
20
** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21
**
22
**************************************************************************
23
24
************************************************************************
25
**
26
** @file addgroup.cpp
27
** @author Roman Telezhynskyi <dismine(at)gmail.com>
28
** @date 6 4, 2016
29
**
30
** @brief
31
** @copyright
32
** This source code is part of the Valentina project, a pattern making
33
** program, whose allow create and modeling patterns of clothing.
34
** Copyright (C) 2016 Valentina project
35
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
36
**
37
** Valentina is free software: you can redistribute it and/or modify
38
** it under the terms of the GNU General Public License as published by
39
** the Free Software Foundation, either version 3 of the License, or
40
** (at your option) any later version.
41
**
42
** Valentina is distributed in the hope that it will be useful,
43
** but WITHOUT ANY WARRANTY; without even the implied warranty of
44
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45
** GNU General Public License for more details.
46
**
47
** You should have received a copy of the GNU General Public License
48
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
49
**
50
*************************************************************************/
51
52
#include "
addgroup.h
"
53
54
#include <QDomNode>
55
#include <QDomNodeList>
56
57
#include "../vmisc/logging.h"
58
#include "../vmisc/vabstractapplication.h"
59
#include "../vmisc/def.h"
60
#include "../vwidgets/vmaingraphicsview.h"
61
#include "../ifc/xml/vabstractpattern.h"
62
#include "
vundocommand.h
"
63
64
//---------------------------------------------------------------------------------------------------------------------
65
AddGroup::AddGroup
(
const
QDomElement &xml,
VAbstractPattern
*doc, QUndoCommand *parent)
66
:
VUndoCommand
(xml, doc, parent)
67
, activeBlockName(doc->getActiveDraftBlockName())
68
{
69
setText(tr(
"add group"
));
70
nodeId
=
doc
->
getParameterId
(
xml
);
71
}
72
73
//---------------------------------------------------------------------------------------------------------------------
74
AddGroup::~AddGroup
()
75
{
76
}
77
78
//---------------------------------------------------------------------------------------------------------------------
79
void
AddGroup::undo
()
80
{
81
qCDebug(vUndo,
"Undo."
);
82
83
doc
->
changeActiveDraftBlock
(
activeBlockName
);
//Without this user will not see this change
84
85
QDomElement groups =
doc
->
createGroups
();
86
if
(!groups.isNull())
87
{
88
QDomElement group =
doc
->
elementById
(
nodeId
,
VAbstractPattern::TagGroup
);
89
if
(group.isElement())
90
{
91
group.setAttribute(
VAbstractPattern::AttrVisible
,
trueStr
);
92
doc
->
parseGroups
(groups);
93
if
(groups.removeChild(group).isNull())
94
{
95
qCDebug(vUndo,
"Can't delete group."
);
96
return
;
97
}
98
emit
updateGroups
();
99
}
100
else
101
{
102
if
(groups.childNodes().isEmpty())
103
{
104
QDomNode parent = groups.parentNode();
105
parent.removeChild(groups);
106
}
107
108
qCDebug(vUndo,
"Can't get group by id = %u."
,
nodeId
);
109
return
;
110
}
111
}
112
else
113
{
114
qCDebug(vUndo,
"Can't get tag Groups."
);
115
return
;
116
}
117
118
VMainGraphicsView::NewSceneRect
(
qApp
->getCurrentScene(),
qApp
->getSceneView());
119
doc
->
setCurrentDraftBlock
(
activeBlockName
);
//Return current pattern piece after undo
120
}
121
122
//---------------------------------------------------------------------------------------------------------------------
123
void
AddGroup::redo
()
124
{
125
qCDebug(vUndo,
"Redo."
);
126
127
doc
->
changeActiveDraftBlock
(
activeBlockName
);
//Without this user will not see this change
128
129
QDomElement groups =
doc
->
createGroups
();
130
if
(!groups.isNull())
131
{
132
groups.appendChild(
xml
);
133
doc
->
parseGroups
(groups);
134
emit
updateGroups
();
135
}
136
else
137
{
138
qCDebug(vUndo,
"Can't get tag Groups."
);
139
return
;
140
}
141
142
VMainGraphicsView::NewSceneRect
(
qApp
->getCurrentScene(),
qApp
->getSceneView());
143
}
addgroup.h
AddGroup::activeBlockName
const QString activeBlockName
Definition:
addgroup.h:76
AddGroup::redo
virtual void redo() Q_DECL_OVERRIDE
Definition:
addgroup.cpp:123
AddGroup::AddGroup
AddGroup(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent=nullptr)
Definition:
addgroup.cpp:65
AddGroup::updateGroups
void updateGroups()
AddGroup::~AddGroup
virtual ~AddGroup()
Definition:
addgroup.cpp:74
AddGroup::undo
virtual void undo() Q_DECL_OVERRIDE
Definition:
addgroup.cpp:79
VAbstractPattern
Definition:
vabstractpattern.h:113
VAbstractPattern::createGroups
QDomElement createGroups()
Definition:
vabstractpattern.cpp:2180
VAbstractPattern::TagGroup
static const QString TagGroup
Definition:
vabstractpattern.h:286
VAbstractPattern::parseGroups
void parseGroups(const QDomElement &domElement)
Definition:
vabstractpattern.cpp:445
VAbstractPattern::setCurrentDraftBlock
void setCurrentDraftBlock(const QString &patterPiece)
VAbstractPattern::AttrVisible
static const QString AttrVisible
Definition:
vabstractpattern.h:311
VAbstractPattern::changeActiveDraftBlock
void changeActiveDraftBlock(const QString &name, const Document &parse=Document::FullParse)
changeActiveDraftBlock set new active draft block name.
Definition:
vabstractpattern.cpp:330
VDomDocument::elementById
QDomElement elementById(quint32 id, const QString &tagName=QString())
Definition:
vdomdocument.cpp:222
VDomDocument::getParameterId
static quint32 getParameterId(const QDomElement &domElement)
getParameterId return value id attribute.
Definition:
vdomdocument.cpp:534
VMainGraphicsView::NewSceneRect
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.
Definition:
vmaingraphicsview.cpp:838
VUndoCommand
Definition:
vundocommand.h:93
VUndoCommand::xml
QDomElement xml
Definition:
vundocommand.h:105
VUndoCommand::doc
VAbstractPattern * doc
Definition:
vundocommand.h:106
VUndoCommand::nodeId
quint32 nodeId
Definition:
vundocommand.h:107
trueStr
const QString trueStr
Definition:
def.cpp:197
qApp
#define qApp
Definition:
vapplication.h:67
vundocommand.h
src
libs
vtools
undocommands
addgroup.cpp
Generated by
1.9.1