QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
16 #include "qgsvectorlayerrenderer.h"
17 
18 #include "diagram/qgsdiagram.h"
19 
20 #include "qgsdiagramrenderer.h"
21 #include "qgsmessagelog.h"
22 #include "qgspallabeling.h"
23 #include "qgsrenderer.h"
24 #include "qgsrendercontext.h"
26 #include "qgssymbollayer.h"
27 #include "qgssymbollayerutils.h"
28 #include "qgssymbol.h"
29 #include "qgsvectorlayer.h"
32 #include "qgsvectorlayerlabeling.h"
34 #include "qgspainteffect.h"
36 #include "qgsexception.h"
37 #include "qgslabelsink.h"
38 #include "qgslogger.h"
43 #include "qgsmapclippingutils.h"
45 
46 #include <QPicture>
47 #include <QTimer>
48 
50  : QgsMapLayerRenderer( layer->id(), &context )
51  , mFeedback( std::make_unique< QgsFeedback >() )
52  , mLayer( layer )
53  , mFields( layer->fields() )
54  , mSource( std::make_unique< QgsVectorLayerFeatureSource >( layer ) )
55  , mNoSetLayerExpressionContext( layer->customProperty( QStringLiteral( "_noset_layer_expression_context" ) ).toBool() )
56 {
57  std::unique_ptr< QgsFeatureRenderer > mainRenderer( layer->renderer() ? layer->renderer()->clone() : nullptr );
58 
59  if ( !mainRenderer )
60  return;
61 
62  QList< const QgsFeatureRendererGenerator * > generators = layer->featureRendererGenerators();
63  std::sort( generators.begin(), generators.end(), []( const QgsFeatureRendererGenerator * g1, const QgsFeatureRendererGenerator * g2 )
64  {
65  return g1->level() < g2->level();
66  } );
67 
68  bool insertedMainRenderer = false;
69  double prevLevel = std::numeric_limits< double >::lowest();
70  mRenderer = mainRenderer.get();
71  for ( const QgsFeatureRendererGenerator *generator : std::as_const( generators ) )
72  {
73  if ( generator->level() >= 0 && prevLevel < 0 && !insertedMainRenderer )
74  {
75  // insert main renderer when level changes from <0 to >0
76  mRenderers.emplace_back( std::move( mainRenderer ) );
77  insertedMainRenderer = true;
78  }
79  mRenderers.emplace_back( generator->createRenderer() );
80  prevLevel = generator->level();
81  }
82  // cppcheck-suppress accessMoved
83  if ( mainRenderer )
84  {
85  // cppcheck-suppress accessMoved
86  mRenderers.emplace_back( std::move( mainRenderer ) );
87  }
88 
89  mSelectedFeatureIds = layer->selectedFeatureIds();
90 
91  mDrawVertexMarkers = nullptr != layer->editBuffer();
92 
93  mGeometryType = layer->geometryType();
94 
95  mFeatureBlendMode = layer->featureBlendMode();
96 
97  if ( context.isTemporal() )
98  {
99  QgsVectorLayerTemporalContext temporalContext;
100  temporalContext.setLayer( layer );
101  mTemporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->temporalProperties() )->createFilterString( temporalContext, context.temporalRange() );
102  QgsDebugMsgLevel( "Rendering with Temporal Filter: " + mTemporalFilter, 2 );
103  }
104 
105  // if there's already a simplification method specified via the context, we respect that. Otherwise, we fall back
106  // to the layer's individual setting
107  if ( renderContext()->vectorSimplifyMethod().simplifyHints() != QgsVectorSimplifyMethod::NoSimplification )
108  {
109  mSimplifyMethod = renderContext()->vectorSimplifyMethod();
112  }
113  else
114  {
115  mSimplifyMethod = layer->simplifyMethod();
117  }
118 
120 
122  if ( markerTypeString == QLatin1String( "Cross" ) )
123  {
124  mVertexMarkerStyle = Qgis::VertexMarkerType::Cross;
125  }
126  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
127  {
129  }
130  else
131  {
132  mVertexMarkerStyle = Qgis::VertexMarkerType::NoMarker;
133  }
134 
136 
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 == QgsWkbTypes::NullGeometry || mGeometryType == QgsWkbTypes::UnknownGeometry )
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 
232 bool 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  QString rendererFilter = renderer->filter( mFields );
268 
269  QgsRectangle requestExtent = context.extent();
270  if ( !mClippingRegions.empty() )
271  {
272  mClipFilterGeom = QgsMapClippingUtils::calculateFeatureRequestGeometry( mClippingRegions, context, mApplyClipFilter );
273  requestExtent = requestExtent.intersect( mClipFilterGeom.boundingBox() );
274 
275  mClipFeatureGeom = QgsMapClippingUtils::calculateFeatureIntersectionGeometry( mClippingRegions, context, mApplyClipGeometries );
276 
277  bool needsPainterClipPath = false;
278  const QPainterPath path = QgsMapClippingUtils::calculatePainterClipRegion( mClippingRegions, context, QgsMapLayerType::VectorLayer, needsPainterClipPath );
279  if ( needsPainterClipPath )
280  context.painter()->setClipPath( path, Qt::IntersectClip );
281 
282  mLabelClipFeatureGeom = QgsMapClippingUtils::calculateLabelIntersectionGeometry( mClippingRegions, context, mApplyLabelClipGeometries );
283 
284  if ( mDiagramProvider )
285  mDiagramProvider->setClipFeatureGeometry( mLabelClipFeatureGeom );
286  }
287  renderer->modifyRequestExtent( requestExtent, context );
288 
289  QgsFeatureRequest featureRequest = QgsFeatureRequest()
290  .setFilterRect( requestExtent )
291  .setSubsetOfAttributes( mAttrNames, mFields )
293  if ( renderer->orderByEnabled() )
294  {
295  featureRequest.setOrderBy( renderer->orderBy() );
296  }
297 
298  const QgsFeatureFilterProvider *featureFilterProvider = context.featureFilterProvider();
299  if ( featureFilterProvider )
300  {
301  featureFilterProvider->filterFeatures( mLayer, featureRequest );
302  }
303  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
304  {
305  featureRequest.combineFilterExpression( rendererFilter );
306  }
307  if ( !mTemporalFilter.isEmpty() )
308  {
309  featureRequest.combineFilterExpression( mTemporalFilter );
310  }
311 
312  if ( renderer->usesEmbeddedSymbols() )
313  {
314  featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::EmbeddedSymbols );
315  }
316 
317  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
318  if ( mSimplifyGeometry )
319  {
320  double map2pixelTol = mSimplifyMethod.threshold();
321  bool validTransform = true;
322 
323  const QgsMapToPixel &mtp = context.mapToPixel();
324  map2pixelTol *= mtp.mapUnitsPerPixel();
325  const QgsCoordinateTransform ct = context.coordinateTransform();
326 
327  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
328  if ( ct.isValid() && !ct.isShortCircuited() )
329  {
330  try
331  {
332  QgsCoordinateTransform toleranceTransform = ct;
333  QgsPointXY center = context.extent().center();
334  double rectSize = toleranceTransform.sourceCrs().mapUnits() == QgsUnitTypes::DistanceDegrees ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
335 
336  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
337  toleranceTransform.setBallparkTransformsAreAppropriate( true );
338  QgsRectangle targetRect = toleranceTransform.transform( sourceRect );
339 
340  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
341  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
342 
343  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
344  {
345  QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
346  QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
347  QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
348  QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
349 
350  double sourceHypothenuse = std::sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
351  double targetHypothenuse = std::sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
352 
353  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
354  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
355 
356  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
357  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
358  }
359  }
360  catch ( QgsCsException &cse )
361  {
362  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
363  validTransform = false;
364  }
365  }
366 
367  if ( validTransform )
368  {
369  QgsSimplifyMethod simplifyMethod;
371  simplifyMethod.setTolerance( map2pixelTol );
372  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
373  simplifyMethod.setForceLocalOptimization( mSimplifyMethod.forceLocalOptimization() );
374  featureRequest.setSimplifyMethod( simplifyMethod );
375 
376  QgsVectorSimplifyMethod vectorMethod = mSimplifyMethod;
377  vectorMethod.setTolerance( map2pixelTol );
378  context.setVectorSimplifyMethod( vectorMethod );
379  }
380  else
381  {
382  QgsVectorSimplifyMethod vectorMethod;
384  context.setVectorSimplifyMethod( vectorMethod );
385  }
386  }
387  else
388  {
389  QgsVectorSimplifyMethod vectorMethod;
391  context.setVectorSimplifyMethod( vectorMethod );
392  }
393 
394  featureRequest.setFeedback( mFeedback.get() );
395  // also set the interruption checker for the expression context, in case the renderer uses some complex expression
396  // which could benefit from early exit paths...
397  context.expressionContext().setFeedback( mFeedback.get() );
398 
399  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
400  // Attach an interruption checker so that iterators that have potentially
401  // slow fetchFeature() implementations, such as in the WFS provider, can
402  // check it, instead of relying on just the mContext.renderingStopped() check
403  // in drawRenderer()
404  fit.setInterruptionChecker( mFeedback.get() );
405 
406  if ( ( renderer->capabilities() & QgsFeatureRenderer::SymbolLevels ) && renderer->usingSymbolLevels() )
407  drawRendererLevels( renderer, fit );
408  else
409  drawRenderer( renderer, fit );
410 
411  if ( !fit.isValid() )
412  {
413  mErrors.append( QStringLiteral( "Data source invalid" ) );
414  }
415 
416  if ( usingEffect )
417  {
418  renderer->paintEffect()->end( context );
419  }
420 
421  context.expressionContext().setFeedback( nullptr );
422  return true;
423 }
424 
425 
426 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureRenderer *renderer, QgsFeatureIterator &fit )
427 {
428  const bool isMainRenderer = renderer == mRenderer;
429 
431  QgsRenderContext &context = *renderContext();
432  context.expressionContext().appendScope( symbolScope );
433 
434  std::unique_ptr< QgsGeometryEngine > clipEngine;
435  if ( mApplyClipFilter )
436  {
437  clipEngine.reset( QgsGeometry::createGeometryEngine( mClipFilterGeom.constGet() ) );
438  clipEngine->prepareGeometry();
439  }
440 
441  QgsFeature fet;
442  while ( fit.nextFeature( fet ) )
443  {
444  try
445  {
446  if ( context.renderingStopped() )
447  {
448  QgsDebugMsgLevel( QStringLiteral( "Drawing of vector layer %1 canceled." ).arg( layerId() ), 2 );
449  break;
450  }
451 
452  if ( !fet.hasGeometry() || fet.geometry().isEmpty() )
453  continue; // skip features without geometry
454 
455  if ( clipEngine && !clipEngine->intersects( fet.geometry().constGet() ) )
456  continue; // skip features outside of clipping region
457 
458  if ( mApplyClipGeometries )
459  context.setFeatureClipGeometry( mClipFeatureGeom );
460 
461  if ( ! mNoSetLayerExpressionContext )
462  context.expressionContext().setFeature( fet );
463 
464  bool sel = isMainRenderer && context.showSelection() && mSelectedFeatureIds.contains( fet.id() );
465  bool drawMarker = isMainRenderer && ( mDrawVertexMarkers && context.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
466 
467  // render feature
468  bool rendered = false;
470  {
471  rendered = renderer->renderFeature( fet, context, -1, sel, drawMarker );
472  }
473  else
474  {
475  rendered = renderer->willRenderFeature( fet, context );
476  }
477 
478  // labeling - register feature
479  if ( rendered )
480  {
481  // as soon as first feature is rendered, we can start showing layer updates.
482  // but if we are blocking render updates (so that a previously cached image is being shown), we wait
483  // at most e.g. 3 seconds before we start forcing progressive updates.
484  if ( !mBlockRenderUpdates || mElapsedTimer.elapsed() > MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
485  {
486  mReadyToCompose = true;
487  }
488 
489  // new labeling engine
490  if ( isMainRenderer && context.labelingEngine() && ( mLabelProvider || mDiagramProvider ) )
491  {
492  QgsGeometry obstacleGeometry;
493  QgsSymbolList symbols = renderer->originalSymbolsForFeature( fet, context );
494  QgsSymbol *symbol = nullptr;
495  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
496  {
497  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, context, symbols );
498  }
499 
500  if ( !symbols.isEmpty() )
501  {
502  symbol = symbols.at( 0 );
503  QgsExpressionContextUtils::updateSymbolScope( symbol, symbolScope );
504  }
505 
506  if ( mApplyLabelClipGeometries )
507  context.setFeatureClipGeometry( mLabelClipFeatureGeom );
508 
509  if ( mLabelProvider )
510  {
511  mLabelProvider->registerFeature( fet, context, obstacleGeometry, symbol );
512  }
513  if ( mDiagramProvider )
514  {
515  mDiagramProvider->registerFeature( fet, context, obstacleGeometry );
516  }
517 
518  if ( mApplyLabelClipGeometries )
519  context.setFeatureClipGeometry( QgsGeometry() );
520  }
521  }
522  }
523  catch ( const QgsCsException &cse )
524  {
525  Q_UNUSED( cse )
526  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
527  .arg( fet.id() ).arg( cse.what() ) );
528  }
529  }
530 
531  delete context.expressionContext().popScope();
532 
533  stopRenderer( renderer, nullptr );
534 }
535 
536 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureRenderer *renderer, QgsFeatureIterator &fit )
537 {
538  const bool isMainRenderer = renderer == mRenderer;
539 
540  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
541  QgsRenderContext &context = *renderContext();
542 
543  QgsSingleSymbolRenderer *selRenderer = nullptr;
544  if ( !mSelectedFeatureIds.isEmpty() )
545  {
546  selRenderer = new QgsSingleSymbolRenderer( QgsSymbol::defaultSymbol( mGeometryType ) );
547  selRenderer->symbol()->setColor( context.selectionColor() );
548  selRenderer->setVertexMarkerAppearance( mVertexMarkerStyle, mVertexMarkerSize );
549  selRenderer->startRender( context, mFields );
550  }
551 
553  std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.expressionContext(), symbolScope );
554 
555 
556  std::unique_ptr< QgsGeometryEngine > clipEngine;
557  if ( mApplyClipFilter )
558  {
559  clipEngine.reset( QgsGeometry::createGeometryEngine( mClipFilterGeom.constGet() ) );
560  clipEngine->prepareGeometry();
561  }
562 
563  if ( mApplyLabelClipGeometries )
564  context.setFeatureClipGeometry( mLabelClipFeatureGeom );
565 
566  // 1. fetch features
567  QgsFeature fet;
568  while ( fit.nextFeature( fet ) )
569  {
570  if ( context.renderingStopped() )
571  {
572  qDebug( "rendering stop!" );
573  stopRenderer( renderer, selRenderer );
574  return;
575  }
576 
577  if ( !fet.hasGeometry() )
578  continue; // skip features without geometry
579 
580  if ( clipEngine && !clipEngine->intersects( fet.geometry().constGet() ) )
581  continue; // skip features outside of clipping region
582 
583  if ( ! mNoSetLayerExpressionContext )
584  context.expressionContext().setFeature( fet );
585  QgsSymbol *sym = renderer->symbolForFeature( fet, context );
586  if ( !sym )
587  {
588  continue;
589  }
590 
592  {
593  if ( !features.contains( sym ) )
594  {
595  features.insert( sym, QList<QgsFeature>() );
596  }
597  features[sym].append( fet );
598  }
599 
600  // new labeling engine
601  if ( isMainRenderer && context.labelingEngine() && ( mLabelProvider || mDiagramProvider ) )
602  {
603  QgsGeometry obstacleGeometry;
604  QgsSymbolList symbols = renderer->originalSymbolsForFeature( fet, context );
605  QgsSymbol *symbol = nullptr;
606  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
607  {
608  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, context, symbols );
609  }
610 
611  if ( !symbols.isEmpty() )
612  {
613  symbol = symbols.at( 0 );
614  QgsExpressionContextUtils::updateSymbolScope( symbol, symbolScope );
615  }
616 
617  if ( mLabelProvider )
618  {
619  mLabelProvider->registerFeature( fet, context, obstacleGeometry, symbol );
620  }
621  if ( mDiagramProvider )
622  {
623  mDiagramProvider->registerFeature( fet, context, obstacleGeometry );
624  }
625  }
626  }
627 
628  if ( mApplyLabelClipGeometries )
629  context.setFeatureClipGeometry( QgsGeometry() );
630 
631  scopePopper.reset();
632 
633  if ( features.empty() )
634  {
635  // nothing to draw
636  stopRenderer( renderer, selRenderer );
637  return;
638  }
639 
640  // find out the order
641  QgsSymbolLevelOrder levels;
642  QgsSymbolList symbols = renderer->symbols( context );
643  for ( int i = 0; i < symbols.count(); i++ )
644  {
645  QgsSymbol *sym = symbols[i];
646  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
647  {
648  int level = sym->symbolLayer( j )->renderingPass();
649  if ( level < 0 || level >= 1000 ) // ignore invalid levels
650  continue;
651  QgsSymbolLevelItem item( sym, j );
652  while ( level >= levels.count() ) // append new empty levels
653  levels.append( QgsSymbolLevel() );
654  levels[level].append( item );
655  }
656  }
657 
658  if ( mApplyClipGeometries )
659  context.setFeatureClipGeometry( mClipFeatureGeom );
660 
661  // 2. draw features in correct order
662  for ( int l = 0; l < levels.count(); l++ )
663  {
664  QgsSymbolLevel &level = levels[l];
665  for ( int i = 0; i < level.count(); i++ )
666  {
667  QgsSymbolLevelItem &item = level[i];
668  if ( !features.contains( item.symbol() ) )
669  {
670  QgsDebugMsg( QStringLiteral( "level item's symbol not found!" ) );
671  continue;
672  }
673  int layer = item.layer();
674  QList<QgsFeature> &lst = features[item.symbol()];
675  QList<QgsFeature>::iterator fit;
676  for ( fit = lst.begin(); fit != lst.end(); ++fit )
677  {
678  if ( context.renderingStopped() )
679  {
680  stopRenderer( renderer, selRenderer );
681  return;
682  }
683 
684  bool sel = isMainRenderer && context.showSelection() && mSelectedFeatureIds.contains( fit->id() );
685  // maybe vertex markers should be drawn only during the last pass...
686  bool drawMarker = isMainRenderer && ( mDrawVertexMarkers && context.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
687 
688  if ( ! mNoSetLayerExpressionContext )
689  context.expressionContext().setFeature( *fit );
690 
691  try
692  {
693  renderer->renderFeature( *fit, context, layer, sel, drawMarker );
694 
695  // as soon as first feature is rendered, we can start showing layer updates.
696  // but if we are blocking render updates (so that a previously cached image is being shown), we wait
697  // at most e.g. 3 seconds before we start forcing progressive updates.
698  if ( !mBlockRenderUpdates || mElapsedTimer.elapsed() > MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE )
699  {
700  mReadyToCompose = true;
701  }
702  }
703  catch ( const QgsCsException &cse )
704  {
705  Q_UNUSED( cse )
706  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
707  .arg( fet.id() ).arg( cse.what() ) );
708  }
709  }
710  }
711  }
712 
713  stopRenderer( renderer, selRenderer );
714 }
715 
716 void QgsVectorLayerRenderer::stopRenderer( QgsFeatureRenderer *renderer, QgsSingleSymbolRenderer *selRenderer )
717 {
718  QgsRenderContext &context = *renderContext();
719  renderer->stopRender( context );
720  if ( selRenderer )
721  {
722  selRenderer->stopRender( context );
723  delete selRenderer;
724  }
725 }
726 
727 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
728 {
729  QgsRenderContext &context = *renderContext();
730  // TODO: add attributes for geometry generator
731  if ( QgsLabelingEngine *engine2 = context.labelingEngine() )
732  {
733  if ( layer->labelsEnabled() )
734  {
735  if ( context.labelSink() )
736  {
737  if ( const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( layer->labeling() ) )
738  {
739  mLabelProvider = new QgsRuleBasedLabelSinkProvider( *rbl, layer, context.labelSink() );
740  }
741  else
742  {
743  QgsPalLayerSettings settings = layer->labeling()->settings();
744  mLabelProvider = new QgsLabelSinkProvider( layer, QString(), context.labelSink(), &settings );
745  }
746  }
747  else
748  {
749  mLabelProvider = layer->labeling()->provider( layer );
750  }
751  if ( mLabelProvider )
752  {
753  engine2->addProvider( mLabelProvider );
754  if ( !mLabelProvider->prepare( context, attributeNames ) )
755  {
756  engine2->removeProvider( mLabelProvider );
757  mLabelProvider = nullptr; // deleted by engine
758  }
759  }
760  }
761  }
762 
763 #if 0 // TODO: limit of labels, font not found
764  QgsPalLayerSettings &palyr = mContext.labelingEngine()->layer( mLayerID );
765 
766  // see if feature count limit is set for labeling
767  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
768  {
769  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
770  .setFilterRect( mContext.extent() )
771  .setNoAttributes() );
772 
773  // total number of features that may be labeled
774  QgsFeature f;
775  int nFeatsToLabel = 0;
776  while ( fit.nextFeature( f ) )
777  {
778  nFeatsToLabel++;
779  }
780  palyr.mFeaturesToLabel = nFeatsToLabel;
781  }
782 
783  // notify user about any font substitution
784  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
785  {
786  emit labelingFontNotFound( this, palyr.mTextFontFamily );
787  mLabelFontNotFoundNotified = true;
788  }
789 #endif
790 }
791 
792 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
793 {
794  QgsRenderContext &context = *renderContext();
795  if ( QgsLabelingEngine *engine2 = context.labelingEngine() )
796  {
797  if ( layer->diagramsEnabled() )
798  {
799  mDiagramProvider = new QgsVectorLayerDiagramProvider( layer );
800  // need to be added before calling prepare() - uses map settings from engine
801  engine2->addProvider( mDiagramProvider );
802  if ( !mDiagramProvider->prepare( context, attributeNames ) )
803  {
804  engine2->removeProvider( mDiagramProvider );
805  mDiagramProvider = nullptr; // deleted by engine
806  }
807  }
808  }
809 }
810 
QgsRenderContext::renderedFeatureHandlers
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
Definition: qgsrendercontext.cpp:620
QgsMapClippingUtils::collectClippingRegionsForLayer
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.
Definition: qgsmapclippingutils.cpp:24
QgsVectorLayer::editBuffer
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
Definition: qgsvectorlayer.h:2014
qgsexpressioncontextutils.h
qgssettingsregistrycore.h
QgsVectorLayer::diagramsEnabled
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
Definition: qgsvectorlayer.cpp:799
QgsVectorSimplifyMethod
This class contains information how to simplify geometries fetched from a vector layer.
Definition: qgsvectorsimplifymethod.h:29
QgsRectangle::isFinite
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:559
QgsVectorSimplifyMethod::NoSimplification
@ NoSimplification
No simplification can be applied.
Definition: qgsvectorsimplifymethod.h:52
QgsMapLayerRenderer::mLayerID
QString mLayerID
Definition: qgsmaplayerrenderer.h:153
QgsRenderContext::labelSink
QgsLabelSink * labelSink() const
Returns the associated label sink, or nullptr if not set.
Definition: qgsrendercontext.h:375
QgsVectorLayer::featureBlendMode
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
Definition: qgsvectorlayer.cpp:4605
QgsPalLayerSettings::mFeaturesToLabel
int mFeaturesToLabel
Definition: qgspallabeling.h:1001
QgsPointXY::y
double y
Definition: qgspointxy.h:63
qgspallabeling.h
Qgis::VertexMarkerType::SemiTransparentCircle
@ SemiTransparentCircle
Semi-transparent circle marker.
Qgis::VertexMarkerType::NoMarker
@ NoMarker
No marker.
QgsRenderContext::mapToPixel
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Definition: qgsrendercontext.h:258
QgsSimplifyMethod
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
Definition: qgssimplifymethod.h:28
QgsMapClippingUtils::calculateFeatureIntersectionGeometry
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...
Definition: qgsmapclippingutils.cpp:81
QgsSymbolLevel
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:84
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:625
QgsMapToPixel::mapUnitsPerPixel
double mapUnitsPerPixel() const
Returns the current map units per pixel.
Definition: qgsmaptopixel.h:229
QgsExpressionContext::popScope
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
Definition: qgsexpressioncontext.cpp:504
QgsSymbol::defaultSymbol
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:673
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
QgsRenderContext::setFeatureClipGeometry
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
Definition: qgsrendercontext.cpp:635
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
qgssinglesymbolrenderer.h
QgsMapLayer::opacity
double opacity
Definition: qgsmaplayer.h:82
QgsPalLayerSettings
Contains settings for how a map layer will be labeled.
Definition: qgspallabeling.h:86
QgsVectorLayerProfileResults::mLayer
QPointer< QgsVectorLayer > mLayer
Definition: qgsvectorlayerprofilegenerator.h:68
QgsMapLayer::blendMode
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Definition: qgsmaplayer.cpp:320
QgsRenderContext::drawEditingInformation
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
Definition: qgsrendercontext.cpp:310
QgsTemporalRangeObject::isTemporal
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
Definition: qgstemporalrangeobject.cpp:30
QgsRectangle::center
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
QgsPaintEffect::begin
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
Definition: qgspainteffect.cpp:90
QgsRuleBasedLabelSinkProvider
Implements a derived label provider for rule based labels for use with QgsLabelSink.
Definition: qgslabelsink.h:94
QgsRenderContext::showSelection
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
Definition: qgsrendercontext.cpp:315
QgsVectorLayerDiagramProvider
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine....
Definition: qgsvectorlayerdiagramprovider.h:57
QgsFeatureRenderer::capabilities
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:283
qgsvectorlayerrenderer.h
qgssymbollayerutils.h
QgsRenderContext::hasRenderedFeatureHandlers
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
Definition: qgsrendercontext.h:757
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsExpressionContextUtils::layerScope
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Definition: qgsexpressioncontextutils.cpp:334
QgsVectorLayerRenderer::QgsVectorLayerRenderer
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
Definition: qgsvectorlayerrenderer.cpp:49
QgsFeatureRenderer::type
QString type() const
Definition: qgsrenderer.h:142
QgsSimplifyMethod::setThreshold
void setThreshold(float threshold)
Sets the simplification threshold in pixels. Represents the maximum distance in pixels between two co...
Definition: qgssimplifymethod.h:52
QgsRenderContext::testFlag
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
Definition: qgsrendercontext.cpp:229
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
qgsfeaturefilterprovider.h
QgsTemporalRangeObject::temporalRange
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
Definition: qgstemporalrangeobject.cpp:43
qgsrenderedfeaturehandlerinterface.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsMapLayerRenderer::renderContext
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
Definition: qgsmaplayerrenderer.h:111
QgsSingleSymbolRenderer
Definition: qgssinglesymbolrenderer.h:29
QgsSingleSymbolRenderer::stopRender
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgssinglesymbolrenderer.cpp:71
qgsdiagram.h
qgsfeaturerenderergenerator.h
QgsMapLayerRenderer::mReadyToCompose
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
Definition: qgsmaplayerrenderer.h:171
QgsVectorSimplifyMethod::setSimplifyHints
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:62
QgsFeatureRequest::setSubsetOfAttributes
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Definition: qgsfeaturerequest.cpp:228
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
qgspainteffect.h
QgsSymbol::symbolLayer
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
Definition: qgssymbol.cpp:725
QgsRectangle::intersect
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
Definition: qgsrectangle.h:333
QgsCoordinateTransform::isValid
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
Definition: qgscoordinatetransform.cpp:900
QgsRenderContext::extent
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
Definition: qgsrendercontext.h:239
QgsFeatureRendererGenerator
An interface for objects which generate feature renderers for vector layers.
Definition: qgsfeaturerenderergenerator.h:31
QgsVectorSimplifyMethod::FullSimplification
@ FullSimplification
All simplification hints can be applied ( Geometry + AA-disabling )
Definition: qgsvectorsimplifymethod.h:55
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRuleBasedLabeling
Rule based labeling for a vector layer.
Definition: qgsrulebasedlabeling.h:42
QgsSymbolLevelItem::layer
int layer() const
The layer of this symbol level.
Definition: qgsrenderer.cpp:533
QgsFeatureRenderer::stopRender
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgsrenderer.cpp:110
QgsFeatureRequest::setExpressionContext
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
Definition: qgsfeaturerequest.cpp:187
QgsRenderedFeatureHandlerInterface
An interface for classes which provider custom handlers for features rendered as part of a map render...
Definition: qgsrenderedfeaturehandlerinterface.h:46
QgsFeatureRenderer::SymbolLevels
@ SymbolLevels
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
Definition: qgsrenderer.h:263
QgsSymbolLevelItem::symbol
QgsSymbol * symbol() const
The symbol of this symbol level.
Definition: qgsrenderer.cpp:528
QgsFeatureRequest::flags
Flags flags() const
Returns the flags which affect how features are fetched.
Definition: qgsfeaturerequest.h:673
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:54
QgsFeatureRenderer::willRenderFeature
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
Definition: qgsrenderer.cpp:388
QgsFeatureRenderer::orderBy
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
Definition: qgsrenderer.cpp:459
QgsFeatureRenderer::referenceScale
double referenceScale() const
Returns the symbology reference scale.
Definition: qgsrenderer.h:466
QgsFeatureRenderer::filter
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:206
QgsFeatureRenderer::usesEmbeddedSymbols
virtual bool usesEmbeddedSymbols() const
Returns true if the renderer uses embedded symbols for features.
Definition: qgsrenderer.cpp:117
QgsExpressionContext::setFeedback
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the expression engine to check if expressio...
Definition: qgsexpressioncontext.cpp:629
QgsFeatureRequest::setFilterRect
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
Definition: qgsfeaturerequest.cpp:101
QgsVectorLayer::simplifyDrawingCanbeApplied
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
Definition: qgsvectorlayer.cpp:1035
qgsvectorlayerdiagramprovider.h
QgsVectorLayerDiagramProvider::prepare
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
Definition: qgsvectorlayerdiagramprovider.cpp:150
QgsRenderContext::renderingStopped
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
Definition: qgsrendercontext.h:285
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsRenderContext::coordinateTransform
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Definition: qgsrendercontext.h:178
QgsCoordinateTransform::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from.
Definition: qgscoordinatetransform.cpp:262
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
qgsvectorlayertemporalproperties.h
QgsFeatureFilterProvider::filterFeatures
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...
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsRenderContext::useAdvancedEffects
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
Definition: qgsrendercontext.cpp:300
QgsFeatureRequest::combineFilterExpression
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
Definition: qgsfeaturerequest.cpp:174
QgsCoordinateTransform::isShortCircuited
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
Definition: qgscoordinatetransform.cpp:905
QgsSymbolLayer::renderingPass
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
Definition: qgssymbollayer.cpp:323
QgsVectorLayer::temporalProperties
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
Definition: qgsvectorlayer.cpp:686
QgsSettingsRegistryCore::settingsDigitizingMarkerStyle
static const QgsSettingsEntryString settingsDigitizingMarkerStyle
Settings entry digitizing marker style.
Definition: qgssettingsregistrycore.h:130
QgsUnitTypes::DistanceDegrees
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
QgsCoordinateTransform::setBallparkTransformsAreAppropriate
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
Definition: qgscoordinatetransform.cpp:939
QgsSimplifyMethod::OptimizeForRendering
@ OptimizeForRendering
Simplify using the map2pixel data to optimize the rendering of geometries.
Definition: qgssimplifymethod.h:34
QgsVectorLayerDiagramProvider::setClipFeatureGeometry
void setClipFeatureGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features to when registering them as diagrams.
Definition: qgsvectorlayerdiagramprovider.cpp:182
qgslabelsink.h
QgsMapLayerRenderer::layerId
QString layerId() const
Gets access to the ID of the layer rendered by this class.
Definition: qgsmaplayerrenderer.h:104
QgsSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
QgsMapClippingUtils::calculatePainterClipRegion
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, QgsMapLayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
Definition: qgsmapclippingutils.cpp:127
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsRenderContext::featureFilterProvider
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
Definition: qgsrendercontext.cpp:362
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsFeatureRenderer::clone
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsVectorLayer::labeling
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Definition: qgsvectorlayer.h:1656
QgsFeatureRenderer::originalSymbolsForFeature
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Definition: qgsrenderer.cpp:440
QgsVectorSimplifyMethod::setTolerance
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
Definition: qgsvectorsimplifymethod.h:82
QgsRenderContext::setVectorSimplifyMethod
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
Definition: qgsrendercontext.h:609
QgsException::what
QString what() const
Definition: qgsexception.h:48
QgsVectorLayer::selectedFeatureIds
const Q_INVOKABLE QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
Definition: qgsvectorlayer.cpp:3621
QgsSymbolLevelItem
Definition: qgsrenderer.h:59
QgsMapClippingUtils::calculateLabelIntersectionGeometry
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...
Definition: qgsmapclippingutils.cpp:182
QgsVectorLayerTemporalContext::setLayer
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
Definition: qgsvectorlayertemporalproperties.cpp:704
qgsrendercontext.h
QgsFeatureRenderer::symbols
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
Definition: qgsrenderer.cpp:151
QgsSimplifyMethod::setTolerance
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
Definition: qgssimplifymethod.cpp:27
QgsMapLayerRenderer::mErrors
QStringList mErrors
Definition: qgsmaplayerrenderer.h:152
QgsVectorLayerRenderer::setLayerRenderingTimeHint
void setLayerRenderingTimeHint(int time) override
Sets approximate render time (in ms) for the layer to render.
Definition: qgsvectorlayerrenderer.cpp:184
QgsMessageLog::logMessage
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).
Definition: qgsmessagelog.cpp:27
QgsFeatureRenderer::usingSymbolLevels
bool usingSymbolLevels() const
Definition: qgsrenderer.h:292
QgsFeatureRenderer::symbolForFeature
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
qgssymbollayer.h
QgsVectorSimplifyMethod::threshold
float threshold() const
Gets the simplification threshold of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:89
QgsGeometry::isEmpty
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Definition: qgsgeometry.cpp:379
qgsvectorlayerfeatureiterator.h
QgsFeatureRequest::setFeedback
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the iterator to check if it should be cance...
Definition: qgsfeaturerequest.cpp:402
QgsPaintEffect::end
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
Definition: qgspainteffect.cpp:105
QgsVectorLayerTemporalContext
Encapsulates the context in which a QgsVectorLayer's temporal capabilities will be applied.
Definition: qgsvectorlayertemporalproperties.h:40
Qgis::RenderContextFlag::SkipSymbolRendering
@ SkipSymbolRendering
Disable symbol rendering while still drawing labels if enabled (since QGIS 3.24)
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
qgsrenderer.h
QgsFeatureRequest::setSimplifyMethod
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
Definition: qgsfeaturerequest.cpp:284
QgsScopedQPainterState
Scoped object for saving and restoring a QPainter object's state.
Definition: qgsrendercontext.h:1336
QgsFeatureRenderer::modifyRequestExtent
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
Definition: qgsrenderer.cpp:434
qgsdiagramrenderer.h
QgsFeatureRequest::setNoAttributes
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
Definition: qgsfeaturerequest.cpp:235
QgsMapClippingUtils::calculateFeatureRequestGeometry
static QgsGeometry calculateFeatureRequestGeometry(const QList< QgsMapClippingRegion > &regions, const QgsRenderContext &context, bool &shouldFilter)
Returns the geometry representing the intersection of clipping regions from context.
Definition: qgsmapclippingutils.cpp:38
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:136
QgsVectorLayerRenderer::forceRasterRender
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
Definition: qgsvectorlayerrenderer.cpp:194
QgsVectorSimplifyMethod::forceLocalOptimization
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
Definition: qgsvectorsimplifymethod.h:94
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsVectorLayer::simplifyMethod
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
Definition: qgsvectorlayer.h:2311
QgsRenderContext::vectorSimplifyMethod
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Definition: qgsrendercontext.h:594
QgsSimplifyMethod::setForceLocalOptimization
void setForceLocalOptimization(bool localOptimization)
Sets whether the simplification executes after fetch the geometries from provider,...
Definition: qgssimplifymethod.cpp:32
QgsLabelingEngine
The QgsLabelingEngine class provides map labeling functionality. The input for the engine is a list o...
Definition: qgslabelingengine.h:343
QgsRectangle::toString
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Definition: qgsrectangle.cpp:127
QgsExpressionContext::appendScope
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Definition: qgsexpressioncontext.cpp:494
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsAbstractVectorLayerLabeling::provider
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
Definition: qgsvectorlayerlabeling.h:70
QgsRenderContext::selectionColor
QColor selectionColor() const
Returns the color to use when rendering selected features.
Definition: qgsrendercontext.h:382
QgsRenderContext::labelingEngine
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr).
Definition: qgsrendercontext.h:368
QgsGeometry::createGeometryEngine
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
Definition: qgsgeometry.cpp:3972
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsCoordinateReferenceSystem::mapUnits
QgsUnitTypes::DistanceUnit mapUnits
Definition: qgscoordinatereferencesystem.h:215
QgsSettingsRegistryCore::settingsDigitizingMarkerSizeMm
static const QgsSettingsEntryDouble settingsDigitizingMarkerSizeMm
Settings entry digitizing marker size mm.
Definition: qgssettingsregistrycore.h:133
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
QgsSingleSymbolRenderer::startRender
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
Definition: qgssinglesymbolrenderer.cpp:61
QgsExpressionContextUtils::updateSymbolScope
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
Definition: qgsexpressioncontextutils.cpp:538
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:399
QgsSettingsEntryByReference::value
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:379
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QgsFeatureRenderer::orderByEnabled
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
Definition: qgsrenderer.cpp:469
QgsLabelSinkProvider
Implements a derived label provider for use with QgsLabelSink.
Definition: qgslabelsink.h:74
QgsPointXY::x
double x
Definition: qgspointxy.h:62
QgsVectorLayerFeatureSource
Partial snapshot of vector layer's state (only the members necessary for access to features)
Definition: qgsvectorlayerfeatureiterator.h:52
QgsFeatureRenderer::renderFeature
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.
Definition: qgsrenderer.cpp:127
QgsVectorLayerProfileResults::features
QHash< QgsFeatureId, QVector< Feature > > features
Definition: qgsvectorlayerprofilegenerator.h:67
qgsmapclippingutils.h
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
Qgis::VertexMarkerType::Cross
@ Cross
Cross marker.
QgsSimplifyMethod::setMethodType
void setMethodType(MethodType methodType)
Sets the simplification type.
Definition: qgssimplifymethod.cpp:22
QgsSymbolLevelOrder
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:88
QgsFeatureFilterProvider
Abstract interface for use by classes that filter the features or attributes of a layer.
Definition: qgsfeaturefilterprovider.h:43
QgsVectorLayerLabelProvider::registerFeature
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.
Definition: qgsvectorlayerlabelprovider.cpp:196
QgsFeatureRequest::setOrderBy
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
Definition: qgsfeaturerequest.cpp:210
qgsvectorlayerlabelprovider.h
QgsGeometry::boundingBox
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Definition: qgsgeometry.cpp:1080
QgsVectorSimplifyMethod::simplifyHints
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:64
qgsexception.h
QgsVectorLayerLabelProvider::getPointObstacleGeometry
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.
Definition: qgsvectorlayerlabelprovider.cpp:208
QgsFeatureRenderer::dump
virtual QString dump() const
Returns debug information about this renderer.
Definition: qgsrenderer.cpp:146
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsVectorLayer::featureRendererGenerators
QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const
Returns a list of the feature renderer generators owned by the layer.
Definition: qgsvectorlayer.cpp:3844
QgsFeatureIterator::setInterruptionChecker
void setInterruptionChecker(QgsFeedback *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped.
Definition: qgsfeatureiterator.h:435
qgsvectorlayerlabeling.h
QgsRenderContext::setSymbologyReferenceScale
void setSymbologyReferenceScale(double scale)
Sets the symbology reference scale.
Definition: qgsrendercontext.h:504
QgsFeatureRequest::EmbeddedSymbols
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
Definition: qgsfeaturerequest.h:119
QgsFeatureRenderer::paintEffect
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
Definition: qgsrenderer.cpp:448
QgsVectorLayerLabelProvider::prepare
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
Definition: qgsvectorlayerlabelprovider.cpp:114
qgslogger.h
QgsMapLayerRenderer::MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE
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,...
Definition: qgsmaplayerrenderer.h:181
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:112
QgsPaintEffect::enabled
bool enabled() const
Returns whether the effect is enabled.
Definition: qgspainteffect.h:197
QgsCoordinateTransform::transform
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.
Definition: qgscoordinatetransform.cpp:272
QgsVectorLayerDiagramProvider::registerFeature
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.
Definition: qgsvectorlayerdiagramprovider.cpp:175
QgsSingleSymbolRenderer::symbol
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
Definition: qgssinglesymbolrenderer.cpp:99
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
QgsFeatureRenderer::startRender
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:96
QgsGeometry::type
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
QgsFeatureRenderer::setVertexMarkerAppearance
void setVertexMarkerAppearance(Qgis::VertexMarkerType type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
Definition: qgsrenderer.cpp:382
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
Qgis::RenderContextFlag::UseAdvancedEffects
@ UseAdvancedEffects
Enable layer opacity and blending effects.
QgsSymbol::setColor
void setColor(const QColor &color) const
Sets the color for the symbol.
Definition: qgssymbol.cpp:867
QgsVectorLayerRenderer::feedback
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
Definition: qgsvectorlayerrenderer.cpp:189
QgsFeatureRequest::setFlags
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
Definition: qgsfeaturerequest.cpp:222
qgssymbol.h
QgsSettingsRegistryCore::settingsDigitizingMarkerOnlyForSelected
static const QgsSettingsEntryBool settingsDigitizingMarkerOnlyForSelected
Settings entry digitizing marker only for selected.
Definition: qgssettingsregistrycore.h:127
QgsVectorSimplifyMethod::GeometrySimplification
@ GeometrySimplification
The geometries can be simplified using the current map2pixel context state.
Definition: qgsvectorsimplifymethod.h:53
QgsFeatureIterator::isValid
bool isValid() const
Will return if this iterator is valid.
Definition: qgsfeatureiterator.cpp:280
QgsVectorLayerRenderer::render
bool render() override
Do the rendering (based on data stored in the class).
Definition: qgsvectorlayerrenderer.cpp:199
QgsAbstractVectorLayerLabeling::settings
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
QgsVectorLayer::labelsEnabled
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
Definition: qgsvectorlayer.cpp:789
QgsSymbol::symbolLayerCount
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:215
QgsVectorLayerRenderer::~QgsVectorLayerRenderer
~QgsVectorLayerRenderer() override
QgsSettingsEntryByValue::value
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition: qgssettingsentry.h:520
qgsmessagelog.h
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:525
QgsVectorLayer::renderer
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
Definition: qgsvectorlayer.h:903