QGIS API Documentation  2.99.0-Master (c42dad3)
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 "qgsfeatureiterator.h"
19 #include "diagram/qgsdiagram.h"
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 
39 #include <QSettings>
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  QSettings settings;
74  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "/qgis/digitizing/marker_only_for_selected" ), false ).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 
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 cancelled." ).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  if ( mContext.labelingEngine() )
318  {
319  if ( mLabeling )
320  {
322  }
323  if ( mDiagrams )
324  {
326  }
327  }
328  // new labeling engine
330  {
331  QScopedPointer<QgsGeometry> obstacleGeometry;
333 
334  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
335  {
336  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
337  }
338 
339  if ( !symbols.isEmpty() )
340  {
341  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
342  }
343 
344  if ( mLabelProvider )
345  {
346  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
347  }
348  if ( mDiagramProvider )
349  {
350  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
351  }
352  }
353  }
354  }
355  catch ( const QgsCsException &cse )
356  {
357  Q_UNUSED( cse );
358  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
359  .arg( fet.id() ).arg( cse.what() ) );
360  }
361  }
362 
364 
365  stopRenderer( nullptr );
366 }
367 
368 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator& fit )
369 {
370  QHash< QgsSymbol*, QList<QgsFeature> > features; // key = symbol, value = array of features
371 
372  QgsSingleSymbolRenderer* selRenderer = nullptr;
373  if ( !mSelectedFeatureIds.isEmpty() )
374  {
376  selRenderer->symbol()->setColor( mContext.selectionColor() );
378  selRenderer->startRender( mContext, mFields );
379  }
380 
382  mContext.expressionContext().appendScope( symbolScope );
383 
384  // 1. fetch features
385  QgsFeature fet;
386  while ( fit.nextFeature( fet ) )
387  {
388  if ( mContext.renderingStopped() )
389  {
390  qDebug( "rendering stop!" );
391  stopRenderer( selRenderer );
393  return;
394  }
395 
396  if ( !fet.hasGeometry() )
397  continue; // skip features without geometry
398 
401  if ( !sym )
402  {
403  continue;
404  }
405 
406  if ( !features.contains( sym ) )
407  {
408  features.insert( sym, QList<QgsFeature>() );
409  }
410  features[sym].append( fet );
411 
412  if ( mCache )
413  {
414  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
415  mCache->cacheGeometry( fet.id(), fet.geometry() );
416  }
417 
418  if ( mContext.labelingEngine() )
419  {
421  if ( mLabeling )
422  {
424  }
425  if ( mDiagrams )
426  {
428  }
429  }
430  // new labeling engine
431  if ( mContext.labelingEngineV2() )
432  {
433  QScopedPointer<QgsGeometry> obstacleGeometry;
435 
436  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
437  {
438  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
439  }
440 
441  if ( !symbols.isEmpty() )
442  {
443  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
444  }
445 
446  if ( mLabelProvider )
447  {
448  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
449  }
450  if ( mDiagramProvider )
451  {
452  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
453  }
454  }
455  }
456 
458 
459  // find out the order
460  QgsSymbolLevelOrder levels;
461  QgsSymbolList symbols = mRenderer->symbols( mContext );
462  for ( int i = 0; i < symbols.count(); i++ )
463  {
464  QgsSymbol* sym = symbols[i];
465  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
466  {
467  int level = sym->symbolLayer( j )->renderingPass();
468  if ( level < 0 || level >= 1000 ) // ignore invalid levels
469  continue;
470  QgsSymbolLevelItem item( sym, j );
471  while ( level >= levels.count() ) // append new empty levels
472  levels.append( QgsSymbolLevel() );
473  levels[level].append( item );
474  }
475  }
476 
477  // 2. draw features in correct order
478  for ( int l = 0; l < levels.count(); l++ )
479  {
480  QgsSymbolLevel& level = levels[l];
481  for ( int i = 0; i < level.count(); i++ )
482  {
483  QgsSymbolLevelItem& item = level[i];
484  if ( !features.contains( item.symbol() ) )
485  {
486  QgsDebugMsg( "level item's symbol not found!" );
487  continue;
488  }
489  int layer = item.layer();
490  QList<QgsFeature>& lst = features[item.symbol()];
491  QList<QgsFeature>::iterator fit;
492  for ( fit = lst.begin(); fit != lst.end(); ++fit )
493  {
494  if ( mContext.renderingStopped() )
495  {
496  stopRenderer( selRenderer );
497  return;
498  }
499 
500  bool sel = mSelectedFeatureIds.contains( fit->id() );
501  // maybe vertex markers should be drawn only during the last pass...
502  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
503 
505 
506  try
507  {
508  mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker );
509  }
510  catch ( const QgsCsException &cse )
511  {
512  Q_UNUSED( cse );
513  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
514  .arg( fet.id() ).arg( cse.what() ) );
515  }
516  }
517  }
518  }
519 
520  stopRenderer( selRenderer );
521 }
522 
523 
524 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer* selRenderer )
525 {
527  if ( selRenderer )
528  {
529  selRenderer->stopRender( mContext );
530  delete selRenderer;
531  }
532 }
533 
534 
535 
536 
537 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer* layer, QSet<QString>& attributeNames )
538 {
539  if ( !mContext.labelingEngine() )
540  {
541  if ( QgsLabelingEngine* engine2 = mContext.labelingEngineV2() )
542  {
543  if ( layer->labeling() )
544  {
545  mLabelProvider = layer->labeling()->provider( layer );
546  if ( mLabelProvider )
547  {
548  engine2->addProvider( mLabelProvider );
549  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
550  {
551  engine2->removeProvider( mLabelProvider );
552  mLabelProvider = nullptr; // deleted by engine
553  }
554  }
555  }
556  }
557  return;
558  }
559 
560  if ( mContext.labelingEngine()->prepareLayer( layer, attributeNames, mContext ) )
561  {
562  mLabeling = true;
563 
564 #if 0 // TODO: limit of labels, font not found
566 
567  // see if feature count limit is set for labeling
568  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
569  {
570  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
571  .setFilterRect( mContext.extent() )
572  .setSubsetOfAttributes( QgsAttributeList() ) );
573 
574  // total number of features that may be labeled
575  QgsFeature f;
576  int nFeatsToLabel = 0;
577  while ( fit.nextFeature( f ) )
578  {
579  nFeatsToLabel++;
580  }
581  palyr.mFeaturesToLabel = nFeatsToLabel;
582  }
583 
584  // notify user about any font substitution
585  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
586  {
587  emit labelingFontNotFound( this, palyr.mTextFontFamily );
588  mLabelFontNotFoundNotified = true;
589  }
590 #endif
591  }
592 }
593 
594 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer* layer, QSet<QString>& attributeNames )
595 {
596  if ( !mContext.labelingEngine() )
597  {
598  if ( QgsLabelingEngine* engine2 = mContext.labelingEngineV2() )
599  {
600  if ( layer->diagramsEnabled() )
601  {
603  // need to be added before calling prepare() - uses map settings from engine
604  engine2->addProvider( mDiagramProvider );
605  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
606  {
607  engine2->removeProvider( mDiagramProvider );
608  mDiagramProvider = nullptr; // deleted by engine
609  }
610  }
611  }
612  return;
613  }
614 
615  if ( !layer->diagramsEnabled() )
616  return;
617 
618  mDiagrams = true;
619 
620  mContext.labelingEngine()->prepareDiagramLayer( layer, attributeNames, mContext ); // will make internal copy of diagSettings + initialize it
621 
622 }
623 
624 /* ----------------------------------------- */
625 /* QgsVectorLayerRendererInterruptionChecker */
626 /* ----------------------------------------- */
627 
629 ( const QgsRenderContext& context )
630  : mContext( context )
631 {
632 }
633 
635 {
636  return mContext.renderingStopped();
637 }
QgsVectorLayerRendererInterruptionChecker mInterruptionChecker
QgsFeatureId id
Definition: qgsfeature.h:139
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:35
double y
Definition: qgspoint.h:116
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:221
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
QgsVectorLayer * mLayer
The rendered layer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
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 int prepareLayer(QgsVectorLayer *layer, QSet< QString > &attrNames, QgsRenderContext &ctx)=0
called when starting rendering of a layer
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:143
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:135
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:214
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:196
bool mLabeling
used with old labeling engine (QgsPalLabeling): whether labeling is enabled
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
virtual void registerFeature(const QString &layerID, QgsFeature &feat, QgsRenderContext &context)=0
called for every feature
QString what() const
Definition: qgsexception.h:36
QgsLabelingEngine * labelingEngineV2() const
Get access to new labeling engine (may be nullptr)
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:75
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
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:33
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
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.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
return new default symbol for specified geometry type
Definition: qgssymbol.cpp:266
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.
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:34
bool isEmpty() const
test if 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...
QgsLabelingEngineInterface * labelingEngine() const
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:123
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
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:113
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:323
A class to represent a point.
Definition: qgspoint.h:111
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.
const QgsFeatureFilterProvider * featureFilterProvider() const
Get the filter feature provider used for additional filtering of rendered features.
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:189
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:206
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
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:191
virtual void startRender(QgsRenderContext &context, const QgsFields &fields) override
Needs to be called when a new render cycle is started.
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
virtual QgsSymbolList symbols(QgsRenderContext &context)
Returns list of symbols used by the renderer.
Definition: qgsrenderer.h:215
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)
virtual void registerDiagramFeature(const QString &layerID, QgsFeature &feat, QgsRenderContext &context)
called for every diagram feature
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:217
QPainter * painter()
const QgsMapToPixel & mapToPixel() const
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request) override
Get an iterator for features matching the specified request.
QList< QgsSymbolLevelItem > QgsSymbolLevel
Definition: qgsrenderer.h:72
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.
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:40
virtual QSet< QString > usedAttributes() const =0
Return a list of attributes required by this renderer.
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
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:196
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:313
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:201
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:209
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
bool mDiagrams
used with new labeling engine (QgsPalLabeling): whether diagrams are enabled
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:428
virtual QString dump() const
Returns debug information about this renderer.
virtual int prepareDiagramLayer(QgsVectorLayer *layer, QSet< QString > &attrNames, QgsRenderContext &ctx)
adds a diagram layer to the labeling engine
double x
Definition: qgspoint.h:115