QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
layout
qgslayoutitemgroupundocommand.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutitemgroupundocommand.cpp
3
---------------------------
4
begin : 2016-06-09
5
copyright : (C) 2016 by Sandro Santilli
6
email : strk at kbt dot io
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgslayoutitemgroupundocommand.h
"
19
20
#include "
qgslayout.h
"
21
#include "
qgslayoutitemgroup.h
"
22
#include "
qgsproject.h
"
23
24
#include "moc_qgslayoutitemgroupundocommand.cpp"
25
27
QgsLayoutItemGroupUndoCommand::QgsLayoutItemGroupUndoCommand( State s,
QgsLayoutItemGroup
*group,
QgsLayout
*layout,
const
QString &text, QUndoCommand *parent )
28
: QUndoCommand( text, parent )
29
, mGroupUuid( group->uuid() )
30
, mLayout( layout )
31
, mState( s )
32
{
33
const
QList< QgsLayoutItem * > items = group->
items
();
34
for
(
QgsLayoutItem
*i : items )
35
{
36
mItemUuids.insert( i->uuid() );
37
}
38
}
39
40
void
QgsLayoutItemGroupUndoCommand::redo()
41
{
42
if
( mFirstRun )
43
{
44
mFirstRun =
false
;
45
return
;
46
}
47
switchState();
48
}
49
50
void
QgsLayoutItemGroupUndoCommand::undo()
51
{
52
if
( mFirstRun )
53
{
54
mFirstRun =
false
;
55
return
;
56
}
57
switchState();
58
}
59
60
void
QgsLayoutItemGroupUndoCommand::switchState()
61
{
62
if
( mState == Grouped )
63
{
64
// ungroup
65
QgsLayoutItemGroup
*group =
dynamic_cast<
QgsLayoutItemGroup
*
>
( mLayout->itemByUuid( mGroupUuid ) );
66
Q_ASSERT_X( group,
"QgsLayoutItemGroupUndoCommand::switchState"
,
"Could not find group"
);
67
group->
removeItems
();
68
mLayout->removeLayoutItemPrivate( group );
69
mState = Ungrouped;
70
}
71
else
//Ungrouped
72
{
73
// find group by uuid...
74
QgsLayoutItemGroup
*group =
dynamic_cast<
QgsLayoutItemGroup
*
>
( mLayout->itemByUuid( mGroupUuid ) );
75
if
( !group )
76
{
77
group =
new
QgsLayoutItemGroup
( mLayout );
78
mLayout->addLayoutItemPrivate( group );
79
}
80
81
for
(
const
QString &childUuid : std::as_const( mItemUuids ) )
82
{
83
QgsLayoutItem
*childItem = mLayout->itemByUuid( childUuid );
84
group->
addItem
( childItem );
85
}
86
87
mState = Grouped;
88
}
89
mLayout->project()->setDirty(
true
);
90
}
QgsLayoutItemGroup
A container for grouping several QgsLayoutItems.
Definition
qgslayoutitemgroup.h:28
QgsLayoutItemGroup::removeItems
void removeItems()
Removes all items from the group (but does not delete them).
Definition
qgslayoutitemgroup.cpp:99
QgsLayoutItemGroup::addItem
void addItem(QgsLayoutItem *item)
Adds an item to the group.
Definition
qgslayoutitemgroup.cpp:81
QgsLayoutItemGroup::items
QList< QgsLayoutItem * > items() const
Returns a list of items contained by the group.
Definition
qgslayoutitemgroup.cpp:111
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition
qgslayoutitem.h:106
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition
qgslayout.h:51
qgslayout.h
qgslayoutitemgroup.h
qgslayoutitemgroupundocommand.h
qgsproject.h
Generated on
for QGIS API Documentation by
1.17.0