Skip to content
Permalink
Browse files

Ensure item widgets are deleted if loading composer templates

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 5, 2012
1 parent fd514a0 commit 351ccc0087681a73c52c57fb7d4e810c30f0a746
@@ -915,18 +915,14 @@ void QgsComposer::on_mActionLoadFromTemplate_triggered()
return;
}

emit composerWillBeRemoved( mView );

QDomDocument templateDocument;
if ( !templateDocument.setContent( &templateFile, false ) )
if ( mComposition )
{
QMessageBox::warning( 0, tr( "Read error" ), tr( "Content of template file is not valid" ) );
return;
QDomDocument templateDoc;
if ( templateDoc.setContent( &templateFile ) )
{
mComposition->loadFromTemplate( templateDoc, true );
}
}

deleteItemWidgets();
readXML( templateDocument );
emit composerAdded( mView );
}

void QgsComposer::on_mActionMoveItemContent_triggered()
@@ -6,7 +6,7 @@
#include <QFileDialog>
#include <QSettings>

QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): mHtml( html ), mFrame( frame )
QgsComposerHtmlWidget::QgsComposerHtmlWidget( QgsComposerHtml* html, QgsComposerFrame* frame ): QWidget(), mHtml( html ), mFrame( frame )
{
setupUi( this );

@@ -226,14 +226,14 @@ void QgsComposerMultiFrame::deleteFrames()
{
ResizeMode bkResizeMode = mResizeMode;
mResizeMode = UseExistingFrames;
mComposition->blockSignals( true );
QObject::disconnect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
QList<QgsComposerFrame*>::iterator frameIt = mFrameItems.begin();
for ( ; frameIt != mFrameItems.end(); ++frameIt )
{
mComposition->removeComposerItem( *frameIt, false );
delete *frameIt;
}
mComposition->blockSignals( false );
QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
mFrameItems.clear();
mResizeMode = bkResizeMode;
}
@@ -316,12 +316,25 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu

bool QgsComposition::loadFromTemplate( const QDomDocument& doc, bool addUndoCommands )
{
//delete multiframes and its items
deleteAndRemoveMultiFrames();

//delete all other items
clear();
//delete all items and emit itemRemoved signal
QList<QGraphicsItem *> itemList = items();
QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
for ( ; itemIter != itemList.end(); ++itemIter )
{
QgsComposerItem* cItem = dynamic_cast<QgsComposerItem*>( *itemIter );
if ( cItem )
{
removeItem( cItem );
emit itemRemoved( cItem );
delete cItem;
}
}
mItemZList.clear();

mPages.clear();
mUndoStack.clear();

//read general settings
QDomElement compositionElem = doc.documentElement().firstChildElement( "Composition" );

0 comments on commit 351ccc0

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