QGIS API Documentation  2.99.0-Master (ae4d26a)
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 {
30 }
31 
33 {
34  if ( mState == Removed )
35  {
36  delete mMultiFrame;
37  }
38 }
39 
41 {
42  if ( checkFirstRun() )
43  {
44  return;
45  }
46  switchState();
47 }
48 
50 {
51  if ( checkFirstRun() )
52  {
53  return;
54  }
55  switchState();
56 }
57 
58 void QgsAddRemoveMultiFrameCommand::switchState()
59 {
60  if ( mComposition )
61  {
62  if ( mState == Added )
63  {
64  mComposition->removeMultiFrame( mMultiFrame );
65  mState = Removed;
66  }
67  else
68  {
69  mComposition->addMultiFrame( mMultiFrame );
70  mState = Added;
71  }
72  mComposition->project()->setDirty( true );
73  }
74 }
75 
76 bool QgsAddRemoveMultiFrameCommand::checkFirstRun()
77 {
78  if ( mFirstRun )
79  {
80  mFirstRun = false;
81  return true;
82  }
83  else
84  {
85  return false;
86  }
87 }
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.