Skip to content

Commit

Permalink
Remove multi frame once the last frame is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 27, 2012
1 parent 050c0ff commit d57ecae
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -299,7 +299,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

QgsComposer::~QgsComposer()
{
deleteItems();
deleteItemWidgets();
}

void QgsComposer::setupTheme()
Expand Down Expand Up @@ -909,7 +909,11 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
return;
}

deleteItems();
deleteItemWidgets();
if ( mComposition )
{
mComposition->clear();
}
readXML( templateDocument );
emit composerAdded( mView );
}
Expand Down Expand Up @@ -1233,13 +1237,12 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
setSelectionTool();
}

void QgsComposer::deleteItems()
void QgsComposer::deleteItemWidgets()
{
//delete all the items
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
for ( ; it != mItemWidgetMap.end(); ++it )
{
delete it.key();
delete it.value();
}
mItemWidgetMap.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.h
Expand Up @@ -289,7 +289,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
void writeXML( QDomNode& parentNode, QDomDocument& doc );

//! Removes all the item from the graphics scene and deletes them
void deleteItems();
void deleteItemWidgets();

//! Restores composer map preview states.
//! Initially after reading from xml, states are set to rectangle to achieve faster project loading.
Expand Down
21 changes: 20 additions & 1 deletion src/core/composer/qgscomposermultiframe.cpp
Expand Up @@ -18,6 +18,7 @@

QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
{
mComposition->addMultiFrame( this );
}

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
Expand Down Expand Up @@ -46,6 +47,12 @@ void QgsComposerMultiFrame::recalculateFrameSizes()

QSizeF size = totalSize();
double totalHeight = size.height();

if ( totalHeight < 1 )
{
return;
}

double currentY = 0;
double currentHeight = 0;
QgsComposerFrame* currentItem = 0;
Expand Down Expand Up @@ -109,7 +116,19 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
return;
}
mFrameItems.removeAt( index );
recalculateFrameSizes();

if ( mFrameItems.size() < 1 )
{
if ( mComposition )
{
//schedule this composer multi frame for deletion
mComposition->removeMultiFrame( this );
}
}
else
{
recalculateFrameSizes();
}
}

void QgsComposerMultiFrame::removeFrame( int i )
Expand Down
6 changes: 6 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -1003,6 +1003,12 @@ void QgsComposition::cancelCommand()
mActiveCommand = 0;
}

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

void QgsComposition::addComposerArrow( QgsComposerArrow* arrow )
{
addItem( arrow );
Expand Down
7 changes: 7 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -19,6 +19,7 @@
#include <QDomDocument>
#include <QGraphicsScene>
#include <QLinkedList>
#include <QSet>
#include <QUndoStack>

#include "qgscomposeritemcommand.h"
Expand All @@ -41,6 +42,7 @@ class QgsComposerPicture;
class QgsComposerScaleBar;
class QgsComposerShape;
class QgsComposerAttributeTable;
class QgsComposerMultiFrame;

/** \ingroup MapComposer
* Graphics scene for map printing. The class manages the paper item which always
Expand Down Expand Up @@ -200,6 +202,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Deletes current command*/
void cancelCommand();

void addMultiFrame( QgsComposerMultiFrame* multiFrame ) { mMultiFrames.insert( multiFrame ); }
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 );
/**Adds label to the graphics scene and advices composer to create a widget for it (through signal)*/
Expand Down Expand Up @@ -256,6 +260,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
QLinkedList<QgsComposerItem*> mItemZList;

/**List multiframe objects*/
QSet<QgsComposerMultiFrame*> mMultiFrames;

/**Dpi for printout*/
int mPrintResolution;

Expand Down

0 comments on commit d57ecae

Please sign in to comment.