QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 
29 {
30  if ( mState == Removed ) //command class stores the item if removed from the composition
31  {
32  delete mItem;
33  }
34 }
35 
37 {
38  if ( mFirstRun )
39  {
40  mFirstRun = false;
41  return;
42  }
43  switchState();
44 }
45 
47 {
48  if ( mFirstRun )
49  {
50  mFirstRun = false;
51  return;
52  }
53  switchState();
54 }
55 
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 }
QgsAddRemoveItemCommand(State s, QgsComposerItem *item, QgsComposition *c, const QString &text, QUndoCommand *parent=0)
A item that forms part of a map composition.
void itemAdded(QgsComposerItem *item)
Graphics scene for map printing.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
void itemRemoved(QgsComposerItem *item)
void dirty(bool b)
Definition: qgsproject.cpp:396