Skip to content

Commit

Permalink
Delete composer before removing all the layers when leaving the appli…
Browse files Browse the repository at this point in the history
…cation or the project. Fix for a memory bug in composer

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11357 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 12, 2009
1 parent fb19886 commit f465e50
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 50 deletions.
11 changes: 8 additions & 3 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -206,9 +206,6 @@ QgsComposer::QgsComposer( QgisApp *qgis ): QMainWindow()

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

//mComposition = new QgsComposition( this, 1 );
//mComposition->setActive ( true );

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
mSizeGrip = new QSizeGrip( this );
mSizeGrip->resize( mSizeGrip->sizeHint() );
Expand All @@ -229,6 +226,13 @@ QgsComposer::QgsComposer( QgisApp *qgis ): 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();
}
}

void QgsComposer::setupTheme()
Expand Down Expand Up @@ -1252,6 +1256,7 @@ void QgsComposer::deleteItem( QgsComposerItem* item )
return;
}

delete( it.key() );
delete( it.value() );
mItemWidgetMap.remove( it.key() );
}
Expand Down
58 changes: 12 additions & 46 deletions src/app/qgisapp.cpp
Expand Up @@ -3026,6 +3026,9 @@ void QgisApp::fileExit()

if ( saveDirty() )
{
delete mComposer;
mComposer = 0;

mMapCanvas->freeze( true );
removeAllLayers();
qApp->exit( 0 );
Expand All @@ -3048,6 +3051,9 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
return;
}

delete mComposer;
mComposer = new QgsComposer( this );

if ( thePromptToSaveFlag )
{
if ( !saveDirty() )
Expand All @@ -3065,9 +3071,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
removeAllLayers();
mMapCanvas->clear();

delete mComposer;
mComposer = new QgsComposer( this );

QgsProject* prj = QgsProject::instance();
prj->title( QString::null );
prj->setFileName( QString::null );
Expand Down Expand Up @@ -3283,13 +3286,13 @@ void QgisApp::fileOpen()

delete openFileDialog;

delete mComposer;
mComposer = new QgsComposer( this );

// clear out any stuff from previous project
mMapCanvas->freeze( true );
removeAllLayers();

delete mComposer;
mComposer = new QgsComposer( this );

QgsProject::instance()->setFileName( fullPath );

try
Expand Down Expand Up @@ -3341,13 +3344,13 @@ bool QgisApp::addProject( QString projectFile )

QApplication::setOverrideCursor( Qt::WaitCursor );

// clear the map canvas
removeAllLayers();

//clear the composer
delete mComposer;
mComposer = new QgsComposer( this );

// clear the map canvas
removeAllLayers();

try
{
if ( QgsProject::instance()->read( projectFile ) )
Expand Down Expand Up @@ -3669,43 +3672,6 @@ bool QgisApp::openLayer( const QString & fileName )
return ok;
}


#if 0
void QgisApp::filePrint()
{
//
// Warn the user first that priting is experimental still
//
QString myHeading = "QGIS Printing Support is Experimental";
QString myMessage = "Please note that printing only works on A4 landscape at the moment.\n";
myMessage += "For other page sizes your mileage may vary.\n";
QMessageBox::information( this, tr( myHeading ), tr( myMessage ) );

QPrinter myQPrinter;
if ( myQPrinter.setup( this ) )
{
QgsDebugMsg( ".............................." );
QgsDebugMsg( "...........Printing..........." );
QgsDebugMsg( ".............................." );
// Ithought we could just do this:
//mMapCanvas->render(&myQPrinter);
//but it doesnt work so now we try this....
QPaintDeviceMetrics myMetrics( &myQPrinter ); // need width/height of printer surface
QgsDebugMsg( QString( "Print device width: %1" ).arg( myMetrics.width() ) );
QgsDebugMsg( QString( "Print device height: %1" ).arg( myMetrics.height() ) );
QPainter myQPainter;
myQPainter.begin( &myQPrinter );
QPixmap myQPixmap( myMetrics.width(), myMetrics.height() );
myQPixmap.fill();
mMapCanvas->freeze( false );
mMapCanvas->setDirty( true );
mMapCanvas->render( &myQPixmap );
myQPainter.drawPixmap( 0, 0, myQPixmap );
myQPainter.end();
}
}
#endif

void QgisApp::filePrint()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgscomposerview.cpp
Expand Up @@ -311,7 +311,6 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
composition()->removeItem( *itemIt );
delete( *itemIt );
emit itemRemoved( *itemIt );
}
}
Expand Down

0 comments on commit f465e50

Please sign in to comment.