QGIS API Documentation  2.9.0-Master
qgspointdisplacementrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointdisplacementrenderer.cpp
3  --------------------------------
4  begin : January 26, 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco at hugis dot net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsgeometry.h"
20 #include "qgslogger.h"
21 #include "qgsspatialindex.h"
22 #include "qgssymbolv2.h"
23 #include "qgssymbollayerv2utils.h"
24 #include "qgsvectorlayer.h"
26 #include "qgspainteffect.h"
27 
28 #include <QDomElement>
29 #include <QPainter>
30 
31 #include <cmath>
32 
34  : QgsFeatureRendererV2( "pointDisplacement" )
35  , mLabelAttributeName( labelAttributeName )
36  , mLabelIndex( -1 )
37  , mTolerance( 0.00001 )
38  , mCircleWidth( 0.4 )
39  , mCircleColor( QColor( 125, 125, 125 ) )
40  , mCircleRadiusAddition( 0 )
41  , mMaxLabelScaleDenominator( -1 )
42  , mSpatialIndex( NULL )
43 {
45  mCenterSymbol = new QgsMarkerSymbolV2(); //the symbol for the center of a displacement group
46  mDrawLabels = true;
47 }
48 
50 {
51  delete mCenterSymbol;
52  delete mRenderer;
53 }
54 
56 {
57  QgsPointDisplacementRenderer* r = new QgsPointDisplacementRenderer( mLabelAttributeName );
58  r->setEmbeddedRenderer( mRenderer->clone() );
59  r->setCircleWidth( mCircleWidth );
60  r->setCircleColor( mCircleColor );
61  r->setLabelFont( mLabelFont );
62  r->setLabelColor( mLabelColor );
63  r->setCircleRadiusAddition( mCircleRadiusAddition );
64  r->setMaxLabelScaleDenominator( mMaxLabelScaleDenominator );
65  r->setTolerance( mTolerance );
66  if ( mCenterSymbol )
67  {
68  r->setCenterSymbol( dynamic_cast<QgsMarkerSymbolV2*>( mCenterSymbol->clone() ) );
69  }
70  copyPaintEffect( r );
71  return r;
72 }
73 
74 void QgsPointDisplacementRenderer::toSld( QDomDocument& doc, QDomElement &element ) const
75 {
76  mRenderer->toSld( doc, element );
77 }
78 
79 
80 bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
81 {
82  Q_UNUSED( drawVertexMarker );
83  Q_UNUSED( context );
84  Q_UNUSED( layer );
85 
86  //check, if there is already a point at that position
87  if ( !feature.constGeometry() )
88  return false;
89 
90  QgsSymbolV2* symbol = firstSymbolForFeature( mRenderer, feature );
91 
92  //if the feature has no symbol (eg, no matching rule in a rule-based renderer), skip it
93  if ( !symbol )
94  return false;
95 
96  //point position in screen coords
97  const QgsGeometry* geom = feature.constGeometry();
98  QGis::WkbType geomType = geom->wkbType();
99  if ( geomType != QGis::WKBPoint && geomType != QGis::WKBPoint25D )
100  {
101  //can only render point type
102  return false;
103  }
104 
105  if ( selected )
106  mSelectedFeatures.insert( feature.id() );
107 
108  QList<QgsFeatureId> intersectList = mSpatialIndex->intersects( searchRect( feature.constGeometry()->asPoint() ) );
109  if ( intersectList.empty() )
110  {
111  mSpatialIndex->insertFeature( feature );
112  // create new group
113  DisplacementGroup newGroup;
114  newGroup.insert( feature.id(), qMakePair( feature, symbol ) );
115  mDisplacementGroups.push_back( newGroup );
116  // add to group index
117  mGroupIndex.insert( feature.id(), mDisplacementGroups.count() - 1 );
118  return true;
119  }
120 
121  //go through all the displacement group maps and search an entry where the id equals the result of the spatial search
122  QgsFeatureId existingEntry = intersectList.at( 0 );
123 
124  int groupIdx = mGroupIndex[ existingEntry ];
125  DisplacementGroup& group = mDisplacementGroups[groupIdx];
126 
127  // add to a group
128  group.insert( feature.id(), qMakePair( feature, symbol ) );
129  // add to group index
130  mGroupIndex.insert( feature.id(), groupIdx );
131  return true;
132 }
133 
134 void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, QgsRenderContext& context )
135 {
136  const QgsFeature& feature = group.begin().value().first;
137  bool selected = mSelectedFeatures.contains( feature.id() ); // maybe we should highlight individual features instead of the whole group?
138 
139  QPointF pt;
140  _getPoint( pt, context, feature.constGeometry()->asWkb() );
141 
142  //get list of labels and symbols
143  QStringList labelAttributeList;
144  QList<QgsMarkerSymbolV2*> symbolList;
145 
146  for ( DisplacementGroup::const_iterator attIt = group.constBegin(); attIt != group.constEnd(); ++attIt )
147  {
148  labelAttributeList << ( mDrawLabels ? getLabel( attIt.value().first ) : QString() );
149  symbolList << dynamic_cast<QgsMarkerSymbolV2*>( attIt.value().second );
150  }
151 
152  //draw symbol
153  double diagonal = 0;
154  double currentWidthFactor; //scale symbol size to map unit and output resolution
155 
156  QList<QgsMarkerSymbolV2*>::const_iterator it = symbolList.constBegin();
157  for ( ; it != symbolList.constEnd(); ++it )
158  {
159  if ( *it )
160  {
161  currentWidthFactor = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context, ( *it )->outputUnit(), ( *it )->mapUnitScale() );
162  double currentDiagonal = sqrt( 2 * (( *it )->size() * ( *it )->size() ) ) * currentWidthFactor;
163  if ( currentDiagonal > diagonal )
164  {
165  diagonal = currentDiagonal;
166  }
167  }
168  }
169 
170 
171  QgsSymbolV2RenderContext symbolContext( context, QgsSymbolV2::MM, 1.0, selected );
172  double circleAdditionPainterUnits = symbolContext.outputLineWidth( mCircleRadiusAddition );
173  double radius = qMax(( diagonal / 2 ), labelAttributeList.size() * diagonal / 2 / M_PI ) + circleAdditionPainterUnits;
174 
175  //draw Circle
176  drawCircle( radius, symbolContext, pt, symbolList.size() );
177 
178  QList<QPointF> symbolPositions;
179  QList<QPointF> labelPositions;
180  calculateSymbolAndLabelPositions( pt, labelAttributeList.size(), radius, diagonal, symbolPositions, labelPositions );
181 
182  //draw mid point
183  if ( labelAttributeList.size() > 1 )
184  {
185  if ( mCenterSymbol )
186  {
187  mCenterSymbol->renderPoint( pt, &feature, context, -1, selected );
188  }
189  else
190  {
191  context.painter()->drawRect( QRectF( pt.x() - symbolContext.outputLineWidth( 1 ), pt.y() - symbolContext.outputLineWidth( 1 ), symbolContext.outputLineWidth( 2 ), symbolContext.outputLineWidth( 2 ) ) );
192  }
193  }
194 
195  //draw symbols on the circle
196  drawSymbols( feature, context, symbolList, symbolPositions, selected );
197  //and also the labels
198  drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
199 }
200 
202 {
203  delete mRenderer;
204  mRenderer = r;
205 }
206 
208 {
209  QList<QString> attributeList;
210  if ( !mLabelAttributeName.isEmpty() )
211  {
212  attributeList.push_back( mLabelAttributeName );
213  }
214  if ( mRenderer )
215  {
216  attributeList += mRenderer->usedAttributes();
217  }
218  return attributeList;
219 }
220 
222 {
223  if ( !mRenderer )
224  {
225  return 0;
226  }
227  return mRenderer->capabilities();
228 }
229 
231 {
232  if ( !mRenderer )
233  {
234  return QgsSymbolV2List();
235  }
236  return mRenderer->symbols();
237 }
238 
240 {
241  if ( !mRenderer )
242  {
243  return 0;
244  }
245  return mRenderer->symbolForFeature( feature );
246 }
247 
249 {
250  if ( !mRenderer )
251  return 0;
252  return mRenderer->originalSymbolForFeature( feat );
253 }
254 
256 {
257  if ( !mRenderer )
258  {
259  return QgsSymbolV2List();
260  }
261  return mRenderer->symbolsForFeature( feature );
262 }
263 
265 {
266  if ( !mRenderer )
267  return QgsSymbolV2List();
268  return mRenderer->originalSymbolsForFeature( feat );
269 }
270 
272 {
273  if ( !mRenderer )
274  {
275  return false;
276  }
277  return mRenderer->willRenderFeature( feat );
278 }
279 
280 
282 {
283  mRenderer->startRender( context, fields );
284 
285  mDisplacementGroups.clear();
286  mGroupIndex.clear();
287  mSpatialIndex = new QgsSpatialIndex;
288  mSelectedFeatures.clear();
289 
290  if ( mLabelAttributeName.isEmpty() )
291  {
292  mLabelIndex = -1;
293  }
294  else
295  {
296  mLabelIndex = fields.fieldNameIndex( mLabelAttributeName );
297  }
298 
299  if ( mMaxLabelScaleDenominator > 0 && context.rendererScale() > mMaxLabelScaleDenominator )
300  {
301  mDrawLabels = false;
302  }
303  else
304  {
305  mDrawLabels = true;
306  }
307 
308  if ( mCenterSymbol )
309  {
310  mCenterSymbol->startRender( context, &fields );
311  }
312 }
313 
315 {
316  QgsDebugMsg( "QgsPointDisplacementRenderer::stopRender" );
317 
318  //printInfoDisplacementGroups(); //just for debugging
319 
320  for ( QList<DisplacementGroup>::const_iterator it = mDisplacementGroups.begin(); it != mDisplacementGroups.end(); ++it )
321  drawGroup( *it, context );
322 
323  mDisplacementGroups.clear();
324  mGroupIndex.clear();
325  delete mSpatialIndex;
326  mSpatialIndex = 0;
327  mSelectedFeatures.clear();
328 
329  mRenderer->stopRender( context );
330  if ( mCenterSymbol )
331  {
332  mCenterSymbol->stopRender( context );
333  }
334 }
335 
337 {
339  r->setLabelAttributeName( symbologyElem.attribute( "labelAttributeName" ) );
340  QFont labelFont;
341  labelFont.fromString( symbologyElem.attribute( "labelFont", "" ) );
342  r->setLabelFont( labelFont );
343  r->setCircleWidth( symbologyElem.attribute( "circleWidth", "0.4" ).toDouble() );
344  r->setCircleColor( QgsSymbolLayerV2Utils::decodeColor( symbologyElem.attribute( "circleColor", "" ) ) );
345  r->setLabelColor( QgsSymbolLayerV2Utils::decodeColor( symbologyElem.attribute( "labelColor", "" ) ) );
346  r->setCircleRadiusAddition( symbologyElem.attribute( "circleRadiusAddition", "0.0" ).toDouble() );
347  r->setMaxLabelScaleDenominator( symbologyElem.attribute( "maxLabelScaleDenominator", "-1" ).toDouble() );
348  r->setTolerance( symbologyElem.attribute( "tolerance", "0.00001" ).toDouble() );
349 
350  //look for an embedded renderer <renderer-v2>
351  QDomElement embeddedRendererElem = symbologyElem.firstChildElement( "renderer-v2" );
352  if ( !embeddedRendererElem.isNull() )
353  {
354  r->setEmbeddedRenderer( QgsFeatureRendererV2::load( embeddedRendererElem ) );
355  }
356 
357  //center symbol
358  QDomElement centerSymbolElem = symbologyElem.firstChildElement( "symbol" );
359  if ( !centerSymbolElem.isNull() )
360  {
361  r->setCenterSymbol( QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( centerSymbolElem ) );
362  }
363  return r;
364 }
365 
366 QDomElement QgsPointDisplacementRenderer::save( QDomDocument& doc )
367 {
368  QDomElement rendererElement = doc.createElement( RENDERER_TAG_NAME );
369  rendererElement.setAttribute( "type", "pointDisplacement" );
370  rendererElement.setAttribute( "labelAttributeName", mLabelAttributeName );
371  rendererElement.setAttribute( "labelFont", mLabelFont.toString() );
372  rendererElement.setAttribute( "circleWidth", QString::number( mCircleWidth ) );
373  rendererElement.setAttribute( "circleColor", QgsSymbolLayerV2Utils::encodeColor( mCircleColor ) );
374  rendererElement.setAttribute( "labelColor", QgsSymbolLayerV2Utils::encodeColor( mLabelColor ) );
375  rendererElement.setAttribute( "circleRadiusAddition", QString::number( mCircleRadiusAddition ) );
376  rendererElement.setAttribute( "maxLabelScaleDenominator", QString::number( mMaxLabelScaleDenominator ) );
377  rendererElement.setAttribute( "tolerance", QString::number( mTolerance ) );
378 
379  if ( mRenderer )
380  {
381  QDomElement embeddedRendererElem = mRenderer->save( doc );
382  rendererElement.appendChild( embeddedRendererElem );
383  }
384  if ( mCenterSymbol )
385  {
386  QDomElement centerSymbolElem = QgsSymbolLayerV2Utils::saveSymbol( "centerSymbol", mCenterSymbol, doc );
387  rendererElement.appendChild( centerSymbolElem );
388  }
389 
390  if ( mPaintEffect )
391  mPaintEffect->saveProperties( doc, rendererElement );
392 
393  return rendererElement;
394 }
395 
397 {
398  if ( mRenderer )
399  {
400  return mRenderer->legendSymbologyItems( iconSize );
401  }
402  return QgsLegendSymbologyList();
403 }
404 
406 {
407  if ( mRenderer )
408  {
409  return mRenderer->legendSymbolItems( scaleDenominator, rule );
410  }
411  return QgsLegendSymbolList();
412 }
413 
414 
415 QgsRectangle QgsPointDisplacementRenderer::searchRect( const QgsPoint& p ) const
416 {
417  return QgsRectangle( p.x() - mTolerance, p.y() - mTolerance, p.x() + mTolerance, p.y() + mTolerance );
418 }
419 
420 void QgsPointDisplacementRenderer::printInfoDisplacementGroups()
421 {
422  int nGroups = mDisplacementGroups.size();
423  QgsDebugMsg( "number of displacement groups:" + QString::number( nGroups ) );
424  for ( int i = 0; i < nGroups; ++i )
425  {
426  QgsDebugMsg( "***************displacement group " + QString::number( i ) );
427  DisplacementGroup::const_iterator it = mDisplacementGroups.at( i ).constBegin();
428  for ( ; it != mDisplacementGroups.at( i ).constEnd(); ++it )
429  {
430  QgsDebugMsg( FID_TO_STRING( it.key() ) );
431  }
432  }
433 }
434 
435 QString QgsPointDisplacementRenderer::getLabel( const QgsFeature& f )
436 {
437  QString attribute;
438  QgsAttributes attrs = f.attributes();
439  if ( mLabelIndex >= 0 && mLabelIndex < attrs.count() )
440  {
441  attribute = attrs[mLabelIndex].toString();
442  }
443  return attribute;
444 }
445 
447 {
448  delete mCenterSymbol;
449  mCenterSymbol = symbol;
450 }
451 
452 
453 
454 void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius,
455  double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const
456 {
457  symbolPositions.clear();
458  labelShifts.clear();
459 
460  if ( nPosition < 1 )
461  {
462  return;
463  }
464  else if ( nPosition == 1 ) //If there is only one feature, draw it exactly at the center position
465  {
466  symbolPositions.append( centerPoint );
467  labelShifts.append( QPointF( symbolDiagonal / 2.0, -symbolDiagonal / 2.0 ) );
468  return;
469  }
470 
471  double fullPerimeter = 2 * M_PI;
472  double angleStep = fullPerimeter / nPosition;
473  double currentAngle;
474 
475  for ( currentAngle = 0.0; currentAngle < fullPerimeter; currentAngle += angleStep )
476  {
477  double sinusCurrentAngle = sin( currentAngle );
478  double cosinusCurrentAngle = cos( currentAngle );
479  QPointF positionShift( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
480  QPointF labelShift(( radius + symbolDiagonal / 2 ) * sinusCurrentAngle, ( radius + symbolDiagonal / 2 ) * cosinusCurrentAngle );
481  symbolPositions.append( centerPoint + positionShift );
482  labelShifts.append( labelShift );
483  }
484 }
485 
486 void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols )
487 {
488  QPainter* p = context.renderContext().painter();
489  if ( nSymbols < 2 || !p ) //draw circle only if multiple features
490  {
491  return;
492  }
493 
494  //draw Circle
495  QPen circlePen( mCircleColor );
496  circlePen.setWidthF( context.outputLineWidth( mCircleWidth ) );
497  p->setPen( circlePen );
498  p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
499 }
500 
501 void QgsPointDisplacementRenderer::drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
502 {
503  QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
504  QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
505  for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
506  {
507  if ( *symbolIt )
508  {
509  ( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
510  }
511  }
512 }
513 
514 void QgsPointDisplacementRenderer::drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList )
515 {
516  QPainter* p = context.renderContext().painter();
517  if ( !p )
518  {
519  return;
520  }
521 
522  QPen labelPen( mLabelColor );
523  p->setPen( labelPen );
524 
525  //scale font (for printing)
526  QFont pixelSizeFont = mLabelFont;
527  pixelSizeFont.setPixelSize( context.outputLineWidth( mLabelFont.pointSizeF() * 0.3527 ) );
528  QFont scaledFont = pixelSizeFont;
529  scaledFont.setPixelSize( pixelSizeFont.pixelSize() * context.renderContext().rasterScaleFactor() );
530  p->setFont( scaledFont );
531 
532  QFontMetricsF fontMetrics( pixelSizeFont );
533  QPointF currentLabelShift; //considers the signs to determine the label position
534 
535  QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
536  QStringList::const_iterator text_it = labelList.constBegin();
537 
538  for ( ; labelPosIt != labelShifts.constEnd() && text_it != labelList.constEnd(); ++labelPosIt, ++text_it )
539  {
540  currentLabelShift = *labelPosIt;
541  if ( currentLabelShift.x() < 0 )
542  {
543  currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( *text_it ) );
544  }
545  if ( currentLabelShift.y() > 0 )
546  {
547  currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
548  }
549 
550  QPointF drawingPoint( centerPoint + currentLabelShift );
551  p->save();
552  p->translate( drawingPoint.x(), drawingPoint.y() );
553  p->scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
554  p->drawText( QPointF( 0, 0 ), *text_it );
555  p->restore();
556  }
557 }
558 
559 QgsSymbolV2* QgsPointDisplacementRenderer::firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f )
560 {
561  if ( !r )
562  {
563  return 0;
564  }
565 
566  QgsSymbolV2List symbolList = r->symbolsForFeature( f );
567  if ( symbolList.size() < 1 )
568  {
569  return 0;
570  }
571 
572  return symbolList.at( 0 );
573 }
574 
576 {
577  if ( renderer->type() == "pointDisplacement" )
578  {
579  return dynamic_cast<QgsPointDisplacementRenderer*>( renderer->clone() );
580  }
581 
582  if ( renderer->type() == "singleSymbol" ||
583  renderer->type() == "categorizedSymbol" ||
584  renderer->type() == "graduatedSymbol" ||
585  renderer->type() == "RuleRenderer" )
586  {
588  pointRenderer->setEmbeddedRenderer( renderer->clone() );
589  return pointRenderer;
590  }
591  return 0;
592 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:51
#define RENDERER_TAG_NAME
Definition: qgsrendererv2.h:48
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:96
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:39
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.
static const unsigned char * _getPoint(QPointF &pt, QgsRenderContext &context, const unsigned char *wkb)
static QgsFeatureRendererV2 * create(QDomElement &symbologyElem)
create a renderer from XML element
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
void setLabelAttributeName(const QString &name)
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name - case insensitive TODO: sort out case sensitive (indexFromName()) vs...
Definition: qgsfield.cpp:354
double rendererScale() const
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
void setCenterSymbol(QgsMarkerSymbolV2 *symbol)
Sets the center symbol (takes ownership)
QgsLegendSymbologyList legendSymbologyItems(QSize iconSize) override
return a list of symbology items for the legend
#define FID_TO_STRING(fid)
Definition: qgsfeature.h:89
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
Container of fields for a vector layer.
Definition: qgsfield.h:173
static QgsPointDisplacementRenderer * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
creates a QgsPointDisplacementRenderer from an existing renderer.
static QColor decodeColor(QString str)
QDomElement save(QDomDocument &doc) override
store renderer info to XML element
virtual QgsSymbolV2List symbolsForFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.
virtual QList< QString > usedAttributes()=0
WkbType
Used for symbology operations.
Definition: qgis.h:53
QgsPointDisplacementRenderer(const QString &labelAttributeName="")
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:119
void startRender(QgsRenderContext &context, const QgsFields &fields) override
QList< QgsFeatureId > intersects(QgsRectangle rect) const
returns features that intersect the specified rectangle
QgsPaintEffect * mPaintEffect
double x() const
Definition: qgspoint.h:126
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
static QString encodeColor(QColor color)
virtual void stopRender(QgsRenderContext &context)=0
QString type() const
Definition: qgsrendererv2.h:82
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
virtual QgsSymbolV2List symbols()=0
for symbol levels
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
virtual QgsFeatureRendererV2 * clone() const =0
void setEmbeddedRenderer(QgsFeatureRendererV2 *r)
Sets embedded renderer (takes ownership)
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
QgsAttributes attributes() const
Returns the feature's attributes.
Definition: qgsfeature.cpp:90
#define M_PI
virtual void toSld(QDomDocument &doc, QDomElement &element) const override
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QgsSymbolV2 * clone() const override
double rasterScaleFactor() const
static QgsFeatureRendererV2 * defaultRenderer(QGis::GeometryType geomType)
return a new renderer - used by default in vector layers
void renderPoint(const QPointF &point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="") override
A class to represent a point.
Definition: qgspoint.h:63
bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Reimplemented from QgsFeatureRendererV2.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
void stopRender(QgsRenderContext &context) override
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
A renderer that automatically displaces points with the same position.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
Contains information about the context of a rendering operation.
bool insertFeature(const QgsFeature &f)
add feature to index
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature) override
Proxy that will call this method on the embedded renderer.
QPainter * painter()
void stopRender(QgsRenderContext &context)
void copyPaintEffect(QgsFeatureRendererV2 *destRenderer) const
Copies paint effect of this renderer to another renderer.
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
virtual QgsSymbolV2List symbols() override
Proxy that will call this method on the embedded renderer.
QVector< QVariant > QgsAttributes
Definition: qgsfeature.h:106
virtual QgsSymbolV2List symbolsForFeature(QgsFeature &feat)
return list of symbols used for rendering the feature.
static QgsFeatureRendererV2 * load(QDomElement &symbologyElem)
create a renderer from XML element
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:221
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:68
qint64 QgsFeatureId
Definition: qgsfeature.h:31
double y() const
Definition: qgspoint.h:134
virtual int capabilities() override
Proxy that will call this method on the embedded renderer.
virtual bool willRenderFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.
double outputLineWidth(double width) const
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
virtual QList< QString > usedAttributes() override
Partial proxy that will call this method on the embedded renderer.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:43
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
QgsFeatureRendererV2 * clone() const override
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.