Quantum GIS API Documentation
1.7.5-Wroclaw
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
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
21
QgsAddRemoveItemCommand::QgsAddRemoveItemCommand
(
State
s,
QgsComposerItem
* item,
QgsComposition
* c,
const
QString& text, QUndoCommand* parent ):
22
QUndoCommand( text, parent ), mItem( item ), mComposition( c ), mState( s ), mFirstRun( true )
23
{
24
}
25
26
QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand
()
27
{
28
if
(
mState
==
Removed
)
//command class stores the item if removed from the composition
29
{
30
delete
mItem
;
31
}
32
}
33
34
void
QgsAddRemoveItemCommand::redo
()
35
{
36
if
(
mFirstRun
)
37
{
38
mFirstRun
=
false
;
39
return
;
40
}
41
switchState
();
42
}
43
44
void
QgsAddRemoveItemCommand::undo
()
45
{
46
if
(
mFirstRun
)
47
{
48
mFirstRun
=
false
;
49
return
;
50
}
51
switchState
();
52
}
53
54
void
QgsAddRemoveItemCommand::switchState
()
55
{
56
if
(
mState
==
Added
)
57
{
58
if
(
mComposition
)
59
{
60
mComposition
->removeItem(
mItem
);
61
}
62
emit
itemRemoved
(
mItem
);
63
mState
=
Removed
;
64
}
65
else
//Removed
66
{
67
if
(
mComposition
)
68
{
69
mComposition
->addItem(
mItem
);
70
}
71
emit
itemAdded
(
mItem
);
72
mState
=
Added
;
73
}
74
}
Generated on Wed Jun 13 2012 13:54:10 for Quantum GIS API Documentation by
1.8.1