QGIS API Documentation  2.99.0-Master (9caa722)
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 
34  : mState( Added )
35  , mFirstRun( true )
36 {
37 }
38 
40 {
41  if ( mState == Removed )
42  {
43  delete mMultiFrame;
44  }
45 }
46 
48 {
49  if ( checkFirstRun() )
50  {
51  return;
52  }
53  switchState();
54 }
55 
57 {
58  if ( checkFirstRun() )
59  {
60  return;
61  }
62  switchState();
63 }
64 
65 void QgsAddRemoveMultiFrameCommand::switchState()
66 {
67  if ( mComposition )
68  {
69  if ( mState == Added )
70  {
71  mComposition->removeMultiFrame( mMultiFrame );
72  mState = Removed;
73  }
74  else
75  {
76  mComposition->addMultiFrame( mMultiFrame );
77  mState = Added;
78  }
79  mComposition->project()->setDirty( true );
80  }
81 }
82 
83 bool QgsAddRemoveMultiFrameCommand::checkFirstRun()
84 {
85  if ( mFirstRun )
86  {
87  mFirstRun = false;
88  return true;
89  }
90  else
91  {
92  return false;
93  }
94 }
QgsAddRemoveMultiFrameCommand(State s, QgsComposerMultiFrame *multiFrame, QgsComposition *c, const QString &text, QUndoCommand *parent=0)
void setDirty(bool b=true)
Flag the project as dirty (modified).
Definition: qgsproject.cpp:410
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)
QgsProject * project() const
The project associated with the composition.
void addMultiFrame(QgsComposerMultiFrame *multiFrame)
Adds multiframe. The object is owned by QgsComposition until removeMultiFrame is called.