QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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"
39 
40 #include <QPicture>
41 
42 
44  : QgsMapLayerRenderer( layer->id() )
45  , mContext( context )
46  , mInterruptionChecker( qgis::make_unique< QgsVectorLayerRendererInterruptionChecker >( context ) )
47  , mLayer( layer )
48  , mFields( layer->fields() )
49  , mLabeling( false )
50  , mDiagrams( false )
51 {
52  mSource = new QgsVectorLayerFeatureSource( layer );
53 
54  mRenderer = layer->renderer() ? layer->renderer()->clone() : nullptr;
56 
57  mDrawVertexMarkers = nullptr != layer->editBuffer();
58 
59  mGeometryType = layer->geometryType();
60 
64 
65  QgsSettings settings;
66  mVertexMarkerOnlyForSelection = settings.value( QStringLiteral( "qgis/digitizing/marker_only_for_selected" ), true ).toBool();
67 
68  QString markerTypeString = settings.value( QStringLiteral( "qgis/digitizing/marker_style" ), "Cross" ).toString();
69  if ( markerTypeString == QLatin1String( "Cross" ) )
70  {
72  }
73  else if ( markerTypeString == QLatin1String( "SemiTransparentCircle" ) )
74  {
76  }
77  else
78  {
80  }
81 
82  mVertexMarkerSize = settings.value( QStringLiteral( "qgis/digitizing/marker_size_mm" ), 2.0 ).toDouble();
83 
84  if ( !mRenderer )
85  return;
86 
87  QgsDebugMsgLevel( "rendering v2:\n " + mRenderer->dump(), 2 );
88 
89  if ( mDrawVertexMarkers )
90  {
91  // set editing vertex markers style
93  }
95 
96  mAttrNames = mRenderer->usedAttributes( context );
97 
98  //register label and diagram layer to the labeling engine
99  prepareLabeling( layer, mAttrNames );
100  prepareDiagrams( layer, mAttrNames );
101 }
102 
103 
105 {
106  delete mRenderer;
107  delete mSource;
108 }
109 
111 {
112  return mInterruptionChecker.get();
113 }
114 
116 {
118  return true;
119 
120  if ( !mRenderer )
121  {
122  mErrors.append( QObject::tr( "No renderer for drawing." ) );
123  return false;
124  }
125 
126  bool usingEffect = false;
128  {
129  usingEffect = true;
131  }
132 
133  // Per feature blending mode
134  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
135  {
136  // set the painter to the feature blend mode, so that features drawn
137  // on this layer will interact and blend with each other
138  mContext.painter()->setCompositionMode( mFeatureBlendMode );
139  }
140 
142 
143  QString rendererFilter = mRenderer->filter( mFields );
144 
145  QgsRectangle requestExtent = mContext.extent();
146  mRenderer->modifyRequestExtent( requestExtent, mContext );
147 
148  QgsFeatureRequest featureRequest = QgsFeatureRequest()
149  .setFilterRect( requestExtent )
152  if ( mRenderer->orderByEnabled() )
153  {
154  featureRequest.setOrderBy( mRenderer->orderBy() );
155  }
156 
157  const QgsFeatureFilterProvider *featureFilterProvider = mContext.featureFilterProvider();
158  if ( featureFilterProvider )
159  {
160  featureFilterProvider->filterFeatures( mLayer, featureRequest );
161  }
162  if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String( "TRUE" ) )
163  {
164  featureRequest.combineFilterExpression( rendererFilter );
165  }
166 
167  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
168  if ( mSimplifyGeometry )
169  {
170  double map2pixelTol = mSimplifyMethod.threshold();
171  bool validTransform = true;
172 
173  const QgsMapToPixel &mtp = mContext.mapToPixel();
174  map2pixelTol *= mtp.mapUnitsPerPixel();
176 
177  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
178  if ( ct.isValid() && !ct.isShortCircuited() )
179  {
180  try
181  {
182  QgsPointXY center = mContext.extent().center();
183  double rectSize = ct.sourceCrs().isGeographic() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
184 
185  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
186  QgsRectangle targetRect = ct.transform( sourceRect );
187 
188  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ), 4 );
189  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ), 4 );
190 
191  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
192  {
193  QgsPointXY minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
194  QgsPointXY maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
195  QgsPointXY minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
196  QgsPointXY maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
197 
198  double sourceHypothenuse = std::sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
199  double targetHypothenuse = std::sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
200 
201  QgsDebugMsgLevel( QStringLiteral( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
202  QgsDebugMsgLevel( QStringLiteral( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
203 
204  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
205  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
206  }
207  }
208  catch ( QgsCsException &cse )
209  {
210  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
211  validTransform = false;
212  }
213  }
214 
215  if ( validTransform )
216  {
217  QgsSimplifyMethod simplifyMethod;
219  simplifyMethod.setTolerance( map2pixelTol );
220  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
222  featureRequest.setSimplifyMethod( simplifyMethod );
223 
225  vectorMethod.setTolerance( map2pixelTol );
226  mContext.setVectorSimplifyMethod( vectorMethod );
227  }
228  else
229  {
230  QgsVectorSimplifyMethod vectorMethod;
232  mContext.setVectorSimplifyMethod( vectorMethod );
233  }
234  }
235  else
236  {
237  QgsVectorSimplifyMethod vectorMethod;
239  mContext.setVectorSimplifyMethod( vectorMethod );
240  }
241 
242  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
243  // Attach an interruption checker so that iterators that have potentially
244  // slow fetchFeature() implementations, such as in the WFS provider, can
245  // check it, instead of relying on just the mContext.renderingStopped() check
246  // in drawRenderer()
248 
250  drawRendererLevels( fit );
251  else
252  drawRenderer( fit );
253 
254  if ( usingEffect )
255  {
257  }
258 
259  return true;
260 }
261 
262 
263 void QgsVectorLayerRenderer::drawRenderer( QgsFeatureIterator &fit )
264 {
266  mContext.expressionContext().appendScope( symbolScope );
267 
268  QgsFeature fet;
269  while ( fit.nextFeature( fet ) )
270  {
271  try
272  {
273  if ( mContext.renderingStopped() )
274  {
275  QgsDebugMsg( QStringLiteral( "Drawing of vector layer %1 canceled." ).arg( layerId() ) );
276  break;
277  }
278 
279  if ( !fet.hasGeometry() || fet.geometry().isEmpty() )
280  continue; // skip features without geometry
281 
283 
284  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
285  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
286 
287  // render feature
288  bool rendered = mRenderer->renderFeature( fet, mContext, -1, sel, drawMarker );
289 
290  // labeling - register feature
291  if ( rendered )
292  {
293  // new labeling engine
295  {
296  QgsGeometry obstacleGeometry;
298 
299  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
300  {
301  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
302  }
303 
304  if ( !symbols.isEmpty() )
305  {
306  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
307  }
308 
309  if ( mLabelProvider )
310  {
311  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry );
312  }
313  if ( mDiagramProvider )
314  {
315  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
316  }
317  }
318  }
319  }
320  catch ( const QgsCsException &cse )
321  {
322  Q_UNUSED( cse );
323  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
324  .arg( fet.id() ).arg( cse.what() ) );
325  }
326  }
327 
329 
330  stopRenderer( nullptr );
331 }
332 
333 void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
334 {
335  QHash< QgsSymbol *, QList<QgsFeature> > features; // key = symbol, value = array of features
336 
337  QgsSingleSymbolRenderer *selRenderer = nullptr;
338  if ( !mSelectedFeatureIds.isEmpty() )
339  {
341  selRenderer->symbol()->setColor( mContext.selectionColor() );
343  selRenderer->startRender( mContext, mFields );
344  }
345 
347  mContext.expressionContext().appendScope( symbolScope );
348 
349  // 1. fetch features
350  QgsFeature fet;
351  while ( fit.nextFeature( fet ) )
352  {
353  if ( mContext.renderingStopped() )
354  {
355  qDebug( "rendering stop!" );
356  stopRenderer( selRenderer );
358  return;
359  }
360 
361  if ( !fet.hasGeometry() )
362  continue; // skip features without geometry
363 
366  if ( !sym )
367  {
368  continue;
369  }
370 
371  if ( !features.contains( sym ) )
372  {
373  features.insert( sym, QList<QgsFeature>() );
374  }
375  features[sym].append( fet );
376 
377  // new labeling engine
379  {
380  QgsGeometry obstacleGeometry;
382 
383  if ( !symbols.isEmpty() && fet.geometry().type() == QgsWkbTypes::PointGeometry )
384  {
385  obstacleGeometry = QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols );
386  }
387 
388  if ( !symbols.isEmpty() )
389  {
390  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
391  }
392 
393  if ( mLabelProvider )
394  {
395  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry );
396  }
397  if ( mDiagramProvider )
398  {
399  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry );
400  }
401  }
402  }
403 
405 
406  if ( features.empty() )
407  {
408  // nothing to draw
409  stopRenderer( selRenderer );
410  return;
411  }
412 
413  // find out the order
414  QgsSymbolLevelOrder levels;
415  QgsSymbolList symbols = mRenderer->symbols( mContext );
416  for ( int i = 0; i < symbols.count(); i++ )
417  {
418  QgsSymbol *sym = symbols[i];
419  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
420  {
421  int level = sym->symbolLayer( j )->renderingPass();
422  if ( level < 0 || level >= 1000 ) // ignore invalid levels
423  continue;
424  QgsSymbolLevelItem item( sym, j );
425  while ( level >= levels.count() ) // append new empty levels
426  levels.append( QgsSymbolLevel() );
427  levels[level].append( item );
428  }
429  }
430 
431  // 2. draw features in correct order
432  for ( int l = 0; l < levels.count(); l++ )
433  {
434  QgsSymbolLevel &level = levels[l];
435  for ( int i = 0; i < level.count(); i++ )
436  {
437  QgsSymbolLevelItem &item = level[i];
438  if ( !features.contains( item.symbol() ) )
439  {
440  QgsDebugMsg( QStringLiteral( "level item's symbol not found!" ) );
441  continue;
442  }
443  int layer = item.layer();
444  QList<QgsFeature> &lst = features[item.symbol()];
445  QList<QgsFeature>::iterator fit;
446  for ( fit = lst.begin(); fit != lst.end(); ++fit )
447  {
448  if ( mContext.renderingStopped() )
449  {
450  stopRenderer( selRenderer );
451  return;
452  }
453 
454  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fit->id() );
455  // maybe vertex markers should be drawn only during the last pass...
456  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
457 
459 
460  try
461  {
462  mRenderer->renderFeature( *fit, mContext, layer, sel, drawMarker );
463  }
464  catch ( const QgsCsException &cse )
465  {
466  Q_UNUSED( cse );
467  QgsDebugMsg( QStringLiteral( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
468  .arg( fet.id() ).arg( cse.what() ) );
469  }
470  }
471  }
472  }
473 
474  stopRenderer( selRenderer );
475 }
476 
477 
478 void QgsVectorLayerRenderer::stopRenderer( QgsSingleSymbolRenderer *selRenderer )
479 {
481  if ( selRenderer )
482  {
483  selRenderer->stopRender( mContext );
484  delete selRenderer;
485  }
486 }
487 
488 
489 
490 
491 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer *layer, QSet<QString> &attributeNames )
492 {
493  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
494  {
495  if ( layer->labelsEnabled() )
496  {
497  mLabelProvider = layer->labeling()->provider( layer );
498  if ( mLabelProvider )
499  {
500  engine2->addProvider( mLabelProvider );
501  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
502  {
503  engine2->removeProvider( mLabelProvider );
504  mLabelProvider = nullptr; // deleted by engine
505  }
506  }
507  }
508  }
509 
510 #if 0 // TODO: limit of labels, font not found
512 
513  // see if feature count limit is set for labeling
514  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
515  {
516  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
517  .setFilterRect( mContext.extent() )
518  .setNoAttributes() );
519 
520  // total number of features that may be labeled
521  QgsFeature f;
522  int nFeatsToLabel = 0;
523  while ( fit.nextFeature( f ) )
524  {
525  nFeatsToLabel++;
526  }
527  palyr.mFeaturesToLabel = nFeatsToLabel;
528  }
529 
530  // notify user about any font substitution
531  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
532  {
533  emit labelingFontNotFound( this, palyr.mTextFontFamily );
534  mLabelFontNotFoundNotified = true;
535  }
536 #endif
537 }
538 
539 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer *layer, QSet<QString> &attributeNames )
540 {
541  if ( QgsLabelingEngine *engine2 = mContext.labelingEngine() )
542  {
543  if ( layer->diagramsEnabled() )
544  {
546  // need to be added before calling prepare() - uses map settings from engine
547  engine2->addProvider( mDiagramProvider );
548  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
549  {
550  engine2->removeProvider( mDiagramProvider );
551  mDiagramProvider = nullptr; // deleted by engine
552  }
553  }
554  }
555 }
556 
557 /* ----------------------------------------- */
558 /* QgsVectorLayerRendererInterruptionChecker */
559 /* ----------------------------------------- */
560 
562 ( const QgsRenderContext &context )
563  : mContext( context )
564  , mTimer( new QTimer( this ) )
565 {
566  connect( mTimer, &QTimer::timeout, this, [ = ]
567  {
568  if ( mContext.renderingStopped() )
569  {
570  mTimer->stop();
571  cancel();
572  }
573  } );
574  mTimer->start( 50 );
575 
576 }
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.
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
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:40
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:425
float threshold() const
Gets the simplification threshold of the vector layer managed.
QgsVectorLayer * mLayer
The rendered layer.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
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
QColor selectionColor() const
Returns the color to use when rendering selected features.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
Definition: qgsrectangle.h:515
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:171
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.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:150
The geometries can be simplified using the current map2pixel context state.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from...
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
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:278
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) override
Gets an iterator for features matching the specified request.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
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.
bool usingSymbolLevels() const
Definition: qgsrenderer.h:271
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
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr)
bool enabled() const
Returns whether the effect is enabled.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QPainter::CompositionMode mFeatureBlendMode
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
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 null)
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent...
QgsVectorSimplifyMethod mSimplifyMethod
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
QList< QgsSymbolLevel > QgsSymbolLevelOrder
Definition: qgsrenderer.h:77
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
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:36
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.
QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on...
No simplification can be applied.
QgsVectorLayerRendererInterruptionChecker(const QgsRenderContext &context)
Constructor.
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:43
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:275
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:176
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
QgsFeatureRenderer * mRenderer
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:161
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
bool renderingStopped() const
Returns TRUE if the rendering operation has been stopped and any ongoing rendering should be canceled...
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.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
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...
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:229
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsVectorLayerFeatureSource * mSource
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
double mapUnitsPerPixel() const
Returns current map units per pixel.
int renderingPass() const
Abstract interface for use by classes that filter the features of a layer.
QgsFeatureRenderer * renderer()
Returns renderer.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layer contained in the symbol.
Definition: qgssymbol.cpp:340
bool drawEditingInformation() const
Returns TRUE if edit markers should be drawn during the render operation.
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
double x
Definition: qgspointxy.h:47
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
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
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
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)
QString what() const
Definition: qgsexception.h:48
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
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...
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
virtual QString dump() const
Returns debug information about this renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:92
void setMethodType(MethodType methodType)
Sets the simplification type.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
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.
const QgsMapToPixel & mapToPixel() const
Returns the context&#39;s map to pixel transform, which transforms between map coordinates and device coo...
Base class for utility classes that encapsulate information necessary for rendering of map layers...
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
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.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
QgsGeometry geometry
Definition: qgsfeature.h:67
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
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)
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
QgsVectorLayerDiagramProvider * mDiagramProvider
used with new labeling engine (QgsLabelingEngine): provider for diagrams.
Represents a vector layer which manages a vector based data sets.
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
bool isGeographic() const
Returns whether the CRS is a geographic CRS (using lat/lon coordinates)
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:166
QgsSymbol * symbol()
Definition: qgsrenderer.h:65
QString layerId() const
Gets access to the ID of the layer rendered by this class.
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.
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.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
void setColor(const QColor &color)
Sets the color for the symbol.
Definition: qgssymbol.cpp:450