QGIS API Documentation
2.2.0-Valmiera
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
23
QgsAddRemoveItemCommand::QgsAddRemoveItemCommand
(
State
s,
QgsComposerItem
* item,
QgsComposition
* c,
const
QString& text, QUndoCommand* parent ):
24
QUndoCommand( text, parent ), mItem( item ), mComposition( c ), mState( s ), mFirstRun( true )
25
{
26
}
27
28
QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand
()
29
{
30
if
(
mState
==
Removed
)
//command class stores the item if removed from the composition
31
{
32
delete
mItem
;
33
}
34
}
35
36
void
QgsAddRemoveItemCommand::redo
()
37
{
38
if
(
mFirstRun
)
39
{
40
mFirstRun
=
false
;
41
return
;
42
}
43
switchState
();
44
}
45
46
void
QgsAddRemoveItemCommand::undo
()
47
{
48
if
(
mFirstRun
)
49
{
50
mFirstRun
=
false
;
51
return
;
52
}
53
switchState
();
54
}
55
56
void
QgsAddRemoveItemCommand::switchState
()
57
{
58
if
(
mState
==
Added
)
59
{
60
if
(
mComposition
)
61
{
62
mComposition
->removeItem(
mItem
);
63
}
64
emit
itemRemoved
(
mItem
);
65
mState
=
Removed
;
66
}
67
else
//Removed
68
{
69
if
(
mComposition
)
70
{
71
mComposition
->addItem(
mItem
);
72
}
73
emit
itemAdded
(
mItem
);
74
mState
=
Added
;
75
}
76
QgsProject::instance
()->
dirty
(
true
);
77
}
Generated on Sun Feb 23 2014 14:27:18 for QGIS API Documentation by
1.8.1.2