Skip to content
Permalink
Browse files

Possible fix for slow loading projects when the project contains

print compositions and there is network issues with connections
to installed printers. (workaround QTBUG-3033)

(refs #12234)
  • Loading branch information
nyalldawson committed May 19, 2015
1 parent 7216670 commit 06732f137357ff1f3c2a55a3253037d8df85596b
Showing with 25 additions and 12 deletions.
  1. +22 −10 src/app/composer/qgscomposer.cpp
  2. +3 −2 src/app/composer/qgscomposer.h
@@ -105,6 +105,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
: QMainWindow()
, mTitle( title )
, mQgis( qgis )
, mPrinter( 0 )
, mUndoView( 0 )
, mAtlasFeatureAction( 0 )
{
@@ -645,6 +646,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
QgsComposer::~QgsComposer()
{
deleteItemWidgets();
delete mPrinter;
}

void QgsComposer::setupTheme()
@@ -1716,7 +1718,7 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
}

//orientation and page size are already set to QPrinter in the page setup dialog
QPrintDialog printDialog( &mPrinter, 0 );
QPrintDialog printDialog( printer(), 0 );
if ( printDialog.exec() != QDialog::Accepted )
{
return;
@@ -1728,15 +1730,15 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( mode == QgsComposer::Single )
{
mComposition->print( mPrinter, true );
mComposition->print( *printer(), true );
}
else
{
//prepare for first feature, so that we know paper size to begin with
atlasMap->prepareForFeature( 0 );

mComposition->beginPrint( mPrinter, true );
QPainter painter( &mPrinter );
mComposition->beginPrint( *printer(), true );
QPainter painter( printer() );

loadAtlasPredefinedScalesFromProject();
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
@@ -1775,7 +1777,7 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
}

//start print on a new page if we're not on the first feature
mComposition->doPrint( mPrinter, painter, i > 0 );
mComposition->doPrint( *printer(), painter, i > 0 );
}
atlasMap->endRender();
painter.end();
@@ -3569,7 +3571,7 @@ void QgsComposer::on_mActionPageSetup_triggered()
return;
}

QPageSetupDialog pageSetupDialog( &mPrinter, this );
QPageSetupDialog pageSetupDialog( printer(), this );
pageSetupDialog.exec();
}

@@ -3742,11 +3744,11 @@ void QgsComposer::setPrinterPageOrientation( QString orientation )
{
if ( orientation == tr( "Landscape" ) )
{
mPrinter.setOrientation( QPrinter::Landscape );
printer()->setOrientation( QPrinter::Landscape );
}
else
{
mPrinter.setOrientation( QPrinter::Portrait );
printer()->setOrientation( QPrinter::Portrait );
}
}

@@ -3758,11 +3760,11 @@ void QgsComposer::setPrinterPageDefaults()
//set printer page orientation
if ( paperWidth > paperHeight )
{
mPrinter.setOrientation( QPrinter::Landscape );
printer()->setOrientation( QPrinter::Landscape );
}
else
{
mPrinter.setOrientation( QPrinter::Portrait );
printer()->setOrientation( QPrinter::Portrait );
}
}

@@ -3815,3 +3817,13 @@ void QgsComposer::loadAtlasPredefinedScalesFromProject()
atlasMap.setPredefinedScales( pScales );
}

QPrinter *QgsComposer::printer()
{
//only create the printer on demand - creating a printer object can be very slow
//due to QTBUG-3033
if ( !mPrinter )
mPrinter = new QPrinter();

return mPrinter;
}

@@ -19,7 +19,6 @@
#include "ui_qgscomposerbase.h"
#include "qgscomposermap.h"
#include "qgscontexthelp.h"
#include <QPrinter>
#include <QDockWidget>

class QgisApp;
@@ -508,6 +507,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Load predefined scales from the project's properties
void loadAtlasPredefinedScalesFromProject();

QPrinter* printer();

/**Composer title*/
QString mTitle;

@@ -557,7 +558,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QAction *mActionPaste;

//! Page & Printer Setup
QPrinter mPrinter;
QPrinter* mPrinter;

QUndoView* mUndoView;

0 comments on commit 06732f1

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