Skip to content

Commit 05a8491

Browse files
committed
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) cherry-picked from 06732f1
1 parent b3d11c7 commit 05a8491

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/app/composer/qgscomposer.cpp

+22-10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
105105
: QMainWindow()
106106
, mTitle( title )
107107
, mQgis( qgis )
108+
, mPrinter( 0 )
108109
, mUndoView( 0 )
109110
, mAtlasFeatureAction( 0 )
110111
{
@@ -645,6 +646,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
645646
QgsComposer::~QgsComposer()
646647
{
647648
deleteItemWidgets();
649+
delete mPrinter;
648650
}
649651

650652
void QgsComposer::setupTheme()
@@ -1701,7 +1703,7 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
17011703
}
17021704

17031705
//orientation and page size are already set to QPrinter in the page setup dialog
1704-
QPrintDialog printDialog( &mPrinter, 0 );
1706+
QPrintDialog printDialog( printer(), 0 );
17051707
if ( printDialog.exec() != QDialog::Accepted )
17061708
{
17071709
return;
@@ -1713,15 +1715,15 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
17131715
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
17141716
if ( mode == QgsComposer::Single )
17151717
{
1716-
mComposition->print( mPrinter, true );
1718+
mComposition->print( *printer(), true );
17171719
}
17181720
else
17191721
{
17201722
//prepare for first feature, so that we know paper size to begin with
17211723
atlasMap->prepareForFeature( 0 );
17221724

1723-
mComposition->beginPrint( mPrinter, true );
1724-
QPainter painter( &mPrinter );
1725+
mComposition->beginPrint( *printer(), true );
1726+
QPainter painter( printer() );
17251727

17261728
loadAtlasPredefinedScalesFromProject();
17271729
if ( ! atlasMap->beginRender() && !atlasMap->featureFilterErrorString().isEmpty() )
@@ -1759,7 +1761,7 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )
17591761
}
17601762

17611763
//start print on a new page if we're not on the first feature
1762-
mComposition->doPrint( mPrinter, painter, i > 0 );
1764+
mComposition->doPrint( *printer(), painter, i > 0 );
17631765
}
17641766
atlasMap->endRender();
17651767
painter.end();
@@ -3556,7 +3558,7 @@ void QgsComposer::on_mActionPageSetup_triggered()
35563558
return;
35573559
}
35583560

3559-
QPageSetupDialog pageSetupDialog( &mPrinter, this );
3561+
QPageSetupDialog pageSetupDialog( printer(), this );
35603562
pageSetupDialog.exec();
35613563
}
35623564

@@ -3726,11 +3728,11 @@ void QgsComposer::setPrinterPageOrientation( QString orientation )
37263728
{
37273729
if ( orientation == tr( "Landscape" ) )
37283730
{
3729-
mPrinter.setOrientation( QPrinter::Landscape );
3731+
printer()->setOrientation( QPrinter::Landscape );
37303732
}
37313733
else
37323734
{
3733-
mPrinter.setOrientation( QPrinter::Portrait );
3735+
printer()->setOrientation( QPrinter::Portrait );
37343736
}
37353737
}
37363738

@@ -3742,11 +3744,11 @@ void QgsComposer::setPrinterPageDefaults()
37423744
//set printer page orientation
37433745
if ( paperWidth > paperHeight )
37443746
{
3745-
mPrinter.setOrientation( QPrinter::Landscape );
3747+
printer()->setOrientation( QPrinter::Landscape );
37463748
}
37473749
else
37483750
{
3749-
mPrinter.setOrientation( QPrinter::Portrait );
3751+
printer()->setOrientation( QPrinter::Portrait );
37503752
}
37513753
}
37523754

@@ -3799,3 +3801,13 @@ void QgsComposer::loadAtlasPredefinedScalesFromProject()
37993801
atlasMap.setPredefinedScales( pScales );
38003802
}
38013803

3804+
QPrinter *QgsComposer::printer()
3805+
{
3806+
//only create the printer on demand - creating a printer object can be very slow
3807+
//due to QTBUG-3033
3808+
if ( !mPrinter )
3809+
mPrinter = new QPrinter();
3810+
3811+
return mPrinter;
3812+
}
3813+

src/app/composer/qgscomposer.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "ui_qgscomposerbase.h"
2020
#include "qgscomposermap.h"
2121
#include "qgscontexthelp.h"
22-
#include <QPrinter>
2322
#include <QDockWidget>
2423

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

511+
QPrinter* printer();
512+
512513
/**Composer title*/
513514
QString mTitle;
514515

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

560561
//! Page & Printer Setup
561-
QPrinter mPrinter;
562+
QPrinter* mPrinter;
562563

563564
QUndoView* mUndoView;
564565

0 commit comments

Comments
 (0)