QgsLayout::~QgsLayout() { // no need for undo commands when we're destroying the layout mUndoStack->blockCommands( true ); deleteAndRemoveMultiFrames(); // make sure that all layout items are removed before // this class is deconstructed - to avoid segfaults // when layout items access in destructor layout that isn't valid anymore // since deletion of some item types (e.g. groups) trigger deletion // of other items, we have to do this careful, one at a time... QList<QGraphicsItem *> itemList = items(); bool deleted = true; while ( deleted ) { deleted = false; for ( QGraphicsItem *item : qgis::as_const( itemList ) ) { if ( dynamic_cast< QgsLayoutItem * >( item ) && !dynamic_cast< QgsLayoutItemPage *>( item ) ) { delete item; deleted = true; break; } } itemList = items(); } mItemsModel.reset(); // manually delete, so we can control order of destruction }
QgsComposition::~QgsComposition() { removePaperItems(); deleteAndRemoveMultiFrames(); // make sure that all composer items are removed before // this class is deconstructed - to avoid segfaults // when composer items access in destructor composition that isn't valid anymore clear(); delete mActiveItemCommand; delete mActiveMultiFrameCommand; }
void QgsLayout::clear() { deleteAndRemoveMultiFrames(); //delete all non paper items const QList<QGraphicsItem *> itemList = items(); for ( QGraphicsItem *item : itemList ) { QgsLayoutItem *cItem = dynamic_cast<QgsLayoutItem *>( item ); QgsLayoutItemPage *pItem = dynamic_cast<QgsLayoutItemPage *>( item ); if ( cItem && !pItem ) { removeLayoutItemPrivate( cItem ); } } mItemsModel->clear(); mPageCollection->clear(); mUndoStack->stack()->clear(); }
bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QString>* substitutionMap, bool addUndoCommands ) { deleteAndRemoveMultiFrames(); //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(); QDomDocument importDoc; if ( substitutionMap ) { QString xmlString = doc.toString(); QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin(); for ( ; sIt != substitutionMap->constEnd(); ++sIt ) { xmlString = xmlString.replace( "[" + sIt.key() + "]", encodeStringForXML( sIt.value() ) ); } QString errorMsg; int errorLine, errorColumn; if ( !importDoc.setContent( xmlString, &errorMsg, &errorLine, &errorColumn ) ) { return false; } } else { importDoc = doc; } //read general settings QDomElement compositionElem = importDoc.documentElement().firstChildElement( "Composition" ); if ( compositionElem.isNull() ) { return false; } bool ok = readXML( compositionElem, importDoc ); if ( !ok ) { return false; } //addItemsFromXML addItemsFromXML( importDoc.documentElement(), importDoc, 0, addUndoCommands, 0 ); // read atlas parameters QDomElement atlasElem = importDoc.documentElement().firstChildElement( "Atlas" ); atlasComposition().readXML( atlasElem, importDoc ); return true; }