Skip to content

Commit d57ecae

Browse files
committed
Remove multi frame once the last frame is deleted
1 parent 050c0ff commit d57ecae

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
299299

300300
QgsComposer::~QgsComposer()
301301
{
302-
deleteItems();
302+
deleteItemWidgets();
303303
}
304304

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

912-
deleteItems();
912+
deleteItemWidgets();
913+
if ( mComposition )
914+
{
915+
mComposition->clear();
916+
}
913917
readXML( templateDocument );
914918
emit composerAdded( mView );
915919
}
@@ -1233,13 +1237,12 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
12331237
setSelectionTool();
12341238
}
12351239

1236-
void QgsComposer::deleteItems()
1240+
void QgsComposer::deleteItemWidgets()
12371241
{
12381242
//delete all the items
12391243
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
12401244
for ( ; it != mItemWidgetMap.end(); ++it )
12411245
{
1242-
delete it.key();
12431246
delete it.value();
12441247
}
12451248
mItemWidgetMap.clear();

src/app/composer/qgscomposer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
289289
void writeXML( QDomNode& parentNode, QDomDocument& doc );
290290

291291
//! Removes all the item from the graphics scene and deletes them
292-
void deleteItems();
292+
void deleteItemWidgets();
293293

294294
//! Restores composer map preview states.
295295
//! Initially after reading from xml, states are set to rectangle to achieve faster project loading.

src/core/composer/qgscomposermultiframe.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c ): mComposition( c ), mResizeMode( UseExistingFrames )
2020
{
21+
mComposition->addMultiFrame( this );
2122
}
2223

2324
QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
@@ -46,6 +47,12 @@ void QgsComposerMultiFrame::recalculateFrameSizes()
4647

4748
QSizeF size = totalSize();
4849
double totalHeight = size.height();
50+
51+
if ( totalHeight < 1 )
52+
{
53+
return;
54+
}
55+
4956
double currentY = 0;
5057
double currentHeight = 0;
5158
QgsComposerFrame* currentItem = 0;
@@ -109,7 +116,19 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
109116
return;
110117
}
111118
mFrameItems.removeAt( index );
112-
recalculateFrameSizes();
119+
120+
if ( mFrameItems.size() < 1 )
121+
{
122+
if ( mComposition )
123+
{
124+
//schedule this composer multi frame for deletion
125+
mComposition->removeMultiFrame( this );
126+
}
127+
}
128+
else
129+
{
130+
recalculateFrameSizes();
131+
}
113132
}
114133

115134
void QgsComposerMultiFrame::removeFrame( int i )

src/core/composer/qgscomposition.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,12 @@ void QgsComposition::cancelCommand()
10031003
mActiveCommand = 0;
10041004
}
10051005

1006+
void QgsComposition::removeMultiFrame( QgsComposerMultiFrame* multiFrame )
1007+
{
1008+
mMultiFrames.remove( multiFrame );
1009+
delete multiFrame; //e.v. use deleteLater() in case of stability problems
1010+
}
1011+
10061012
void QgsComposition::addComposerArrow( QgsComposerArrow* arrow )
10071013
{
10081014
addItem( arrow );

src/core/composer/qgscomposition.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QDomDocument>
2020
#include <QGraphicsScene>
2121
#include <QLinkedList>
22+
#include <QSet>
2223
#include <QUndoStack>
2324

2425
#include "qgscomposeritemcommand.h"
@@ -41,6 +42,7 @@ class QgsComposerPicture;
4142
class QgsComposerScaleBar;
4243
class QgsComposerShape;
4344
class QgsComposerAttributeTable;
45+
class QgsComposerMultiFrame;
4446

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

205+
void addMultiFrame( QgsComposerMultiFrame* multiFrame ) { mMultiFrames.insert( multiFrame ); }
206+
void removeMultiFrame( QgsComposerMultiFrame* multiFrame );
203207
/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
204208
void addComposerArrow( QgsComposerArrow* arrow );
205209
/**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
256260
/**Maintains z-Order of items. Starts with item at position 1 (position 0 is always paper item)*/
257261
QLinkedList<QgsComposerItem*> mItemZList;
258262

263+
/**List multiframe objects*/
264+
QSet<QgsComposerMultiFrame*> mMultiFrames;
265+
259266
/**Dpi for printout*/
260267
int mPrintResolution;
261268

0 commit comments

Comments
 (0)