QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 #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 );
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();
238 }
239 
241 {
242  if ( !mRenderer )
243  {
244  return 0;
245  }
246  return mRenderer->symbolForFeature( feature );
247 }
248 
250 {
251  if ( !mRenderer )
252  return 0;
253  return mRenderer->originalSymbolForFeature( feat );
254 }
255 
257 {
258  if ( !mRenderer )
259  {
260  return QgsSymbolV2List();
261  }
262  return mRenderer->symbolsForFeature( feature );
263 }
264 
266 {
267  if ( !mRenderer )
268  return QgsSymbolV2List();
269  return mRenderer->originalSymbolsForFeature( feat );
270 }
271 
273 {
274  if ( !mRenderer )
275  {
276  return false;
277  }
278  return mRenderer->willRenderFeature( feat );
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 }
314 
316 {
317  QgsDebugMsg( "QgsPointDisplacementRenderer::stopRender" );
318 
319  //printInfoDisplacementGroups(); //just for debugging
320 
321  for ( QList<DisplacementGroup>::const_iterator it = mDisplacementGroups.begin(); it != mDisplacementGroups.end(); ++it )
322  drawGroup( *it, context );
323 
324  mDisplacementGroups.clear();
325  mGroupIndex.clear();
326  delete mSpatialIndex;
327  mSpatialIndex = 0;
328  mSelectedFeatures.clear();
329 
330  mRenderer->stopRender( context );
331  if ( mCenterSymbol )
332  {
333  mCenterSymbol->stopRender( context );
334  }
335 }
336 
338 {
340  r->setLabelAttributeName( symbologyElem.attribute( "labelAttributeName" ) );
342  if ( !QgsFontUtils::setFromXmlChildNode( labelFont, symbologyElem, "labelFontProperties" ) )
343  {
344  labelFont.fromString( symbologyElem.attribute( "labelFont", "" ) );
345  }
346  r->setLabelFont( labelFont );
347  r->setCircleWidth( symbologyElem.attribute( "circleWidth", "0.4" ).toDouble() );
348  r->setCircleColor( QgsSymbolLayerV2Utils::decodeColor( symbologyElem.attribute( "circleColor", "" ) ) );
349  r->setLabelColor( QgsSymbolLayerV2Utils::decodeColor( symbologyElem.attribute( "labelColor", "" ) ) );
350  r->setCircleRadiusAddition( symbologyElem.attribute( "circleRadiusAddition", "0.0" ).toDouble() );
351  r->setMaxLabelScaleDenominator( symbologyElem.attribute( "maxLabelScaleDenominator", "-1" ).toDouble() );
352  r->setTolerance( symbologyElem.attribute( "tolerance", "0.00001" ).toDouble() );
353 
354  //look for an embedded renderer <renderer-v2>
355  QDomElement embeddedRendererElem = symbologyElem.firstChildElement( "renderer-v2" );
356  if ( !embeddedRendererElem.isNull() )
357  {
358  r->setEmbeddedRenderer( QgsFeatureRendererV2::load( embeddedRendererElem ) );
359  }
360 
361  //center symbol
362  QDomElement centerSymbolElem = symbologyElem.firstChildElement( "symbol" );
363  if ( !centerSymbolElem.isNull() )
364  {
365  r->setCenterSymbol( QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( centerSymbolElem ) );
366  }
367  return r;
368 }
369 
371 {
372  QDomElement rendererElement = doc.createElement( RENDERER_TAG_NAME );
373  rendererElement.setAttribute( "type", "pointDisplacement" );
374  rendererElement.setAttribute( "labelAttributeName", mLabelAttributeName );
375  rendererElement.appendChild( QgsFontUtils::toXmlElement( mLabelFont, doc, "labelFontProperties" ) );
376  rendererElement.setAttribute( "circleWidth", QString::number( mCircleWidth ) );
377  rendererElement.setAttribute( "circleColor", QgsSymbolLayerV2Utils::encodeColor( mCircleColor ) );
378  rendererElement.setAttribute( "labelColor", QgsSymbolLayerV2Utils::encodeColor( mLabelColor ) );
379  rendererElement.setAttribute( "circleRadiusAddition", QString::number( mCircleRadiusAddition ) );
380  rendererElement.setAttribute( "maxLabelScaleDenominator", QString::number( mMaxLabelScaleDenominator ) );
381  rendererElement.setAttribute( "tolerance", QString::number( mTolerance ) );
382 
383  if ( mRenderer )
384  {
385  QDomElement embeddedRendererElem = mRenderer->save( doc );
386  rendererElement.appendChild( embeddedRendererElem );
387  }
388  if ( mCenterSymbol )
389  {
390  QDomElement centerSymbolElem = QgsSymbolLayerV2Utils::saveSymbol( "centerSymbol", mCenterSymbol, doc );
391  rendererElement.appendChild( centerSymbolElem );
392  }
393 
394  if ( mPaintEffect )
395  mPaintEffect->saveProperties( doc, rendererElement );
396 
397  return rendererElement;
398 }
399 
401 {
402  if ( mRenderer )
403  {
404  return mRenderer->legendSymbologyItems( iconSize );
405  }
406  return QgsLegendSymbologyList();
407 }
408 
410 {
411  if ( mRenderer )
412  {
413  return mRenderer->legendSymbolItems( scaleDenominator, rule );
414  }
415  return QgsLegendSymbolList();
416 }
417 
418 
419 QgsRectangle QgsPointDisplacementRenderer::searchRect( const QgsPoint& p ) const
420 {
421  return QgsRectangle( p.x() - mTolerance, p.y() - mTolerance, p.x() + mTolerance, p.y() + mTolerance );
422 }
423 
424 void QgsPointDisplacementRenderer::printInfoDisplacementGroups()
425 {
426  int nGroups = mDisplacementGroups.size();
427  QgsDebugMsg( "number of displacement groups:" + QString::number( nGroups ) );
428  for ( int i = 0; i < nGroups; ++i )
429  {
430  QgsDebugMsg( "***************displacement group " + QString::number( i ) );
431  DisplacementGroup::const_iterator it = mDisplacementGroups.at( i ).constBegin();
432  for ( ; it != mDisplacementGroups.at( i ).constEnd(); ++it )
433  {
434  QgsDebugMsg( FID_TO_STRING( it.key() ) );
435  }
436  }
437 }
438 
439 QString QgsPointDisplacementRenderer::getLabel( const QgsFeature& f )
440 {
441  QString attribute;
442  QgsAttributes attrs = f.attributes();
443  if ( mLabelIndex >= 0 && mLabelIndex < attrs.count() )
444  {
445  attribute = attrs[mLabelIndex].toString();
446  }
447  return attribute;
448 }
449 
451 {
452  delete mCenterSymbol;
453  mCenterSymbol = symbol;
454 }
455 
456 
457 
458 void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius,
459  double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const
460 {
461  symbolPositions.clear();
462  labelShifts.clear();
463 
464  if ( nPosition < 1 )
465  {
466  return;
467  }
468  else if ( nPosition == 1 ) //If there is only one feature, draw it exactly at the center position
469  {
470  symbolPositions.append( centerPoint );
471  labelShifts.append( QPointF( symbolDiagonal / 2.0, -symbolDiagonal / 2.0 ) );
472  return;
473  }
474 
475  double fullPerimeter = 2 * M_PI;
476  double angleStep = fullPerimeter / nPosition;
477  double currentAngle;
478 
479  for ( currentAngle = 0.0; currentAngle < fullPerimeter; currentAngle += angleStep )
480  {
481  double sinusCurrentAngle = sin( currentAngle );
482  double cosinusCurrentAngle = cos( currentAngle );
483  QPointF positionShift( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
484  QPointF labelShift(( radius + symbolDiagonal / 2 ) * sinusCurrentAngle, ( radius + symbolDiagonal / 2 ) * cosinusCurrentAngle );
485  symbolPositions.append( centerPoint + positionShift );
486  labelShifts.append( labelShift );
487  }
488 }
489 
490 void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols )
491 {
492  QPainter* p = context.renderContext().painter();
493  if ( nSymbols < 2 || !p ) //draw circle only if multiple features
494  {
495  return;
496  }
497 
498  //draw Circle
499  QPen circlePen( mCircleColor );
500  circlePen.setWidthF( context.outputLineWidth( mCircleWidth ) );
501  p->setPen( circlePen );
502  p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
503 }
504 
505 void QgsPointDisplacementRenderer::drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
506 {
507  QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
509  for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
510  {
511  if ( *symbolIt )
512  {
513  ( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
514  }
515  }
516 }
517 
518 void QgsPointDisplacementRenderer::drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList )
519 {
520  QPainter* p = context.renderContext().painter();
521  if ( !p )
522  {
523  return;
524  }
525 
526  QPen labelPen( mLabelColor );
527  p->setPen( labelPen );
528 
529  //scale font (for printing)
530  QFont pixelSizeFont = mLabelFont;
531  pixelSizeFont.setPixelSize( context.outputLineWidth( mLabelFont.pointSizeF() * 0.3527 ) );
532  QFont scaledFont = pixelSizeFont;
533  scaledFont.setPixelSize( pixelSizeFont.pixelSize() * context.renderContext().rasterScaleFactor() );
534  p->setFont( scaledFont );
535 
536  QFontMetricsF fontMetrics( pixelSizeFont );
537  QPointF currentLabelShift; //considers the signs to determine the label position
538 
539  QList<QPointF>::const_iterator labelPosIt = labelShifts.constBegin();
540  QStringList::const_iterator text_it = labelList.constBegin();
541 
542  for ( ; labelPosIt != labelShifts.constEnd() && text_it != labelList.constEnd(); ++labelPosIt, ++text_it )
543  {
544  currentLabelShift = *labelPosIt;
545  if ( currentLabelShift.x() < 0 )
546  {
547  currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( *text_it ) );
548  }
549  if ( currentLabelShift.y() > 0 )
550  {
551  currentLabelShift.setY( currentLabelShift.y() + fontMetrics.ascent() );
552  }
553 
554  QPointF drawingPoint( centerPoint + currentLabelShift );
555  p->save();
556  p->translate( drawingPoint.x(), drawingPoint.y() );
557  p->scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
558  p->drawText( QPointF( 0, 0 ), *text_it );
559  p->restore();
560  }
561 }
562 
563 QgsSymbolV2* QgsPointDisplacementRenderer::firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f )
564 {
565  if ( !r )
566  {
567  return 0;
568  }
569 
570  QgsSymbolV2List symbolList = r->symbolsForFeature( f );
571  if ( symbolList.size() < 1 )
572  {
573  return 0;
574  }
575 
576  return symbolList.at( 0 );
577 }
578 
580 {
581  if ( renderer->type() == "pointDisplacement" )
582  {
583  return dynamic_cast<QgsPointDisplacementRenderer*>( renderer->clone() );
584  }
585 
586  if ( renderer->type() == "singleSymbol" ||
587  renderer->type() == "categorizedSymbol" ||
588  renderer->type() == "graduatedSymbol" ||
589  renderer->type() == "RuleRenderer" )
590  {
592  pointRenderer->setEmbeddedRenderer( renderer->clone() );
593  return pointRenderer;
594  }
595  return 0;
596 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:51
void clear()
#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
int pixelSize() const
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:39
QDomNode appendChild(const QDomNode &newChild)
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.
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
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)
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:173
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.
WkbType
Used for symbology operations.
Definition: qgis.h:53
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
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
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
int size() const
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...
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)
qreal x() const
qreal y() const
void append(const T &value)
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
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
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.
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
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.
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
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
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)
virtual bool willRenderFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.
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
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
QgsFeatureRendererV2 * clone() const override
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat) override
Proxy that will call this method on the embedded renderer.