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