QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 "qgslogger.h"
38 #include "qgssettings.h"
41 
42 #include <QPicture>
43 
44 
46  : QgsMapLayerRenderer( layer->id(), &context )
47  , mLayer( layer )
48  , mFields( layer->fields() )
49  , mLabeling( false )
50  , mDiagrams( false )
51 {
52  mSource = new QgsVectorLayerFeatureSource( layer );
53 
54  mRenderer = layer->renderer() ? layer->renderer()->clone() : nullptr;
56 
57  mDrawVertexMarkers = nullptr != layer->editBuffer();
58 
59  mGeometryType = layer->geometryType();
60 
62 
63  // if there's already a simplification method specified via the context, we respect that. Otherwise, we fall back
64  // to the layer's individual setting
65  if ( renderContext()->vectorSimplifyMethod().simplifyHints() != QgsVectorSimplifyMethod::NoSimplification )
66  {
70  }
71  else
72  {
75  }
76 
77  QgsSettings settings;
78  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "qgis/digitizing/marker_only_for_selected" ), true ).toBool();
79 
80  QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
81  if ( markerTypeString == QLatin1String( "Cross" ) )
82  {
84  }
85  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
86  {
88  }
89  else
90  {
92  }
93 
94  mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size_mm" ), 2.0 ).toDouble();
95 
96  if ( !mRenderer )
97  return;
98 
99  QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
100 
101  if ( mDrawVertexMarkers )
102  {
103  // set editing vertex markers style
105  }
107 
108  mAttrNames = mRenderer->usedAttributes( context );
109  if ( context.hasRenderedFeatureHandlers() )
110  {
111  const QList< QgsRenderedFeatureHandlerInterface * > handlers = context.renderedFeatureHandlers();
112  for ( QgsRenderedFeatureHandlerInterface *handler : handlers )
113  mAttrNames.unite( handler->usedAttributes( layer, context ) );
114  }
115 
116  //register label and diagram layer to the labeling engine
117  prepareLabeling( layer, mAttrNames );
118  prepareDiagrams( layer, mAttrNames );
119 }
120 
121 
123 {
124  delete mRenderer;
125  delete mSource;
126 }
127 
129 {
130  return mInterruptionChecker.get();
131 }
132 
134 {
136  return true;
137 
138  if ( !mRenderer )
139  {
140  mErrors.append( QObject::tr( "No renderer for drawing." ) );
141  return false;
142  }
143 
144  if ( mRenderer->type() == QStringLiteral( "nullSymbol" ) )
145  {
146  // a little shortcut for the null symbol renderer - most of the time it is not going to render anything
147  // so we can even skip the whole loop to fetch features
149  return true;
150  }
151 
152  QgsRenderContext &context = *renderContext();
153 
154  // MUST be created in the thread doing the rendering
155  mInterruptionChecker = qgis::make_unique< QgsVectorLayerRendererInterruptionChecker >( context );
156  bool usingEffect = false;
158  {
159  usingEffect = true;
160  mRenderer->paintEffect()->begin( context );
161  }
162 
163  // Per feature blending mode
164  if ( context.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
165  {
166  // set the painter to the feature blend mode, so that features drawn
167  // on this layer will interact and blend with each other
168  context.painter()->setCompositionMode( mFeatureBlendMode );
169  }
170 
171  mRenderer->startRender( context, mFields );
172 
173  QString rendererFilter = mRenderer->filter( mFields );
174 
175  QgsRectangle requestExtent = context.extent();
176  mRenderer->modifyRequestExtent( requestExtent, context );
177 
178  QgsFeatureRequest featureRequest = QgsFeatureRequest()
179  .setFilterRect( requestExtent )
182  if ( mRenderer->orderByEnabled() )
183  {
184  featureRequest.setOrderBy( mRenderer->orderBy() );
185  }
186 
187  const QgsFeatureFilterProvider *featureFilterProvider = context.featureFilterProvider();
188  if ( featureFilterProvider )
189  {
190  featureFilterProvider->filterFeatures( mLayer, featureRequest );
191  }
192  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
193  {
194  featureRequest.combineFilterExpression( rendererFilter );
195  }
196 
197  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
198  if ( mSimplifyGeometry )
199  {
200  double map2pixelTol = mSimplifyMethod.threshold();
201  bool validTransform = true;
202 
203  const QgsMapToPixel &mtp = context.mapToPixel();
204  map2pixelTol *= mtp.mapUnitsPerPixel();
206 
207  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
208  if ( ct.isValid() && !ct.isShortCircuited() )
209  {
210  try
211  {
212  QgsPointXY center = context.extent().center();
213  double rectSize = ct.sourceCrs().isGeographic() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
214 
215  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
216  QgsRectangle targetRect = ct.transform( sourceRect );
217 
218  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
219  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
220 
221  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
222  {
223  QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
224  QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
225  QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
226  QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
227 
228  double sourceHypothenuse = std::sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
229  double targetHypothenuse = std::sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
230 
231  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
232  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
233 
234  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
235  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
236  }
237  }
238  catch ( QgsCsException &cse )
239  {
240  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
241  validTransform = false;
242  }
243  }
244 
245  if ( validTransform )
246  {
247  QgsSimplifyMethod simplifyMethod;
249  simplifyMethod.setTolerance( map2pixelTol );
250  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
252  featureRequest.setSimplifyMethod( simplifyMethod );
253 
255  vectorMethod.setTolerance( map2pixelTol );
256  context.setVectorSimplifyMethod( vectorMethod );
257  }
258  else
259  {
260  QgsVectorSimplifyMethod vectorMethod;
262  context.setVectorSimplifyMethod( vectorMethod );
263  }
264  }
265  else
266  {
267  QgsVectorSimplifyMethod vectorMethod;
269  context.setVectorSimplifyMethod( vectorMethod );
270  }
271 
272  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
273  // Attach an interruption checker so that iterators that have potentially
274  // slow fetchFeature() implementations, such as in the WFS provider, can
275  // check it, instead of relying on just the mContext.renderingStopped() check
276  // in drawRenderer()
278 
280  drawRendererLevels( fit );
281  else
282  drawRenderer( fit );
283 
284  if ( !fit.isValid() )
285  {
286  mErrors.append( QStringLiteral( "Data source invalid" ) );
287  }
288 
289  if ( usingEffect )
290  {
291  mRenderer->paintEffect()->end( context );
292  }
293 
294  mInterruptionChecker.reset();
295  return true;
296 }
297 
298 
299 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureIterator &fit )
300 {
302  QgsRenderContext &context = *renderContext();
303  context.expressionContext().appendScope( symbolScope );
304 
305  QgsFeature fet;
306  while ( fit.nextFeature( fet ) )
307  {
308  try
309  {
310  if ( context.renderingStopped() )
311  {
312  QgsDebugMsg( QStringLiteral( "Drawing of vector layer %1 canceled." ).arg( layerId() ) );
313  break;
314  }
315 
316  if ( !fet.hasGeometry() || fet.geometry().isEmpty() )
317  continue; // skip features without geometry
318 
319  context.expressionContext().setFeature( fet );
320 
321  bool sel = context.showSelection() && mSelectedFeatureIds.contains( fet.id() );
322  bool drawMarker = ( mDrawVertexMarkers && context.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
323 
324  // render feature
325  bool rendered = mRenderer->renderFeature( fet, context, -1, sel, drawMarker );
326 
327  // labeling - register feature
328  if ( rendered )
329  {
330  // new labeling engine
331  if ( context.labelingEngine() && ( mLabelProvider || mDiagramProvider ) )
332  {
333  QgsGeometry obstacleGeometry;
334  QgsSymbolList symbols = mRenderer->originalSymbolsForFeature( fet, context );
335  QgsSymbol *symbol = nullptr;
336  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
337  {
338  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, context, symbols );
339  }
340 
341  if ( !symbols.isEmpty() )
342  {
343  symbol = symbols.at( 0 );
344  QgsExpressionContextUtils::updateSymbolScope( symbol, symbolScope );
345  }
346 
347  if ( mLabelProvider )
348  {
349  mLabelProvider->registerFeature( fet, context, obstacleGeometry, symbol );
350  }
351  if ( mDiagramProvider )
352  {
353  mDiagramProvider->registerFeature( fet, context, obstacleGeometry );
354  }
355  }
356  }
357  }
358  catch ( const QgsCsException &cse )
359  {
360  Q_UNUSED( cse )
361  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
362  .arg( fet.id() ).arg( cse.what() ) );
363  }
364  }
365 
366  delete context.expressionContext().popScope();
367 
368  stopRenderer( nullptr );
369 }
370 
371 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
372 {
373  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
374  QgsRenderContext &context = *renderContext();
375 
376  QgsSingleSymbolRenderer *selRenderer = nullptr;
377  if ( !mSelectedFeatureIds.isEmpty() )
378  {
380  selRenderer->symbol()->setColor( context.selectionColor() );
382  selRenderer->startRender( context, mFields );
383  }
384 
386  std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = qgis::make_unique< QgsExpressionContextScopePopper >( context.expressionContext(), symbolScope );
387 
388  // 1. fetch features
389  QgsFeature fet;
390  while ( fit.nextFeature( fet ) )
391  {
392  if ( context.renderingStopped() )
393  {
394  qDebug( "rendering stop!" );
395  stopRenderer( selRenderer );
396  return;
397  }
398 
399  if ( !fet.hasGeometry() )
400  continue; // skip features without geometry
401 
402  context.expressionContext().setFeature( fet );
403  QgsSymbol *sym = mRenderer->symbolForFeature( fet, context );
404  if ( !sym )
405  {
406  continue;
407  }
408 
409  if ( !features.contains( sym ) )
410  {
411  features.insert( sym, QList<QgsFeature>() );
412  }
413  features[sym].append( fet );
414 
415  // new labeling engine
416  if ( context.labelingEngine() && ( mLabelProvider || mDiagramProvider ) )
417  {
418  QgsGeometry obstacleGeometry;
419  QgsSymbolList symbols = mRenderer->originalSymbolsForFeature( fet, context );
420  std::unique_ptr< QgsSymbol > symbol;
421  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
422  {
423  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, context, symbols );
424  }
425 
426  if ( !symbols.isEmpty() )
427  {
428  symbol.reset( symbols.at( 0 )->clone() );
429  QgsExpressionContextUtils::updateSymbolScope( symbol.get(), symbolScope );
430  }
431 
432  if ( mLabelProvider )
433  {
434  mLabelProvider->registerFeature( fet, context, obstacleGeometry, symbol.release() );
435  }
436  if ( mDiagramProvider )
437  {
438  mDiagramProvider->registerFeature( fet, context, obstacleGeometry );
439  }
440  }
441  }
442 
443  scopePopper.reset();
444 
445  if ( features.empty() )
446  {
447  // nothing to draw
448  stopRenderer( selRenderer );
449  return;
450  }
451 
452  // find out the order
453  QgsSymbolLevelOrder levels;
454  QgsSymbolList symbols = mRenderer->symbols( context );
455  for ( int i = 0; i < symbols.count(); i++ )
456  {
457  QgsSymbol *sym = symbols[i];
458  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
459  {
460  int level = sym->symbolLayer( j )->renderingPass();
461  if ( level < 0 || level >= 1000 ) // ignore invalid levels
462  continue;
463  QgsSymbolLevelItem item( sym, j );
464  while ( level >= levels.count() ) // append new empty levels
465  levels.append( QgsSymbolLevel() );
466  levels[level].append( item );
467  }
468  }
469 
470  // 2. draw features in correct order
471  for ( int l = 0; l < levels.count(); l++ )
472  {
473  QgsSymbolLevel &level = levels[l];
474  for ( int i = 0; i < level.count(); i++ )
475  {
476  QgsSymbolLevelItem &item = level[i];
477  if ( !features.contains( item.symbol() ) )
478  {
479  QgsDebugMsg( QStringLiteral( "level item's symbol not found!" ) );
480  continue;
481  }
482  int layer = item.layer();
483  QList<QgsFeature> &lst = features[item.symbol()];
484  QList<QgsFeature>::iterator fit;
485  for ( fit = lst.begin(); fit != lst.end(); ++fit )
486  {
487  if ( context.renderingStopped() )
488  {
489  stopRenderer( selRenderer );
490  return;
491  }
492 
493  bool sel = context.showSelection() && mSelectedFeatureIds.contains( fit->id() );
494  // maybe vertex markers should be drawn only during the last pass...
495  bool drawMarker = ( mDrawVertexMarkers && context.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
496 
497  context.expressionContext().setFeature( *fit );
498 
499  try
500  {
501  mRenderer->renderFeature( *fit, context, layer, sel, drawMarker );
502  }
503  catch ( const QgsCsException &cse )
504  {
505  Q_UNUSED( cse )
506  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
507  .arg( fet.id() ).arg( cse.what() ) );
508  }
509  }
510  }
511  }
512 
513  stopRenderer( selRenderer );
514 }
515 
516 
517 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer *selRenderer )
518 {
519  QgsRenderContext &context = *renderContext();
520  mRenderer->stopRender( context );
521  if ( selRenderer )
522  {
523  selRenderer->stopRender( context );
524  delete selRenderer;
525  }
526 }
527 
528 
529 
530 
531 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
532 {
533  QgsRenderContext &context = *renderContext();
534  // TODO: add attributes for geometry generator
535  if ( QgsLabelingEngine *engine2 = context.labelingEngine() )
536  {
537  if ( layer->labelsEnabled() )
538  {
539  mLabelProvider = layer->labeling()->provider( layer );
540  if ( mLabelProvider )
541  {
542  engine2->addProvider( mLabelProvider );
543  if ( !mLabelProvider->prepare( context, attributeNames ) )
544  {
545  engine2->removeProvider( mLabelProvider );
546  mLabelProvider = nullptr; // deleted by engine
547  }
548  }
549  }
550  }
551 
552 #if 0 // TODO: limit of labels, font not found
553  QgsPalLayerSettings &palyr = mContext.labelingEngine()->layer( mLayerID );
554 
555  // see if feature count limit is set for labeling
556  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
557  {
558  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
559  .setFilterRect( mContext.extent() )
560  .setNoAttributes() );
561 
562  // total number of features that may be labeled
563  QgsFeature f;
564  int nFeatsToLabel = 0;
565  while ( fit.nextFeature( f ) )
566  {
567  nFeatsToLabel++;
568  }
569  palyr.mFeaturesToLabel = nFeatsToLabel;
570  }
571 
572  // notify user about any font substitution
573  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
574  {
575  emit labelingFontNotFound( this, palyr.mTextFontFamily );
576  mLabelFontNotFoundNotified = true;
577  }
578 #endif
579 }
580 
581 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
582 {
583  QgsRenderContext &context = *renderContext();
584  if ( QgsLabelingEngine *engine2 = context.labelingEngine() )
585  {
586  if ( layer->diagramsEnabled() )
587  {
589  // need to be added before calling prepare() - uses map settings from engine
590  engine2->addProvider( mDiagramProvider );
591  if ( !mDiagramProvider->prepare( context, attributeNames ) )
592  {
593  engine2->removeProvider( mDiagramProvider );
594  mDiagramProvider = nullptr; // deleted by engine
595  }
596  }
597  }
598 }
599 
600 /* ----------------------------------------- */
601 /* QgsVectorLayerRendererInterruptionChecker */
602 /* ----------------------------------------- */
603 
605 ( const QgsRenderContext &context )
606  : mContext( context )
607  , mTimer( new QTimer( this ) )
608 {
609  connect( mTimer, &QTimer::timeout, this, [ = ]
610  {
611  if ( mContext.renderingStopped() )
612  {
613  mTimer->stop();
614  cancel();
615  }
616  } );
617  mTimer->start( 50 );
618 
619 }
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsFeatureId id
Definition: qgsfeature.h:64
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
Wrapper for iterator of features from vector data provider or vector layer.
void setThreshold(float threshold)
Sets the simplification threshold in pixels. Represents the maximum distance in pixels between two co...
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsVectorLayer * mLayer
The rendered layer.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
The geometries can be simplified using the current map2pixel context state.
double y
Definition: qgspointxy.h:48
A class to represent a 2D point.
Definition: qgspointxy.h:43
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:280
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) override
Gets an iterator for features matching the specified request.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
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:194
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QPainter::CompositionMode mFeatureBlendMode
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:173
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
QgsVectorSimplifyMethod mSimplifyMethod
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
QString what() const
Definition: qgsexception.h:48
All simplification hints can be applied ( Geometry + AA-disabling )
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:78
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
QgsWkbTypes::GeometryType mGeometryType
Simplify using the map2pixel data to optimize the rendering of geometries.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
No simplification can be applied.
QgsVectorLayerRendererInterruptionChecker(const QgsRenderContext &context)
Constructor.
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:297
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
QString type() const
Definition: qgsrenderer.h:130
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
QgsFeatureRenderer * mRenderer
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:426
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
QgsVectorLayerLabelProvider * mLabelProvider
used with new labeling engine (QgsLabelingEngine): provider for labels.
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent...
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine...
std::unique_ptr< QgsVectorLayerRendererInterruptionChecker > mInterruptionChecker
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
An interface for classes which provider custom handlers for features rendered as part of a map render...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void setInterruptionChecker(QgsFeedback *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped...
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsVectorLayerFeatureSource * mSource
QColor selectionColor() const
Returns the color to use when rendering selected features.
float threshold() const
Gets the simplification threshold of the vector layer managed.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Abstract interface for use by classes that filter the features of a layer.
QgsFeatureRenderer * renderer()
Returns renderer.
bool enabled() const
Returns whether the effect is enabled.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Single scope for storing variables and functions for use within a QgsExpressionContext.
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
Definition: qgssymbol.cpp:362
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:516
double x
Definition: qgspointxy.h:47
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.
int maxNumLabels
The maximum number of labels which should be drawn for this layer.
Partial snapshot of vector layer&#39;s state (only the members necessary for access to features) ...
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...
virtual void 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...
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
Definition: qgsrenderer.h:243
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
void setForceLocalOptimization(bool localOptimization)
Sets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries.
The QgsLabelingEngine class provides map labeling functionality.
bool render() override
Do the rendering (based on data stored in the class)
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:272
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context&#39;s map to pixel transform, which transforms between map coordinates and device coo...
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:74
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...
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:93
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
QString layerId() const
Gets access to the ID of the layer rendered by this class.
void setMethodType(MethodType methodType)
Sets the simplification type.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Class for doing transforms between two map coordinate systems.
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
Base class for utility classes that encapsulate information necessary for rendering of map layers...
bool limitNumLabels
true if the number of labels drawn should be limited.
void setVertexMarkerAppearance(int type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:126
QgsGeometry geometry
Definition: qgsfeature.h:67
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
QgsVectorLayerDiagramProvider * mDiagramProvider
used with new labeling engine (QgsLabelingEngine): provider for diagrams.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
Represents a vector layer which manages a vector based data sets.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
QgsSymbol * symbol()
Definition: qgsrenderer.h:66
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
virtual bool isValid() const
Will return if this iterator is valid.
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:263
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
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.
void setColor(const QColor &color)
Sets the color for the symbol.
Definition: qgssymbol.cpp:474
virtual QString dump() const
Returns debug information about this renderer.