Skip to content

Commit

Permalink
Cleanup items before reading from template. Fixes bug #2083
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12098 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 13, 2009
1 parent 8372756 commit 2dca1cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -184,7 +184,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
connectSlots();

mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
mComposition->setParent(mView);
mComposition->setParent( mView );
mView->setComposition( mComposition );

QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mCompositionOptionsFrame, mComposition );
Expand Down Expand Up @@ -220,13 +220,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),

QgsComposer::~QgsComposer()
{
//delete all the items
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
for ( ; it != mItemWidgetMap.end(); ++it )
{
delete it.key();
delete it.value();
}
deleteItems();
}

void QgsComposer::setupTheme()
Expand Down Expand Up @@ -842,6 +836,7 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
return;
}

deleteItems();
readXML( templateDocument );

//clean up after template read (e.g. legend and map extent)
Expand Down Expand Up @@ -1176,6 +1171,18 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
setSelectionTool();
}

void QgsComposer::deleteItems()
{
//delete all the items
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
for ( ; it != mItemWidgetMap.end(); ++it )
{
delete it.key();
delete it.value();
}
mItemWidgetMap.clear();
}

void QgsComposer::addComposerMap( QgsComposerMap* map )
{
if ( !map )
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -246,6 +246,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Writes state under DOM element
void writeXML( QDomNode& parentNode, QDomDocument& doc );

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

/**Composer title*/
QString mTitle;

Expand Down

0 comments on commit 2dca1cb

Please sign in to comment.