Quantum GIS API Documentation  master-693a1fe
src/core/composer/qgsaddremovemultiframecommand.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsaddremovemultiframecommand.cpp
00003                           ---------------------------------
00004     begin                : 2012-07-31
00005     copyright            : (C) 2012 by Marco Hugentobler
00006     email                : marco dot hugentobler at sourcepole dot ch
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qgsaddremovemultiframecommand.h"
00019 #include "qgscomposermultiframe.h"
00020 #include "qgscomposition.h"
00021 
00022 
00023 QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent ):
00024     QUndoCommand( text, parent ), mMultiFrame( multiFrame ), mComposition( c ), mState( s ), mFirstRun( true )
00025 {
00026 }
00027 
00028 QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand(): mMultiFrame( 0 ), mComposition( 0 )
00029 {
00030 }
00031 
00032 QgsAddRemoveMultiFrameCommand::~QgsAddRemoveMultiFrameCommand()
00033 {
00034   if ( mState == Removed )
00035   {
00036     delete mMultiFrame;
00037   }
00038 }
00039 
00040 void QgsAddRemoveMultiFrameCommand::redo()
00041 {
00042   if ( checkFirstRun() )
00043   {
00044     return;
00045   }
00046   switchState();
00047 }
00048 
00049 void QgsAddRemoveMultiFrameCommand::undo()
00050 {
00051   if ( checkFirstRun() )
00052   {
00053     return;
00054   }
00055   switchState();
00056 }
00057 
00058 void QgsAddRemoveMultiFrameCommand::switchState()
00059 {
00060   if ( mComposition )
00061   {
00062     if ( mState == Added )
00063     {
00064       mComposition->removeMultiFrame( mMultiFrame );
00065       mState = Removed;
00066     }
00067     else
00068     {
00069       mComposition->addMultiFrame( mMultiFrame );
00070       mState = Added;
00071     }
00072   }
00073 }
00074 
00075 bool QgsAddRemoveMultiFrameCommand::checkFirstRun()
00076 {
00077   if ( mFirstRun )
00078   {
00079     mFirstRun = false;
00080     return true;
00081   }
00082   else
00083   {
00084     return false;
00085   }
00086 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines