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)

cherry-picked from 06732f1
  • Loading branch information
nyalldawson committed Jun 24, 2015
1 parent b3d11c7 commit 05a8491
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
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 @@ -1701,7 +1703,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 @@ -1713,15 +1715,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 @@ -1759,7 +1761,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 @@ -3556,7 +3558,7 @@ void QgsComposer::on_mActionPageSetup_triggered()
return;
}

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

Expand Down Expand Up @@ -3726,11 +3728,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 @@ -3742,11 +3744,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 @@ -3799,3 +3801,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
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 @@ -509,6 +508,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 @@ -558,7 +559,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 05a8491

Please sign in to comment.