QGIS API Documentation  2.13.0-Master
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 
154 
155  QgsFeatureRequest featureRequest = QgsFeatureRequest()
156  .setFilterRect( requestExtent )
159  .setOrderBy( orderBy );
160 
161  const QgsFeatureFilterProvider* featureFilterProvider = mContext.featureFilterProvider();
162  if ( featureFilterProvider )
163  {
164  featureFilterProvider->filterFeatures( mLayer, featureRequest );
165  }
166  if ( !rendererFilter.isEmpty() && rendererFilter != "TRUE" )
167  {
168  featureRequest.combineFilterExpression( rendererFilter );
169  }
170 
171  // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine.
172  if ( mSimplifyGeometry )
173  {
174  double map2pixelTol = mSimplifyMethod.threshold();
175  bool validTransform = true;
176 
177  const QgsMapToPixel& mtp = mContext.mapToPixel();
178  map2pixelTol *= mtp.mapUnitsPerPixel();
180 
181  // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem
182  if ( ct && !( ct->isShortCircuited() ) )
183  {
184  try
185  {
186  QgsPoint center = mContext.extent().center();
187  double rectSize = ct->sourceCrs().geographicFlag() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100;
188 
189  QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize );
190  QgsRectangle targetRect = ct->transform( sourceRect );
191 
192  QgsDebugMsg( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ) );
193  QgsDebugMsg( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ) );
194 
195  if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
196  {
197  QgsPoint minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() );
198  QgsPoint maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() );
199  QgsPoint minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
200  QgsPoint maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
201 
202  double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
203  double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
204 
205  QgsDebugMsg( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ) );
206  QgsDebugMsg( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ) );
207 
208  if ( !qgsDoubleNear( targetHypothenuse, 0.0 ) )
209  map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
210  }
211  }
212  catch ( QgsCsException &cse )
213  {
214  QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
215  validTransform = false;
216  }
217  }
218 
219  if ( validTransform )
220  {
221  QgsSimplifyMethod simplifyMethod;
223  simplifyMethod.setTolerance( map2pixelTol );
224  simplifyMethod.setThreshold( mSimplifyMethod.threshold() );
225 
227 
228  featureRequest.setSimplifyMethod( simplifyMethod );
229 
231  mContext.setVectorSimplifyMethod( vectorMethod );
232  }
233  else
234  {
235  QgsVectorSimplifyMethod vectorMethod;
237  mContext.setVectorSimplifyMethod( vectorMethod );
238  }
239  }
240  else
241  {
242  QgsVectorSimplifyMethod vectorMethod;
244  mContext.setVectorSimplifyMethod( vectorMethod );
245  }
246 
247  QgsFeatureIterator fit = mSource->getFeatures( featureRequest );
248 
250  drawRendererV2Levels( fit );
251  else
252  drawRendererV2( fit );
253 
254  if ( usingEffect )
255  {
257  }
258 
259  //apply layer transparency for vector layers
261  {
262  // a layer transparency has been set, so update the alpha for the flattened layer
263  // by combining it with the layer transparency
264  QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * mLayerTransparency / 100 ) );
265  // use destination in composition mode to merge source's alpha with destination
266  mContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
268  mContext.painter()->device()->height(), transparentFillColor );
269  }
270 
271  return true;
272 }
273 
275 {
276  mCache = cache;
277 
278  if ( mCache )
279  {
280  // Destroy all cached geometries and clear the references to them
282  }
283 }
284 
285 
286 
287 void QgsVectorLayerRenderer::drawRendererV2( QgsFeatureIterator& fit )
288 {
290  mContext.expressionContext().appendScope( symbolScope );
291 
292  QgsFeature fet;
293  while ( fit.nextFeature( fet ) )
294  {
295  try
296  {
297  if ( !fet.constGeometry() )
298  continue; // skip features without geometry
299 
300  if ( mContext.renderingStopped() )
301  {
302  QgsDebugMsg( QString( "Drawing of vector layer %1 cancelled." ).arg( layerID() ) );
303  break;
304  }
305 
307 
308  bool sel = mContext.showSelection() && mSelectedFeatureIds.contains( fet.id() );
309  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
310 
311  if ( mCache )
312  {
313  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
314  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
315  }
316 
317  // render feature
318  bool rendered = mRendererV2->renderFeature( fet, mContext, -1, sel, drawMarker );
319 
320  // labeling - register feature
321  if ( rendered )
322  {
323  if ( mContext.labelingEngine() )
324  {
325  if ( mLabeling )
326  {
328  }
329  if ( mDiagrams )
330  {
332  }
333  }
334  // new labeling engine
335  if ( mContext.labelingEngineV2() )
336  {
337  QScopedPointer<QgsGeometry> obstacleGeometry;
339 
340  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
341  {
342  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
343  }
344 
345  if ( !symbols.isEmpty() )
346  {
347  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
348  }
349 
350  if ( mLabelProvider )
351  {
352  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
353  }
354  if ( mDiagramProvider )
355  {
356  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
357  }
358  }
359  }
360  }
361  catch ( const QgsCsException &cse )
362  {
363  Q_UNUSED( cse );
364  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
365  .arg( fet.id() ).arg( cse.what() ) );
366  }
367  }
368 
370 
371  stopRendererV2( nullptr );
372 }
373 
374 void QgsVectorLayerRenderer::drawRendererV2Levels( QgsFeatureIterator& fit )
375 {
376  QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features
377 
378  QgsSingleSymbolRendererV2* selRenderer = nullptr;
379  if ( !mSelectedFeatureIds.isEmpty() )
380  {
382  selRenderer->symbol()->setColor( mContext.selectionColor() );
384  selRenderer->startRender( mContext, mFields );
385  }
386 
388  mContext.expressionContext().appendScope( symbolScope );
389 
390  // 1. fetch features
391  QgsFeature fet;
392  while ( fit.nextFeature( fet ) )
393  {
394  if ( !fet.constGeometry() )
395  continue; // skip features without geometry
396 
397  if ( mContext.renderingStopped() )
398  {
399  qDebug( "rendering stop!" );
400  stopRendererV2( selRenderer );
402  return;
403  }
404 
407  if ( !sym )
408  {
409  continue;
410  }
411 
412  if ( !features.contains( sym ) )
413  {
414  features.insert( sym, QList<QgsFeature>() );
415  }
416  features[sym].append( fet );
417 
418  if ( mCache )
419  {
420  // Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
421  mCache->cacheGeometry( fet.id(), *fet.constGeometry() );
422  }
423 
424  if ( mContext.labelingEngine() )
425  {
427  if ( mLabeling )
428  {
430  }
431  if ( mDiagrams )
432  {
434  }
435  }
436  // new labeling engine
437  if ( mContext.labelingEngineV2() )
438  {
439  QScopedPointer<QgsGeometry> obstacleGeometry;
441 
442  if ( !symbols.isEmpty() && fet.constGeometry()->type() == QGis::Point )
443  {
444  obstacleGeometry.reset( QgsVectorLayerLabelProvider::getPointObstacleGeometry( fet, mContext, symbols ) );
445  }
446 
447  if ( !symbols.isEmpty() )
448  {
449  QgsExpressionContextUtils::updateSymbolScope( symbols.at( 0 ), symbolScope );
450  }
451 
452  if ( mLabelProvider )
453  {
454  mLabelProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
455  }
456  if ( mDiagramProvider )
457  {
458  mDiagramProvider->registerFeature( fet, mContext, obstacleGeometry.data() );
459  }
460  }
461  }
462 
464 
465  // find out the order
466  QgsSymbolV2LevelOrder levels;
468  for ( int i = 0; i < symbols.count(); i++ )
469  {
470  QgsSymbolV2* sym = symbols[i];
471  for ( int j = 0; j < sym->symbolLayerCount(); j++ )
472  {
473  int level = sym->symbolLayer( j )->renderingPass();
474  if ( level < 0 || level >= 1000 ) // ignore invalid levels
475  continue;
476  QgsSymbolV2LevelItem item( sym, j );
477  while ( level >= levels.count() ) // append new empty levels
478  levels.append( QgsSymbolV2Level() );
479  levels[level].append( item );
480  }
481  }
482 
483  // 2. draw features in correct order
484  for ( int l = 0; l < levels.count(); l++ )
485  {
486  QgsSymbolV2Level& level = levels[l];
487  for ( int i = 0; i < level.count(); i++ )
488  {
489  QgsSymbolV2LevelItem& item = level[i];
490  if ( !features.contains( item.symbol() ) )
491  {
492  QgsDebugMsg( "level item's symbol not found!" );
493  continue;
494  }
495  int layer = item.layer();
496  QList<QgsFeature>& lst = features[item.symbol()];
498  for ( fit = lst.begin(); fit != lst.end(); ++fit )
499  {
500  if ( mContext.renderingStopped() )
501  {
502  stopRendererV2( selRenderer );
503  return;
504  }
505 
506  bool sel = mSelectedFeatureIds.contains( fit->id() );
507  // maybe vertex markers should be drawn only during the last pass...
508  bool drawMarker = ( mDrawVertexMarkers && mContext.drawEditingInformation() && ( !mVertexMarkerOnlyForSelection || sel ) );
509 
511 
512  try
513  {
514  mRendererV2->renderFeature( *fit, mContext, layer, sel, drawMarker );
515  }
516  catch ( const QgsCsException &cse )
517  {
518  Q_UNUSED( cse );
519  QgsDebugMsg( QString( "Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
520  .arg( fet.id() ).arg( cse.what() ) );
521  }
522  }
523  }
524  }
525 
526  stopRendererV2( selRenderer );
527 }
528 
529 
530 void QgsVectorLayerRenderer::stopRendererV2( QgsSingleSymbolRendererV2* selRenderer )
531 {
533  if ( selRenderer )
534  {
535  selRenderer->stopRender( mContext );
536  delete selRenderer;
537  }
538 }
539 
540 
541 
542 
543 void QgsVectorLayerRenderer::prepareLabeling( QgsVectorLayer* layer, QStringList& attributeNames )
544 {
545  if ( !mContext.labelingEngine() )
546  {
547  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
548  {
549  if ( layer->labeling() )
550  {
551  mLabelProvider = layer->labeling()->provider( layer );
552  if ( mLabelProvider )
553  {
554  engine2->addProvider( mLabelProvider );
555  if ( !mLabelProvider->prepare( mContext, attributeNames ) )
556  {
557  engine2->removeProvider( mLabelProvider );
558  mLabelProvider = nullptr; // deleted by engine
559  }
560  }
561  }
562  }
563  return;
564  }
565 
566  if ( mContext.labelingEngine()->prepareLayer( layer, attributeNames, mContext ) )
567  {
568  mLabeling = true;
569 
570 #if 0 // TODO: limit of labels, font not found
572 
573  // see if feature count limit is set for labeling
574  if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
575  {
576  QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
577  .setFilterRect( mContext.extent() )
578  .setSubsetOfAttributes( QgsAttributeList() ) );
579 
580  // total number of features that may be labeled
581  QgsFeature f;
582  int nFeatsToLabel = 0;
583  while ( fit.nextFeature( f ) )
584  {
585  nFeatsToLabel++;
586  }
587  palyr.mFeaturesToLabel = nFeatsToLabel;
588  }
589 
590  // notify user about any font substitution
591  if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
592  {
593  emit labelingFontNotFound( this, palyr.mTextFontFamily );
594  mLabelFontNotFoundNotified = true;
595  }
596 #endif
597  }
598 }
599 
600 void QgsVectorLayerRenderer::prepareDiagrams( QgsVectorLayer* layer, QStringList& attributeNames )
601 {
602  if ( !mContext.labelingEngine() )
603  {
604  if ( QgsLabelingEngineV2* engine2 = mContext.labelingEngineV2() )
605  {
606  if ( layer->diagramsEnabled() )
607  {
609  // need to be added before calling prepare() - uses map settings from engine
610  engine2->addProvider( mDiagramProvider );
611  if ( !mDiagramProvider->prepare( mContext, attributeNames ) )
612  {
613  engine2->removeProvider( mDiagramProvider );
614  mDiagramProvider = nullptr; // deleted by engine
615  }
616  }
617  }
618  return;
619  }
620 
621  if ( !layer->diagramsEnabled() )
622  return;
623 
624  mDiagrams = true;
625 
626  mContext.labelingEngine()->prepareDiagramLayer( layer, attributeNames, mContext ); // will make internal copy of diagSettings + initialize it
627 
628 }
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:196
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
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:201
const QgsAbstractVectorLayerLabeling * labeling() const
Access to labeling configuration.
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:186
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:128
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'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
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:191
QString toString() const
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:216
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.
Represents a list of OrderByClauses, with the most important first and the least important last...
QgsLabelingEngineInterface * labelingEngine() const