mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Allow canceling background map renders
This commit is contained in:
parent
16596599de
commit
4a2226af31
@ -47,6 +47,9 @@ class QgsMapRendererTask : QgsTask
|
||||
Adds ``annotations`` to be rendered on the map.
|
||||
%End
|
||||
|
||||
virtual void cancel();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void renderingComplete();
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "qgsannotation.h"
|
||||
#include "qgsannotationmanager.h"
|
||||
#include "qgsmaprenderertask.h"
|
||||
#include "qgsmaprenderercustompainterjob.h"
|
||||
|
||||
|
||||
QgsMapRendererTask::QgsMapRendererTask( const QgsMapSettings &ms, const QString &fileName, const QString &fileFormat )
|
||||
@ -47,6 +46,16 @@ void QgsMapRendererTask::addAnnotations( QList< QgsAnnotation * > annotations )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsMapRendererTask::cancel()
|
||||
{
|
||||
mJobMutex.lock();
|
||||
if ( mJob )
|
||||
mJob->cancelWithoutBlocking();
|
||||
mJobMutex.unlock();
|
||||
|
||||
QgsTask::cancel();
|
||||
}
|
||||
|
||||
bool QgsMapRendererTask::run()
|
||||
{
|
||||
QImage img;
|
||||
@ -73,14 +82,26 @@ bool QgsMapRendererTask::run()
|
||||
if ( !destPainter )
|
||||
return false;
|
||||
|
||||
QgsMapRendererCustomPainterJob r( mMapSettings, destPainter );
|
||||
r.renderSynchronously();
|
||||
mJobMutex.lock();
|
||||
mJob.reset( new QgsMapRendererCustomPainterJob( mMapSettings, destPainter ) );
|
||||
mJobMutex.unlock();
|
||||
mJob->renderSynchronously();
|
||||
|
||||
mJobMutex.lock();
|
||||
mJob.reset( nullptr );
|
||||
mJobMutex.unlock();
|
||||
|
||||
if ( isCanceled() )
|
||||
return false;
|
||||
|
||||
QgsRenderContext context = QgsRenderContext::fromMapSettings( mMapSettings );
|
||||
context.setPainter( destPainter );
|
||||
|
||||
Q_FOREACH ( QgsAnnotation *annotation, mAnnotations )
|
||||
{
|
||||
if ( isCanceled() )
|
||||
return false;
|
||||
|
||||
if ( !annotation || !annotation->isVisible() )
|
||||
{
|
||||
continue;
|
||||
|
@ -24,8 +24,10 @@
|
||||
#include "qgsannotationmanager.h"
|
||||
#include "qgsmapsettings.h"
|
||||
#include "qgstaskmanager.h"
|
||||
#include "qgsmaprenderercustompainterjob.h"
|
||||
|
||||
#include <QPainter>
|
||||
class QgsMapRendererCustomPainterJob;
|
||||
|
||||
/**
|
||||
* \class QgsMapRendererTask
|
||||
@ -65,6 +67,8 @@ class CORE_EXPORT QgsMapRendererTask : public QgsTask
|
||||
*/
|
||||
void addAnnotations( QList< QgsAnnotation * > annotations );
|
||||
|
||||
void cancel() override;
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
@ -86,6 +90,9 @@ class CORE_EXPORT QgsMapRendererTask : public QgsTask
|
||||
|
||||
QgsMapSettings mMapSettings;
|
||||
|
||||
QMutex mJobMutex;
|
||||
std::unique_ptr< QgsMapRendererCustomPainterJob > mJob;
|
||||
|
||||
QPainter *mPainter = nullptr;
|
||||
|
||||
QString mFileName;
|
||||
|
Loading…
x
Reference in New Issue
Block a user