Skip to content

Commit

Permalink
Possible fix for slow loading projects when the project contains
Browse files Browse the repository at this point in the history
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 06732f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
32 changes: 22 additions & 10 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
: QMainWindow()
, mTitle( title )
, mQgis( qgis )
, mPrinter( 0 )
, mUndoView( 0 )
, mAtlasFeatureAction( 0 )
{
Expand Down Expand Up @@ -645,6 +646,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
QgsComposer::~QgsComposer()
{
deleteItemWidgets();
delete mPrinter;
}

void QgsComposer::setupTheme()
Expand Down Expand Up @@ -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;
Expand All @@ -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() )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -3569,7 +3571,7 @@ void QgsComposer::on_mActionPageSetup_triggered()
return;
}

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

Expand Down Expand Up @@ -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 );
}
}

Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -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;
}

5 changes: 3 additions & 2 deletions src/app/composer/qgscomposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "ui_qgscomposerbase.h"
#include "qgscomposermap.h"
#include "qgscontexthelp.h"
#include <QPrinter>
#include <QDockWidget>

class QgisApp;
Expand Down Expand Up @@ -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;

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

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

QUndoView* mUndoView;

Expand Down

0 comments on commit 06732f1

Please sign in to comment.