Skip to content
Permalink
Browse files

Remove multi frame once the last frame is deleted

  • Loading branch information
mhugent committed Jul 27, 2012
1 parent 050c0ff commit d57ecae57b9f1cdda47a7771cf09cca468e9aa75
@@ -299,7 +299,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

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

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

deleteItems();
deleteItemWidgets();
if ( mComposition )
{
mComposition->clear();
}
readXML( templateDocument );
emit composerAdded( mView );
}
@@ -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();
@@ -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.
@@ -18,6 +18,7 @@

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

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
@@ -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;
@@ -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 )
@@ -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 );
@@ -19,6 +19,7 @@
#include <QDomDocument>
#include <QGraphicsScene>
#include <QLinkedList>
#include <QSet>
#include <QUndoStack>

#include "qgscomposeritemcommand.h"
@@ -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
@@ -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)*/
@@ -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;

0 comments on commit d57ecae

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