Skip to content

Commit

Permalink
[composer] Manually removing a frame from a multi frame forces the mu…
Browse files Browse the repository at this point in the history
…lti frame to UseExistingFrames mode, otherwise the frame may not actually be removed. This changes makes the behaviour of multi frames a bit more predictable (sponsored by City of Uster, Switzerland)
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent 86304b9 commit e9b253d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/core/composer/qgscomposermultiframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
#include "qgscomposerframe.h"
#include "qgscomposition.h"

QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands ): mComposition( c ), mResizeMode( UseExistingFrames ), mCreateUndoCommands( createUndoCommands )
QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands ):
mComposition( c ),
mResizeMode( UseExistingFrames ),
mCreateUndoCommands( createUndoCommands ),
mIsRecalculatingSize( false )
{
mComposition->addMultiFrame( this );
connect( mComposition, SIGNAL( nPagesChanged() ), this, SLOT( handlePageChange() ) );
}

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
QgsComposerMultiFrame::QgsComposerMultiFrame():
mComposition( 0 ),
mResizeMode( UseExistingFrames ),
mIsRecalculatingSize( false )
{
}

Expand Down Expand Up @@ -159,6 +166,13 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
mFrameItems.removeAt( index );
if ( mFrameItems.size() > 0 )
{
if ( resizeMode() != QgsComposerMultiFrame::RepeatOnEveryPage && !mIsRecalculatingSize )
{
//removing a frame forces the multi frame to UseExistingFrames resize mode
//otherwise the frame may not actually be removed, leading to confusing ui behaviour
mResizeMode = QgsComposerMultiFrame::UseExistingFrames;
emit changed();
}
recalculateFrameSizes();
}
}
Expand Down Expand Up @@ -206,10 +220,17 @@ void QgsComposerMultiFrame::handlePageChange()

void QgsComposerMultiFrame::removeFrame( int i )
{
if ( i >= mFrameItems.count() )
{
return;
}

QgsComposerFrame* frameItem = mFrameItems[i];
if ( mComposition )
{
mIsRecalculatingSize = true;
mComposition->removeComposerItem( frameItem );
mIsRecalculatingSize = false;
}
mFrameItems.removeAt( i );
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposermultiframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class CORE_EXPORT QgsComposerMultiFrame: public QObject
private:
QgsComposerMultiFrame(); //forbidden

bool mIsRecalculatingSize;

signals:
void changed();
};
Expand Down

0 comments on commit e9b253d

Please sign in to comment.