QGIS API Documentation  2.14.0-Essen
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  , mLayer( layer )
48  , mFields( layer->fields() )
49  , mRendererV2( nullptr )
50  , mCache( nullptr )
51  , mLabeling( false )
52  , mDiagrams( false )
53  , mLabelProvider( nullptr )
54  , mDiagramProvider( nullptr )
55  , mLayerTransparency( 0 )
56 {
57  mSource = new QgsVectorLayerFeatureSource( layer );
58 
59  mRendererV2 = layer->rendererV2() ? layer->rendererV2()->clone() : nullptr;
61 
62  mDrawVertexMarkers = nullptr != layer->editBuffer();
63 
64  mGeometryType = layer->geometryType();
65 
68 
71 
72  QSettings settings;
73  mVertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();
74 
75  QString markerTypeString = settings.value( "/qgis/digitizing/marker_style", "Cross" ).toString();
76  if ( markerTypeString == "Cross" )
77  {
79  }
80  else if ( markerTypeString == "SemiTransparentCircle" )
81  {
83  }
84  else
85  {
87  }
88 
89  mVertexMarkerSize = settings.value( "/qgis/digitizing/marker_size", 3 ).toInt();
90 
91  if ( !mRendererV2 )
92  return;
93 
94  QgsDebugMsg( "rendering v2:\n " + mRendererV2->dump() );
95 
96  if ( mDrawVertexMarkers )
97  {
98  // set editing vertex markers style
100  }
101 
103 
105 
106  //register label and diagram layer to the labeling engine
107  prepareLabeling( layer, mAttrNames );
108  prepareDiagrams( layer, mAttrNames );
109 
110 }
111 
112 
114 {
115  delete mRendererV2;
116  delete mSource;
117 }
118 
119 
121 {
123  return true;
124 
125  if ( !mRendererV2 )
126  {
127  mErrors.append( QObject::tr( "No renderer for drawing." ) );
128  return false;
129  }
130 
131  bool usingEffect = false;
133  {
134  usingEffect = true;
136  }
137 
138  // Per feature blending mode
139  if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver )
140  {
141  // set the painter to the feature blend mode, so that features drawn
142  // on this layer will interact and blend with each other
144  }
145 
147 
148  QString rendererFilter = mRendererV2->filter( mFields );
149 
150  QgsRectangle requestExtent = mContext.extent();
151  mRendererV2->modifyRequestExtent( requestExtent, mContext );
152 
153  QgsFeatureRequest featureRequest = QgsFeatureRequest()
154  .setFilterRect( requestExtent )
157  if ( mRendererV2->orderByEnabled() )
158  {
159  featureRequest.setOrderBy( mRendererV2->orderBy() );
160  }
161 
162  const QgsFeatureFilterProvider* featureFilterProvider = mContext.featureFilterProvider();
163  if ( featureFilterProvider )
164  {
165  featureFilterProvider->filterFeatures( mLayer, featureRequest );
166  }
167  if ( !rendererFilter.isEmpty() && rendererFilter != "TRUE" )
168  {
169  featureRequest.combineFilterExpression( rendererFilter );
170  }
171 
172  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
173  if ( mSimplifyGeometry )
174  {
175  double map2pixelTol = mSimplifyMethod.threshold();
176  bool validTransform = true;
177 
178  const QgsMapToPixel& mtp = mContext.mapToPixel();
179  map2pixelTol *= mtp.mapUnitsPerPixel();
181 
182  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
183  if ( ct && !( ct->isShortCircuited() ) )
184  {
185  try
186  {
187  QgsPoint center = mContext.extent().center();
188  double rectSize = ct->sourceCrs().geographicFlag() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
189 
190  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
191  QgsRectangle targetRect = ct->transform( sourceRect );
192 
193  QgsDebugMsg( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ) );
194  QgsDebugMsg( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ) );
195 
196  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
197  {
198  QgsPoint minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
199  QgsPoint maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
200  QgsPoint minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
201  QgsPoint maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
202 
203  double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
204  double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
205 
206  QgsDebugMsg( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ) );
207  QgsDebugMsg( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ) );
208 
209  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
210  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
211  }
212  }
213  catch ( QgsCsException &cse )
214  {
215  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
216  validTransform = false;
217  }
218  }
219 
220  if ( validTransform )
221  {
222  QgsSimplifyMethod simplifyMethod;
224  simplifyMethod.setTolerance( map2pixelTol );
225  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
226 
228 
229  featureRequest.setSimplifyMethod( simplifyMethod );
230 
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 
251  drawRendererV2Levels( fit );
252  else
253  drawRendererV2( fit );
254 
255  if ( usingEffect )
256  {
258  }
259 
260  //apply layer transparency for vector layers
262  {
263  // a layer transparency has been set, so update the alpha for the flattened layer
264  // by combining it with the layer transparency
265  QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * mLayerTransparency / 100 ) );
266  // use destination in composition mode to merge source's alpha with destination
267  mContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
269  mContext.painter()->device()->height(), transparentFillColor );
270  }
271 
272  return true;
273 }
274 
276 {
277  mCache = cache;
278 
279  if ( mCache )
280  {
281  // Destroy all cached geometries and clear the references to them
283  }
284 }
285 
286 
287 
288 void QgsVectorLayerRenderer::drawRendererV2( QgsFeatureIterator& fit )
289 {
291  mContext.expressionContext().appendScope( symbolScope );
292 
293  QgsFeature fet;
294  while ( fit.nextFeature( fet ) )
295  {
296  try
297  {
298  if ( !fet.constGeometry() )
299  continue; // skip features without geometry
300 
301  if ( mContext.renderingStopped() )
302  {
303  QgsDebugMsg( QString( "Drawing of vector layer %1 cancelled." ).arg( layerID() ) );
304  break;
305  }
306 
308 
309  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
310  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
311 
312  if ( mCache )
313  {
314  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
315  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
316  }
317 
318  // render feature
319  bool rendered = mRendererV2->renderFeature( fet, mContext, -1, sel, drawMarker );
320 
321  // labeling - register feature
322  if ( rendered )
323  {
324  if ( mContext.labelingEngine() )
325  {
326  if ( mLabeling )
327  {
329  }
330  if ( mDiagrams )
331  {
333  }
334  }
335  // new labeling engine
336  if ( mContext.labelingEngineV2() )
337  {
338  QScopedPointer<QgsGeometry> obstacleGeometry;
340 
341  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
342  {
343  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
344  }
345 
346  if ( !symbols.isEmpty() )
347  {
348  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
349  }
350 
351  if ( mLabelProvider )
352  {
353  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
354  }
355  if ( mDiagramProvider )
356  {
357  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
358  }
359  }
360  }
361  }
362  catch ( const QgsCsException &cse )
363  {
364  Q_UNUSED( cse );
365  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
366  .arg( fet.id() ).arg( cse.what() ) );
367  }
368  }
369 
371 
372  stopRendererV2( nullptr );
373 }
374 
375 void QgsVectorLayerRenderer::drawRendererV2Levels( QgsFeatureIterator& fit )
376 {
377  QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features
378 
379  QgsSingleSymbolRendererV2* selRenderer = nullptr;
380  if ( !mSelectedFeatureIds.isEmpty() )
381  {
383  selRenderer->symbol()->setColor( mContext.selectionColor() );
385  selRenderer->startRender( mContext, mFields );
386  }
387 
389  mContext.expressionContext().appendScope( symbolScope );
390 
391  // 1. fetch features
392  QgsFeature fet;
393  while ( fit.nextFeature( fet ) )
394  {
395  if ( !fet.constGeometry() )
396  continue; // skip features without geometry
397 
398  if ( mContext.renderingStopped() )
399  {
400  qDebug( "rendering stop!" );
401  stopRendererV2( selRenderer );
403  return;
404  }
405 
408  if ( !sym )
409  {
410  continue;
411  }
412 
413  if ( !features.contains( sym ) )
414  {
415  features.insert( sym, QList<QgsFeature>() );
416  }
417  features[sym].append( fet );
418 
419  if ( mCache )
420  {
421  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
422  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
423  }
424 
425  if ( mContext.labelingEngine() )
426  {
428  if ( mLabeling )
429  {
431  }
432  if ( mDiagrams )
433  {
435  }
436  }
437  // new labeling engine
438  if ( mContext.labelingEngineV2() )
439  {
440  QScopedPointer<QgsGeometry> obstacleGeometry;
442 
443  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
444  {
445  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
446  }
447 
448  if ( !symbols.isEmpty() )
449  {
450  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
451  }
452 
453  if ( mLabelProvider )
454  {
455  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
456  }
457  if ( mDiagramProvider )
458  {
459  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
460  }
461  }
462  }
463 
465 
466  // find out the order
467  QgsSymbolV2LevelOrder levels;
469  for ( int i = 0; i < symbols.count(); i++ )
470  {
471  QgsSymbolV2* sym = symbols[i];
472  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
473  {
474  int level = sym->symbolLayer( j )->renderingPass();
475  if ( level < 0 || level >= 1000 ) // ignore invalid levels
476  continue;
477  QgsSymbolV2LevelItem item( sym, j );
478  while ( level >= levels.count() ) // append new empty levels
479  levels.append( QgsSymbolV2Level() );
480  levels[level].append( item );
481  }
482  }
483 
484  // 2. draw features in correct order
485  for ( int l = 0; l < levels.count(); l++ )
486  {
487  QgsSymbolV2Level& level = levels[l];
488  for ( int i = 0; i < level.count(); i++ )
489  {
490  QgsSymbolV2LevelItem& item = level[i];
491  if ( !features.contains( item.symbol() ) )
492  {
493  QgsDebugMsg( "level item's symbol not found!" );
494  continue;
495  }
496  int layer = item.layer();
497  QList<QgsFeature>& lst = features[item.symbol()];
499  for ( fit = lst.begin(); fit != lst.end(); ++fit )
500  {
501  if ( mContext.renderingStopped() )
502  {
503  stopRendererV2( selRenderer );
504  return;
505  }
506 
507  bool sel = mSelectedFeatureIds.contains( fit->id() );
508  // maybe vertex markers should be drawn only during the last pass...
509  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
510 
512 
513  try
514  {
515  mRendererV2->renderFeature( *fit, mContext, layer, sel, drawMarker );
516  }
517  catch ( const QgsCsException &cse )
518  {
519  Q_UNUSED( cse );
520  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
521  .arg( fet.id() ).arg( cse.what() ) );
522  }
523  }
524  }
525  }
526 
527  stopRendererV2( selRenderer );
528 }
529 
530 
531 void QgsVectorLayerRenderer::stopRendererV2( QgsSingleSymbolRendererV2* selRenderer )
532 {
534  if ( selRenderer )
535  {
536  selRenderer->stopRender( mContext );
537  delete selRenderer;
538  }
539 }
540 
541 
542 
543 
544 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer* layer, QStringList& attributeNames )
545 {
546  if ( !mContext.labelingEngine() )
547  {
548  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
549  {
550  if ( layer->labeling() )
551  {
552  mLabelProvider = layer->labeling()->provider( layer );
553  if ( mLabelProvider )
554  {
555  engine2->addProvider( mLabelProvider );
556  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
557  {
558  engine2->removeProvider( mLabelProvider );
559  mLabelProvider = nullptr; // deleted by engine
560  }
561  }
562  }
563  }
564  return;
565  }
566 
567  if ( mContext.labelingEngine()->prepareLayer( layer, attributeNames, mContext ) )
568  {
569  mLabeling = true;
570 
571 #if 0 // TODO: limit of labels, font not found
573 
574  // see if feature count limit is set for labeling
575  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
576  {
577  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
578  .setFilterRect( mContext.extent() )
579  .setSubsetOfAttributes( QgsAttributeList() ) );
580 
581  // total number of features that may be labeled
582  QgsFeature f;
583  int nFeatsToLabel = 0;
584  while ( fit.nextFeature( f ) )
585  {
586  nFeatsToLabel++;
587  }
588  palyr.mFeaturesToLabel = nFeatsToLabel;
589  }
590 
591  // notify user about any font substitution
592  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
593  {
594  emit labelingFontNotFound( this, palyr.mTextFontFamily );
595  mLabelFontNotFoundNotified = true;
596  }
597 #endif
598  }
599 }
600 
601 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer* layer, QStringList& attributeNames )
602 {
603  if ( !mContext.labelingEngine() )
604  {
605  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
606  {
607  if ( layer->diagramsEnabled() )
608  {
610  // need to be added before calling prepare() - uses map settings from engine
611  engine2->addProvider( mDiagramProvider );
612  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
613  {
614  engine2->removeProvider( mDiagramProvider );
615  mDiagramProvider = nullptr; // deleted by engine
616  }
617  }
618  }
619  return;
620  }
621 
622  if ( !layer->diagramsEnabled() )
623  return;
624 
625  mDiagrams = true;
626 
627  mContext.labelingEngine()->prepareDiagramLayer( layer, attributeNames, mContext ); // will make internal copy of diagSettings + initialize it
628 
629 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:65
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 void registerFeature(const QString &layerID, QgsFeature &feat, QgsRenderContext &context, const QString &dxfLayer=QString::null)=0
called for every feature
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...
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)
Definition: qgis.h:285
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:128
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.
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:65
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:58
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:136
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.
QgsLabelingEngineInterface * labelingEngine() const