QGIS API Documentation  2.15.0-Master (5f66276)
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() );
228  featureRequest.setSimplifyMethod( simplifyMethod );
229 
231  vectorMethod.setTolerance( map2pixelTol );
232  mContext.setVectorSimplifyMethod( vectorMethod );
233  }
234  else
235  {
236  QgsVectorSimplifyMethod vectorMethod;
238  mContext.setVectorSimplifyMethod( vectorMethod );
239  }
240  }
241  else
242  {
243  QgsVectorSimplifyMethod vectorMethod;
245  mContext.setVectorSimplifyMethod( vectorMethod );
246  }
247 
248  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
249  // Attach an interruption checker so that iterators that have potentially
250  // slow fetchFeature() implementations, such as in the WFS provider, can
251  // check it, instead of relying on just the mContext.renderingStopped() check
252  // in drawRendererV2()
254 
256  drawRendererV2Levels( fit );
257  else
258  drawRendererV2( fit );
259 
260  if ( usingEffect )
261  {
263  }
264 
265  //apply layer transparency for vector layers
267  {
268  // a layer transparency has been set, so update the alpha for the flattened layer
269  // by combining it with the layer transparency
270  QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * mLayerTransparency / 100 ) );
271  // use destination in composition mode to merge source's alpha with destination
272  mContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
274  mContext.painter()->device()->height(), transparentFillColor );
275  }
276 
277  return true;
278 }
279 
281 {
282  mCache = cache;
283 
284  if ( mCache )
285  {
286  // Destroy all cached geometries and clear the references to them
288  }
289 }
290 
291 
292 
293 void QgsVectorLayerRenderer::drawRendererV2( QgsFeatureIterator& fit )
294 {
296  mContext.expressionContext().appendScope( symbolScope );
297 
298  QgsFeature fet;
299  while ( fit.nextFeature( fet ) )
300  {
301  try
302  {
303  if ( mContext.renderingStopped() )
304  {
305  QgsDebugMsg( QString( "Drawing of vector layer %1 cancelled." ).arg( layerID() ) );
306  break;
307  }
308 
309  if ( !fet.constGeometry() )
310  continue; // skip features without geometry
311 
313 
314  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
315  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
316 
317  if ( mCache )
318  {
319  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
320  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
321  }
322 
323  // render feature
324  bool rendered = mRendererV2->renderFeature( fet, mContext, -1, sel, drawMarker );
325 
326  // labeling - register feature
327  if ( rendered )
328  {
329  if ( mContext.labelingEngine() )
330  {
331  if ( mLabeling )
332  {
334  }
335  if ( mDiagrams )
336  {
338  }
339  }
340  // new labeling engine
341  if ( mContext.labelingEngineV2() )
342  {
343  QScopedPointer<QgsGeometry> obstacleGeometry;
345 
346  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
347  {
348  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
349  }
350 
351  if ( !symbols.isEmpty() )
352  {
353  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
354  }
355 
356  if ( mLabelProvider )
357  {
358  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
359  }
360  if ( mDiagramProvider )
361  {
362  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
363  }
364  }
365  }
366  }
367  catch ( const QgsCsException &cse )
368  {
369  Q_UNUSED( cse );
370  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
371  .arg( fet.id() ).arg( cse.what() ) );
372  }
373  }
374 
376 
377  stopRendererV2( nullptr );
378 }
379 
380 void QgsVectorLayerRenderer::drawRendererV2Levels( QgsFeatureIterator& fit )
381 {
382  QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features
383 
384  QgsSingleSymbolRendererV2* selRenderer = nullptr;
385  if ( !mSelectedFeatureIds.isEmpty() )
386  {
388  selRenderer->symbol()->setColor( mContext.selectionColor() );
390  selRenderer->startRender( mContext, mFields );
391  }
392 
394  mContext.expressionContext().appendScope( symbolScope );
395 
396  // 1. fetch features
397  QgsFeature fet;
398  while ( fit.nextFeature( fet ) )
399  {
400  if ( mContext.renderingStopped() )
401  {
402  qDebug( "rendering stop!" );
403  stopRendererV2( selRenderer );
405  return;
406  }
407 
408  if ( !fet.constGeometry() )
409  continue; // skip features without geometry
410 
413  if ( !sym )
414  {
415  continue;
416  }
417 
418  if ( !features.contains( sym ) )
419  {
420  features.insert( sym, QList<QgsFeature>() );
421  }
422  features[sym].append( fet );
423 
424  if ( mCache )
425  {
426  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
427  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
428  }
429 
430  if ( mContext.labelingEngine() )
431  {
433  if ( mLabeling )
434  {
436  }
437  if ( mDiagrams )
438  {
440  }
441  }
442  // new labeling engine
443  if ( mContext.labelingEngineV2() )
444  {
445  QScopedPointer<QgsGeometry> obstacleGeometry;
447 
448  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
449  {
450  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
451  }
452 
453  if ( !symbols.isEmpty() )
454  {
455  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
456  }
457 
458  if ( mLabelProvider )
459  {
460  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
461  }
462  if ( mDiagramProvider )
463  {
464  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
465  }
466  }
467  }
468 
470 
471  // find out the order
472  QgsSymbolV2LevelOrder levels;
474  for ( int i = 0; i < symbols.count(); i++ )
475  {
476  QgsSymbolV2* sym = symbols[i];
477  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
478  {
479  int level = sym->symbolLayer( j )->renderingPass();
480  if ( level < 0 || level >= 1000 ) // ignore invalid levels
481  continue;
482  QgsSymbolV2LevelItem item( sym, j );
483  while ( level >= levels.count() ) // append new empty levels
484  levels.append( QgsSymbolV2Level() );
485  levels[level].append( item );
486  }
487  }
488 
489  // 2. draw features in correct order
490  for ( int l = 0; l < levels.count(); l++ )
491  {
492  QgsSymbolV2Level& level = levels[l];
493  for ( int i = 0; i < level.count(); i++ )
494  {
495  QgsSymbolV2LevelItem& item = level[i];
496  if ( !features.contains( item.symbol() ) )
497  {
498  QgsDebugMsg( "level item's symbol not found!" );
499  continue;
500  }
501  int layer = item.layer();
502  QList<QgsFeature>& lst = features[item.symbol()];
504  for ( fit = lst.begin(); fit != lst.end(); ++fit )
505  {
506  if ( mContext.renderingStopped() )
507  {
508  stopRendererV2( selRenderer );
509  return;
510  }
511 
512  bool sel = mSelectedFeatureIds.contains( fit->id() );
513  // maybe vertex markers should be drawn only during the last pass...
514  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
515 
517 
518  try
519  {
520  mRendererV2->renderFeature( *fit, mContext, layer, sel, drawMarker );
521  }
522  catch ( const QgsCsException &cse )
523  {
524  Q_UNUSED( cse );
525  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
526  .arg( fet.id() ).arg( cse.what() ) );
527  }
528  }
529  }
530  }
531 
532  stopRendererV2( selRenderer );
533 }
534 
535 
536 void QgsVectorLayerRenderer::stopRendererV2( QgsSingleSymbolRendererV2* selRenderer )
537 {
539  if ( selRenderer )
540  {
541  selRenderer->stopRender( mContext );
542  delete selRenderer;
543  }
544 }
545 
546 
547 
548 
549 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer* layer, QStringList& attributeNames )
550 {
551  if ( !mContext.labelingEngine() )
552  {
553  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
554  {
555  if ( layer->labeling() )
556  {
557  mLabelProvider = layer->labeling()->provider( layer );
558  if ( mLabelProvider )
559  {
560  engine2->addProvider( mLabelProvider );
561  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
562  {
563  engine2->removeProvider( mLabelProvider );
564  mLabelProvider = nullptr; // deleted by engine
565  }
566  }
567  }
568  }
569  return;
570  }
571 
572  if ( mContext.labelingEngine()->prepareLayer( layer, attributeNames, mContext ) )
573  {
574  mLabeling = true;
575 
576 #if 0 // TODO: limit of labels, font not found
578 
579  // see if feature count limit is set for labeling
580  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
581  {
582  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
583  .setFilterRect( mContext.extent() )
584  .setSubsetOfAttributes( QgsAttributeList() ) );
585 
586  // total number of features that may be labeled
587  QgsFeature f;
588  int nFeatsToLabel = 0;
589  while ( fit.nextFeature( f ) )
590  {
591  nFeatsToLabel++;
592  }
593  palyr.mFeaturesToLabel = nFeatsToLabel;
594  }
595 
596  // notify user about any font substitution
597  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
598  {
599  emit labelingFontNotFound( this, palyr.mTextFontFamily );
600  mLabelFontNotFoundNotified = true;
601  }
602 #endif
603  }
604 }
605 
606 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer* layer, QStringList& attributeNames )
607 {
608  if ( !mContext.labelingEngine() )
609  {
610  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
611  {
612  if ( layer->diagramsEnabled() )
613  {
615  // need to be added before calling prepare() - uses map settings from engine
616  engine2->addProvider( mDiagramProvider );
617  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
618  {
619  engine2->removeProvider( mDiagramProvider );
620  mDiagramProvider = nullptr; // deleted by engine
621  }
622  }
623  }
624  return;
625  }
626 
627  if ( !layer->diagramsEnabled() )
628  return;
629 
630  mDiagrams = true;
631 
632  mContext.labelingEngine()->prepareDiagramLayer( layer, attributeNames, mContext ); // will make internal copy of diagSettings + initialize it
633 
634 }
635 
636 /* ----------------------------------------- */
637 /* QgsVectorLayerRendererInterruptionChecker */
638 /* ----------------------------------------- */
639 
641 ( const QgsRenderContext& context )
642  : mContext( context )
643 {
644 }
645 
647 {
648  return mContext.renderingStopped();
649 }
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.
rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
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.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units.
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