Skip to content
Permalink
Browse files

Add/Remove command for composer multipage

  • Loading branch information
mhugent committed Jul 31, 2012
1 parent eb08414 commit ec0a02b788b78eb91169b113bb7dafeaf8509b7f
@@ -112,6 +112,7 @@ SET(QGIS_CORE_SRCS
qgsnetworkaccessmanager.cpp

composer/qgsaddremoveitemcommand.cpp
composer/qgsaddremovemultiframecommand.cpp
composer/qgscomposerarrow.cpp
composer/qgscomposerframe.cpp
composer/qgscomposeritem.cpp
@@ -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;
}
}
@@ -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
@@ -112,7 +112,6 @@ void QgsComposerHtml::addFrame( QgsComposerFrame* frame )
if ( mComposition )
{
mComposition->addComposerHtmlFrame( this, frame );
mComposition->pushAddRemoveCommand( frame, tr( "HTML frame added" ) );
}
}

@@ -15,6 +15,7 @@

#include "qgscomposermultiframe.h"
#include "qgscomposerframe.h"
#include "qgsaddremovemultiframecommand.h"

QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
{
@@ -124,6 +125,8 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
{
//schedule this composer multi frame for deletion
mComposition->removeMultiFrame( this );
QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Removed, this, mComposition, tr( "Html removed" ), 0 );
mComposition->undoStack()->push( c );
}
}
else
@@ -1034,10 +1034,15 @@ void QgsComposition::cancelCommand()
mActiveCommand = 0;
}

void QgsComposition::addMultiFrame( QgsComposerMultiFrame* multiFrame )
{
mMultiFrames.insert( multiFrame );
}

void QgsComposition::removeMultiFrame( QgsComposerMultiFrame* multiFrame )
{
mMultiFrames.remove( multiFrame );
delete multiFrame; //e.v. use deleteLater() in case of stability problems
//delete multiFrame; //e.v. use deleteLater() in case of stability problems
}

void QgsComposition::addComposerArrow( QgsComposerArrow* arrow )
@@ -202,7 +202,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Deletes current command*/
void cancelCommand();

void addMultiFrame( QgsComposerMultiFrame* multiFrame ) { mMultiFrames.insert( multiFrame ); }
void addMultiFrame( QgsComposerMultiFrame* multiFrame );
/**Removes multi frame (but does not delete it)*/
void removeMultiFrame( QgsComposerMultiFrame* multiFrame );
/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
void addComposerArrow( QgsComposerArrow* arrow );
@@ -34,6 +34,7 @@
#include "qgscomposershape.h"
#include "qgscomposerattributetable.h"
#include "qgslogger.h"
#include "qgsaddremovemultiframecommand.h"

QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f )
: QGraphicsView( parent )
@@ -328,6 +329,9 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
delete mRubberBandItem;
mRubberBandItem = 0;
emit actionFinished();

QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Added, composerHtml, composition(), tr( "HTML added" ), 0 );
composition()->undoStack()->push( c );
}
default:
break;

0 comments on commit ec0a02b

Please sign in to comment.
You can’t perform that action at this time.