Skip to content

Commit

Permalink
Merge pull request #8705 from arnaud-morvan/server_diagrams_filter
Browse files Browse the repository at this point in the history
Apply featureFilterProvider in QgsVectorLayerDiagramProvider
  • Loading branch information
m-kuhn authored Jan 10, 2019
2 parents 29ad9d7 + a222906 commit fd00cd5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaprendererjob.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ emitted when asynchronous rendering is finished (or canceled).




};


Expand Down
19 changes: 9 additions & 10 deletions src/core/qgsmaprenderercustompainterjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ void QgsMapRendererCustomPainterJob::doRender()
mLabelJob.img->fill( 0 );
painter.begin( mLabelJob.img );
mLabelJob.context.setPainter( &painter );
drawLabeling( mSettings, mLabelJob.context, mLabelingEngineV2.get(), &painter );
drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), &painter );
painter.end();
}
else
{
drawLabeling( mSettings, mLabelJob.context, mLabelingEngineV2.get(), mPainter );
drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), mPainter );
}

mLabelJob.complete = true;
Expand All @@ -318,8 +318,7 @@ void QgsMapRendererCustomPainterJob::doRender()
QgsDebugMsgLevel( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ), 2 );
}


void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
void QgsMapRendererJob::drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
{
QgsDebugMsgLevel( QStringLiteral( "Draw labeling start" ), 5 );

Expand All @@ -329,22 +328,22 @@ void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderC
// Reset the composition mode before rendering the labels
painter->setCompositionMode( QPainter::CompositionMode_SourceOver );

// TODO: this is not ideal - we could override rendering stopped flag that has been set in meanwhile
renderContext = QgsRenderContext::fromMapSettings( settings );
renderContext.setPainter( painter );

if ( labelingEngine2 )
{
// set correct extent
renderContext.setExtent( settings.visibleExtent() );
renderContext.setCoordinateTransform( QgsCoordinateTransform() );

labelingEngine2->run( renderContext );
}

QgsDebugMsg( QStringLiteral( "Draw labeling took (seconds): %1" ).arg( t.elapsed() / 1000. ) );
}

void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
{
Q_UNUSED( settings );

drawLabeling( renderContext, labelingEngine2, painter );
}

bool QgsMapRendererJob::needTemporaryImage( QgsMapLayer *ml )
{
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaprendererjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ LabelRenderJob QgsMapRendererJob::prepareLabelingJob( QPainter *painter, QgsLabe
job.context.setPainter( painter );
job.context.setLabelingEngine( labelingEngine2 );
job.context.setExtent( mSettings.visibleExtent() );
job.context.setFeatureFilterProvider( mFeatureFilterProvider );

// if we can use the cache, let's do it and avoid rendering!
bool hasCache = canUseLabelCache && mCache && mCache->hasCacheImage( LABEL_CACHE_ID );
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsmaprendererjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,14 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
*/
void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;

/**
* \note not available in Python bindings
* \deprecated Will be removed in QGIS 4.0
*/
Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;

//! \note not available in Python bindings
static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;

private:

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprendererparalleljob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob *s
// draw the labels!
try
{
drawLabeling( self->mSettings, job.context, self->mLabelingEngineV2.get(), &painter );
drawLabeling( job.context, self->mLabelingEngineV2.get(), &painter );
}
catch ( QgsException &e )
{
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsvectorlayerdiagramprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ QList<QgsLabelFeature *> QgsVectorLayerDiagramProvider::labelFeatures( QgsRender
QgsFeatureRequest request;
request.setFilterRect( layerExtent );
request.setSubsetOfAttributes( attributeNames, mFields );
const QgsFeatureFilterProvider *featureFilterProvider = context.featureFilterProvider();
if ( featureFilterProvider )
{
featureFilterProvider->filterFeatures( qobject_cast<QgsVectorLayer *>( mLayer ), request );
}
QgsFeatureIterator fit = mSource->getFeatures( request );


QgsFeature fet;
while ( fit.nextFeature( fet ) )
{
Expand Down

0 comments on commit fd00cd5

Please sign in to comment.