QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
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 = QgsWKBTypes::hasZ(( QgsWKBTypes::Type )wkbType );
70  bool hasMValue = QgsWKBTypes::hasM(( QgsWKBTypes::Type )wkbType );
71 
72  double x = 0.0;
73  double y = 0.0;
74  const QgsCoordinateTransform* ct = context.coordinateTransform();
75  const QgsMapToPixel& mtp = context.mapToPixel();
76 
77  //apply clipping for large lines to achieve a better rendering performance
78  if ( clipToExtent && nPoints > 1 )
79  {
80  const QgsRectangle& e = context.extent();
81  double cw = e.width() / 10; double ch = e.height() / 10;
82  QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
83  wkbPtr = QgsConstWkbPtr( QgsClipper::clippedLineWKB( wkb, clipRect, pts ) );
84  }
85  else
86  {
87  pts.resize( nPoints );
88 
89  QPointF* ptr = pts.data();
90  for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
91  {
92  wkbPtr >> x >> y;
93  if ( hasZValue )
94  wkbPtr += sizeof( double );
95  if ( hasMValue )
96  wkbPtr += sizeof( double );
97 
98  *ptr = QPointF( x, y );
99  }
100  }
101 
102  //transform the QPolygonF to screen coordinates
103  if ( ct )
104  {
105  ct->transformPolygon( pts );
106  }
107 
108  QPointF* ptr = pts.data();
109  for ( int i = 0; i < pts.size(); ++i, ++ptr )
110  {
111  mtp.transformInPlace( ptr->rx(), ptr->ry() );
112  }
113 
114  return wkbPtr;
115 }
116 
117 const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
118 {
119  QgsConstWkbPtr wkbPtr( wkb + 1 );
120 
121  unsigned int wkbType, numRings;
122  wkbPtr >> wkbType >> numRings;
123 
124  if ( numRings == 0 ) // sanity check for zero rings in polygon
125  return wkbPtr;
126 
127  bool hasZValue = QgsWKBTypes::hasZ(( QgsWKBTypes::Type )wkbType );
128  bool hasMValue = QgsWKBTypes::hasM(( QgsWKBTypes::Type )wkbType );
129 
130  double x, y;
131  holes.clear();
132 
133  const QgsCoordinateTransform* ct = context.coordinateTransform();
134  const QgsMapToPixel& mtp = context.mapToPixel();
135  const QgsRectangle& e = context.extent();
136  double cw = e.width() / 10; double ch = e.height() / 10;
137  QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
138 
139  for ( unsigned int idx = 0; idx < numRings; idx++ )
140  {
141  unsigned int nPoints;
142  wkbPtr >> nPoints;
143 
144  QPolygonF poly( nPoints );
145 
146  // Extract the points from the WKB and store in a pair of vectors.
147  QPointF* ptr = poly.data();
148  for ( unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
149  {
150  wkbPtr >> x >> y;
151  if ( hasZValue )
152  wkbPtr += sizeof( double );
153  if ( hasMValue )
154  wkbPtr += sizeof( double );
155 
156  *ptr = QPointF( x, y );
157  }
158 
159  if ( nPoints < 1 )
160  continue;
161 
162  //clip close to view extent, if needed
163  QRectF ptsRect = poly.boundingRect();
164  if ( clipToExtent && !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );
165 
166  //transform the QPolygonF to screen coordinates
167  if ( ct )
168  {
169  ct->transformPolygon( poly );
170  }
171 
172 
173  ptr = poly.data();
174  for ( int i = 0; i < poly.size(); ++i, ++ptr )
175  {
176  mtp.transformInPlace( ptr->rx(), ptr->ry() );
177  }
178 
179  if ( idx == 0 )
180  pts = poly;
181  else
182  holes.append( poly );
183  }
184 
185  return wkbPtr;
186 }
187 
189 {
190  if ( symbol )
191  {
192  if ( symbol->type() == QgsSymbolV2::Marker )
193  {
194  QgsMarkerSymbolV2* ms = static_cast<QgsMarkerSymbolV2*>( symbol );
195  if ( ms )
196  {
197  ms->setScaleMethod(( QgsSymbolV2::ScaleMethod )scaleMethod );
198  }
199  }
200  }
201 }
202 
204 {
205  if ( !destRenderer || !mPaintEffect )
206  return;
207 
208  destRenderer->setPaintEffect( mPaintEffect->clone() );
209 }
210 
211 
213  : mType( type )
214  , mUsingSymbolLevels( false )
215  , mCurrentVertexMarkerType( QgsVectorLayer::Cross )
216  , mCurrentVertexMarkerSize( 3 )
217  , mPaintEffect( 0 )
218  , mForceRaster( false )
219 {
221  mPaintEffect->setEnabled( false );
222 }
223 
225 {
226  delete mPaintEffect;
227 }
228 
230 {
231  return new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geomType ) );
232 }
233 
235 {
236  QgsRenderContext context;
238  return symbolForFeature( feature, context );
239 }
240 
242 {
243  Q_UNUSED( context );
244  // base method calls deprecated symbolForFeature to maintain API
246  return symbolForFeature( feature );
248 }
249 
251 {
253  return symbolForFeature( feature );
255 }
256 
258 {
259  return symbolForFeature( feature, context );
260 }
261 
263 {
264  startRender( context, vlayer->fields() );
265 }
266 
267 bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
268 {
269  QgsSymbolV2* symbol = symbolForFeature( feature, context );
270  if ( symbol == NULL )
271  return false;
272 
273  renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
274  return true;
275 }
276 
277 void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
278 {
279  QgsSymbolV2::SymbolType symbolType = symbol->type();
280 
281  const QgsGeometry* geom = feature.constGeometry();
282  if ( !geom || !geom->geometry() )
283  {
284  return;
285  }
286 
287  //convert curve types to normal point/line/polygon ones
288  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
289  {
295  {
296  QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
297  if ( !g )
298  {
299  return;
300  }
301  feature.setGeometry( new QgsGeometry( g ) );
302  geom = feature.constGeometry();
303  }
304  default:
305  break;
306  }
307 
308  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
309  {
310  case QgsWKBTypes::Point:
311  {
312  if ( symbolType != QgsSymbolV2::Marker )
313  {
314  QgsDebugMsg( "point can be drawn only with marker symbol!" );
315  break;
316  }
317  QPointF pt;
318  _getPoint( pt, context, geom->asWkb() );
319  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
320 
321  //if ( drawVertexMarker )
322  // renderVertexMarker( pt, context );
323  }
324  break;
326  {
327  if ( symbolType != QgsSymbolV2::Line )
328  {
329  QgsDebugMsg( "linestring can be drawn only with line symbol!" );
330  break;
331  }
332  QPolygonF pts;
333  _getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
334  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
335 
336  if ( drawVertexMarker )
337  renderVertexMarkerPolyline( pts, context );
338  }
339  break;
341  {
342  if ( symbolType != QgsSymbolV2::Fill )
343  {
344  QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
345  break;
346  }
347  QPolygonF pts;
348  QList<QPolygonF> holes;
349  _getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
350  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
351 
352  if ( drawVertexMarker )
353  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
354  }
355  break;
356 
358  {
359  if ( symbolType != QgsSymbolV2::Marker )
360  {
361  QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
362  break;
363  }
364 
365  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
366  unsigned int num;
367  wkbPtr >> num;
368  const unsigned char* ptr = wkbPtr;
369  QPointF pt;
370 
371  for ( unsigned int i = 0; i < num; ++i )
372  {
373  ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
374  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
375 
376  //if ( drawVertexMarker )
377  // renderVertexMarker( pt, context );
378  }
379  }
380  break;
381 
384  {
385  if ( symbolType != QgsSymbolV2::Line )
386  {
387  QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
388  break;
389  }
390 
391  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
392  unsigned int num;
393  wkbPtr >> num;
394  const unsigned char* ptr = wkbPtr;
395  QPolygonF pts;
396 
397  for ( unsigned int i = 0; i < num; ++i )
398  {
399  ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
400  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
401 
402  if ( drawVertexMarker )
403  renderVertexMarkerPolyline( pts, context );
404  }
405  }
406  break;
407 
410  {
411  if ( symbolType != QgsSymbolV2::Fill )
412  {
413  QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
414  break;
415  }
416 
417  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
418  unsigned int num;
419  wkbPtr >> num;
420  const unsigned char* ptr = wkbPtr;
421  QPolygonF pts;
422  QList<QPolygonF> holes;
423 
424  for ( unsigned int i = 0; i < num; ++i )
425  {
426  ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
427  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
428 
429  if ( drawVertexMarker )
430  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
431  }
432  break;
433  }
434  default:
435  QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
436  }
437 }
438 
440 {
441  return "UNKNOWN RENDERER\n";
442 }
443 
445 {
446  QgsRenderContext context;
447  return symbols( context );
448 }
449 
451 {
452  Q_UNUSED( context );
453 
454  //base implementation calls deprecated method to maintain API
456  return symbols();
458 }
459 
460 
462 {
463  // <renderer-v2 type=""> ... </renderer-v2>
464 
465  if ( element.isNull() )
466  return NULL;
467 
468  // load renderer
469  QString rendererType = element.attribute( "type" );
470 
472  if ( m == NULL )
473  return NULL;
474 
475  QgsFeatureRendererV2* r = m->createRenderer( element );
476  if ( r )
477  {
478  r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
479  r->setForceRasterRender( element.attribute( "forceraster", "0" ).toInt() );
480 
481  //restore layer effect
482  QDomElement effectElem = element.firstChildElement( "effect" );
483  if ( !effectElem.isNull() )
484  {
485  r->setPaintEffect( QgsPaintEffectRegistry::instance()->createEffect( effectElem ) );
486  }
487  }
488  return r;
489 }
490 
492 {
493  // create empty renderer element
494  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
495  rendererElem.setAttribute( "forceraster", ( mForceRaster ? "1" : "0" ) );
496 
497  if ( mPaintEffect )
498  mPaintEffect->saveProperties( doc, rendererElem );
499 
500  return rendererElem;
501 }
502 
504 {
505  QDomElement element = node.toElement();
506  if ( element.isNull() )
507  return NULL;
508 
509  // get the UserStyle element
510  QDomElement userStyleElem = element.firstChildElement( "UserStyle" );
511  if ( userStyleElem.isNull() )
512  {
513  // UserStyle element not found, nothing will be rendered
514  errorMessage = "Info: UserStyle element not found.";
515  return NULL;
516  }
517 
518  // get the FeatureTypeStyle element
519  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( "FeatureTypeStyle" );
520  if ( featTypeStyleElem.isNull() )
521  {
522  errorMessage = "Info: FeatureTypeStyle element not found.";
523  return NULL;
524  }
525 
526  // use the RuleRenderer when more rules are present or the rule
527  // has filters or min/max scale denominators set,
528  // otherwise use the SingleSymbol renderer
529  bool needRuleRenderer = false;
530  int ruleCount = 0;
531 
532  QDomElement ruleElem = featTypeStyleElem.firstChildElement( "Rule" );
533  while ( !ruleElem.isNull() )
534  {
535  ruleCount++;
536 
537  // more rules present, use the RuleRenderer
538  if ( ruleCount > 1 )
539  {
540  QgsDebugMsg( "more Rule elements found: need a RuleRenderer" );
541  needRuleRenderer = true;
542  break;
543  }
544 
545  QDomElement ruleChildElem = ruleElem.firstChildElement();
546  while ( !ruleChildElem.isNull() )
547  {
548  // rule has filter or min/max scale denominator, use the RuleRenderer
549  if ( ruleChildElem.localName() == "Filter" ||
550  ruleChildElem.localName() == "MinScaleDenominator" ||
551  ruleChildElem.localName() == "MaxScaleDenominator" )
552  {
553  QgsDebugMsg( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
554  needRuleRenderer = true;
555  break;
556  }
557 
558  ruleChildElem = ruleChildElem.nextSiblingElement();
559  }
560 
561  if ( needRuleRenderer )
562  {
563  break;
564  }
565 
566  ruleElem = ruleElem.nextSiblingElement( "Rule" );
567  }
568 
569  QString rendererType;
570  if ( needRuleRenderer )
571  {
572  rendererType = "RuleRenderer";
573  }
574  else
575  {
576  rendererType = "singleSymbol";
577  }
578  QgsDebugMsg( QString( "Instantiating a '%1' renderer..." ).arg( rendererType ) );
579 
580  // create the renderer and return it
582  if ( m == NULL )
583  {
584  errorMessage = QString( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
585  return NULL;
586  }
587 
588  QgsFeatureRendererV2* r = m->createRendererFromSld( featTypeStyleElem, geomType );
589  return r;
590 }
591 
593 {
594  return writeSld( doc, layer.name() );
595 }
596 
598 {
599  QDomElement userStyleElem = doc.createElement( "UserStyle" );
600 
601  QDomElement nameElem = doc.createElement( "se:Name" );
602  nameElem.appendChild( doc.createTextNode( styleName ) );
603  userStyleElem.appendChild( nameElem );
604 
605  QDomElement featureTypeStyleElem = doc.createElement( "se:FeatureTypeStyle" );
606  toSld( doc, featureTypeStyleElem );
607  userStyleElem.appendChild( featureTypeStyleElem );
608 
609  return userStyleElem;
610 }
611 
613 {
614  Q_UNUSED( iconSize );
615  // empty list by default
616  return QgsLegendSymbologyList();
617 }
618 
620 {
621  return false;
622 }
623 
625 {
626  Q_UNUSED( key );
627  return false;
628 }
629 
631 {
632  Q_UNUSED( key );
633  Q_UNUSED( state );
634 }
635 
637 {
638  Q_UNUSED( scaleDenominator );
639  Q_UNUSED( rule );
640  return QgsLegendSymbolList();
641 }
642 
644 {
645  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
647  int i = 0;
648  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
649  {
650  lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
651  }
652  return lst2;
653 }
654 
656 {
659 }
660 
662 {
664  return symbolForFeature( feat ) != NULL;
666 }
667 
669 {
670  return symbolForFeature( feat, context ) != NULL;
671 }
672 
674 {
675  QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
678 }
679 
681 {
682  foreach ( QPointF pt, pts )
683  renderVertexMarker( pt, context );
684 }
685 
687 {
688  foreach ( QPointF pt, pts )
689  renderVertexMarker( pt, context );
690 
691  if ( rings )
692  {
693  foreach ( QPolygonF ring, *rings )
694  {
695  foreach ( QPointF pt, ring )
696  renderVertexMarker( pt, context );
697  }
698  }
699 }
700 
702 {
703  QgsSymbolV2List lst;
705  QgsSymbolV2* s = symbolForFeature( feat );
707  if ( s ) lst.append( s );
708  return lst;
709 }
710 
712 {
713  QgsSymbolV2List lst;
714  QgsSymbolV2* s = symbolForFeature( feat, context );
715  if ( s ) lst.append( s );
716  return lst;
717 }
718 
720 {
721  QgsSymbolV2List lst;
725  if ( s ) lst.append( s );
726  return lst;
727 }
728 
730 {
731  QgsSymbolV2List lst;
732  QgsSymbolV2* s = originalSymbolForFeature( feat, context );
733  if ( s ) lst.append( s );
734  return lst;
735 }
736 
738 {
739  return mPaintEffect;
740 }
741 
743 {
744  delete mPaintEffect;
745  mPaintEffect = effect;
746 }
747 
749 {
750  if ( symbol->type() == QgsSymbolV2::Marker )
751  {
752  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
754  {
755  const QgsDataDefined dd( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" );
756  s->setDataDefinedSize( dd );
757  }
758  else
759  {
760  const QgsDataDefined dd( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" );
761  s->setDataDefinedSize( dd );
762  }
764  }
765  else if ( symbol->type() == QgsSymbolV2::Line )
766  {
767  QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
768  const QgsDataDefined dd( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" );
769  s->setDataDefinedWidth( dd );
770  }
771 }
772 
774 {
775  if ( symbol->type() == QgsSymbolV2::Marker )
776  {
777  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
778  const QgsDataDefined dd(( s->angle()
779  ? QString::number( s->angle() ) + " + "
780  : QString() ) + field );
781  s->setDataDefinedAngle( dd );
782  }
783 }
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 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
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:192
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QgsFields fields() const
Returns the list of fields of this layer.
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
virtual Q_DECL_DEPRECATED QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
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:203
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:464
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.
Container of fields for a vector layer.
Definition: qgsfield.h:177
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:162
const QgsCoordinateTransform * coordinateTransform() const
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
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
Needs to be called when a new render cycle is started.
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 Q_DECL_DEPRECATED 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
void transformInPlace(double &x, double &y) const
Transform device coordinates to map (world) coordinates.
QString number(int n, int base)
int count(const T &value) const
virtual Q_DECL_DEPRECATED QgsSymbolV2 * symbolForFeature(QgsFeature &feature)
To be overridden.
qreal x() const
qreal y() const
void append(const T &value)
double width() const
QString localName() const
static bool hasM(Type type)
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.
void setAttribute(const QString &name, const QString &value)
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)
static bool hasZ(Type type)
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
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbols()
for symbol levels
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
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:465
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 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
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)
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
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
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
static void convertSymbolRotation(QgsSymbolV2 *symbol, const QString &field)