QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 ), mMultiFrame( multiFrame ), mComposition( c ), mState( s ), mFirstRun( true )
26 {
27 }
28 
29 QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand(): mMultiFrame( 0 ), mComposition( 0 )
30 {
31 }
32 
34 {
35  if ( mState == Removed )
36  {
37  delete mMultiFrame;
38  }
39 }
40 
42 {
43  if ( checkFirstRun() )
44  {
45  return;
46  }
47  switchState();
48 }
49 
51 {
52  if ( checkFirstRun() )
53  {
54  return;
55  }
56  switchState();
57 }
58 
59 void QgsAddRemoveMultiFrameCommand::switchState()
60 {
61  if ( mComposition )
62  {
63  if ( mState == Added )
64  {
65  mComposition->removeMultiFrame( mMultiFrame );
66  mState = Removed;
67  }
68  else
69  {
70  mComposition->addMultiFrame( mMultiFrame );
71  mState = Added;
72  }
73  QgsProject::instance()->dirty( true );
74  }
75 }
76 
77 bool QgsAddRemoveMultiFrameCommand::checkFirstRun()
78 {
79  if ( mFirstRun )
80  {
81  mFirstRun = false;
82  return true;
83  }
84  else
85  {
86  return false;
87  }
88 }
QgsAddRemoveMultiFrameCommand(State s, QgsComposerMultiFrame *multiFrame, QgsComposition *c, const QString &text, QUndoCommand *parent=0)
Abstract base class for composer items with the ability to distribute the content to several frames (...
Graphics scene for map printing.
void removeMultiFrame(QgsComposerMultiFrame *multiFrame)
Removes multi frame (but does not delete it)
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
void addMultiFrame(QgsComposerMultiFrame *multiFrame)
Adds multiframe.
void dirty(bool b)
Definition: qgsproject.cpp:396