QGIS API Documentation  2.11.0-Master
qgsrendererv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererv2.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsrendererv2.h"
17 #include "qgssymbolv2.h"
18 #include "qgssymbollayerv2utils.h"
19 #include "qgsrulebasedrendererv2.h"
20 #include "qgsdatadefined.h"
21 
22 #include "qgssinglesymbolrendererv2.h" // for default renderer
23 
24 #include "qgsrendererv2registry.h"
25 
26 #include "qgsrendercontext.h"
27 #include "qgsclipper.h"
28 #include "qgsgeometry.h"
29 #include "qgsfeature.h"
30 #include "qgslogger.h"
31 #include "qgsvectorlayer.h"
32 #include "qgspainteffect.h"
33 #include "qgseffectstack.h"
34 #include "qgspainteffectregistry.h"
35 #include "qgswkbptr.h"
36 
37 #include <QDomElement>
38 #include <QDomDocument>
39 #include <QPolygonF>
40 
41 
42 
43 const unsigned char* QgsFeatureRendererV2::_getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb )
44 {
45  QgsConstWkbPtr wkbPtr( wkb + 1 );
46  unsigned int wkbType;
47  wkbPtr >> wkbType >> pt.rx() >> pt.ry();
48 
49  if ( wkbType == QGis::WKBPoint25D || wkbType == QgsWKBTypes::PointZ )
50  wkbPtr += sizeof( double );
51 
52  if ( context.coordinateTransform() )
53  {
54  double z = 0; // dummy variable for coordiante transform
55  context.coordinateTransform()->transformInPlace( pt.rx(), pt.ry(), z );
56  }
57 
58  context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
59 
60  return wkbPtr;
61 }
62 
63 const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
64 {
65  QgsConstWkbPtr wkbPtr( wkb + 1 );
66  unsigned int wkbType, nPoints;
67  wkbPtr >> wkbType >> nPoints;
68 
69  bool hasZValue = wkbType == QGis::WKBLineString25D || wkbType == QgsWKBTypes::LineStringZ;
70 
71  double x = 0.0;
72  double y = 0.0;
73  const QgsCoordinateTransform* ct = context.coordinateTransform();
74  const QgsMapToPixel& mtp = context.mapToPixel();
75 
76  //apply clipping for large lines to achieve a better rendering performance
77  if ( clipToExtent && nPoints > 1 )
78  {
79  const QgsRectangle& e = context.extent();
80  double cw = e.width() / 10; double ch = e.height() / 10;
81  QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
82  wkbPtr = QgsConstWkbPtr( QgsClipper::clippedLineWKB( wkb, clipRect, pts ) );
83  }
84  else
85  {
86  pts.resize( nPoints );
87 
88  QPointF* ptr = pts.data();
89  for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
90  {
91  wkbPtr >> x >> y;
92  if ( hasZValue )
93  wkbPtr += sizeof( double );
94 
95  *ptr = QPointF( x, y );
96  }
97  }
98 
99  //transform the QPolygonF to screen coordinates
100  if ( ct )
101  {
102  ct->transformPolygon( pts );
103  }
104 
105  QPointF* ptr = pts.data();
106  for ( int i = 0; i < pts.size(); ++i, ++ptr )
107  {
108  mtp.transformInPlace( ptr->rx(), ptr->ry() );
109  }
110 
111  return wkbPtr;
112 }
113 
114 const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
115 {
116  QgsConstWkbPtr wkbPtr( wkb + 1 );
117 
118  unsigned int wkbType, numRings;
119  wkbPtr >> wkbType >> numRings;
120 
121  if ( numRings == 0 ) // sanity check for zero rings in polygon
122  return wkbPtr;
123 
124  bool hasZValue = wkbType == QGis::WKBPolygon25D || wkbType == QgsWKBTypes::PolygonZ;
125 
126  double x, y;
127  holes.clear();
128 
129  const QgsCoordinateTransform* ct = context.coordinateTransform();
130  const QgsMapToPixel& mtp = context.mapToPixel();
131  const QgsRectangle& e = context.extent();
132  double cw = e.width() / 10; double ch = e.height() / 10;
133  QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
134 
135  for ( unsigned int idx = 0; idx < numRings; idx++ )
136  {
137  unsigned int nPoints;
138  wkbPtr >> nPoints;
139 
140  QPolygonF poly( nPoints );
141 
142  // Extract the points from the WKB and store in a pair of vectors.
143  QPointF* ptr = poly.data();
144  for ( unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
145  {
146  wkbPtr >> x >> y;
147  if ( hasZValue )
148  wkbPtr += sizeof( double );
149 
150  *ptr = QPointF( x, y );
151  }
152 
153  if ( nPoints < 1 )
154  continue;
155 
156  //clip close to view extent, if needed
157  QRectF ptsRect = poly.boundingRect();
158  if ( clipToExtent && !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );
159 
160  //transform the QPolygonF to screen coordinates
161  if ( ct )
162  {
163  ct->transformPolygon( poly );
164  }
165 
166 
167  ptr = poly.data();
168  for ( int i = 0; i < poly.size(); ++i, ++ptr )
169  {
170  mtp.transformInPlace( ptr->rx(), ptr->ry() );
171  }
172 
173  if ( idx == 0 )
174  pts = poly;
175  else
176  holes.append( poly );
177  }
178 
179  return wkbPtr;
180 }
181 
183 {
184  if ( symbol )
185  {
186  if ( symbol->type() == QgsSymbolV2::Marker )
187  {
188  QgsMarkerSymbolV2* ms = static_cast<QgsMarkerSymbolV2*>( symbol );
189  if ( ms )
190  {
191  ms->setScaleMethod(( QgsSymbolV2::ScaleMethod )scaleMethod );
192  }
193  }
194  }
195 }
196 
198 {
199  if ( !destRenderer || !mPaintEffect )
200  return;
201 
202  destRenderer->setPaintEffect( mPaintEffect->clone() );
203 }
204 
205 
207  : mType( type )
208  , mUsingSymbolLevels( false )
209  , mCurrentVertexMarkerType( QgsVectorLayer::Cross )
210  , mCurrentVertexMarkerSize( 3 )
211  , mPaintEffect( 0 )
212 {
214  mPaintEffect->setEnabled( false );
215 }
216 
218 {
219  delete mPaintEffect;
220 }
221 
223 {
224  return new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geomType ) );
225 }
226 
228 {
229  startRender( context, vlayer->pendingFields() );
230 }
231 
232 bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
233 {
234  QgsSymbolV2* symbol = symbolForFeature( feature );
235  if ( symbol == NULL )
236  return false;
237 
238  renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
239  return true;
240 }
241 
242 void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
243 {
244  QgsSymbolV2::SymbolType symbolType = symbol->type();
245 
246  const QgsGeometry* geom = feature.constGeometry();
247  if ( !geom || !geom->geometry() )
248  {
249  return;
250  }
251 
252  //convert curve types to normal point/line/polygon ones
253  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
254  {
260  {
261  QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
262  if ( !g )
263  {
264  return;
265  }
266  feature.setGeometry( new QgsGeometry( g ) );
267  geom = feature.constGeometry();
268  }
269  default:
270  break;
271  }
272 
273  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
274  {
275  case QgsWKBTypes::Point:
276  {
277  if ( symbolType != QgsSymbolV2::Marker )
278  {
279  QgsDebugMsg( "point can be drawn only with marker symbol!" );
280  break;
281  }
282  QPointF pt;
283  _getPoint( pt, context, geom->asWkb() );
284  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
285 
286  //if ( drawVertexMarker )
287  // renderVertexMarker( pt, context );
288  }
289  break;
291  {
292  if ( symbolType != QgsSymbolV2::Line )
293  {
294  QgsDebugMsg( "linestring can be drawn only with line symbol!" );
295  break;
296  }
297  QPolygonF pts;
298  _getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
299  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
300 
301  if ( drawVertexMarker )
302  renderVertexMarkerPolyline( pts, context );
303  }
304  break;
306  {
307  if ( symbolType != QgsSymbolV2::Fill )
308  {
309  QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
310  break;
311  }
312  QPolygonF pts;
313  QList<QPolygonF> holes;
314  _getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
315  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
316 
317  if ( drawVertexMarker )
318  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
319  }
320  break;
321 
323  {
324  if ( symbolType != QgsSymbolV2::Marker )
325  {
326  QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
327  break;
328  }
329 
330  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
331  unsigned int num;
332  wkbPtr >> num;
333  const unsigned char* ptr = wkbPtr;
334  QPointF pt;
335 
336  for ( unsigned int i = 0; i < num; ++i )
337  {
338  ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
339  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
340 
341  //if ( drawVertexMarker )
342  // renderVertexMarker( pt, context );
343  }
344  }
345  break;
346 
348  {
349  if ( symbolType != QgsSymbolV2::Line )
350  {
351  QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
352  break;
353  }
354 
355  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
356  unsigned int num;
357  wkbPtr >> num;
358  const unsigned char* ptr = wkbPtr;
359  QPolygonF pts;
360 
361  for ( unsigned int i = 0; i < num; ++i )
362  {
363  ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
364  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
365 
366  if ( drawVertexMarker )
367  renderVertexMarkerPolyline( pts, context );
368  }
369  }
370  break;
371 
373  {
374  if ( symbolType != QgsSymbolV2::Fill )
375  {
376  QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
377  break;
378  }
379 
380  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
381  unsigned int num;
382  wkbPtr >> num;
383  const unsigned char* ptr = wkbPtr;
384  QPolygonF pts;
385  QList<QPolygonF> holes;
386 
387  for ( unsigned int i = 0; i < num; ++i )
388  {
389  ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
390  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
391 
392  if ( drawVertexMarker )
393  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
394  }
395  break;
396  }
397  default:
398  QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
399  }
400 }
401 
403 {
404  return "UNKNOWN RENDERER\n";
405 }
406 
407 
409 {
410  // <renderer-v2 type=""> ... </renderer-v2>
411 
412  if ( element.isNull() )
413  return NULL;
414 
415  // load renderer
416  QString rendererType = element.attribute( "type" );
417 
419  if ( m == NULL )
420  return NULL;
421 
422  QgsFeatureRendererV2* r = m->createRenderer( element );
423  if ( r )
424  {
425  r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
426 
427  //restore layer effect
428  QDomElement effectElem = element.firstChildElement( "effect" );
429  if ( !effectElem.isNull() )
430  {
431  r->setPaintEffect( QgsPaintEffectRegistry::instance()->createEffect( effectElem ) );
432  }
433  }
434  return r;
435 }
436 
438 {
439  // create empty renderer element
440  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
441 
442  if ( mPaintEffect )
443  mPaintEffect->saveProperties( doc, rendererElem );
444 
445  return rendererElem;
446 }
447 
449 {
450  QDomElement element = node.toElement();
451  if ( element.isNull() )
452  return NULL;
453 
454  // get the UserStyle element
455  QDomElement userStyleElem = element.firstChildElement( "UserStyle" );
456  if ( userStyleElem.isNull() )
457  {
458  // UserStyle element not found, nothing will be rendered
459  errorMessage = "Info: UserStyle element not found.";
460  return NULL;
461  }
462 
463  // get the FeatureTypeStyle element
464  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( "FeatureTypeStyle" );
465  if ( featTypeStyleElem.isNull() )
466  {
467  errorMessage = "Info: FeatureTypeStyle element not found.";
468  return NULL;
469  }
470 
471  // use the RuleRenderer when more rules are present or the rule
472  // has filters or min/max scale denominators set,
473  // otherwise use the SingleSymbol renderer
474  bool needRuleRenderer = false;
475  int ruleCount = 0;
476 
477  QDomElement ruleElem = featTypeStyleElem.firstChildElement( "Rule" );
478  while ( !ruleElem.isNull() )
479  {
480  ruleCount++;
481 
482  // more rules present, use the RuleRenderer
483  if ( ruleCount > 1 )
484  {
485  QgsDebugMsg( "more Rule elements found: need a RuleRenderer" );
486  needRuleRenderer = true;
487  break;
488  }
489 
490  QDomElement ruleChildElem = ruleElem.firstChildElement();
491  while ( !ruleChildElem.isNull() )
492  {
493  // rule has filter or min/max scale denominator, use the RuleRenderer
494  if ( ruleChildElem.localName() == "Filter" ||
495  ruleChildElem.localName() == "MinScaleDenominator" ||
496  ruleChildElem.localName() == "MaxScaleDenominator" )
497  {
498  QgsDebugMsg( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
499  needRuleRenderer = true;
500  break;
501  }
502 
503  ruleChildElem = ruleChildElem.nextSiblingElement();
504  }
505 
506  if ( needRuleRenderer )
507  {
508  break;
509  }
510 
511  ruleElem = ruleElem.nextSiblingElement( "Rule" );
512  }
513 
514  QString rendererType;
515  if ( needRuleRenderer )
516  {
517  rendererType = "RuleRenderer";
518  }
519  else
520  {
521  rendererType = "singleSymbol";
522  }
523  QgsDebugMsg( QString( "Instantiating a '%1' renderer..." ).arg( rendererType ) );
524 
525  // create the renderer and return it
527  if ( m == NULL )
528  {
529  errorMessage = QString( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
530  return NULL;
531  }
532 
533  QgsFeatureRendererV2* r = m->createRendererFromSld( featTypeStyleElem, geomType );
534  return r;
535 }
536 
538 {
539  return writeSld( doc, layer.name() );
540 }
541 
543 {
544  QDomElement userStyleElem = doc.createElement( "UserStyle" );
545 
546  QDomElement nameElem = doc.createElement( "se:Name" );
547  nameElem.appendChild( doc.createTextNode( styleName ) );
548  userStyleElem.appendChild( nameElem );
549 
550  QDomElement featureTypeStyleElem = doc.createElement( "se:FeatureTypeStyle" );
551  toSld( doc, featureTypeStyleElem );
552  userStyleElem.appendChild( featureTypeStyleElem );
553 
554  return userStyleElem;
555 }
556 
558 {
559  Q_UNUSED( iconSize );
560  // empty list by default
561  return QgsLegendSymbologyList();
562 }
563 
565 {
566  return false;
567 }
568 
570 {
571  Q_UNUSED( key );
572  return false;
573 }
574 
576 {
577  Q_UNUSED( key );
578  Q_UNUSED( state );
579 }
580 
582 {
583  Q_UNUSED( scaleDenominator );
584  Q_UNUSED( rule );
585  return QgsLegendSymbolList();
586 }
587 
589 {
590  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
592  int i = 0;
593  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
594  {
595  lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
596  }
597  return lst2;
598 }
599 
601 {
604 }
605 
607 {
608  QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
611 }
612 
614 {
615  foreach ( QPointF pt, pts )
616  renderVertexMarker( pt, context );
617 }
618 
620 {
621  foreach ( QPointF pt, pts )
622  renderVertexMarker( pt, context );
623 
624  if ( rings )
625  {
626  foreach ( QPolygonF ring, *rings )
627  {
628  foreach ( QPointF pt, ring )
629  renderVertexMarker( pt, context );
630  }
631  }
632 }
633 
635 {
636  QgsSymbolV2List lst;
637  QgsSymbolV2* s = symbolForFeature( feat );
638  if ( s ) lst.append( s );
639  return lst;
640 }
641 
643 {
644  QgsSymbolV2List lst;
646  if ( s ) lst.append( s );
647  return lst;
648 }
649 
651 {
652  return mPaintEffect;
653 }
654 
656 {
657  delete mPaintEffect;
658  mPaintEffect = effect;
659 }
660 
662 {
663  if ( symbol->type() == QgsSymbolV2::Marker )
664  {
665  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
667  {
668  const QgsDataDefined dd( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" );
669  s->setDataDefinedSize( dd );
670  }
671  else
672  {
673  const QgsDataDefined dd( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" );
674  s->setDataDefinedSize( dd );
675  }
677  }
678  else if ( symbol->type() == QgsSymbolV2::Line )
679  {
680  QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
681  const QgsDataDefined dd( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" );
682  s->setDataDefinedWidth( dd );
683  }
684 }
685 
687 {
688  if ( symbol->type() == QgsSymbolV2::Marker )
689  {
690  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
691  const QgsDataDefined dd(( s->angle()
692  ? QString::number( s->angle() ) + " + "
693  : QString() ) + field );
694  s->setDataDefinedAngle( dd );
695  }
696 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:51
void clear()
static QgsRendererV2Registry * instance()
#define RENDERER_TAG_NAME
Definition: qgsrendererv2.h:48
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:96
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
const QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
void setDataDefinedAngle(const QgsDataDefined &dd)
Set data defined angle for whole symbol (including all symbol layers).
A container class for data source field mapping or expression.
QgsRendererV2AbstractMetadata * rendererMetadata(QString rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
QDomNode appendChild(const QDomNode &newChild)
static QgsFeatureRendererV2 * loadSld(const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage)
create a new renderer according to the information contained in the UserStyle element of a SLD style ...
SymbolType type() const
Definition: qgssymbolv2.h:86
static const unsigned char * _getPoint(QPointF &pt, QgsRenderContext &context, const unsigned char *wkb)
void transformPolygon(QPolygonF &poly, TransformDirection direction=ForwardTransform) const
QString attribute(const QString &name, const QString &defValue) const
virtual QString dump() const
for debugging
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:192
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
void transformInPlace(qreal &x, qreal &y) const
Transform device coordinates to map (world) coordinates.
double size() const
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
static const unsigned char * clippedLineWKB(const unsigned char *wkb, const QgsRectangle &clipExtent, QPolygonF &line)
Reads a polyline from WKB and clips it to clipExtent.
Definition: qgsclipper.cpp:40
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
double clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
Definition: qgssymbolv2.h:183
Base class for visual effects which can be applied to QPicture drawings.
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
QDomElement nextSiblingElement(const QString &tagName) const
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:75
Stores metadata about one renderer class.
virtual ~QgsFeatureRendererV2()
GeometryType
Definition: qgis.h:155
const QgsRectangle & extent() const
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:119
const QgsCoordinateTransform * coordinateTransform() const
QgsPaintEffect * mPaintEffect
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
void renderFeatureWithSymbol(QgsFeature &feature, QgsSymbolV2 *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
QString type() const
Definition: qgsrendererv2.h:82
QDomElement toElement() const
const QString & name() const
Get the display name of the layer.
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
T * data()
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
static Type flatType(Type type)
Definition: qgswkbtypes.cpp:46
void transformInPlace(double &x, double &y, double &z, TransformDirection direction=ForwardTransform) const
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
Definition: qgsfeature.cpp:104
QString number(int n, int base)
int count(const T &value) const
qreal x() const
qreal y() const
void append(const T &value)
double width() const
QString localName() const
void resize(int size)
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects. ...
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:197
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:182
static QgsPaintEffectRegistry * instance()
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
int mCurrentVertexMarkerSize
The current size of editing marker.
VertexMarkerType
Editing vertex markers.
int toInt(bool *ok, int base) const
int mCurrentVertexMarkerType
The current type of editing marker.
double angle() const
static const unsigned char * _getPolygon(QPolygonF &pts, QList< QPolygonF > &holes, QgsRenderContext &context, const unsigned char *wkb, bool clipToExtent=true)
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the renderer.
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
virtual QgsFeatureRendererV2 * createRenderer(QDomElement &elem)=0
Return new instance of the renderer given the DOM element.
static QgsFeatureRendererV2 * defaultRenderer(QGis::GeometryType geomType)
return a new renderer - used by default in vector layers
static void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y.
static void convertSymbolSizeScale(QgsSymbolV2 *symbol, QgsSymbolV2::ScaleMethod method, const QString &field)
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
QDomText createTextNode(const QString &value)
iterator end()
QgsFeatureRendererV2(QString type)
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QgsAbstractGeometryV2 * segmentize() const
Returns a version of the geometry without curves.
bool isNull() const
void setDataDefinedWidth(const QgsDataDefined &dd)
Set data defined width for whole symbol (including all symbol layers).
void setUsingSymbolLevels(bool usingSymbolLevels)
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.
QRectF boundingRect() const
QPainter * painter()
void copyPaintEffect(QgsFeatureRendererV2 *destRenderer) const
Copies paint effect of this renderer to another renderer.
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
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
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const
Return a list of symbology items for the legend.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
QDomElement firstChildElement(const QString &tagName) const
void setScaleMethodToSymbol(QgsSymbolV2 *symbol, int scaleMethod)
virtual Q_DECL_DEPRECATED QDomElement writeSld(QDomDocument &doc, const QgsVectorLayer &layer) const
create the SLD UserStyle element following the SLD v1.1 specs
void renderVertexMarkerPolygon(QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
render editing vertex marker for a polygon
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:68
qreal & rx()
qreal & ry()
Class for doing transforms between two map coordinate systems.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
const QgsMapToPixel & mapToPixel() const
static const unsigned char * _getLineString(QPolygonF &pts, QgsRenderContext &context, const unsigned char *wkb, bool clipToExtent=true)
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QDomElement createElement(const QString &tagName)
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:202
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
Definition: qgsclipper.h:178
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
int size() const
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:43
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:187
iterator begin()
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
void renderVertexMarker(QPointF &pt, QgsRenderContext &context)
render editing vertex marker at specified point
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
static void convertSymbolRotation(QgsSymbolV2 *symbol, const QString &field)