QGIS API Documentation
2.8.2-Wien
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
core
composer
qgsaddremoveitemcommand.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsaddremoveitemcommand.cpp
3
---------------------------
4
begin : 2010-11-27
5
copyright : (C) 2010 by Marco Hugentobler
6
email : marco dot hugentobler at sourcepole dot ch
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 "
qgsaddremoveitemcommand.h
"
19
#include "
qgscomposeritem.h
"
20
#include "
qgscomposition.h
"
21
#include "
qgsproject.h
"
22
#include "
qgscomposermodel.h
"
23
24
QgsAddRemoveItemCommand::QgsAddRemoveItemCommand
(
State
s,
QgsComposerItem
* item,
QgsComposition
* c,
const
QString& text, QUndoCommand* parent ):
25
QUndoCommand( text, parent ), mItem( item ), mComposition( c ), mState( s ), mFirstRun( true )
26
{
27
}
28
29
QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand
()
30
{
31
if
( mState ==
Removed
)
//command class stores the item if removed from the composition
32
{
33
delete
mItem;
34
}
35
}
36
37
void
QgsAddRemoveItemCommand::redo
()
38
{
39
if
( mFirstRun )
40
{
41
mFirstRun =
false
;
42
return
;
43
}
44
switchState();
45
}
46
47
void
QgsAddRemoveItemCommand::undo
()
48
{
49
if
( mFirstRun )
50
{
51
mFirstRun =
false
;
52
return
;
53
}
54
switchState();
55
}
56
57
void
QgsAddRemoveItemCommand::switchState()
58
{
59
if
( mState ==
Added
)
60
{
61
if
( mComposition )
62
{
63
mComposition->
itemsModel
()->
setItemRemoved
( mItem );
64
mComposition->removeItem( mItem );
65
}
66
emit
itemRemoved
( mItem );
67
mState =
Removed
;
68
}
69
else
//Removed
70
{
71
if
( mComposition )
72
{
73
mComposition->
itemsModel
()->
setItemRestored
( mItem );
74
mComposition->addItem( mItem );
75
}
76
emit
itemAdded
( mItem );
77
mState =
Added
;
78
}
79
QgsProject::instance
()->
dirty
(
true
);
80
}
Generated on Sun May 10 2015 16:33:23 for QGIS API Documentation by
1.8.1.2