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