Skip to content

Commit ec0a02b

Browse files
committedJul 31, 2012
Add/Remove command for composer multipage
1 parent eb08414 commit ec0a02b

8 files changed

+156
-3
lines changed
 

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ SET(QGIS_CORE_SRCS
112112
qgsnetworkaccessmanager.cpp
113113

114114
composer/qgsaddremoveitemcommand.cpp
115+
composer/qgsaddremovemultiframecommand.cpp
115116
composer/qgscomposerarrow.cpp
116117
composer/qgscomposerframe.cpp
117118
composer/qgscomposeritem.cpp
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
18+
#include "qgsaddremovemultiframecommand.h"
19+
#include "qgscomposermultiframe.h"
20+
#include "qgscomposition.h"
21+
22+
23+
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent ):
24+
QUndoCommand( text, parent ), mMultiFrame( multiFrame ), mComposition( c ), mState(s), mFirstRun( true )
25+
{
26+
}
27+
28+
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand(): mMultiFrame( 0 ), mComposition( 0 )
29+
{
30+
}
31+
32+
QgsAddRemoveMultiFrameCommand::~QgsAddRemoveMultiFrameCommand()
33+
{
34+
if( mState == Removed )
35+
{
36+
delete mMultiFrame;
37+
}
38+
}
39+
40+
void QgsAddRemoveMultiFrameCommand::redo()
41+
{
42+
if( checkFirstRun() )
43+
{
44+
return;
45+
}
46+
switchState();
47+
}
48+
49+
void QgsAddRemoveMultiFrameCommand::undo()
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+
}
73+
}
74+
75+
bool QgsAddRemoveMultiFrameCommand::checkFirstRun()
76+
{
77+
if( mFirstRun )
78+
{
79+
mFirstRun = false;
80+
return true;
81+
}
82+
else
83+
{
84+
return false;
85+
}
86+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
qgsaddremovemultiframecommand.h
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+
18+
#ifndef QGSADDREMOVEMULTIFRAMECOMMAND_H
19+
#define QGSADDREMOVEMULTIFRAMECOMMAND_H
20+
21+
#include <QUndoCommand>
22+
23+
class QgsComposerMultiFrame;
24+
class QgsComposition;
25+
26+
class CORE_EXPORT QgsAddRemoveMultiFrameCommand: public QUndoCommand
27+
{
28+
public:
29+
30+
enum State
31+
{
32+
Added = 0,
33+
Removed
34+
};
35+
36+
QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent = 0 );
37+
~QgsAddRemoveMultiFrameCommand();
38+
void redo();
39+
void undo();
40+
41+
private:
42+
QgsAddRemoveMultiFrameCommand();
43+
44+
//changes between added / removed state
45+
void switchState();
46+
bool checkFirstRun();
47+
48+
QgsComposerMultiFrame* mMultiFrame;
49+
QgsComposition* mComposition;
50+
State mState;
51+
bool mFirstRun;
52+
};
53+
54+
#endif // QGSADDREMOVEMULTIFRAMECOMMAND_H

‎src/core/composer/qgscomposerhtml.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void QgsComposerHtml::addFrame( QgsComposerFrame* frame )
112112
if ( mComposition )
113113
{
114114
mComposition->addComposerHtmlFrame( this, frame );
115-
mComposition->pushAddRemoveCommand( frame, tr( "HTML frame added" ) );
116115
}
117116
}
118117

‎src/core/composer/qgscomposermultiframe.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "qgscomposermultiframe.h"
1717
#include "qgscomposerframe.h"
18+
#include "qgsaddremovemultiframecommand.h"
1819

1920
QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
2021
{
@@ -124,6 +125,8 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
124125
{
125126
//schedule this composer multi frame for deletion
126127
mComposition->removeMultiFrame( this );
128+
QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Removed, this, mComposition, tr( "Html removed" ), 0 );
129+
mComposition->undoStack()->push( c );
127130
}
128131
}
129132
else

‎src/core/composer/qgscomposition.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,15 @@ void QgsComposition::cancelCommand()
10341034
mActiveCommand = 0;
10351035
}
10361036

1037+
void QgsComposition::addMultiFrame( QgsComposerMultiFrame* multiFrame )
1038+
{
1039+
mMultiFrames.insert( multiFrame );
1040+
}
1041+
10371042
void QgsComposition::removeMultiFrame( QgsComposerMultiFrame* multiFrame )
10381043
{
10391044
mMultiFrames.remove( multiFrame );
1040-
delete multiFrame; //e.v. use deleteLater() in case of stability problems
1045+
//delete multiFrame; //e.v. use deleteLater() in case of stability problems
10411046
}
10421047

10431048
void QgsComposition::addComposerArrow( QgsComposerArrow* arrow )

‎src/core/composer/qgscomposition.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
202202
/**Deletes current command*/
203203
void cancelCommand();
204204

205-
void addMultiFrame( QgsComposerMultiFrame* multiFrame ) { mMultiFrames.insert( multiFrame ); }
205+
void addMultiFrame( QgsComposerMultiFrame* multiFrame );
206+
/**Removes multi frame (but does not delete it)*/
206207
void removeMultiFrame( QgsComposerMultiFrame* multiFrame );
207208
/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
208209
void addComposerArrow( QgsComposerArrow* arrow );

‎src/gui/qgscomposerview.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "qgscomposershape.h"
3535
#include "qgscomposerattributetable.h"
3636
#include "qgslogger.h"
37+
#include "qgsaddremovemultiframecommand.h"
3738

3839
QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f )
3940
: QGraphicsView( parent )
@@ -328,6 +329,9 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
328329
delete mRubberBandItem;
329330
mRubberBandItem = 0;
330331
emit actionFinished();
332+
333+
QgsAddRemoveMultiFrameCommand* c = new QgsAddRemoveMultiFrameCommand( QgsAddRemoveMultiFrameCommand::Added, composerHtml, composition(), tr( "HTML added" ), 0 );
334+
composition()->undoStack()->push( c );
331335
}
332336
default:
333337
break;

0 commit comments

Comments
 (0)
Please sign in to comment.