QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsaddremovemultiframecommand.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsaddremovemultiframecommand.cpp
3  ---------------------------------
4  begin : 2012-07-31
5  copyright : (C) 2012 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 "qgscomposermultiframe.h"
20 #include "qgscomposition.h"
21 #include "qgsproject.h"
22 
23 
24 QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent )
25  : QUndoCommand( text, parent )
26  , mMultiFrame( multiFrame )
27  , mComposition( c )
28  , mState( s )
29  , mFirstRun( true )
30 {
31 }
32 
33 QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand()
34  : mMultiFrame( 0 )
35  , mComposition( 0 )
36  , mState( Added )
37  , mFirstRun( true )
38 {
39 }
40 
42 {
43  if ( mState == Removed )
44  {
45  delete mMultiFrame;
46  }
47 }
48 
50 {
51  if ( checkFirstRun() )
52  {
53  return;
54  }
55  switchState();
56 }
57 
59 {
60  if ( checkFirstRun() )
61  {
62  return;
63  }
64  switchState();
65 }
66 
67 void QgsAddRemoveMultiFrameCommand::switchState()
68 {
69  if ( mComposition )
70  {
71  if ( mState == Added )
72  {
73  mComposition->removeMultiFrame( mMultiFrame );
74  mState = Removed;
75  }
76  else
77  {
78  mComposition->addMultiFrame( mMultiFrame );
79  mState = Added;
80  }
81  QgsProject::instance()->dirty( true );
82  }
83 }
84 
85 bool QgsAddRemoveMultiFrameCommand::checkFirstRun()
86 {
87  if ( mFirstRun )
88  {
89  mFirstRun = false;
90  return true;
91  }
92  else
93  {
94  return false;
95  }
96 }