Skip to content

Commit 93f4044

Browse files
author
mhugent
committed
Delete composer before removing all the layers when leaving the application or the project. Fix for a memory bug in composer
git-svn-id: http://svn.osgeo.org/qgis/trunk@11357 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9092cda commit 93f4044

File tree

3 files changed

+20
-50
lines changed

3 files changed

+20
-50
lines changed

src/app/composer/qgscomposer.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()
206206

207207
mCompositionNameComboBox->insertItem( 0, tr( "Map 1" ) );
208208

209-
//mComposition = new QgsComposition( this, 1 );
210-
//mComposition->setActive ( true );
211-
212209
// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
213210
mSizeGrip = new QSizeGrip( this );
214211
mSizeGrip->resize( mSizeGrip->sizeHint() );
@@ -229,6 +226,13 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()
229226

230227
QgsComposer::~QgsComposer()
231228
{
229+
//delete all the items
230+
QMap<QgsComposerItem*, QWidget*>::iterator it = mItemWidgetMap.begin();
231+
for ( ; it != mItemWidgetMap.end(); ++it )
232+
{
233+
delete it.key();
234+
delete it.value();
235+
}
232236
}
233237

234238
void QgsComposer::setupTheme()
@@ -1252,6 +1256,7 @@ void QgsComposer::deleteItem( QgsComposerItem* item )
12521256
return;
12531257
}
12541258

1259+
delete( it.key() );
12551260
delete( it.value() );
12561261
mItemWidgetMap.remove( it.key() );
12571262
}

src/app/qgisapp.cpp

+12-46
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,9 @@ void QgisApp::fileExit()
30263026

30273027
if ( saveDirty() )
30283028
{
3029+
delete mComposer;
3030+
mComposer = 0;
3031+
30293032
mMapCanvas->freeze( true );
30303033
removeAllLayers();
30313034
qApp->exit( 0 );
@@ -3048,6 +3051,9 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
30483051
return;
30493052
}
30503053

3054+
delete mComposer;
3055+
mComposer = new QgsComposer( this );
3056+
30513057
if ( thePromptToSaveFlag )
30523058
{
30533059
if ( !saveDirty() )
@@ -3065,9 +3071,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
30653071
removeAllLayers();
30663072
mMapCanvas->clear();
30673073

3068-
delete mComposer;
3069-
mComposer = new QgsComposer( this );
3070-
30713074
QgsProject* prj = QgsProject::instance();
30723075
prj->title( QString::null );
30733076
prj->setFileName( QString::null );
@@ -3283,13 +3286,13 @@ void QgisApp::fileOpen()
32833286

32843287
delete openFileDialog;
32853288

3289+
delete mComposer;
3290+
mComposer = new QgsComposer( this );
3291+
32863292
// clear out any stuff from previous project
32873293
mMapCanvas->freeze( true );
32883294
removeAllLayers();
32893295

3290-
delete mComposer;
3291-
mComposer = new QgsComposer( this );
3292-
32933296
QgsProject::instance()->setFileName( fullPath );
32943297

32953298
try
@@ -3341,13 +3344,13 @@ bool QgisApp::addProject( QString projectFile )
33413344

33423345
QApplication::setOverrideCursor( Qt::WaitCursor );
33433346

3344-
// clear the map canvas
3345-
removeAllLayers();
3346-
33473347
//clear the composer
33483348
delete mComposer;
33493349
mComposer = new QgsComposer( this );
33503350

3351+
// clear the map canvas
3352+
removeAllLayers();
3353+
33513354
try
33523355
{
33533356
if ( QgsProject::instance()->read( projectFile ) )
@@ -3669,43 +3672,6 @@ bool QgisApp::openLayer( const QString & fileName )
36693672
return ok;
36703673
}
36713674

3672-
3673-
#if 0
3674-
void QgisApp::filePrint()
3675-
{
3676-
//
3677-
// Warn the user first that priting is experimental still
3678-
//
3679-
QString myHeading = "QGIS Printing Support is Experimental";
3680-
QString myMessage = "Please note that printing only works on A4 landscape at the moment.\n";
3681-
myMessage += "For other page sizes your mileage may vary.\n";
3682-
QMessageBox::information( this, tr( myHeading ), tr( myMessage ) );
3683-
3684-
QPrinter myQPrinter;
3685-
if ( myQPrinter.setup( this ) )
3686-
{
3687-
QgsDebugMsg( ".............................." );
3688-
QgsDebugMsg( "...........Printing..........." );
3689-
QgsDebugMsg( ".............................." );
3690-
// Ithought we could just do this:
3691-
//mMapCanvas->render(&myQPrinter);
3692-
//but it doesnt work so now we try this....
3693-
QPaintDeviceMetrics myMetrics( &myQPrinter ); // need width/height of printer surface
3694-
QgsDebugMsg( QString( "Print device width: %1" ).arg( myMetrics.width() ) );
3695-
QgsDebugMsg( QString( "Print device height: %1" ).arg( myMetrics.height() ) );
3696-
QPainter myQPainter;
3697-
myQPainter.begin( &myQPrinter );
3698-
QPixmap myQPixmap( myMetrics.width(), myMetrics.height() );
3699-
myQPixmap.fill();
3700-
mMapCanvas->freeze( false );
3701-
mMapCanvas->setDirty( true );
3702-
mMapCanvas->render( &myQPixmap );
3703-
myQPainter.drawPixmap( 0, 0, myQPixmap );
3704-
myQPainter.end();
3705-
}
3706-
}
3707-
#endif
3708-
37093675
void QgisApp::filePrint()
37103676
{
37113677
if ( mMapCanvas && mMapCanvas->isDrawing() )

src/gui/qgscomposerview.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
311311
for ( ; itemIt != composerItemList.end(); ++itemIt )
312312
{
313313
composition()->removeItem( *itemIt );
314-
delete( *itemIt );
315314
emit itemRemoved( *itemIt );
316315
}
317316
}

0 commit comments

Comments
 (0)