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