QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsvectorlayerrenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerrenderer.cpp
3 --------------------------------------
4 Date : December 2013
5 Copyright : (C) 2013 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18
19#include "qgsmessagelog.h"
20#include "qgspallabeling.h"
21#include "qgsrenderer.h"
22#include "qgsrendercontext.h"
24#include "qgssymbollayer.h"
25#include "qgssymbol.h"
26#include "qgsvectorlayer.h"
31#include "qgspainteffect.h"
33#include "qgsexception.h"
34#include "qgslabelsink.h"
35#include "qgslogger.h"
40#include "qgsmapclippingutils.h"
43
44#include <QPicture>
45#include <QTimer>
46
48 : QgsMapLayerRenderer( layer->id(), &context )
49 , mFeedback( std::make_unique< QgsFeedback >() )
50 , mLayer( layer )
51 , mFields( layer->fields() )
52 , mSource( std::make_unique< QgsVectorLayerFeatureSource >( layer ) )
53 , mNoSetLayerExpressionContext( layer->customProperty( QStringLiteral( "_noset_layer_expression_context" ) ).toBool() )
54{
55 std::unique_ptr< QgsFeatureRenderer > mainRenderer( layer->renderer() ? layer->renderer()->clone() : nullptr );
56
57 if ( !mainRenderer )
58 return;
59
60 QList< const QgsFeatureRendererGenerator * > generators = layer->featureRendererGenerators();
61 std::sort( generators.begin(), generators.end(), []( const QgsFeatureRendererGenerator * g1, const QgsFeatureRendererGenerator * g2 )
62 {
63 return g1->level() < g2->level();
64 } );
65
66 bool insertedMainRenderer = false;
67 double prevLevel = std::numeric_limits< double >::lowest();
68 // cppcheck-suppress danglingLifetime
69 mRenderer = mainRenderer.get();
70 for ( const QgsFeatureRendererGenerator *generator : std::as_const( generators ) )
71 {
72 if ( generator->level() >= 0 && prevLevel < 0 && !insertedMainRenderer )
73 {
74 // insert main renderer when level changes from <0 to >0
75 mRenderers.emplace_back( std::move( mainRenderer ) );
76 insertedMainRenderer = true;
77 }
78 mRenderers.emplace_back( generator->createRenderer() );
79 prevLevel = generator->level();
80 }
81 // cppcheck-suppress accessMoved
82 if ( mainRenderer )
83 {
84 // cppcheck-suppress accessMoved
85 mRenderers.emplace_back( std::move( mainRenderer ) );
86 }
87
88 mSelectedFeatureIds = layer->selectedFeatureIds();
89
90 mDrawVertexMarkers = nullptr != layer->editBuffer();
91
92 mGeometryType = layer->geometryType();
93
94 mFeatureBlendMode = layer->featureBlendMode();
95
96 if ( context.isTemporal() )
97 {
98 QgsVectorLayerTemporalContext temporalContext;
99 temporalContext.setLayer( layer );
100 mTemporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->temporalProperties() )->createFilterString( temporalContext, context.temporalRange() );
101 QgsDebugMsgLevel( "Rendering with Temporal Filter: " + mTemporalFilter, 2 );
102 }
103
104 // if there's already a simplification method specified via the context, we respect that. Otherwise, we fall back
105 // to the layer's individual setting
106 if ( renderContext()->vectorSimplifyMethod().simplifyHints() != QgsVectorSimplifyMethod::NoSimplification )
107 {
108 mSimplifyMethod = renderContext()->vectorSimplifyMethod();
111 }
112 else
113 {
114 mSimplifyMethod = layer->simplifyMethod();
116 }
117
119
121 if ( markerTypeString == QLatin1String( "Cross" ) )
122 {
123 mVertexMarkerStyle = Qgis::VertexMarkerType::Cross;
124 }
125 else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
126 {
128 }
129 else
130 {
131 mVertexMarkerStyle = Qgis::VertexMarkerType::NoMarker;
132 }
133
135
136 // cppcheck-suppress danglingLifetime
137 QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
138
139 if ( mDrawVertexMarkers )
140 {
141 // set editing vertex markers style (main renderer only)
142 mRenderer->setVertexMarkerAppearance( mVertexMarkerStyle, mVertexMarkerSize );
143 }
144 if ( !mNoSetLayerExpressionContext )
146
147 for ( const std::unique_ptr< QgsFeatureRenderer > &renderer : mRenderers )
148 {
149 mAttrNames.unite( renderer->usedAttributes( context ) );
150 }
151 if ( context.hasRenderedFeatureHandlers() )
152 {
153 const QList< QgsRenderedFeatureHandlerInterface * > handlers = context.renderedFeatureHandlers();
154 for ( QgsRenderedFeatureHandlerInterface *handler : handlers )
155 mAttrNames.unite( handler->usedAttributes( layer, context ) );
156 }
157
158 //register label and diagram layer to the labeling engine
159 prepareLabeling( layer, mAttrNames );
160 prepareDiagrams( layer, mAttrNames );
161
162 mClippingRegions = QgsMapClippingUtils::collectClippingRegionsForLayer( context, layer );
163
164 if ( std::any_of( mRenderers.begin(), mRenderers.end(), []( const auto & renderer ) { return renderer->forceRasterRender(); } ) )
165 {
166 //raster rendering is forced for this layer
167 mForceRasterRender = true;
168 }
169
171 ( ( layer->blendMode() != QPainter::CompositionMode_SourceOver )
172 || ( layer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
173 || ( !qgsDoubleNear( layer->opacity(), 1.0 ) ) ) )
174 {
175 //layer properties require rasterization
176 mForceRasterRender = true;
177 }
178
179 mReadyToCompose = false;
180}
181
183
185{
186 mRenderTimeHint = time;
187}
188
190{
191 return mFeedback.get();
192}
193
195{
196 return mForceRasterRender;
197}
198
200{
201 if ( mGeometryType == Qgis::GeometryType::Null || mGeometryType == Qgis::GeometryType::Unknown )
202 {
203 mReadyToCompose = true;
204 return true;
205 }
206
207 if ( mRenderers.empty() )
208 {
209 mReadyToCompose = true;
210 mErrors.append( QObject::tr( "No renderer for drawing." ) );
211 return false;
212 }
213
214 // if the previous layer render was relatively quick (e.g. less than 3 seconds), the we show any previously
215 // cached version of the layer during rendering instead of the usual progressive updates
216 if ( mRenderTimeHint > 0 && mRenderTimeHint <= MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
217 {
218 mBlockRenderUpdates = true;
219 mElapsedTimer.start();
220 }
221
222 bool res = true;
223 for ( const std::unique_ptr< QgsFeatureRenderer > &renderer : mRenderers )
224 {
225 res = renderInternal( renderer.get() ) && res;
226 }
227
228 mReadyToCompose = true;
229 return res && !renderContext()->renderingStopped();
230}
231
232bool QgsVectorLayerRenderer::renderInternal( QgsFeatureRenderer *renderer )
233{
234 const bool isMainRenderer = renderer == mRenderer;
235
236 QgsRenderContext &context = *renderContext();
237 context.setSymbologyReferenceScale( renderer->referenceScale() );
238
239 if ( renderer->type() == QLatin1String( "nullSymbol" ) )
240 {
241 // a little shortcut for the null symbol renderer - most of the time it is not going to render anything
242 // so we can even skip the whole loop to fetch features
243 if ( !isMainRenderer ||
244 ( !mDrawVertexMarkers && !mLabelProvider && !mDiagramProvider && mSelectedFeatureIds.isEmpty() ) )
245 return true;
246 }
247
248 QgsScopedQPainterState painterState( context.painter() );
249
250 bool usingEffect = false;
251 if ( renderer->paintEffect() && renderer->paintEffect()->enabled() )
252 {
253 usingEffect = true;
254 renderer->paintEffect()->begin( context );
255 }
256
257 // Per feature blending mode
258 if ( context.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
259 {
260 // set the painter to the feature blend mode, so that features drawn
261 // on this layer will interact and blend with each other
262 context.painter()->setCompositionMode( mFeatureBlendMode );
263 }
264
265 renderer->startRender( context, mFields );
266
267 if ( renderer->canSkipRender() )
268 {
269 // nothing to draw for now...
270 renderer->stopRender( context );
271 return true;
272 }
273
274 QString rendererFilter = renderer->filter( mFields );
275
276 QgsRectangle requestExtent = context.extent();
277 if ( !mClippingRegions.empty() )
278 {
279 mClipFilterGeom = QgsMapClippingUtils::calculateFeatureRequestGeometry( mClippingRegions, context, mApplyClipFilter );
280 requestExtent = requestExtent.intersect( mClipFilterGeom.boundingBox() );
281
282 mClipFeatureGeom = QgsMapClippingUtils::calculateFeatureIntersectionGeometry( mClippingRegions, context, mApplyClipGeometries );
283
284 bool needsPainterClipPath = false;
285 const QPainterPath path = QgsMapClippingUtils::calculatePainterClipRegion( mClippingRegions, context, Qgis::LayerType::Vector, needsPainterClipPath );
286 if ( needsPainterClipPath )
287 context.painter()->setClipPath( path, Qt::IntersectClip );
288
289 mLabelClipFeatureGeom = QgsMapClippingUtils::calculateLabelIntersectionGeometry( mClippingRegions, context, mApplyLabelClipGeometries );
290
291 if ( mDiagramProvider )
292 mDiagramProvider->setClipFeatureGeometry( mLabelClipFeatureGeom );
293 }
294 renderer->modifyRequestExtent( requestExtent, context );
295
296 QgsFeatureRequest featureRequest = QgsFeatureRequest()
297 .setFilterRect( requestExtent )
298 .setSubsetOfAttributes( mAttrNames, mFields )
300 if ( renderer->orderByEnabled() )
301 {
302 featureRequest.setOrderBy( renderer->orderBy() );
303 }
304
305 const QgsFeatureFilterProvider *featureFilterProvider = context.featureFilterProvider();
306 if ( featureFilterProvider )
307 {
308 featureFilterProvider->filterFeatures( mLayer, featureRequest );
309 }
310 if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
311 {
312 featureRequest.combineFilterExpression( rendererFilter );
313 }
314 if ( !mTemporalFilter.isEmpty() )
315 {
316 featureRequest.combineFilterExpression( mTemporalFilter );
317 }
318
319 if ( renderer->usesEmbeddedSymbols() )
320 {
321 featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::EmbeddedSymbols );
322 }
323
324 // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
325 if ( mSimplifyGeometry )
326 {
327 double map2pixelTol = mSimplifyMethod.threshold();
328 bool validTransform = true;
329
330 const QgsMapToPixel &mtp = context.mapToPixel();
331 map2pixelTol *= mtp.mapUnitsPerPixel();
332 const QgsCoordinateTransform ct = context.coordinateTransform();
333
334 // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
335 if ( ct.isValid() && !ct.isShortCircuited() )
336 {
337 try
338 {
339 QgsCoordinateTransform toleranceTransform = ct;
340 QgsPointXY center = context.extent().center();
341 double rectSize = toleranceTransform.sourceCrs().mapUnits() == Qgis::DistanceUnit::Degrees ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
342
343 QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
344 toleranceTransform.setBallparkTransformsAreAppropriate( true );
345 QgsRectangle targetRect = toleranceTransform.transform( sourceRect );
346
347 QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
348 QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
349
350 if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
351 {
352 QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
353 QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
354 QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
355 QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
356
357 double sourceHypothenuse = std::sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
358 double targetHypothenuse = std::sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
359
360 QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
361 QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
362
363 if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
364 map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
365 }
366 }
367 catch ( QgsCsException &cse )
368 {
369 QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
370 validTransform = false;
371 }
372 }
373
374 if ( validTransform )
375 {
376 QgsSimplifyMethod simplifyMethod;
378 simplifyMethod.setTolerance( map2pixelTol );
379 simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
380 simplifyMethod.setForceLocalOptimization( mSimplifyMethod.forceLocalOptimization() );
381 featureRequest.setSimplifyMethod( simplifyMethod );
382
383 QgsVectorSimplifyMethod vectorMethod = mSimplifyMethod;
384 vectorMethod.setTolerance( map2pixelTol );
385 context.setVectorSimplifyMethod( vectorMethod );
386 }
387 else
388 {
389 QgsVectorSimplifyMethod vectorMethod;
391 context.setVectorSimplifyMethod( vectorMethod );
392 }
393 }
394 else
395 {
396 QgsVectorSimplifyMethod vectorMethod;
398 context.setVectorSimplifyMethod( vectorMethod );
399 }
400
401 featureRequest.setFeedback( mFeedback.get() );
402 // also set the interruption checker for the expression context, in case the renderer uses some complex expression
403 // which could benefit from early exit paths...
404 context.expressionContext().setFeedback( mFeedback.get() );
405
406 QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
407 // Attach an interruption checker so that iterators that have potentially
408 // slow fetchFeature() implementations, such as in the WFS provider, can
409 // check it, instead of relying on just the mContext.renderingStopped() check
410 // in drawRenderer()
411 fit.setInterruptionChecker( mFeedback.get() );
412
413 if ( ( renderer->capabilities() & QgsFeatureRenderer::SymbolLevels ) && renderer->usingSymbolLevels() )
414 drawRendererLevels( renderer, fit );
415 else
416 drawRenderer( renderer, fit );
417
418 if ( !fit.isValid() )
419 {
420 mErrors.append( QStringLiteral( "Data source invalid" ) );
421 }
422
423 if ( usingEffect )
424 {
425 renderer->paintEffect()->end( context );
426 }
427
428 context.expressionContext().setFeedback( nullptr );
429 return true;
430}
431
432
433void QgsVectorLayerRenderer::drawRenderer( QgsFeatureRenderer *renderer, QgsFeatureIterator &fit )
434{
435 const bool isMainRenderer = renderer == mRenderer;
436
438 QgsRenderContext &context = *renderContext();
439 context.expressionContext().appendScope( symbolScope );
440
441 std::unique_ptr< QgsGeometryEngine > clipEngine;
442 if ( mApplyClipFilter )
443 {
444 clipEngine.reset( QgsGeometry::createGeometryEngine( mClipFilterGeom.constGet() ) );
445 clipEngine->prepareGeometry();
446 }
447
448 QgsFeature fet;
449 while ( fit.nextFeature( fet ) )
450 {
451 try
452 {
453 if ( context.renderingStopped() )
454 {
455 QgsDebugMsgLevel( QStringLiteral( "Drawing of vector layer %1 canceled." ).arg( layerId() ), 2 );
456 break;
457 }
458
459 if ( !fet.hasGeometry() || fet.geometry().isEmpty() )
460 continue; // skip features without geometry
461
462 if ( clipEngine && !clipEngine->intersects( fet.geometry().constGet() ) )
463 continue; // skip features outside of clipping region
464
465 if ( mApplyClipGeometries )
466 context.setFeatureClipGeometry( mClipFeatureGeom );
467
468 if ( ! mNoSetLayerExpressionContext )
469 context.expressionContext().setFeature( fet );
470
471 bool sel = isMainRenderer && context.showSelection() && mSelectedFeatureIds.contains( fet.id() );
472 bool drawMarker = isMainRenderer && ( mDrawVertexMarkers && context.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
473
474 // render feature
475 bool rendered = false;
477 {
478 rendered = renderer->renderFeature( fet, context, -1, sel, drawMarker );
479 }
480 else
481 {
482 rendered = renderer->willRenderFeature( fet, context );
483 }
484
485 // labeling - register feature
486 if ( rendered )
487 {
488 // as soon as first feature is rendered, we can start showing layer updates.
489 // but if we are blocking render updates (so that a previously cached image is being shown), we wait
490 // at most e.g. 3 seconds before we start forcing progressive updates.
491 if ( !mBlockRenderUpdates || mElapsedTimer.elapsed() > MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
492 {
493 mReadyToCompose = true;
494 }
495
496 // new labeling engine
497 if ( isMainRenderer && context.labelingEngine() && ( mLabelProvider || mDiagramProvider ) )
498 {
499 QgsGeometry obstacleGeometry;
500 QgsSymbolList symbols = renderer->originalSymbolsForFeature( fet, context );
501 QgsSymbol *symbol = nullptr;
502 if ( !symbols.isEmpty() && fet.geometry().type() == Qgis::GeometryType::Point )
503 {
504 obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, context, symbols );
505 }
506
507 if ( !symbols.isEmpty() )
508 {
509 symbol = symbols.at( 0 );
511 }
512
513 if ( mApplyLabelClipGeometries )
514 context.setFeatureClipGeometry( mLabelClipFeatureGeom );
515
516 if ( mLabelProvider )
517 {
518 mLabelProvider->registerFeature( fet, context, obstacleGeometry, symbol );
519 }
520 if ( mDiagramProvider )
521 {
522 mDiagramProvider->registerFeature( fet, context, obstacleGeometry );
523 }
524
525 if ( mApplyLabelClipGeometries )
527 }
528 }
529 }
530 catch ( const QgsCsException &cse )
531 {
532 Q_UNUSED( cse )
533 QgsDebugError( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
534 .arg( fet.id() ).arg( cse.what() ) );
535 }
536 }
537
538 delete context.expressionContext().popScope();
539
540 stopRenderer( renderer, nullptr );
541}
542
543void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureRenderer *renderer, QgsFeatureIterator &fit )
544{
545 const bool isMainRenderer = renderer == mRenderer;
546
547 // We need to figure out in which order all the features should be rendered.
548 // Ordering is based on (a) a "level" which is determined by the configured
549 // feature rendering order" and (b) the symbol level. The "level" is
550 // determined by the values of the attributes defined in the feature
551 // rendering order settings. Each time the attribute(s) have a new distinct
552 // value, a new empty QHash is added to the "features" list. This QHash is
553 // then filled by mappings from the symbol to a list of all the features
554 // that should be rendered by that symbol.
555 //
556 // If orderBy is not enabled, this list will only ever contain a single
557 // element.
558 QList<QHash< QgsSymbol *, QList<QgsFeature> >> features;
559
560 // We have at least one "level" for the features.
561 features.push_back( {} );
562
563 QSet<int> orderByAttributeIdx;
564 if ( renderer->orderByEnabled() )
565 {
566 orderByAttributeIdx = renderer->orderBy().usedAttributeIndices( mSource->fields() );
567 }
568
569 QgsRenderContext &context = *renderContext();
570
571 QgsSingleSymbolRenderer *selRenderer = nullptr;
572 if ( !mSelectedFeatureIds.isEmpty() )
573 {
574 selRenderer = new QgsSingleSymbolRenderer( QgsSymbol::defaultSymbol( mGeometryType ) );
575 selRenderer->symbol()->setColor( context.selectionColor() );
576 selRenderer->setVertexMarkerAppearance( mVertexMarkerStyle, mVertexMarkerSize );
577 selRenderer->startRender( context, mFields );
578 }
579
581 std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.expressionContext(), symbolScope );
582
583
584 std::unique_ptr< QgsGeometryEngine > clipEngine;
585 if ( mApplyClipFilter )
586 {
587 clipEngine.reset( QgsGeometry::createGeometryEngine( mClipFilterGeom.constGet() ) );
588 clipEngine->prepareGeometry();
589 }
590
591 if ( mApplyLabelClipGeometries )
592 context.setFeatureClipGeometry( mLabelClipFeatureGeom );
593
594 // 1. fetch features
595 QgsFeature fet;
596 QVector<QVariant> prevValues; // previous values of ORDER BY attributes
597 while ( fit.nextFeature( fet ) )
598 {
599 if ( context.renderingStopped() )
600 {
601 qDebug( "rendering stop!" );
602 stopRenderer( renderer, selRenderer );
603 return;
604 }
605
606 if ( !fet.hasGeometry() )
607 continue; // skip features without geometry
608
609 if ( clipEngine && !clipEngine->intersects( fet.geometry().constGet() ) )
610 continue; // skip features outside of clipping region
611
612 if ( ! mNoSetLayerExpressionContext )
613 context.expressionContext().setFeature( fet );
614 QgsSymbol *sym = renderer->symbolForFeature( fet, context );
615 if ( !sym )
616 {
617 continue;
618 }
619
620 if ( renderer->orderByEnabled() )
621 {
622 QVector<QVariant> currentValues;
623 for ( auto const idx : orderByAttributeIdx )
624 {
625 currentValues.push_back( fet.attribute( idx ) );
626 }
627 if ( prevValues.empty() )
628 {
629 prevValues = std::move( currentValues );
630 }
631 else if ( currentValues != prevValues )
632 {
633 // Current values of ORDER BY attributes are different than previous
634 // values of these attributes. Start a new level.
635 prevValues = std::move( currentValues );
636 features.push_back( {} );
637 }
638 }
639
641 {
642 if ( !features.back().contains( sym ) )
643 {
644 features.back().insert( sym, QList<QgsFeature>() );
645 }
646 features.back()[sym].append( fet );
647 }
648
649 // new labeling engine
650 if ( isMainRenderer && context.labelingEngine() && ( mLabelProvider || mDiagramProvider ) )
651 {
652 QgsGeometry obstacleGeometry;
653 QgsSymbolList symbols = renderer->originalSymbolsForFeature( fet, context );
654 QgsSymbol *symbol = nullptr;
655 if ( !symbols.isEmpty() && fet.geometry().type() == Qgis::GeometryType::Point )
656 {
657 obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, context, symbols );
658 }
659
660 if ( !symbols.isEmpty() )
661 {
662 symbol = symbols.at( 0 );
664 }
665
666 if ( mLabelProvider )
667 {
668 mLabelProvider->registerFeature( fet, context, obstacleGeometry, symbol );
669 }
670 if ( mDiagramProvider )
671 {
672 mDiagramProvider->registerFeature( fet, context, obstacleGeometry );
673 }
674 }
675 }
676
677 if ( mApplyLabelClipGeometries )
679
680 scopePopper.reset();
681
682 if ( features.back().empty() )
683 {
684 // nothing to draw
685 stopRenderer( renderer, selRenderer );
686 return;
687 }
688
689 // find out the order
690 QgsSymbolLevelOrder levels;
691 QgsSymbolList symbols = renderer->symbols( context );
692 for ( int i = 0; i < symbols.count(); i++ )
693 {
694 QgsSymbol *sym = symbols[i];
695 for ( int j = 0; j < sym->symbolLayerCount(); j++ )
696 {
697 int level = sym->symbolLayer( j )->renderingPass();
698 if ( level < 0 || level >= 1000 ) // ignore invalid levels
699 continue;
700 QgsSymbolLevelItem item( sym, j );
701 while ( level >= levels.count() ) // append new empty levels
702 levels.append( QgsSymbolLevel() );
703 levels[level].append( item );
704 }
705 }
706
707 if ( mApplyClipGeometries )
708 context.setFeatureClipGeometry( mClipFeatureGeom );
709
710 // 2. draw features in correct order
711 for ( auto &featureLists : features )
712 {
713 for ( int l = 0; l < levels.count(); l++ )
714 {
715 const QgsSymbolLevel &level = levels[l];
716 for ( int i = 0; i < level.count(); i++ )
717 {
718 const QgsSymbolLevelItem &item = level[i];
719 if ( !featureLists.contains( item.symbol() ) )
720 {
721 QgsDebugError( QStringLiteral( "level item's symbol not found!" ) );
722 continue;
723 }
724 const int layer = item.layer();
725 const QList<QgsFeature> &lst = featureLists[item.symbol()];
726 for ( auto fit = lst.begin(); fit != lst.end(); ++fit )
727 {
728 if ( context.renderingStopped() )
729 {
730 stopRenderer( renderer, selRenderer );
731 return;
732 }
733
734 const bool sel = isMainRenderer && context.showSelection() && mSelectedFeatureIds.contains( fit->id() );
735 // maybe vertex markers should be drawn only during the last pass...
736 const bool drawMarker = isMainRenderer && ( mDrawVertexMarkers && context.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
737
738 if ( ! mNoSetLayerExpressionContext )
739 context.expressionContext().setFeature( *fit );
740
741 try
742 {
743 renderer->renderFeature( *fit, context, layer, sel, drawMarker );
744
745 // as soon as first feature is rendered, we can start showing layer updates.
746 // but if we are blocking render updates (so that a previously cached image is being shown), we wait
747 // at most e.g. 3 seconds before we start forcing progressive updates.
748 if ( !mBlockRenderUpdates || mElapsedTimer.elapsed() > MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
749 {
750 mReadyToCompose = true;
751 }
752 }
753 catch ( const QgsCsException &cse )
754 {
755 Q_UNUSED( cse )
756 QgsDebugError( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
757 .arg( fet.id() ).arg( cse.what() ) );
758 }
759 }
760 }
761 }
762 }
763
764 stopRenderer( renderer, selRenderer );
765}
766
767void QgsVectorLayerRenderer::stopRenderer( QgsFeatureRenderer *renderer, QgsSingleSymbolRenderer *selRenderer )
768{
769 QgsRenderContext &context = *renderContext();
770 renderer->stopRender( context );
771 if ( selRenderer )
772 {
773 selRenderer->stopRender( context );
774 delete selRenderer;
775 }
776}
777
778void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
779{
780 QgsRenderContext &context = *renderContext();
781 // TODO: add attributes for geometry generator
782 if ( QgsLabelingEngine *engine2 = context.labelingEngine() )
783 {
784 if ( layer->labelsEnabled() )
785 {
786 if ( context.labelSink() )
787 {
788 if ( const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( layer->labeling() ) )
789 {
790 mLabelProvider = new QgsRuleBasedLabelSinkProvider( *rbl, layer, context.labelSink() );
791 }
792 else
793 {
794 QgsPalLayerSettings settings = layer->labeling()->settings();
795 mLabelProvider = new QgsLabelSinkProvider( layer, QString(), context.labelSink(), &settings );
796 }
797 }
798 else
799 {
800 mLabelProvider = layer->labeling()->provider( layer );
801 }
802 if ( mLabelProvider )
803 {
804 engine2->addProvider( mLabelProvider );
805 if ( !mLabelProvider->prepare( context, attributeNames ) )
806 {
807 engine2->removeProvider( mLabelProvider );
808 mLabelProvider = nullptr; // deleted by engine
809 }
810 }
811 }
812 }
813
814#if 0 // TODO: limit of labels, font not found
815 QgsPalLayerSettings &palyr = mContext.labelingEngine()->layer( mLayerID );
816
817 // see if feature count limit is set for labeling
818 if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
819 {
820 QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
821 .setFilterRect( mContext.extent() )
822 .setNoAttributes() );
823
824 // total number of features that may be labeled
825 QgsFeature f;
826 int nFeatsToLabel = 0;
827 while ( fit.nextFeature( f ) )
828 {
829 nFeatsToLabel++;
830 }
831 palyr.mFeaturesToLabel = nFeatsToLabel;
832 }
833
834 // notify user about any font substitution
835 if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
836 {
837 emit labelingFontNotFound( this, palyr.mTextFontFamily );
838 mLabelFontNotFoundNotified = true;
839 }
840#endif
841}
842
843void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
844{
845 QgsRenderContext &context = *renderContext();
846 if ( QgsLabelingEngine *engine2 = context.labelingEngine() )
847 {
848 if ( layer->diagramsEnabled() )
849 {
850 mDiagramProvider = new QgsVectorLayerDiagramProvider( layer );
851 // need to be added before calling prepare() - uses map settings from engine
852 engine2->addProvider( mDiagramProvider );
853 if ( !mDiagramProvider->prepare( context, attributeNames ) )
854 {
855 engine2->removeProvider( mDiagramProvider );
856 mDiagramProvider = nullptr; // deleted by engine
857 }
858 }
859 }
860}
861
@ SkipSymbolRendering
Disable symbol rendering while still drawing labels if enabled (since QGIS 3.24)
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ SemiTransparentCircle
Semi-transparent circle marker.
@ Cross
Cross marker.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
Q_GADGET Qgis::DistanceUnit mapUnits
Class for doing transforms between two map coordinate systems.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:67
QString what() const
Definition: qgsexception.h:49
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the expression engine to check if expressio...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Abstract interface for use by classes that filter the features or attributes of a layer.
virtual void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &featureRequest) const =0
Add additional filters to the feature request to further restrict the features returned by the reques...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
void setInterruptionChecker(QgsFeedback *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped.
bool isValid() const
Will return if this iterator is valid.
An interface for objects which generate feature renderers for vector layers.
virtual bool canSkipRender()
Returns true if the renderer can be entirely skipped, i.e.
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
virtual QString filter(const QgsFields &fields=QgsFields())
If a renderer does not require all the features this method may be overridden and return an expressio...
Definition: qgsrenderer.h:216
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QString type() const
Definition: qgsrenderer.h:142
virtual bool usesEmbeddedSymbols() const
Returns true if the renderer uses embedded symbols for features.
double referenceScale() const
Returns the symbology reference scale.
Definition: qgsrenderer.h:502
bool usingSymbolLevels() const
Definition: qgsrenderer.h:302
virtual QString dump() const
Returns debug information about this renderer.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:293
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
@ SymbolLevels
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
Definition: qgsrenderer.h:273
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:90
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
void setVertexMarkerAppearance(Qgis::VertexMarkerType type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QSet< int > CORE_EXPORT usedAttributeIndices(const QgsFields &fields) const
Returns a set of used, validated attribute indices.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Flags flags() const
Returns the flags which affect how features are fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the iterator to check if it should be cance...
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QgsGeometry geometry
Definition: qgsfeature.h:67
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Definition: qgsfeature.cpp:335
Q_GADGET QgsFeatureId id
Definition: qgsfeature.h:64
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Qgis::GeometryType type
Definition: qgsgeometry.h:167
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Implements a derived label provider for use with QgsLabelSink.
Definition: qgslabelsink.h:75
The QgsLabelingEngine class provides map labeling functionality.
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, Qgis::LayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
static QgsGeometry calculateLabelIntersectionGeometry(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, bool &shouldClip)
Returns the geometry representing the intersection of clipping regions from context which should be u...
static QgsGeometry calculateFeatureIntersectionGeometry(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, bool &shouldClip)
Returns the geometry representing the intersection of clipping regions from context which should be u...
static QgsGeometry calculateFeatureRequestGeometry(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, bool &shouldFilter)
Returns the geometry representing the intersection of clipping regions from context.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
static constexpr int MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE
Maximum time (in ms) to allow display of a previously cached preview image while rendering layers,...
QString layerId() const
Gets access to the ID of the layer rendered by this class.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
double opacity
Definition: qgsmaplayer.h:82
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
double mapUnitsPerPixel() const
Returns the current map units per pixel.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
bool enabled() const
Returns whether the effect is enabled.
Contains settings for how a map layer will be labeled.
A class to represent a 2D point.
Definition: qgspointxy.h:59
double y
Definition: qgspointxy.h:63
Q_GADGET double x
Definition: qgspointxy.h:62
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
Definition: qgsrectangle.h:333
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:559
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
Contains information about the context of a rendering operation.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
QgsLabelSink * labelSink() const
Returns the associated label sink, or nullptr if not set.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
void setSymbologyReferenceScale(double scale)
Sets the symbology reference scale.
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QColor selectionColor() const
Returns the color to use when rendering selected features.
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr).
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
An interface for classes which provider custom handlers for features rendered as part of a map render...
Implements a derived label provider for rule based labels for use with QgsLabelSink.
Definition: qgslabelsink.h:95
Rule based labeling for a vector layer.
Scoped object for saving and restoring a QPainter object's state.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
static const QgsSettingsEntryDouble * settingsDigitizingMarkerSizeMm
Settings entry digitizing marker size mm.
static const QgsSettingsEntryBool * settingsDigitizingMarkerOnlyForSelected
Settings entry digitizing marker only for selected.
static const QgsSettingsEntryString * settingsDigitizingMarkerStyle
Settings entry digitizing marker style.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
void setThreshold(float threshold)
Sets the simplification threshold in pixels. Represents the maximum distance in pixels between two co...
void setForceLocalOptimization(bool localOptimization)
Sets whether the simplification executes after fetch the geometries from provider,...
void setMethodType(MethodType methodType)
Sets the simplification type.
@ OptimizeForRendering
Simplify using the map2pixel data to optimize the rendering of geometries.
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
int layer() const
The layer of this symbol level.
QgsSymbol * symbol() const
The symbol of this symbol level.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:94
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
Definition: qgssymbol.cpp:759
void setColor(const QColor &color) const
Sets the color for the symbol.
Definition: qgssymbol.cpp:901
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:216
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:704
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures.
void setClipFeatureGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features to when registering them as diagrams.
Partial snapshot of vector layer's state (only the members necessary for access to features)
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
static QgsGeometry getPointObstacleGeometry(QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols)
Returns the geometry for a point feature which should be used as an obstacle for labels.
virtual QList< QgsLabelFeature * > registerFeature(const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
~QgsVectorLayerRenderer() override
void setLayerRenderingTimeHint(int time) override
Sets approximate render time (in ms) for the layer to render.
bool render() override
Do the rendering (based on data stored in the class).
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
Encapsulates the context in which a QgsVectorLayer's temporal capabilities will be applied.
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
Represents a vector layer which manages a vector based data sets.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
Q_INVOKABLE const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const
Returns a list of the feature renderer generators owned by the layer.
This class contains information how to simplify geometries fetched from a vector layer.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
float threshold() const
Gets the simplification threshold of the vector layer managed.
@ GeometrySimplification
The geometries can be simplified using the current map2pixel context state.
@ FullSimplification
All simplification hints can be applied ( Geometry + AA-disabling )
@ NoSimplification
No simplification can be applied.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:3988
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define QgsDebugError(str)
Definition: qgslogger.h:38
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:88
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:84
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44