Skip to content

Commit 9bfca65

Browse files
committed
Add API to enable/disable preview jobs
Disabled by default, and enabled only for main canvas (not secondary canvases)
1 parent 628a1b0 commit 9bfca65

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

python/gui/qgsmapcanvas.sip

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,27 @@ returns last position of mouse cursor
593593
:rtype: QgsLabelingEngineSettings
594594
%End
595595

596+
bool previewJobsEnabled() const;
597+
%Docstring
598+
Returns true if canvas map preview jobs (low priority render jobs which render portions
599+
of the view just outside of the canvas extent, to allow preview of these
600+
out-of-canvas areas when panning or zooming out the map) are enabled
601+
for the canvas.
602+
.. seealso:: setPreviewJobsEnabled()
603+
.. versionadded:: 3.0
604+
:rtype: bool
605+
%End
606+
607+
void setPreviewJobsEnabled( bool enabled );
608+
%Docstring
609+
Sets whether canvas map preview jobs (low priority render jobs which render portions
610+
of the view just outside of the canvas extent, to allow preview of these
611+
out-of-canvas areas when panning or zooming out the map) are ``enabled``
612+
for the canvas.
613+
.. seealso:: previewJobsEnabled()
614+
.. versionadded:: 3.0
615+
%End
616+
596617
public slots:
597618

598619
void refresh();

src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
727727
connect( mMapCanvas, &QgsMapCanvas::messageEmitted, this, &QgisApp::displayMessage );
728728
mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector "
729729
"layers are displayed when added to the map" ) );
730+
mMapCanvas->setPreviewJobsEnabled( true );
730731

731732
// set canvas color right away
732733
int myRed = settings.value( QStringLiteral( "qgis/default_canvas_color_red" ), 255 ).toInt();

src/gui/qgsmapcanvas.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ void QgsMapCanvas::rendererJobFinished()
629629
p.end();
630630

631631
mMap->setContent( img, imageRect( img, mSettings ) );
632-
startPreviewJobs();
632+
if ( mUsePreviewJobs )
633+
startPreviewJobs();
633634
}
634635

635636
// now we are in a slot called from mJob - do not delete it immediately
@@ -664,6 +665,16 @@ QgsRectangle QgsMapCanvas::imageRect( const QImage &img, const QgsMapSettings &m
664665
return rect;
665666
}
666667

668+
bool QgsMapCanvas::previewJobsEnabled() const
669+
{
670+
return mUsePreviewJobs;
671+
}
672+
673+
void QgsMapCanvas::setPreviewJobsEnabled( bool enabled )
674+
{
675+
mUsePreviewJobs = enabled;
676+
}
677+
667678
void QgsMapCanvas::mapUpdateTimeout()
668679
{
669680
if ( mJob )

src/gui/qgsmapcanvas.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
8484

8585
Q_OBJECT
8686
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
87+
Q_PROPERTY( bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
8788

8889
public:
8990

@@ -523,6 +524,26 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
523524
*/
524525
const QgsLabelingEngineSettings &labelingEngineSettings() const;
525526

527+
/**
528+
* Returns true if canvas map preview jobs (low priority render jobs which render portions
529+
* of the view just outside of the canvas extent, to allow preview of these
530+
* out-of-canvas areas when panning or zooming out the map) are enabled
531+
* for the canvas.
532+
* \see setPreviewJobsEnabled()
533+
* \since QGIS 3.0
534+
*/
535+
bool previewJobsEnabled() const;
536+
537+
/**
538+
* Sets whether canvas map preview jobs (low priority render jobs which render portions
539+
* of the view just outside of the canvas extent, to allow preview of these
540+
* out-of-canvas areas when panning or zooming out the map) are \a enabled
541+
* for the canvas.
542+
* \see previewJobsEnabled()
543+
* \since QGIS 3.0
544+
*/
545+
void setPreviewJobsEnabled( bool enabled );
546+
526547
public slots:
527548

528549
//! Repaints the canvas map
@@ -854,6 +875,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
854875

855876
bool mAnnotationsVisible = true;
856877

878+
bool mUsePreviewJobs = false;
879+
857880
//! Force a resize of the map canvas item
858881
//! \since QGIS 2.16
859882
void updateMapSize();

tests/src/python/test_qgsmapcanvas.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def tearDown(self):
4747
with open(report_file_path, 'a') as report_file:
4848
report_file.write(self.report)
4949

50+
def testGettersSetters(self):
51+
canvas = QgsMapCanvas()
52+
53+
# should be disabled by default
54+
self.assertFalse(canvas.previewJobsEnabled())
55+
canvas.setPreviewJobsEnabled(True)
56+
self.assertTrue(canvas.previewJobsEnabled())
57+
5058
def testDeferredUpdate(self):
5159
""" test that map canvas doesn't auto refresh on deferred layer update """
5260
canvas = QgsMapCanvas()

0 commit comments

Comments
 (0)