Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
156 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*************************************************************************** | ||
qgsaddremovemultiframecommand.cpp | ||
--------------------------------- | ||
begin : 2012-07-31 | ||
copyright : (C) 2012 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsaddremovemultiframecommand.h" | ||
#include "qgscomposermultiframe.h" | ||
#include "qgscomposition.h" | ||
|
||
|
||
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent ): | ||
QUndoCommand( text, parent ), mMultiFrame( multiFrame ), mComposition( c ), mState(s), mFirstRun( true ) | ||
{ | ||
} | ||
|
||
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand(): mMultiFrame( 0 ), mComposition( 0 ) | ||
{ | ||
} | ||
|
||
QgsAddRemoveMultiFrameCommand::~QgsAddRemoveMultiFrameCommand() | ||
{ | ||
if( mState == Removed ) | ||
{ | ||
delete mMultiFrame; | ||
} | ||
} | ||
|
||
void QgsAddRemoveMultiFrameCommand::redo() | ||
{ | ||
if( checkFirstRun() ) | ||
{ | ||
return; | ||
} | ||
switchState(); | ||
} | ||
|
||
void QgsAddRemoveMultiFrameCommand::undo() | ||
{ | ||
if( checkFirstRun() ) | ||
{ | ||
return; | ||
} | ||
switchState(); | ||
} | ||
|
||
void QgsAddRemoveMultiFrameCommand::switchState() | ||
{ | ||
if( mComposition ) | ||
{ | ||
if( mState == Added ) | ||
{ | ||
mComposition->removeMultiFrame( mMultiFrame ); | ||
mState = Removed; | ||
} | ||
else | ||
{ | ||
mComposition->addMultiFrame( mMultiFrame ); | ||
mState = Added; | ||
} | ||
} | ||
} | ||
|
||
bool QgsAddRemoveMultiFrameCommand::checkFirstRun() | ||
{ | ||
if( mFirstRun ) | ||
{ | ||
mFirstRun = false; | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
qgsaddremovemultiframecommand.h | ||
------------------------------- | ||
begin : 2012-07-31 | ||
copyright : (C) 2012 by Marco Hugentobler | ||
email : marco dot hugentobler at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSADDREMOVEMULTIFRAMECOMMAND_H | ||
#define QGSADDREMOVEMULTIFRAMECOMMAND_H | ||
|
||
#include <QUndoCommand> | ||
|
||
class QgsComposerMultiFrame; | ||
class QgsComposition; | ||
|
||
class CORE_EXPORT QgsAddRemoveMultiFrameCommand: public QUndoCommand | ||
{ | ||
public: | ||
|
||
enum State | ||
{ | ||
Added = 0, | ||
Removed | ||
}; | ||
|
||
QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent = 0 ); | ||
~QgsAddRemoveMultiFrameCommand(); | ||
void redo(); | ||
void undo(); | ||
|
||
private: | ||
QgsAddRemoveMultiFrameCommand(); | ||
|
||
//changes between added / removed state | ||
void switchState(); | ||
bool checkFirstRun(); | ||
|
||
QgsComposerMultiFrame* mMultiFrame; | ||
QgsComposition* mComposition; | ||
State mState; | ||
bool mFirstRun; | ||
}; | ||
|
||
#endif // QGSADDREMOVEMULTIFRAMECOMMAND_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters