QGIS API Documentation  2.99.0-Master (bdf46d7)
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 "qgsgeometrycache.h"
22 #include "qgsmessagelog.h"
23 #include "qgspallabeling.h"
24 #include "qgsrenderer.h"
25 #include "qgsrendercontext.h"
27 #include "qgssymbollayer.h"
28 #include "qgssymbol.h"
29 #include "qgsvectorlayer.h"
32 #include "qgsvectorlayerlabeling.h"
34 #include "qgspainteffect.h"
36 #include "qgscsexception.h"
37 #include "qgslogger.h"
38 #include "qgssettings.h"
39 
40 #include <QPicture>
41 
42 // TODO:
43 // - passing of cache to QgsVectorLayer
44 
45 
47  : QgsMapLayerRenderer( layer->id() )
48  , mContext( context )
49  , mInterruptionChecker( context )
50  , mLayer( layer )
51  , mFields( layer->fields() )
52  , mRenderer( nullptr )
53  , mCache( nullptr )
54  , mLabeling( false )
55  , mDiagrams( false )
56  , mLabelProvider( nullptr )
57  , mDiagramProvider( nullptr )
58 {
59  mSource = new QgsVectorLayerFeatureSource( layer );
60 
61  mRenderer = layer->renderer() ? layer->renderer()->clone() : nullptr;
63 
64  mDrawVertexMarkers = nullptr != layer->editBuffer();
65 
66  mGeometryType = layer->geometryType();
67 
69 
72 
73  QgsSettings settings;
74  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "qgis/digitizing/marker_only_for_selected" ), true ).toBool();
75 
76  QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
77  if ( markerTypeString == QLatin1String( "Cross" ) )
78  {
80  }
81  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
82  {
84  }
85  else
86  {
88  }
89 
90  mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size" ), 3 ).toInt();
91 
92  if ( !mRenderer )
93  return;
94 
95  QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
96 
97  if ( mDrawVertexMarkers )
98  {
99  // set editing vertex markers style
101  }
102 
104 
105  mAttrNames = mRenderer->usedAttributes( context );
106 
107  //register label and diagram layer to the labeling engine
108  prepareLabeling( layer, mAttrNames );
109  prepareDiagrams( layer, mAttrNames );
110 
111 }
112 
113 
115 {
116  delete mRenderer;
117  delete mSource;
118 }
119 
120 
122 {
124  return true;
125 
126  if ( !mRenderer )
127  {
128  mErrors.append( QObject::tr( "No renderer for drawing." ) );
129  return false;
130  }
131 
132  bool usingEffect = false;
134  {
135  usingEffect = true;
137  }
138 
139  // Per feature blending mode
140  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
141  {
142  // set the painter to the feature blend mode, so that features drawn
143  // on this layer will interact and blend with each other
144  mContext.painter()->setCompositionMode( mFeatureBlendMode );
145  }
146 
148 
149  QString rendererFilter = mRenderer->filter( mFields );
150 
151  QgsRectangle requestExtent = mContext.extent();
152  mRenderer->modifyRequestExtent( requestExtent, mContext );
153 
154  QgsFeatureRequest featureRequest = QgsFeatureRequest()
155  .setFilterRect( requestExtent )
158  if ( mRenderer->orderByEnabled() )
159  {
160  featureRequest.setOrderBy( mRenderer->orderBy() );
161  }
162 
163  const QgsFeatureFilterProvider *featureFilterProvider = mContext.featureFilterProvider();
164  if ( featureFilterProvider )
165  {
166  featureFilterProvider->filterFeatures( mLayer, featureRequest );
167  }
168  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
169  {
170  featureRequest.combineFilterExpression( rendererFilter );
171  }
172 
173  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
174  if ( mSimplifyGeometry )
175  {
176  double map2pixelTol = mSimplifyMethod.threshold();
177  bool validTransform = true;
178 
179  const QgsMapToPixel &mtp = mContext.mapToPixel();
180  map2pixelTol *= mtp.mapUnitsPerPixel();
182 
183  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
184  if ( ct.isValid() && !ct.isShortCircuited() )
185  {
186  try
187  {
188  QgsPoint center = mContext.extent().center();
189  double rectSize = ct.sourceCrs().isGeographic() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
190 
191  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
192  QgsRectangle targetRect = ct.transform( sourceRect );
193 
194  QgsDebugMsgLevel( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
195  QgsDebugMsgLevel( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
196 
197  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
198  {
199  QgsPoint minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
200  QgsPoint maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
201  QgsPoint minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
202  QgsPoint maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
203 
204  double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
205  double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
206 
207  QgsDebugMsgLevel( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
208  QgsDebugMsgLevel( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
209 
210  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
211  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
212  }
213  }
214  catch ( QgsCsException &cse )
215  {
216  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
217  validTransform = false;
218  }
219  }
220 
221  if ( validTransform )
222  {
223  QgsSimplifyMethod simplifyMethod;
225  simplifyMethod.setTolerance( map2pixelTol );
226  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
228  featureRequest.setSimplifyMethod( simplifyMethod );
229 
231  vectorMethod.setTolerance( map2pixelTol );
232  mContext.setVectorSimplifyMethod( vectorMethod );
233  }
234  else
235  {
236  QgsVectorSimplifyMethod vectorMethod;
238  mContext.setVectorSimplifyMethod( vectorMethod );
239  }
240  }
241  else
242  {
243  QgsVectorSimplifyMethod vectorMethod;
245  mContext.setVectorSimplifyMethod( vectorMethod );
246  }
247 
248  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
249  // Attach an interruption checker so that iterators that have potentially
250  // slow fetchFeature() implementations, such as in the WFS provider, can
251  // check it, instead of relying on just the mContext.renderingStopped() check
252  // in drawRenderer()
254 
256  drawRendererLevels( fit );
257  else
258  drawRenderer( fit );
259 
260  if ( usingEffect )
261  {
263  }
264 
265  return true;
266 }
267 
269 {
270  mCache = cache;
271 
272  if ( mCache )
273  {
274  // Destroy all cached geometries and clear the references to them
276  }
277 }
278 
279 
280 
281 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureIterator &fit )
282 {
284  mContext.expressionContext().appendScope( symbolScope );
285 
286  QgsFeature fet;
287  while ( fit.nextFeature( fet ) )
288  {
289  try
290  {
291  if ( mContext.renderingStopped() )
292  {
293  QgsDebugMsg( QString( "Drawing of vector layer %1 canceled." ).arg( layerId() ) );
294  break;
295  }
296 
297  if ( !fet.hasGeometry() )
298  continue; // skip features without geometry
299 
301 
302  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
303  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
304 
305  if ( mCache )
306  {
307  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
308  mCache->cacheGeometry( fet.id(), fet.geometry() );
309  }
310 
311  // render feature
312  bool rendered = mRenderer->renderFeature( fet, mContext, -1, sel, drawMarker );
313 
314  // labeling - register feature
315  if ( rendered )
316  {
317  // new labeling engine
319  {
320  std::unique_ptr<QgsGeometry> obstacleGeometry;
322 
323  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
324  {
325  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
326  }
327 
328  if ( !symbols.isEmpty() )
329  {
330  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
331  }
332 
333  if ( mLabelProvider )
334  {
335  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.get() );
336  }
337  if ( mDiagramProvider )
338  {
339  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.get() );
340  }
341  }
342  }
343  }
344  catch ( const QgsCsException &cse )
345  {
346  Q_UNUSED( cse );
347  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
348  .arg( fet.id() ).arg( cse.what() ) );
349  }
350  }
351 
353 
354  stopRenderer( nullptr );
355 }
356 
357 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
358 {
359  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
360 
361  QgsSingleSymbolRenderer *selRenderer = nullptr;
362  if ( !mSelectedFeatureIds.isEmpty() )
363  {
365  selRenderer->symbol()->setColor( mContext.selectionColor() );
367  selRenderer->startRender( mContext, mFields );
368  }
369 
371  mContext.expressionContext().appendScope( symbolScope );
372 
373  // 1. fetch features
374  QgsFeature fet;
375  while ( fit.nextFeature( fet ) )
376  {
377  if ( mContext.renderingStopped() )
378  {
379  qDebug( "rendering stop!" );
380  stopRenderer( selRenderer );
382  return;
383  }
384 
385  if ( !fet.hasGeometry() )
386  continue; // skip features without geometry
387 
390  if ( !sym )
391  {
392  continue;
393  }
394 
395  if ( !features.contains( sym ) )
396  {
397  features.insert( sym, QList<QgsFeature>() );
398  }
399  features[sym].append( fet );
400 
401  if ( mCache )
402  {
403  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
404  mCache->cacheGeometry( fet.id(), fet.geometry() );
405  }
406 
407  // new labeling engine
408  if ( mContext.labelingEngine() )
409  {
410  std::unique_ptr<QgsGeometry> obstacleGeometry;
412 
413  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
414  {
415  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
416  }
417 
418  if ( !symbols.isEmpty() )
419  {
420  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
421  }
422 
423  if ( mLabelProvider )
424  {
425  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.get() );
426  }
427  if ( mDiagramProvider )
428  {
429  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.get() );
430  }
431  }
432  }
433 
435 
436  // find out the order
437  QgsSymbolLevelOrder levels;
438  QgsSymbolList symbols = mRenderer->symbols( mContext );
439  for ( int i = 0; i < symbols.count(); i++ )
440  {
441  QgsSymbol *sym = symbols[i];
442  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
443  {
444  int level = sym->symbolLayer( j )->renderingPass();
445  if ( level < 0 || level >= 1000 ) // ignore invalid levels
446  continue;
447  QgsSymbolLevelItem item( sym, j );
448  while ( level >= levels.count() ) // append new empty levels
449  levels.append( QgsSymbolLevel() );
450  levels[level].append( item );
451  }
452  }
453 
454  // 2. draw features in correct order
455  for ( int l = 0; l < levels.count(); l++ )
456  {
457  QgsSymbolLevel &level = levels[l];
458  for ( int i = 0; i < level.count(); i++ )
459  {
460  QgsSymbolLevelItem &item = level[i];
461  if ( !features.contains( item.symbol() ) )
462  {
463  QgsDebugMsg( "level item's symbol not found!" );
464  continue;
465  }
466  int layer = item.layer();
467  QList<QgsFeature> &lst = features[item.symbol()];
468  QList<QgsFeature>::iterator fit;
469  for ( fit = lst.begin(); fit != lst.end(); ++fit )
470  {
471  if ( mContext.renderingStopped() )
472  {
473  stopRenderer( selRenderer );
474  return;
475  }
476 
477  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fit->id() );
478  // maybe vertex markers should be drawn only during the last pass...
479  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
480 
482 
483  try
484  {
485  mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker );
486  }
487  catch ( const QgsCsException &cse )
488  {
489  Q_UNUSED( cse );
490  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
491  .arg( fet.id() ).arg( cse.what() ) );
492  }
493  }
494  }
495  }
496 
497  stopRenderer( selRenderer );
498 }
499 
500 
501 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer *selRenderer )
502 {
504  if ( selRenderer )
505  {
506  selRenderer->stopRender( mContext );
507  delete selRenderer;
508  }
509 }
510 
511 
512 
513 
514 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
515 {
516  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
517  {
518  if ( layer->labeling() )
519  {
520  mLabelProvider = layer->labeling()->provider( layer );
521  if ( mLabelProvider )
522  {
523  engine2->addProvider( mLabelProvider );
524  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
525  {
526  engine2->removeProvider( mLabelProvider );
527  mLabelProvider = nullptr; // deleted by engine
528  }
529  }
530  }
531  }
532 
533 #if 0 // TODO: limit of labels, font not found
535 
536  // see if feature count limit is set for labeling
537  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
538  {
539  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
540  .setFilterRect( mContext.extent() )
541  .setSubsetOfAttributes( QgsAttributeList() ) );
542 
543  // total number of features that may be labeled
544  QgsFeature f;
545  int nFeatsToLabel = 0;
546  while ( fit.nextFeature( f ) )
547  {
548  nFeatsToLabel++;
549  }
550  palyr.mFeaturesToLabel = nFeatsToLabel;
551  }
552 
553  // notify user about any font substitution
554  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
555  {
556  emit labelingFontNotFound( this, palyr.mTextFontFamily );
557  mLabelFontNotFoundNotified = true;
558  }
559 #endif
560 }
561 
562 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
563 {
564  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
565  {
566  if ( layer->diagramsEnabled() )
567  {
569  // need to be added before calling prepare() - uses map settings from engine
570  engine2->addProvider( mDiagramProvider );
571  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
572  {
573  engine2->removeProvider( mDiagramProvider );
574  mDiagramProvider = nullptr; // deleted by engine
575  }
576  }
577  }
578 }
579 
580 /* ----------------------------------------- */
581 /* QgsVectorLayerRendererInterruptionChecker */
582 /* ----------------------------------------- */
583 
585 ( const QgsRenderContext &context )
586  : mContext( context )
587 {
588 }
589 
591 {
592  return mContext.renderingStopped();
593 }
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
double y
Definition: qgspoint.h:42
QgsPoint center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:146
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:36
The geometries can be simplified using the current map2pixel context state.
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:144
void setGeometryCachePointer(QgsGeometryCache *cache)
where to save the cached geometries
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)
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
void setCachedGeometriesRect(const QgsRectangle &extent)
QgsVectorSimplifyMethod mSimplifyMethod
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:201
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:38
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:34
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:41
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
return new default symbol for specified geometry type
Definition: qgssymbol.cpp:257
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.
QgsPoint transform(const QgsPoint &point, TransformDirection direction=ForwardTransform) const
Transform the point from the source CRS to the destination CRS.
QgsFeatureRenderer * mRenderer
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:37
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:126
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
QList< int > QgsAttributeList
float threshold() const
Gets the simplification threshold of the vector layer managed.
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.
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:314
A class to represent a point.
Definition: qgspoint.h:37
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.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures...
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
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:190
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:106
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.
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:216
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:218
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:73
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.
void cacheGeometry(QgsFeatureId fid, const QgsGeometry &geom)
store a geometry in the cache
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:314
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.
virtual Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:210
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:65
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const =0
Factory for label provider implementation.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
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.
void setColor(const QColor &color)
Definition: qgssymbol.cpp:419
virtual QString dump() const
Returns debug information about this renderer.
double x
Definition: qgspoint.h:41