Skip to content
Permalink
Browse files

Delete composer before removing all the layers when leaving the appli…

…cation 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
  • Loading branch information
mhugent
mhugent committed Aug 12, 2009
1 parent 9092cda commit 93f4044ca4f6218d785271ad829e884628c2503d
Showing with 20 additions and 50 deletions.
  1. +8 −3 src/app/composer/qgscomposer.cpp
  2. +12 −46 src/app/qgisapp.cpp
  3. +0 −1 src/gui/qgscomposerview.cpp
@@ -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() );
@@ -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()
@@ -1252,6 +1256,7 @@ void QgsComposer::deleteItem( QgsComposerItem* item )
return;
}

delete( it.key() );
delete( it.value() );
mItemWidgetMap.remove( it.key() );
}
@@ -3026,6 +3026,9 @@ void QgisApp::fileExit()

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

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

delete mComposer;
mComposer = new QgsComposer( this );

if ( thePromptToSaveFlag )
{
if ( !saveDirty() )
@@ -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 );
@@ -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
@@ -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 ) )
@@ -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() )
@@ -311,7 +311,6 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
composition()->removeItem( *itemIt );
delete( *itemIt );
emit itemRemoved( *itemIt );
}
}

0 comments on commit 93f4044

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