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