QGIS API Documentation  2.15.0-Master (13f053b)
qgsvectorlayerrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerrenderer.cpp
3  --------------------------------------
4  Date : December 2013
5  Copyright : (C) 2013 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsvectorlayerrenderer.h"
17 
18 //#include "qgsfeatureiterator.h"
19 #include "diagram/qgsdiagram.h"
20 #include "qgsdiagramrendererv2.h"
21 #include "qgsgeometrycache.h"
22 #include "qgsmessagelog.h"
23 #include "qgspallabeling.h"
24 #include "qgsrendererv2.h"
25 #include "qgsrendercontext.h"
27 #include "qgssymbollayerv2.h"
28 #include "qgssymbolv2.h"
29 #include "qgsvectorlayer.h"
32 #include "qgsvectorlayerlabeling.h"
34 #include "qgspainteffect.h"
36 
37 #include <QSettings>
38 #include <QPicture>
39 
40 // TODO:
41 // - passing of cache to QgsVectorLayer
42 
43 
45  : QgsMapLayerRenderer( layer->id() )
46  , mContext( context )
47  , mInterruptionChecker( context )
48  , mLayer( layer )
49  , mFields( layer->fields() )
50  , mRendererV2( nullptr )
51  , mCache( nullptr )
52  , mLabeling( false )
53  , mDiagrams( false )
54  , mLabelProvider( nullptr )
55  , mDiagramProvider( nullptr )
56  , mLayerTransparency( 0 )
57 {
58  mSource = new QgsVectorLayerFeatureSource( layer );
59 
60  mRendererV2 = layer->rendererV2() ? layer->rendererV2()->clone() : nullptr;
62 
63  mDrawVertexMarkers = nullptr != layer->editBuffer();
64 
65  mGeometryType = layer->geometryType();
66 
69 
72 
73  QSettings settings;
74  mVertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();
75 
76  QString markerTypeString = settings.value( "/qgis/digitizing/marker_style", "Cross" ).toString();
77  if ( markerTypeString == "Cross" )
78  {
80  }
81  else if ( markerTypeString == "SemiTransparentCircle" )
82  {
84  }
85  else
86  {
88  }
89 
90  mVertexMarkerSize = settings.value( "/qgis/digitizing/marker_size", 3 ).toInt();
91 
92  if ( !mRendererV2 )
93  return;
94 
95  QgsDebugMsg( "rendering v2:\n " + mRendererV2->dump() );
96 
97  if ( mDrawVertexMarkers )
98  {
99  // set editing vertex markers style
101  }
102 
104 
106 
107  //register label and diagram layer to the labeling engine
108  prepareLabeling( layer, mAttrNames );
109  prepareDiagrams( layer, mAttrNames );
110 
111 }
112 
113 
115 {
116  delete mRendererV2;
117  delete mSource;
118 }
119 
120 
122 {
124  return true;
125 
126  if ( !mRendererV2 )
127  {
128  mErrors.append( QObject::tr( "No renderer for drawing." ) );
129  return false;
130  }
131 
132  bool usingEffect = false;
134  {
135  usingEffect = true;
137  }
138 
139  // Per feature blending mode
140  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
141  {
142  // set the painter to the feature blend mode, so that features drawn
143  // on this layer will interact and blend with each other
145  }
146 
148 
149  QString rendererFilter = mRendererV2->filter( mFields );
150 
151  QgsRectangle requestExtent = mContext.extent();
152  mRendererV2->modifyRequestExtent( requestExtent, mContext );
153 
154  QgsFeatureRequest featureRequest = QgsFeatureRequest()
155  .setFilterRect( requestExtent )
158  if ( mRendererV2->orderByEnabled() )
159  {
160  featureRequest.setOrderBy( mRendererV2->orderBy() );
161  }
162 
163  const QgsFeatureFilterProvider* featureFilterProvider = mContext.featureFilterProvider();
164  if ( featureFilterProvider )
165  {
166  featureFilterProvider->filterFeatures( mLayer, featureRequest );
167  }
168  if ( !rendererFilter.isEmpty() && rendererFilter != "TRUE" )
169  {
170  featureRequest.combineFilterExpression( rendererFilter );
171  }
172 
173  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
174  if ( mSimplifyGeometry )
175  {
176  double map2pixelTol = mSimplifyMethod.threshold();
177  bool validTransform = true;
178 
179  const QgsMapToPixel& mtp = mContext.mapToPixel();
180  map2pixelTol *= mtp.mapUnitsPerPixel();
182 
183  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
184  if ( ct && !( ct->isShortCircuited() ) )
185  {
186  try
187  {
188  QgsPoint center = mContext.extent().center();
189  double rectSize = ct->sourceCrs().geographicFlag() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
190 
191  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
192  QgsRectangle targetRect = ct->transform( sourceRect );
193 
194  QgsDebugMsg( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ) );
195  QgsDebugMsg( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ) );
196 
197  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
198  {
199  QgsPoint minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
200  QgsPoint maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
201  QgsPoint minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
202  QgsPoint maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
203 
204  double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
205  double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
206 
207  QgsDebugMsg( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ) );
208  QgsDebugMsg( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ) );
209 
210  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
211  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
212  }
213  }
214  catch ( QgsCsException &cse )
215  {
216  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
217  validTransform = false;
218  }
219  }
220 
221  if ( validTransform )
222  {
223  QgsSimplifyMethod simplifyMethod;
225  simplifyMethod.setTolerance( map2pixelTol );
226  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
227 
229 
230  featureRequest.setSimplifyMethod( simplifyMethod );
231 
233  mContext.setVectorSimplifyMethod( vectorMethod );
234  }
235  else
236  {
237  QgsVectorSimplifyMethod vectorMethod;
239  mContext.setVectorSimplifyMethod( vectorMethod );
240  }
241  }
242  else
243  {
244  QgsVectorSimplifyMethod vectorMethod;
246  mContext.setVectorSimplifyMethod( vectorMethod );
247  }
248 
249  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
250  // Attach an interruption checker so that iterators that have potentially
251  // slow fetchFeature() implementations, such as in the WFS provider, can
252  // check it, instead of relying on just the mContext.renderingStopped() check
253  // in drawRendererV2()
255 
257  drawRendererV2Levels( fit );
258  else
259  drawRendererV2( fit );
260 
261  if ( usingEffect )
262  {
264  }
265 
266  //apply layer transparency for vector layers
268  {
269  // a layer transparency has been set, so update the alpha for the flattened layer
270  // by combining it with the layer transparency
271  QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * mLayerTransparency / 100 ) );
272  // use destination in composition mode to merge source's alpha with destination
273  mContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
275  mContext.painter()->device()->height(), transparentFillColor );
276  }
277 
278  return true;
279 }
280 
282 {
283  mCache = cache;
284 
285  if ( mCache )
286  {
287  // Destroy all cached geometries and clear the references to them
289  }
290 }
291 
292 
293 
294 void QgsVectorLayerRenderer::drawRendererV2( QgsFeatureIterator& fit )
295 {
297  mContext.expressionContext().appendScope( symbolScope );
298 
299  QgsFeature fet;
300  while ( fit.nextFeature( fet ) )
301  {
302  try
303  {
304  if ( mContext.renderingStopped() )
305  {
306  QgsDebugMsg( QString( "Drawing of vector layer %1 cancelled." ).arg( layerID() ) );
307  break;
308  }
309 
310  if ( !fet.constGeometry() )
311  continue; // skip features without geometry
312 
314 
315  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
316  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
317 
318  if ( mCache )
319  {
320  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
321  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
322  }
323 
324  // render feature
325  bool rendered = mRendererV2->renderFeature( fet, mContext, -1, sel, drawMarker );
326 
327  // labeling - register feature
328  if ( rendered )
329  {
330  if ( mContext.labelingEngine() )
331  {
332  if ( mLabeling )
333  {
335  }
336  if ( mDiagrams )
337  {
339  }
340  }
341  // new labeling engine
342  if ( mContext.labelingEngineV2() )
343  {
344  QScopedPointer<QgsGeometry> obstacleGeometry;
346 
347  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
348  {
349  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
350  }
351 
352  if ( !symbols.isEmpty() )
353  {
354  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
355  }
356 
357  if ( mLabelProvider )
358  {
359  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
360  }
361  if ( mDiagramProvider )
362  {
363  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
364  }
365  }
366  }
367  }
368  catch ( const QgsCsException &cse )
369  {
370  Q_UNUSED( cse );
371  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
372  .arg( fet.id() ).arg( cse.what() ) );
373  }
374  }
375 
377 
378  stopRendererV2( nullptr );
379 }
380 
381 void QgsVectorLayerRenderer::drawRendererV2Levels( QgsFeatureIterator& fit )
382 {
383  QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features
384 
385  QgsSingleSymbolRendererV2* selRenderer = nullptr;
386  if ( !mSelectedFeatureIds.isEmpty() )
387  {
389  selRenderer->symbol()->setColor( mContext.selectionColor() );
391  selRenderer->startRender( mContext, mFields );
392  }
393 
395  mContext.expressionContext().appendScope( symbolScope );
396 
397  // 1. fetch features
398  QgsFeature fet;
399  while ( fit.nextFeature( fet ) )
400  {
401  if ( mContext.renderingStopped() )
402  {
403  qDebug( "rendering stop!" );
404  stopRendererV2( selRenderer );
406  return;
407  }
408 
409  if ( !fet.constGeometry() )
410  continue; // skip features without geometry
411 
414  if ( !sym )
415  {
416  continue;
417  }
418 
419  if ( !features.contains( sym ) )
420  {
421  features.insert( sym, QList<QgsFeature>() );
422  }
423  features[sym].append( fet );
424 
425  if ( mCache )
426  {
427  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
428  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
429  }
430 
431  if ( mContext.labelingEngine() )
432  {
434  if ( mLabeling )
435  {
437  }
438  if ( mDiagrams )
439  {
441  }
442  }
443  // new labeling engine
444  if ( mContext.labelingEngineV2() )
445  {
446  QScopedPointer<QgsGeometry> obstacleGeometry;
448 
449  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
450  {
451  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
452  }
453 
454  if ( !symbols.isEmpty() )
455  {
456  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
457  }
458 
459  if ( mLabelProvider )
460  {
461  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
462  }
463  if ( mDiagramProvider )
464  {
465  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
466  }
467  }
468  }
469 
471 
472  // find out the order
473  QgsSymbolV2LevelOrder levels;
475  for ( int i = 0; i < symbols.count(); i++ )
476  {
477  QgsSymbolV2* sym = symbols[i];
478  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
479  {
480  int level = sym->symbolLayer( j )->renderingPass();
481  if ( level < 0 || level >= 1000 ) // ignore invalid levels
482  continue;
483  QgsSymbolV2LevelItem item( sym, j );
484  while ( level >= levels.count() ) // append new empty levels
485  levels.append( QgsSymbolV2Level() );
486  levels[level].append( item );
487  }
488  }
489 
490  // 2. draw features in correct order
491  for ( int l = 0; l < levels.count(); l++ )
492  {
493  QgsSymbolV2Level& level = levels[l];
494  for ( int i = 0; i < level.count(); i++ )
495  {
496  QgsSymbolV2LevelItem& item = level[i];
497  if ( !features.contains( item.symbol() ) )
498  {
499  QgsDebugMsg( "level item's symbol not found!" );
500  continue;
501  }
502  int layer = item.layer();
503  QList<QgsFeature>& lst = features[item.symbol()];
505  for ( fit = lst.begin(); fit != lst.end(); ++fit )
506  {
507  if ( mContext.renderingStopped() )
508  {
509  stopRendererV2( selRenderer );
510  return;
511  }
512 
513  bool sel = mSelectedFeatureIds.contains( fit->id() );
514  // maybe vertex markers should be drawn only during the last pass...
515  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
516 
518 
519  try
520  {
521  mRendererV2->renderFeature( *fit, mContext, layer, sel, drawMarker );
522  }
523  catch ( const QgsCsException &cse )
524  {
525  Q_UNUSED( cse );
526  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
527  .arg( fet.id() ).arg( cse.what() ) );
528  }
529  }
530  }
531  }
532 
533  stopRendererV2( selRenderer );
534 }
535 
536 
537 void QgsVectorLayerRenderer::stopRendererV2( QgsSingleSymbolRendererV2* selRenderer )
538 {
540  if ( selRenderer )
541  {
542  selRenderer->stopRender( mContext );
543  delete selRenderer;
544  }
545 }
546 
547 
548 
549 
550 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer* layer, QStringList& attributeNames )
551 {
552  if ( !mContext.labelingEngine() )
553  {
554  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
555  {
556  if ( layer->labeling() )
557  {
558  mLabelProvider = layer->labeling()->provider( layer );
559  if ( mLabelProvider )
560  {
561  engine2->addProvider( mLabelProvider );
562  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
563  {
564  engine2->removeProvider( mLabelProvider );
565  mLabelProvider = nullptr; // deleted by engine
566  }
567  }
568  }
569  }
570  return;
571  }
572 
573  if ( mContext.labelingEngine()->prepareLayer( layer, attributeNames, mContext ) )
574  {
575  mLabeling = true;
576 
577 #if 0 // TODO: limit of labels, font not found
579 
580  // see if feature count limit is set for labeling
581  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
582  {
583  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
584  .setFilterRect( mContext.extent() )
585  .setSubsetOfAttributes( QgsAttributeList() ) );
586 
587  // total number of features that may be labeled
588  QgsFeature f;
589  int nFeatsToLabel = 0;
590  while ( fit.nextFeature( f ) )
591  {
592  nFeatsToLabel++;
593  }
594  palyr.mFeaturesToLabel = nFeatsToLabel;
595  }
596 
597  // notify user about any font substitution
598  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
599  {
600  emit labelingFontNotFound( this, palyr.mTextFontFamily );
601  mLabelFontNotFoundNotified = true;
602  }
603 #endif
604  }
605 }
606 
607 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer* layer, QStringList& attributeNames )
608 {
609  if ( !mContext.labelingEngine() )
610  {
611  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
612  {
613  if ( layer->diagramsEnabled() )
614  {
616  // need to be added before calling prepare() - uses map settings from engine
617  engine2->addProvider( mDiagramProvider );
618  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
619  {
620  engine2->removeProvider( mDiagramProvider );
621  mDiagramProvider = nullptr; // deleted by engine
622  }
623  }
624  }
625  return;
626  }
627 
628  if ( !layer->diagramsEnabled() )
629  return;
630 
631  mDiagrams = true;
632 
633  mContext.labelingEngine()->prepareDiagramLayer( layer, attributeNames, mContext ); // will make internal copy of diagSettings + initialize it
634 
635 }
636 
637 /* ----------------------------------------- */
638 /* QgsVectorLayerRendererInterruptionChecker */
639 /* ----------------------------------------- */
640 
642 ( const QgsRenderContext& context )
643  : mContext( context )
644 {
645 }
646 
648 {
649  return mContext.renderingStopped();
650 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
QgsVectorLayerRendererInterruptionChecker mInterruptionChecker
const QgsCoordinateReferenceSystem & sourceCrs() const
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:35
bool isEmpty() const
test if rectangle is empty.
iterator insert(const Key &key, const T &value)
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.
virtual int prepareLayer(QgsVectorLayer *layer, QStringList &attrNames, QgsRenderContext &ctx)=0
called when starting rendering of a layer
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setCompositionMode(CompositionMode mode)
QgsFeatureRequest::OrderBy orderBy() const
Get the order in which features shall be processed by this renderer.
virtual bool prepare(const QgsRenderContext &context, QStringList &attributeNames)
Prepare for registration of features.
QColor selectionColor() const
virtual void stopRender(QgsRenderContext &context) override
Needs to be called when a render cycle has finished to clean up.
virtual QString dump() const
for debugging
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:197
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
The geometries can be simplified using the current map2pixel context state.
virtual Q_DECL_DEPRECATED QgsPalLayerSettings & layer(const QString &layerName)=0
returns PAL layer settings for a registered layer
virtual int prepareDiagramLayer(QgsVectorLayer *layer, QStringList &attrNames, QgsRenderContext &ctx)
adds a diagram layer to the labeling engine
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
const T & at(int i) const
void setGeometryCachePointer(QgsGeometryCache *cache)
where to save the cached geometries
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
bool enabled() const
Returns whether the effect is enabled.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
QPainter::CompositionMode mFeatureBlendMode
The QgsLabelingEngineV2 class provides map labeling functionality.
static QgsGeometry * getPointObstacleGeometry(QgsFeature &fet, QgsRenderContext &context, const QgsSymbolV2List &symbols)
Returns the geometry for a point feature which should be used as an obstacle for labels.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
const QgsRectangle & extent() const
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
QgsPoint transform(const QgsPoint &p, TransformDirection direction=ForwardTransform) const
Transform the point from Source Coordinate System to Destination Coordinate System If the direction i...
bool mustStop() const override
return true if the iterator must stop as soon as possible
virtual QList< QString > usedAttributes()=0
Returns a set of attributes required for this renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
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...
const QgsCoordinateTransform * coordinateTransform() const
bool isShortCircuited() const
See if the transform short circuits because src and dest are equivalent.
void setCachedGeometriesRect(const QgsRectangle &extent)
QgsVectorSimplifyMethod mSimplifyMethod
void setSimplifyHints(const SimplifyHints &simplifyHints)
Sets the simplification hints of the vector layer managed.
virtual bool prepare(const QgsRenderContext &context, QStringList &attributeNames)
Prepare for registration of features.
QString tr(const char *sourceText, const char *disambiguation, int n)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:352
bool mLabeling
used with old labeling engine (QgsPalLabeling): whether labeling is enabled
double x() const
Get the x value of the point.
Definition: qgspoint.h:185
virtual void registerFeature(const QString &layerID, QgsFeature &feat, QgsRenderContext &context)=0
called for every feature
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
void reset(T *other)
const QgsFeatureFilterProvider * featureFilterProvider() const
Get the filter feature provider used for additional filtering of rendered features.
QString layerID() const
Get access to the ID of the layer rendered by this class.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
int width() const
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
virtual Q_DECL_DEPRECATED QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
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.
void setColor(const QColor &color)
Simplify using the map2pixel data to optimize the rendering of geometries.
virtual QgsFeatureRendererV2 * clone() const =0
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
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.
int count(const T &value) const
virtual Q_DECL_DEPRECATED QgsSymbolV2 * symbolForFeature(QgsFeature &feature)
To be overridden.
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
void append(const T &value)
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
QgsLabelingEngineV2 * labelingEngineV2() const
Get access to new labeling engine (may be nullptr)
int toInt(bool *ok) const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:202
const QgsAbstractVectorLayerLabeling * labeling() const
Access to labeling configuration.
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:187
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
bool renderingStopped() const
QgsVectorLayerLabelProvider * mLabelProvider
used with new labeling engine (QgsLabelingEngineV2): provider for labels.
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine...
bool isEmpty() const
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
bool isEmpty() const
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QPaintDevice * device() const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsVectorLayerFeatureSource * mSource
QList< int > QgsAttributeList
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:131
double mapUnitsPerPixel() const
Return current map units per pixel.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QgsFeatureRendererV2 * mRendererV2
Abstract interface for use by classes that filter the features of a layer.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbols()
For symbol levels.
Single scope for storing variables and functions for use within a QgsExpressionContext.
A class to represent a point.
Definition: qgspoint.h:117
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures...
bool drawEditingInformation() const
T * data() const
iterator end()
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
Partial snapshot of vector layer&#39;s state (only the members necessary for access to features) ...
virtual void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &featureRequest) const =0
Add additional filters to the feature request to further restrict the features returned by the reques...
int renderingPass() const
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
bool contains(const T &value) const
int layerTransparency() const
Returns the current transparency for the vector layer.
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.
virtual bool render() override
Do the rendering (based on data stored in the class)
virtual void registerDiagramFeature(const QString &layerID, QgsFeature &feat, QgsRenderContext &context)
called for every diagram feature
QString what() const
Definition: qgsexception.h:36
QVariant value(const QString &key, const QVariant &defaultValue) const
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
QPainter * painter()
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request) override
Get an iterator for features matching the specified request.
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
QGis::GeometryType mGeometryType
void setMethodType(MethodType methodType)
Sets the simplification type.
QgsSymbolV2 * symbol()
Definition: qgsrendererv2.h:61
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
bool usingSymbolLevels() const
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:82
void cacheGeometry(QgsFeatureId fid, const QgsGeometry &geom)
store a geometry in the cache
Class for doing transforms between two map coordinate systems.
bool toBool() const
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
bool isEmpty() const
const QgsMapToPixel & mapToPixel() const
double y() const
Get the y value of the point.
Definition: qgspoint.h:193
Base class for utility classes that encapsulate information necessary for rendering of map layers...
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
bool contains(const Key &key) const
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
Custom exception class for Coordinate Reference System related exceptions.
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
int height() const
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.
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
QgsVectorLayerDiagramProvider * mDiagramProvider
used with new labeling engine (QgsLabelingEngineV2): provider for diagrams.
Represents a vector layer which manages a vector based data sets.
bool geographicFlag() const
Returns whether the CRS is a geographic CRS.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
virtual void startRender(QgsRenderContext &context, const QgsFields &fields) override
Needs to be called when a new render cycle is started.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbolV2 *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbolV2 to an expression context.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:192
QString toString() const
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:217
iterator begin()
bool mDiagrams
used with new labeling engine (QgsPalLabeling): whether diagrams are enabled
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const =0
Factory for label provider implementation.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
void setInterruptionChecker(QgsInterruptionChecker *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped...
QgsLabelingEngineInterface * labelingEngine() const