mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Merge pull request #5035 from nyalldawson/preview_tasks
Tweaks to map preview tasks
This commit is contained in:
commit
251354eaaa
@ -593,6 +593,27 @@ returns last position of mouse cursor
|
|||||||
:rtype: QgsLabelingEngineSettings
|
:rtype: QgsLabelingEngineSettings
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
bool previewJobsEnabled() const;
|
||||||
|
%Docstring
|
||||||
|
Returns true if canvas map preview jobs (low priority render jobs which render portions
|
||||||
|
of the view just outside of the canvas extent, to allow preview of these
|
||||||
|
out-of-canvas areas when panning or zooming out the map) are enabled
|
||||||
|
for the canvas.
|
||||||
|
.. seealso:: setPreviewJobsEnabled()
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
:rtype: bool
|
||||||
|
%End
|
||||||
|
|
||||||
|
void setPreviewJobsEnabled( bool enabled );
|
||||||
|
%Docstring
|
||||||
|
Sets whether canvas map preview jobs (low priority render jobs which render portions
|
||||||
|
of the view just outside of the canvas extent, to allow preview of these
|
||||||
|
out-of-canvas areas when panning or zooming out the map) are ``enabled``
|
||||||
|
for the canvas.
|
||||||
|
.. seealso:: previewJobsEnabled()
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
%End
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
@ -727,6 +727,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
|
|||||||
connect( mMapCanvas, &QgsMapCanvas::messageEmitted, this, &QgisApp::displayMessage );
|
connect( mMapCanvas, &QgsMapCanvas::messageEmitted, this, &QgisApp::displayMessage );
|
||||||
mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector "
|
mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector "
|
||||||
"layers are displayed when added to the map" ) );
|
"layers are displayed when added to the map" ) );
|
||||||
|
mMapCanvas->setPreviewJobsEnabled( true );
|
||||||
|
|
||||||
// set canvas color right away
|
// set canvas color right away
|
||||||
int myRed = settings.value( QStringLiteral( "qgis/default_canvas_color_red" ), 255 ).toInt();
|
int myRed = settings.value( QStringLiteral( "qgis/default_canvas_color_red" ), 255 ).toInt();
|
||||||
|
@ -629,7 +629,8 @@ void QgsMapCanvas::rendererJobFinished()
|
|||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
mMap->setContent( img, imageRect( img, mSettings ) );
|
mMap->setContent( img, imageRect( img, mSettings ) );
|
||||||
startPreviewJobs();
|
if ( mUsePreviewJobs )
|
||||||
|
startPreviewJobs();
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we are in a slot called from mJob - do not delete it immediately
|
// 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
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsMapCanvas::previewJobsEnabled() const
|
||||||
|
{
|
||||||
|
return mUsePreviewJobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsMapCanvas::setPreviewJobsEnabled( bool enabled )
|
||||||
|
{
|
||||||
|
mUsePreviewJobs = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void QgsMapCanvas::mapUpdateTimeout()
|
void QgsMapCanvas::mapUpdateTimeout()
|
||||||
{
|
{
|
||||||
if ( mJob )
|
if ( mJob )
|
||||||
@ -2132,7 +2143,7 @@ const QgsLabelingEngineSettings &QgsMapCanvas::labelingEngineSettings() const
|
|||||||
void QgsMapCanvas::startPreviewJobs()
|
void QgsMapCanvas::startPreviewJobs()
|
||||||
{
|
{
|
||||||
stopPreviewJobs(); //just in case still running
|
stopPreviewJobs(); //just in case still running
|
||||||
startPreviewJob( 0 );
|
schedulePreviewJob( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapCanvas::startPreviewJob( int number )
|
void QgsMapCanvas::startPreviewJob( int number )
|
||||||
@ -2160,22 +2171,14 @@ void QgsMapCanvas::startPreviewJob( int number )
|
|||||||
jobSettings.setExtent( jobExtent );
|
jobSettings.setExtent( jobExtent );
|
||||||
jobSettings.setFlag( QgsMapSettings::DrawLabeling, false );
|
jobSettings.setFlag( QgsMapSettings::DrawLabeling, false );
|
||||||
|
|
||||||
QgsMapRendererQImageJob *job = new QgsMapRendererParallelJob( jobSettings );
|
QgsMapRendererQImageJob *job = new QgsMapRendererSequentialJob( jobSettings );
|
||||||
mPreviewJobs.append( job );
|
mPreviewJobs.append( job );
|
||||||
connect( job, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
|
connect( job, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
|
||||||
job->start();
|
job->start();
|
||||||
|
|
||||||
if ( number < 8 )
|
if ( number < 8 )
|
||||||
{
|
{
|
||||||
mPreviewTimer.setSingleShot( true );
|
schedulePreviewJob( number + 1 );
|
||||||
mPreviewTimer.setInterval( 250 );
|
|
||||||
disconnect( mPreviewTimerConnection );
|
|
||||||
mPreviewTimerConnection = connect( &mPreviewTimer, &QTimer::timeout, [ = ]()
|
|
||||||
{
|
|
||||||
startPreviewJob( number + 1 );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
mPreviewTimer.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2194,3 +2197,16 @@ void QgsMapCanvas::stopPreviewJobs()
|
|||||||
}
|
}
|
||||||
mPreviewJobs.clear();
|
mPreviewJobs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsMapCanvas::schedulePreviewJob( int number )
|
||||||
|
{
|
||||||
|
mPreviewTimer.setSingleShot( true );
|
||||||
|
mPreviewTimer.setInterval( 250 );
|
||||||
|
disconnect( mPreviewTimerConnection );
|
||||||
|
mPreviewTimerConnection = connect( &mPreviewTimer, &QTimer::timeout, [ = ]()
|
||||||
|
{
|
||||||
|
startPreviewJob( number );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
mPreviewTimer.start();
|
||||||
|
}
|
||||||
|
@ -84,6 +84,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
|
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
|
||||||
|
Q_PROPERTY( bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -523,6 +524,26 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
*/
|
*/
|
||||||
const QgsLabelingEngineSettings &labelingEngineSettings() const;
|
const QgsLabelingEngineSettings &labelingEngineSettings() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if canvas map preview jobs (low priority render jobs which render portions
|
||||||
|
* of the view just outside of the canvas extent, to allow preview of these
|
||||||
|
* out-of-canvas areas when panning or zooming out the map) are enabled
|
||||||
|
* for the canvas.
|
||||||
|
* \see setPreviewJobsEnabled()
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
bool previewJobsEnabled() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether canvas map preview jobs (low priority render jobs which render portions
|
||||||
|
* of the view just outside of the canvas extent, to allow preview of these
|
||||||
|
* out-of-canvas areas when panning or zooming out the map) are \a enabled
|
||||||
|
* for the canvas.
|
||||||
|
* \see previewJobsEnabled()
|
||||||
|
* \since QGIS 3.0
|
||||||
|
*/
|
||||||
|
void setPreviewJobsEnabled( bool enabled );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
//! Repaints the canvas map
|
//! Repaints the canvas map
|
||||||
@ -854,6 +875,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
|
|
||||||
bool mAnnotationsVisible = true;
|
bool mAnnotationsVisible = true;
|
||||||
|
|
||||||
|
bool mUsePreviewJobs = false;
|
||||||
|
|
||||||
//! Force a resize of the map canvas item
|
//! Force a resize of the map canvas item
|
||||||
//! \since QGIS 2.16
|
//! \since QGIS 2.16
|
||||||
void updateMapSize();
|
void updateMapSize();
|
||||||
@ -882,6 +905,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
|||||||
|
|
||||||
void startPreviewJobs();
|
void startPreviewJobs();
|
||||||
void stopPreviewJobs();
|
void stopPreviewJobs();
|
||||||
|
void schedulePreviewJob( int number );
|
||||||
|
|
||||||
friend class TestQgsMapCanvas;
|
friend class TestQgsMapCanvas;
|
||||||
|
|
||||||
|
@ -47,6 +47,14 @@ class TestQgsMapCanvas(unittest.TestCase):
|
|||||||
with open(report_file_path, 'a') as report_file:
|
with open(report_file_path, 'a') as report_file:
|
||||||
report_file.write(self.report)
|
report_file.write(self.report)
|
||||||
|
|
||||||
|
def testGettersSetters(self):
|
||||||
|
canvas = QgsMapCanvas()
|
||||||
|
|
||||||
|
# should be disabled by default
|
||||||
|
self.assertFalse(canvas.previewJobsEnabled())
|
||||||
|
canvas.setPreviewJobsEnabled(True)
|
||||||
|
self.assertTrue(canvas.previewJobsEnabled())
|
||||||
|
|
||||||
def testDeferredUpdate(self):
|
def testDeferredUpdate(self):
|
||||||
""" test that map canvas doesn't auto refresh on deferred layer update """
|
""" test that map canvas doesn't auto refresh on deferred layer update """
|
||||||
canvas = QgsMapCanvas()
|
canvas = QgsMapCanvas()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user