QGIS API Documentation  2.99.0-Master (009e47e)
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 "qgssymbol.h"
28 #include "qgsvectorlayer.h"
31 #include "qgsvectorlayerlabeling.h"
33 #include "qgspainteffect.h"
35 #include "qgscsexception.h"
36 #include "qgslogger.h"
37 #include "qgssettings.h"
38 
39 #include <QPicture>
40 
41 
43  : QgsMapLayerRenderer( layer->id() )
44  , mContext( context )
45  , mInterruptionChecker( context )
46  , mLayer( layer )
47  , mFields( layer->fields() )
48  , mRenderer( nullptr )
49  , mLabeling( false )
50  , mDiagrams( false )
51  , mLabelProvider( nullptr )
52  , mDiagramProvider( nullptr )
53 {
54  mSource = new QgsVectorLayerFeatureSource( layer );
55 
56  mRenderer = layer->renderer() ? layer->renderer()->clone() : nullptr;
58 
59  mDrawVertexMarkers = nullptr != layer->editBuffer();
60 
61  mGeometryType = layer->geometryType();
62 
64 
67 
68  QgsSettings settings;
69  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "qgis/digitizing/marker_only_for_selected" ), true ).toBool();
70 
71  QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
72  if ( markerTypeString == QLatin1String( "Cross" ) )
73  {
75  }
76  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
77  {
79  }
80  else
81  {
83  }
84 
85  mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size" ), 3 ).toInt();
86 
87  if ( !mRenderer )
88  return;
89 
90  QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
91 
92  if ( mDrawVertexMarkers )
93  {
94  // set editing vertex markers style
96  }
97 
99 
100  mAttrNames = mRenderer->usedAttributes( context );
101 
102  //register label and diagram layer to the labeling engine
103  prepareLabeling( layer, mAttrNames );
104  prepareDiagrams( layer, mAttrNames );
105 
106 }
107 
108 
110 {
111  delete mRenderer;
112  delete mSource;
113 }
114 
115 
117 {
119  return true;
120 
121  if ( !mRenderer )
122  {
123  mErrors.append( QObject::tr( "No renderer for drawing." ) );
124  return false;
125  }
126 
127  bool usingEffect = false;
129  {
130  usingEffect = true;
132  }
133 
134  // Per feature blending mode
135  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
136  {
137  // set the painter to the feature blend mode, so that features drawn
138  // on this layer will interact and blend with each other
139  mContext.painter()->setCompositionMode( mFeatureBlendMode );
140  }
141 
143 
144  QString rendererFilter = mRenderer->filter( mFields );
145 
146  QgsRectangle requestExtent = mContext.extent();
147  mRenderer->modifyRequestExtent( requestExtent, mContext );
148 
149  QgsFeatureRequest featureRequest = QgsFeatureRequest()
150  .setFilterRect( requestExtent )
153  if ( mRenderer->orderByEnabled() )
154  {
155  featureRequest.setOrderBy( mRenderer->orderBy() );
156  }
157 
158  const QgsFeatureFilterProvider *featureFilterProvider = mContext.featureFilterProvider();
159  if ( featureFilterProvider )
160  {
161  featureFilterProvider->filterFeatures( mLayer, featureRequest );
162  }
163  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
164  {
165  featureRequest.combineFilterExpression( rendererFilter );
166  }
167 
168  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
169  if ( mSimplifyGeometry )
170  {
171  double map2pixelTol = mSimplifyMethod.threshold();
172  bool validTransform = true;
173 
174  const QgsMapToPixel &mtp = mContext.mapToPixel();
175  map2pixelTol *= mtp.mapUnitsPerPixel();
177 
178  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
179  if ( ct.isValid() && !ct.isShortCircuited() )
180  {
181  try
182  {
183  QgsPointXY center = mContext.extent().center();
184  double rectSize = ct.sourceCrs().isGeographic() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
185 
186  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
187  QgsRectangle targetRect = ct.transform( sourceRect );
188 
189  QgsDebugMsgLevel( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
190  QgsDebugMsgLevel( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
191 
192  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
193  {
194  QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
195  QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
196  QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
197  QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
198 
199  double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
200  double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
201 
202  QgsDebugMsgLevel( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
203  QgsDebugMsgLevel( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
204 
205  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
206  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
207  }
208  }
209  catch ( QgsCsException &cse )
210  {
211  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
212  validTransform = false;
213  }
214  }
215 
216  if ( validTransform )
217  {
218  QgsSimplifyMethod simplifyMethod;
220  simplifyMethod.setTolerance( map2pixelTol );
221  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
223  featureRequest.setSimplifyMethod( simplifyMethod );
224 
226  vectorMethod.setTolerance( map2pixelTol );
227  mContext.setVectorSimplifyMethod( vectorMethod );
228  }
229  else
230  {
231  QgsVectorSimplifyMethod vectorMethod;
233  mContext.setVectorSimplifyMethod( vectorMethod );
234  }
235  }
236  else
237  {
238  QgsVectorSimplifyMethod vectorMethod;
240  mContext.setVectorSimplifyMethod( vectorMethod );
241  }
242 
243  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
244  // Attach an interruption checker so that iterators that have potentially
245  // slow fetchFeature() implementations, such as in the WFS provider, can
246  // check it, instead of relying on just the mContext.renderingStopped() check
247  // in drawRenderer()
249 
251  drawRendererLevels( fit );
252  else
253  drawRenderer( fit );
254 
255  if ( usingEffect )
256  {
258  }
259 
260  return true;
261 }
262 
263 
264 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureIterator &fit )
265 {
267  mContext.expressionContext().appendScope( symbolScope );
268 
269  QgsFeature fet;
270  while ( fit.nextFeature( fet ) )
271  {
272  try
273  {
274  if ( mContext.renderingStopped() )
275  {
276  QgsDebugMsg( QString( "Drawing of vector layer %1 canceled." ).arg( layerId() ) );
277  break;
278  }
279 
280  if ( !fet.hasGeometry() )
281  continue; // skip features without geometry
282 
284 
285  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
286  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
287 
288  // render feature
289  bool rendered = mRenderer->renderFeature( fet, mContext, -1, sel, drawMarker );
290 
291  // labeling - register feature
292  if ( rendered )
293  {
294  // new labeling engine
296  {
297  QgsGeometry obstacleGeometry;
299 
300  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
301  {
302  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
303  }
304 
305  if ( !symbols.isEmpty() )
306  {
307  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
308  }
309 
310  if ( mLabelProvider )
311  {
312  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry );
313  }
314  if ( mDiagramProvider )
315  {
316  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
317  }
318  }
319  }
320  }
321  catch ( const QgsCsException &cse )
322  {
323  Q_UNUSED( cse );
324  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
325  .arg( fet.id() ).arg( cse.what() ) );
326  }
327  }
328 
330 
331  stopRenderer( nullptr );
332 }
333 
334 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
335 {
336  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
337 
338  QgsSingleSymbolRenderer *selRenderer = nullptr;
339  if ( !mSelectedFeatureIds.isEmpty() )
340  {
342  selRenderer->symbol()->setColor( mContext.selectionColor() );
344  selRenderer->startRender( mContext, mFields );
345  }
346 
348  mContext.expressionContext().appendScope( symbolScope );
349 
350  // 1. fetch features
351  QgsFeature fet;
352  while ( fit.nextFeature( fet ) )
353  {
354  if ( mContext.renderingStopped() )
355  {
356  qDebug( "rendering stop!" );
357  stopRenderer( selRenderer );
359  return;
360  }
361 
362  if ( !fet.hasGeometry() )
363  continue; // skip features without geometry
364 
367  if ( !sym )
368  {
369  continue;
370  }
371 
372  if ( !features.contains( sym ) )
373  {
374  features.insert( sym, QList<QgsFeature>() );
375  }
376  features[sym].append( fet );
377 
378  // new labeling engine
379  if ( mContext.labelingEngine() )
380  {
381  QgsGeometry obstacleGeometry;
383 
384  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
385  {
386  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
387  }
388 
389  if ( !symbols.isEmpty() )
390  {
391  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
392  }
393 
394  if ( mLabelProvider )
395  {
396  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry );
397  }
398  if ( mDiagramProvider )
399  {
400  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
401  }
402  }
403  }
404 
406 
407  // find out the order
408  QgsSymbolLevelOrder levels;
409  QgsSymbolList symbols = mRenderer->symbols( mContext );
410  for ( int i = 0; i < symbols.count(); i++ )
411  {
412  QgsSymbol *sym = symbols[i];
413  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
414  {
415  int level = sym->symbolLayer( j )->renderingPass();
416  if ( level < 0 || level >= 1000 ) // ignore invalid levels
417  continue;
418  QgsSymbolLevelItem item( sym, j );
419  while ( level >= levels.count() ) // append new empty levels
420  levels.append( QgsSymbolLevel() );
421  levels[level].append( item );
422  }
423  }
424 
425  // 2. draw features in correct order
426  for ( int l = 0; l < levels.count(); l++ )
427  {
428  QgsSymbolLevel &level = levels[l];
429  for ( int i = 0; i < level.count(); i++ )
430  {
431  QgsSymbolLevelItem &item = level[i];
432  if ( !features.contains( item.symbol() ) )
433  {
434  QgsDebugMsg( "level item's symbol not found!" );
435  continue;
436  }
437  int layer = item.layer();
438  QList<QgsFeature> &lst = features[item.symbol()];
439  QList<QgsFeature>::iterator fit;
440  for ( fit = lst.begin(); fit != lst.end(); ++fit )
441  {
442  if ( mContext.renderingStopped() )
443  {
444  stopRenderer( selRenderer );
445  return;
446  }
447 
448  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fit->id() );
449  // maybe vertex markers should be drawn only during the last pass...
450  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
451 
453 
454  try
455  {
456  mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker );
457  }
458  catch ( const QgsCsException &cse )
459  {
460  Q_UNUSED( cse );
461  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
462  .arg( fet.id() ).arg( cse.what() ) );
463  }
464  }
465  }
466  }
467 
468  stopRenderer( selRenderer );
469 }
470 
471 
472 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer *selRenderer )
473 {
475  if ( selRenderer )
476  {
477  selRenderer->stopRender( mContext );
478  delete selRenderer;
479  }
480 }
481 
482 
483 
484 
485 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
486 {
487  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
488  {
489  if ( layer->labeling() )
490  {
491  mLabelProvider = layer->labeling()->provider( layer );
492  if ( mLabelProvider )
493  {
494  engine2->addProvider( mLabelProvider );
495  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
496  {
497  engine2->removeProvider( mLabelProvider );
498  mLabelProvider = nullptr; // deleted by engine
499  }
500  }
501  }
502  }
503 
504 #if 0 // TODO: limit of labels, font not found
506 
507  // see if feature count limit is set for labeling
508  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
509  {
510  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
511  .setFilterRect( mContext.extent() )
512  .setSubsetOfAttributes( QgsAttributeList() ) );
513 
514  // total number of features that may be labeled
515  QgsFeature f;
516  int nFeatsToLabel = 0;
517  while ( fit.nextFeature( f ) )
518  {
519  nFeatsToLabel++;
520  }
521  palyr.mFeaturesToLabel = nFeatsToLabel;
522  }
523 
524  // notify user about any font substitution
525  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
526  {
527  emit labelingFontNotFound( this, palyr.mTextFontFamily );
528  mLabelFontNotFoundNotified = true;
529  }
530 #endif
531 }
532 
533 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
534 {
535  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
536  {
537  if ( layer->diagramsEnabled() )
538  {
540  // need to be added before calling prepare() - uses map settings from engine
541  engine2->addProvider( mDiagramProvider );
542  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
543  {
544  engine2->removeProvider( mDiagramProvider );
545  mDiagramProvider = nullptr; // deleted by engine
546  }
547  }
548  }
549 }
550 
551 /* ----------------------------------------- */
552 /* QgsVectorLayerRendererInterruptionChecker */
553 /* ----------------------------------------- */
554 
556 ( const QgsRenderContext &context )
557  : mContext( context )
558 {
559 }
560 
562 {
563  return mContext.renderingStopped();
564 }
QgsVectorLayerRendererInterruptionChecker mInterruptionChecker
QgsFeatureId id
Definition: qgsfeature.h:70
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.
virtual QgsSymbolList originalSymbolsForFeature(QgsFeature &feat, QgsRenderContext &context)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
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:38
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
QgsVectorLayer * mLayer
The rendered layer.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:54
QgsLabelingEngine * labelingEngine() const
Get access to new labeling engine (may be nullptr)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
The geometries can be simplified using the current map2pixel context state.
double y
Definition: qgspointxy.h:47
A class to represent a 2D point.
Definition: qgspointxy.h:42
QgsFeatureRequest::OrderBy orderBy() const
Get the order in which features shall be processed by this renderer.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) override
Get an iterator for features matching the specified request.
virtual void stopRender(QgsRenderContext &context) override
Needs to be called when a render cycle has finished 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:175
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool renderingStopped() const
QPainter::CompositionMode mFeatureBlendMode
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:96
bool mustStop() const override
return true if the iterator must stop as soon as possible
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:190
QgsVectorSimplifyMethod mSimplifyMethod
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:203
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
Get the filter feature provider used for additional filtering of rendered features.
QString what() const
Definition: qgsexception.h:42
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:76
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:35
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Return 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
No simplification can be applied.
QgsVectorLayerRendererInterruptionChecker(const QgsRenderContext &context)
Constructor.
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:43
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
return new default symbol for specified geometry type
Definition: qgssymbol.cpp:254
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
const QgsFeatureIds & selectedFeatureIds() const
Return reference to identifiers of selected features.
QgsFeatureRenderer * mRenderer
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:38
bool isEmpty() const
Returns true if the rectangle is empty.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
const QgsRectangle & extent() const
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
QgsVectorLayerLabelProvider * mLabelProvider
used with new labeling engine (QgsLabelingEngine): provider for labels.
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...
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:139
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
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsVectorLayerFeatureSource * mSource
QColor selectionColor() const
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.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
Abstract interface for use by classes that filter the features of a layer.
QgsFeatureRenderer * renderer()
Return renderer.
bool isGeographic() const
Returns whether the CRS is a geographic CRS (using lat/lon coordinates)
bool enabled() const
Returns whether the effect is enabled.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
const QgsAbstractVectorLayerLabeling * labeling() const
Access to labeling configuration.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
Definition: qgsfeature.cpp:101
double mapUnitsPerPixel() const
Return current map units per pixel.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
Definition: qgssymbol.cpp:320
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
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.
double x
Definition: qgspointxy.h:46
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...
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
Definition: qgsrenderer.h:221
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:106
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:91
virtual void startRender(QgsRenderContext &context, const QgsFields &fields) override
Needs to be called when a new render cycle is started.
virtual QgsSymbolList symbols(QgsRenderContext &context)
Returns list of symbols used by the renderer.
Definition: qgsrenderer.h:247
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.
virtual bool render() override
Do the rendering (based on data stored in the class)
static void logMessage(const QString &message, const QString &tag=QString(), MessageLevel level=QgsMessageLog::WARNING)
add a message to the instance (and create it if necessary)
virtual QgsSymbol * symbolForFeature(QgsFeature &feature, QgsRenderContext &context)=0
To be overridden.
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:249
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
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:72
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...
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const
Transform the point from the source CRS to the destination CRS.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
QString layerId() const
Get 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.
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:96
Base class for utility classes that encapsulate information necessary for rendering of map layers...
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
Definition: qgsrenderer.h:337
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:101
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.
Custom exception class for Coordinate Reference System related exceptions.
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:146
QList< int > QgsAttributeList
Definition: qgsfield.h:27
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.
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:64
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:241
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
Definition: qgsrenderer.cpp:98
void setInterruptionChecker(QgsInterruptionChecker *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped...
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)
Definition: qgssymbol.cpp:422
virtual QString dump() const
Returns debug information about this renderer.