QGIS API Documentation  2.99.0-Master (dcec6bb)
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 "qgsexception.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 
66 
67  QgsSettings settings;
68  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "qgis/digitizing/marker_only_for_selected" ), true ).toBool();
69 
70  QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
71  if ( markerTypeString == QLatin1String( "Cross" ) )
72  {
74  }
75  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
76  {
78  }
79  else
80  {
82  }
83 
84  mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size" ), 3 ).toInt();
85 
86  if ( !mRenderer )
87  return;
88 
89  QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
90 
91  if ( mDrawVertexMarkers )
92  {
93  // set editing vertex markers style
95  }
97 
98  mAttrNames = mRenderer->usedAttributes( context );
99 
100  //register label and diagram layer to the labeling engine
101  prepareLabeling( layer, mAttrNames );
102  prepareDiagrams( layer, mAttrNames );
103 }
104 
105 
107 {
108  delete mRenderer;
109  delete mSource;
110 }
111 
112 
114 {
116  return true;
117 
118  if ( !mRenderer )
119  {
120  mErrors.append( QObject::tr( "No renderer for drawing." ) );
121  return false;
122  }
123 
124  bool usingEffect = false;
126  {
127  usingEffect = true;
129  }
130 
131  // Per feature blending mode
132  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
133  {
134  // set the painter to the feature blend mode, so that features drawn
135  // on this layer will interact and blend with each other
136  mContext.painter()->setCompositionMode( mFeatureBlendMode );
137  }
138 
140 
141  QString rendererFilter = mRenderer->filter( mFields );
142 
143  QgsRectangle requestExtent = mContext.extent();
144  mRenderer->modifyRequestExtent( requestExtent, mContext );
145 
146  QgsFeatureRequest featureRequest = QgsFeatureRequest()
147  .setFilterRect( requestExtent )
150  if ( mRenderer->orderByEnabled() )
151  {
152  featureRequest.setOrderBy( mRenderer->orderBy() );
153  }
154 
155  const QgsFeatureFilterProvider *featureFilterProvider = mContext.featureFilterProvider();
156  if ( featureFilterProvider )
157  {
158  featureFilterProvider->filterFeatures( mLayer, featureRequest );
159  }
160  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
161  {
162  featureRequest.combineFilterExpression( rendererFilter );
163  }
164 
165  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
166  if ( mSimplifyGeometry )
167  {
168  double map2pixelTol = mSimplifyMethod.threshold();
169  bool validTransform = true;
170 
171  const QgsMapToPixel &mtp = mContext.mapToPixel();
172  map2pixelTol *= mtp.mapUnitsPerPixel();
174 
175  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
176  if ( ct.isValid() && !ct.isShortCircuited() )
177  {
178  try
179  {
180  QgsPointXY center = mContext.extent().center();
181  double rectSize = ct.sourceCrs().isGeographic() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
182 
183  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
184  QgsRectangle targetRect = ct.transform( sourceRect );
185 
186  QgsDebugMsgLevel( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
187  QgsDebugMsgLevel( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
188 
189  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
190  {
191  QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
192  QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
193  QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
194  QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
195 
196  double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
197  double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
198 
199  QgsDebugMsgLevel( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
200  QgsDebugMsgLevel( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
201 
202  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
203  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
204  }
205  }
206  catch ( QgsCsException &cse )
207  {
208  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
209  validTransform = false;
210  }
211  }
212 
213  if ( validTransform )
214  {
215  QgsSimplifyMethod simplifyMethod;
217  simplifyMethod.setTolerance( map2pixelTol );
218  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
220  featureRequest.setSimplifyMethod( simplifyMethod );
221 
223  vectorMethod.setTolerance( map2pixelTol );
224  mContext.setVectorSimplifyMethod( vectorMethod );
225  }
226  else
227  {
228  QgsVectorSimplifyMethod vectorMethod;
230  mContext.setVectorSimplifyMethod( vectorMethod );
231  }
232  }
233  else
234  {
235  QgsVectorSimplifyMethod vectorMethod;
237  mContext.setVectorSimplifyMethod( vectorMethod );
238  }
239 
240  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
241  // Attach an interruption checker so that iterators that have potentially
242  // slow fetchFeature() implementations, such as in the WFS provider, can
243  // check it, instead of relying on just the mContext.renderingStopped() check
244  // in drawRenderer()
246 
248  drawRendererLevels( fit );
249  else
250  drawRenderer( fit );
251 
252  if ( usingEffect )
253  {
255  }
256 
257  return true;
258 }
259 
260 
261 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureIterator &fit )
262 {
264  mContext.expressionContext().appendScope( symbolScope );
265 
266  QgsFeature fet;
267  while ( fit.nextFeature( fet ) )
268  {
269  try
270  {
271  if ( mContext.renderingStopped() )
272  {
273  QgsDebugMsg( QString( "Drawing of vector layer %1 canceled." ).arg( layerId() ) );
274  break;
275  }
276 
277  if ( !fet.hasGeometry() )
278  continue; // skip features without geometry
279 
281 
282  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
283  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
284 
285  // render feature
286  bool rendered = mRenderer->renderFeature( fet, mContext, -1, sel, drawMarker );
287 
288  // labeling - register feature
289  if ( rendered )
290  {
291  // new labeling engine
293  {
294  QgsGeometry obstacleGeometry;
296 
297  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
298  {
299  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
300  }
301 
302  if ( !symbols.isEmpty() )
303  {
304  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
305  }
306 
307  if ( mLabelProvider )
308  {
309  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry );
310  }
311  if ( mDiagramProvider )
312  {
313  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
314  }
315  }
316  }
317  }
318  catch ( const QgsCsException &cse )
319  {
320  Q_UNUSED( cse );
321  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
322  .arg( fet.id() ).arg( cse.what() ) );
323  }
324  }
325 
327 
328  stopRenderer( nullptr );
329 }
330 
331 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
332 {
333  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
334 
335  QgsSingleSymbolRenderer *selRenderer = nullptr;
336  if ( !mSelectedFeatureIds.isEmpty() )
337  {
339  selRenderer->symbol()->setColor( mContext.selectionColor() );
341  selRenderer->startRender( mContext, mFields );
342  }
343 
345  mContext.expressionContext().appendScope( symbolScope );
346 
347  // 1. fetch features
348  QgsFeature fet;
349  while ( fit.nextFeature( fet ) )
350  {
351  if ( mContext.renderingStopped() )
352  {
353  qDebug( "rendering stop!" );
354  stopRenderer( selRenderer );
356  return;
357  }
358 
359  if ( !fet.hasGeometry() )
360  continue; // skip features without geometry
361 
364  if ( !sym )
365  {
366  continue;
367  }
368 
369  if ( !features.contains( sym ) )
370  {
371  features.insert( sym, QList<QgsFeature>() );
372  }
373  features[sym].append( fet );
374 
375  // new labeling engine
376  if ( mContext.labelingEngine() )
377  {
378  QgsGeometry obstacleGeometry;
380 
381  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
382  {
383  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
384  }
385 
386  if ( !symbols.isEmpty() )
387  {
388  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
389  }
390 
391  if ( mLabelProvider )
392  {
393  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry );
394  }
395  if ( mDiagramProvider )
396  {
397  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
398  }
399  }
400  }
401 
403 
404  // find out the order
405  QgsSymbolLevelOrder levels;
406  QgsSymbolList symbols = mRenderer->symbols( mContext );
407  for ( int i = 0; i < symbols.count(); i++ )
408  {
409  QgsSymbol *sym = symbols[i];
410  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
411  {
412  int level = sym->symbolLayer( j )->renderingPass();
413  if ( level < 0 || level >= 1000 ) // ignore invalid levels
414  continue;
415  QgsSymbolLevelItem item( sym, j );
416  while ( level >= levels.count() ) // append new empty levels
417  levels.append( QgsSymbolLevel() );
418  levels[level].append( item );
419  }
420  }
421 
422  // 2. draw features in correct order
423  for ( int l = 0; l < levels.count(); l++ )
424  {
425  QgsSymbolLevel &level = levels[l];
426  for ( int i = 0; i < level.count(); i++ )
427  {
428  QgsSymbolLevelItem &item = level[i];
429  if ( !features.contains( item.symbol() ) )
430  {
431  QgsDebugMsg( "level item's symbol not found!" );
432  continue;
433  }
434  int layer = item.layer();
435  QList<QgsFeature> &lst = features[item.symbol()];
436  QList<QgsFeature>::iterator fit;
437  for ( fit = lst.begin(); fit != lst.end(); ++fit )
438  {
439  if ( mContext.renderingStopped() )
440  {
441  stopRenderer( selRenderer );
442  return;
443  }
444 
445  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fit->id() );
446  // maybe vertex markers should be drawn only during the last pass...
447  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
448 
450 
451  try
452  {
453  mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker );
454  }
455  catch ( const QgsCsException &cse )
456  {
457  Q_UNUSED( cse );
458  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
459  .arg( fet.id() ).arg( cse.what() ) );
460  }
461  }
462  }
463  }
464 
465  stopRenderer( selRenderer );
466 }
467 
468 
469 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer *selRenderer )
470 {
472  if ( selRenderer )
473  {
474  selRenderer->stopRender( mContext );
475  delete selRenderer;
476  }
477 }
478 
479 
480 
481 
482 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
483 {
484  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
485  {
486  if ( layer->labeling() )
487  {
488  mLabelProvider = layer->labeling()->provider( layer );
489  if ( mLabelProvider )
490  {
491  engine2->addProvider( mLabelProvider );
492  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
493  {
494  engine2->removeProvider( mLabelProvider );
495  mLabelProvider = nullptr; // deleted by engine
496  }
497  }
498  }
499  }
500 
501 #if 0 // TODO: limit of labels, font not found
503 
504  // see if feature count limit is set for labeling
505  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
506  {
507  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
508  .setFilterRect( mContext.extent() )
509  .setSubsetOfAttributes( QgsAttributeList() ) );
510 
511  // total number of features that may be labeled
512  QgsFeature f;
513  int nFeatsToLabel = 0;
514  while ( fit.nextFeature( f ) )
515  {
516  nFeatsToLabel++;
517  }
518  palyr.mFeaturesToLabel = nFeatsToLabel;
519  }
520 
521  // notify user about any font substitution
522  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
523  {
524  emit labelingFontNotFound( this, palyr.mTextFontFamily );
525  mLabelFontNotFoundNotified = true;
526  }
527 #endif
528 }
529 
530 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
531 {
532  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
533  {
534  if ( layer->diagramsEnabled() )
535  {
537  // need to be added before calling prepare() - uses map settings from engine
538  engine2->addProvider( mDiagramProvider );
539  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
540  {
541  engine2->removeProvider( mDiagramProvider );
542  mDiagramProvider = nullptr; // deleted by engine
543  }
544  }
545  }
546 }
547 
548 /* ----------------------------------------- */
549 /* QgsVectorLayerRendererInterruptionChecker */
550 /* ----------------------------------------- */
551 
553 ( const QgsRenderContext &context )
554  : mContext( context )
555 {
556 }
557 
559 {
560  return mContext.renderingStopped();
561 }
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
int symbolLayerCount() const
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:139
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:48
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...
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
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...
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
bool limitNumLabels
True if the number of labels drawn should be limited.
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.
Definition: qgsexception.h:64
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:428
virtual QString dump() const
Returns debug information about this renderer.