QGIS API Documentation  3.9.0-Master (224899f119)
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"
41 
42 #include <QPicture>
43 
44 
46  : QgsMapLayerRenderer( layer->id() )
47  , mContext( 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 
63 
64  // if there's already a simplification method specified via the context, we respect that. Otherwise, we fall back
65  // to the layer's individual setting
67  {
71  }
72  else
73  {
76  }
77 
78  QgsSettings settings;
79  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "qgis/digitizing/marker_only_for_selected" ), true ).toBool();
80 
81  QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
82  if ( markerTypeString == QLatin1String( "Cross" ) )
83  {
85  }
86  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
87  {
89  }
90  else
91  {
93  }
94 
95  mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size_mm" ), 2.0 ).toDouble();
96 
97  if ( !mRenderer )
98  return;
99 
100  QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
101 
102  if ( mDrawVertexMarkers )
103  {
104  // set editing vertex markers style
106  }
108 
109  mAttrNames = mRenderer->usedAttributes( context );
110  if ( context.hasRenderedFeatureHandlers() )
111  {
112  const QList< QgsRenderedFeatureHandlerInterface * > handlers = context.renderedFeatureHandlers();
113  for ( QgsRenderedFeatureHandlerInterface *handler : handlers )
114  mAttrNames.unite( handler->usedAttributes( layer, context ) );
115  }
116 
117  //register label and diagram layer to the labeling engine
118  prepareLabeling( layer, mAttrNames );
119  prepareDiagrams( layer, mAttrNames );
120 }
121 
122 
124 {
125  delete mRenderer;
126  delete mSource;
127 }
128 
130 {
131  return mInterruptionChecker.get();
132 }
133 
135 {
137  return true;
138 
139  if ( !mRenderer )
140  {
141  mErrors.append( QObject::tr( "No renderer for drawing." ) );
142  return false;
143  }
144 
145  if ( mRenderer->type() == QStringLiteral( "nullSymbol" ) )
146  {
147  // a little shortcut for the null symbol renderer - most of the time it is not going to render anything
148  // so we can even skip the whole loop to fetch features
150  return true;
151  }
152 
153  // MUST be created in the thread doing the rendering
154  mInterruptionChecker = qgis::make_unique< QgsVectorLayerRendererInterruptionChecker >( mContext );
155  bool usingEffect = false;
157  {
158  usingEffect = true;
160  }
161 
162  // Per feature blending mode
163  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
164  {
165  // set the painter to the feature blend mode, so that features drawn
166  // on this layer will interact and blend with each other
167  mContext.painter()->setCompositionMode( mFeatureBlendMode );
168  }
169 
171 
172  QString rendererFilter = mRenderer->filter( mFields );
173 
174  QgsRectangle requestExtent = mContext.extent();
175  mRenderer->modifyRequestExtent( requestExtent, mContext );
176 
177  QgsFeatureRequest featureRequest = QgsFeatureRequest()
178  .setFilterRect( requestExtent )
181  if ( mRenderer->orderByEnabled() )
182  {
183  featureRequest.setOrderBy( mRenderer->orderBy() );
184  }
185 
186  const QgsFeatureFilterProvider *featureFilterProvider = mContext.featureFilterProvider();
187  if ( featureFilterProvider )
188  {
189  featureFilterProvider->filterFeatures( mLayer, featureRequest );
190  }
191  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
192  {
193  featureRequest.combineFilterExpression( rendererFilter );
194  }
195 
196  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
197  if ( mSimplifyGeometry )
198  {
199  double map2pixelTol = mSimplifyMethod.threshold();
200  bool validTransform = true;
201 
202  const QgsMapToPixel &mtp = mContext.mapToPixel();
203  map2pixelTol *= mtp.mapUnitsPerPixel();
205 
206  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
207  if ( ct.isValid() && !ct.isShortCircuited() )
208  {
209  try
210  {
211  QgsPointXY center = mContext.extent().center();
212  double rectSize = ct.sourceCrs().isGeographic() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
213 
214  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
215  QgsRectangle targetRect = ct.transform( sourceRect );
216 
217  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
218  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
219 
220  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
221  {
222  QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
223  QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
224  QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
225  QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
226 
227  double sourceHypothenuse = std::sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
228  double targetHypothenuse = std::sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
229 
230  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
231  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
232 
233  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
234  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
235  }
236  }
237  catch ( QgsCsException &cse )
238  {
239  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
240  validTransform = false;
241  }
242  }
243 
244  if ( validTransform )
245  {
246  QgsSimplifyMethod simplifyMethod;
248  simplifyMethod.setTolerance( map2pixelTol );
249  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
251  featureRequest.setSimplifyMethod( simplifyMethod );
252 
254  vectorMethod.setTolerance( map2pixelTol );
255  mContext.setVectorSimplifyMethod( vectorMethod );
256  }
257  else
258  {
259  QgsVectorSimplifyMethod vectorMethod;
261  mContext.setVectorSimplifyMethod( vectorMethod );
262  }
263  }
264  else
265  {
266  QgsVectorSimplifyMethod vectorMethod;
268  mContext.setVectorSimplifyMethod( vectorMethod );
269  }
270 
271  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
272  // Attach an interruption checker so that iterators that have potentially
273  // slow fetchFeature() implementations, such as in the WFS provider, can
274  // check it, instead of relying on just the mContext.renderingStopped() check
275  // in drawRenderer()
277 
279  drawRendererLevels( fit );
280  else
281  drawRenderer( fit );
282 
283  if ( !fit.isValid() )
284  {
285  mErrors.append( QStringLiteral( "Data source invalid" ) );
286  }
287 
288  if ( usingEffect )
289  {
291  }
292 
293  mInterruptionChecker.reset();
294  return true;
295 }
296 
297 
298 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureIterator &fit )
299 {
301  mContext.expressionContext().appendScope( symbolScope );
302 
303  QgsFeature fet;
304  while ( fit.nextFeature( fet ) )
305  {
306  try
307  {
308  if ( mContext.renderingStopped() )
309  {
310  QgsDebugMsg( QStringLiteral( "Drawing of vector layer %1 canceled." ).arg( layerId() ) );
311  break;
312  }
313 
314  if ( !fet.hasGeometry() || fet.geometry().isEmpty() )
315  continue; // skip features without geometry
316 
318 
319  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
320  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
321 
322  // render feature
323  bool rendered = mRenderer->renderFeature( fet, mContext, -1, sel, drawMarker );
324 
325  // labeling - register feature
326  if ( rendered )
327  {
328  // new labeling engine
330  {
331  QgsGeometry obstacleGeometry;
333  QgsSymbol *symbol = nullptr;
334  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
335  {
336  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
337  }
338 
339  if ( !symbols.isEmpty() )
340  {
341  symbol = symbols.at( 0 );
342  QgsExpressionContextUtils::updateSymbolScope( symbol, symbolScope );
343  }
344 
345  if ( mLabelProvider )
346  {
347  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry, symbol );
348  }
349  if ( mDiagramProvider )
350  {
351  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
352  }
353  }
354  }
355  }
356  catch ( const QgsCsException &cse )
357  {
358  Q_UNUSED( cse )
359  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
360  .arg( fet.id() ).arg( cse.what() ) );
361  }
362  }
363 
365 
366  stopRenderer( nullptr );
367 }
368 
369 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
370 {
371  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
372 
373  QgsSingleSymbolRenderer *selRenderer = nullptr;
374  if ( !mSelectedFeatureIds.isEmpty() )
375  {
377  selRenderer->symbol()->setColor( mContext.selectionColor() );
379  selRenderer->startRender( mContext, mFields );
380  }
381 
383  std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = qgis::make_unique< QgsExpressionContextScopePopper >( mContext.expressionContext(), symbolScope );
384 
385  // 1. fetch features
386  QgsFeature fet;
387  while ( fit.nextFeature( fet ) )
388  {
389  if ( mContext.renderingStopped() )
390  {
391  qDebug( "rendering stop!" );
392  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  // new labeling engine
414  {
415  QgsGeometry obstacleGeometry;
417  std::unique_ptr< QgsSymbol > symbol;
418  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
419  {
420  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
421  }
422 
423  if ( !symbols.isEmpty() )
424  {
425  symbol.reset( symbols.at( 0 )->clone() );
426  QgsExpressionContextUtils::updateSymbolScope( symbol.get(), symbolScope );
427  }
428 
429  if ( mLabelProvider )
430  {
431  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry, symbol.release() );
432  }
433  if ( mDiagramProvider )
434  {
435  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
436  }
437  }
438  }
439 
440  scopePopper.reset();
441 
442  if ( features.empty() )
443  {
444  // nothing to draw
445  stopRenderer( selRenderer );
446  return;
447  }
448 
449  // find out the order
450  QgsSymbolLevelOrder levels;
451  QgsSymbolList symbols = mRenderer->symbols( mContext );
452  for ( int i = 0; i < symbols.count(); i++ )
453  {
454  QgsSymbol *sym = symbols[i];
455  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
456  {
457  int level = sym->symbolLayer( j )->renderingPass();
458  if ( level < 0 || level >= 1000 ) // ignore invalid levels
459  continue;
460  QgsSymbolLevelItem item( sym, j );
461  while ( level >= levels.count() ) // append new empty levels
462  levels.append( QgsSymbolLevel() );
463  levels[level].append( item );
464  }
465  }
466 
467  // 2. draw features in correct order
468  for ( int l = 0; l < levels.count(); l++ )
469  {
470  QgsSymbolLevel &level = levels[l];
471  for ( int i = 0; i < level.count(); i++ )
472  {
473  QgsSymbolLevelItem &item = level[i];
474  if ( !features.contains( item.symbol() ) )
475  {
476  QgsDebugMsg( QStringLiteral( "level item's symbol not found!" ) );
477  continue;
478  }
479  int layer = item.layer();
480  QList<QgsFeature> &lst = features[item.symbol()];
481  QList<QgsFeature>::iterator fit;
482  for ( fit = lst.begin(); fit != lst.end(); ++fit )
483  {
484  if ( mContext.renderingStopped() )
485  {
486  stopRenderer( selRenderer );
487  return;
488  }
489 
490  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fit->id() );
491  // maybe vertex markers should be drawn only during the last pass...
492  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
493 
495 
496  try
497  {
498  mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker );
499  }
500  catch ( const QgsCsException &cse )
501  {
502  Q_UNUSED( cse )
503  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
504  .arg( fet.id() ).arg( cse.what() ) );
505  }
506  }
507  }
508  }
509 
510  stopRenderer( selRenderer );
511 }
512 
513 
514 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer *selRenderer )
515 {
517  if ( selRenderer )
518  {
519  selRenderer->stopRender( mContext );
520  delete selRenderer;
521  }
522 }
523 
524 
525 
526 
527 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
528 {
529  // TODO: add attributes for geometry generator
530  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
531  {
532  if ( layer->labelsEnabled() )
533  {
534  mLabelProvider = layer->labeling()->provider( layer );
535  if ( mLabelProvider )
536  {
537  engine2->addProvider( mLabelProvider );
538  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
539  {
540  engine2->removeProvider( mLabelProvider );
541  mLabelProvider = nullptr; // deleted by engine
542  }
543  }
544  }
545  }
546 
547 #if 0 // TODO: limit of labels, font not found
549 
550  // see if feature count limit is set for labeling
551  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
552  {
553  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
554  .setFilterRect( mContext.extent() )
555  .setNoAttributes() );
556 
557  // total number of features that may be labeled
558  QgsFeature f;
559  int nFeatsToLabel = 0;
560  while ( fit.nextFeature( f ) )
561  {
562  nFeatsToLabel++;
563  }
564  palyr.mFeaturesToLabel = nFeatsToLabel;
565  }
566 
567  // notify user about any font substitution
568  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
569  {
570  emit labelingFontNotFound( this, palyr.mTextFontFamily );
571  mLabelFontNotFoundNotified = true;
572  }
573 #endif
574 }
575 
576 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
577 {
578  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
579  {
580  if ( layer->diagramsEnabled() )
581  {
583  // need to be added before calling prepare() - uses map settings from engine
584  engine2->addProvider( mDiagramProvider );
585  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
586  {
587  engine2->removeProvider( mDiagramProvider );
588  mDiagramProvider = nullptr; // deleted by engine
589  }
590  }
591  }
592 }
593 
594 /* ----------------------------------------- */
595 /* QgsVectorLayerRendererInterruptionChecker */
596 /* ----------------------------------------- */
597 
599 ( const QgsRenderContext &context )
600  : mContext( context )
601  , mTimer( new QTimer( this ) )
602 {
603  connect( mTimer, &QTimer::timeout, this, [ = ]
604  {
605  if ( mContext.renderingStopped() )
606  {
607  mTimer->stop();
608  cancel();
609  }
610  } );
611  mTimer->start( 50 );
612 
613 }
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.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
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)
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
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
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:194
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)
Sets the simplification setting to use when rendering vector layers.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:121
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:173
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
All simplification hints can be applied ( Geometry + AA-disabling )
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:78
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:44
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:294
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
QString type() const
Definition: qgsrenderer.h:130
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...
An interface for classes which provider custom handlers for features rendered as part of a map render...
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 the symbol layer at the specified index.
Definition: qgssymbol.cpp:359
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...
virtual void registerFeature(const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
Definition: qgsrenderer.h:243
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:272
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:74
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.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
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:125
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:66
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:263
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:471
virtual QString dump() const
Returns debug information about this renderer.