QGIS API Documentation  2.12.0-Lyon
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"
30 #include "qgsfeature.h"
31 #include "qgslogger.h"
32 #include "qgsvectorlayer.h"
33 #include "qgspainteffect.h"
34 #include "qgseffectstack.h"
35 #include "qgspainteffectregistry.h"
36 #include "qgswkbptr.h"
37 #include "qgspointv2.h"
38 
39 #include <QDomElement>
40 #include <QDomDocument>
41 #include <QPolygonF>
42 
43 
44 
45 const unsigned char* QgsFeatureRendererV2::_getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb )
46 {
47  QgsConstWkbPtr wkbPtr( wkb + 1 );
48  unsigned int wkbType;
49  wkbPtr >> wkbType >> pt.rx() >> pt.ry();
50 
52  wkbPtr += sizeof( double );
53 
54  if ( context.coordinateTransform() )
55  {
56  double z = 0; // dummy variable for coordiante transform
57  context.coordinateTransform()->transformInPlace( pt.rx(), pt.ry(), z );
58  }
59 
60  context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
61 
62  return wkbPtr;
63 }
64 
65 const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
66 {
67  QgsConstWkbPtr wkbPtr( wkb + 1 );
68  unsigned int wkbType, nPoints;
69  wkbPtr >> wkbType >> nPoints;
70 
71  bool hasZValue = QgsWKBTypes::hasZ(( QgsWKBTypes::Type )wkbType );
72  bool hasMValue = QgsWKBTypes::hasM(( QgsWKBTypes::Type )wkbType );
73 
74  double x = 0.0;
75  double y = 0.0;
76  const QgsCoordinateTransform* ct = context.coordinateTransform();
77  const QgsMapToPixel& mtp = context.mapToPixel();
78 
79  //apply clipping for large lines to achieve a better rendering performance
80  if ( clipToExtent && nPoints > 1 )
81  {
82  const QgsRectangle& e = context.extent();
83  double cw = e.width() / 10; double ch = e.height() / 10;
84  QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
85  wkbPtr = QgsConstWkbPtr( QgsClipper::clippedLineWKB( wkb, clipRect, pts ) );
86  }
87  else
88  {
89  pts.resize( nPoints );
90 
91  QPointF* ptr = pts.data();
92  for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
93  {
94  wkbPtr >> x >> y;
95  if ( hasZValue )
96  wkbPtr += sizeof( double );
97  if ( hasMValue )
98  wkbPtr += sizeof( double );
99 
100  *ptr = QPointF( x, y );
101  }
102  }
103 
104  //transform the QPolygonF to screen coordinates
105  if ( ct )
106  {
107  ct->transformPolygon( pts );
108  }
109 
110  QPointF* ptr = pts.data();
111  for ( int i = 0; i < pts.size(); ++i, ++ptr )
112  {
113  mtp.transformInPlace( ptr->rx(), ptr->ry() );
114  }
115 
116  return wkbPtr;
117 }
118 
119 const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent )
120 {
121  QgsConstWkbPtr wkbPtr( wkb + 1 );
122 
123  unsigned int wkbType, numRings;
124  wkbPtr >> wkbType >> numRings;
125 
126  if ( numRings == 0 ) // sanity check for zero rings in polygon
127  return wkbPtr;
128 
129  bool hasZValue = QgsWKBTypes::hasZ(( QgsWKBTypes::Type )wkbType );
130  bool hasMValue = QgsWKBTypes::hasM(( QgsWKBTypes::Type )wkbType );
131 
132  double x, y;
133  holes.clear();
134 
135  const QgsCoordinateTransform* ct = context.coordinateTransform();
136  const QgsMapToPixel& mtp = context.mapToPixel();
137  const QgsRectangle& e = context.extent();
138  double cw = e.width() / 10; double ch = e.height() / 10;
139  QgsRectangle clipRect( e.xMinimum() - cw, e.yMinimum() - ch, e.xMaximum() + cw, e.yMaximum() + ch );
140 
141  for ( unsigned int idx = 0; idx < numRings; idx++ )
142  {
143  unsigned int nPoints;
144  wkbPtr >> nPoints;
145 
146  QPolygonF poly( nPoints );
147 
148  // Extract the points from the WKB and store in a pair of vectors.
149  QPointF* ptr = poly.data();
150  for ( unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
151  {
152  wkbPtr >> x >> y;
153  if ( hasZValue )
154  wkbPtr += sizeof( double );
155  if ( hasMValue )
156  wkbPtr += sizeof( double );
157 
158  *ptr = QPointF( x, y );
159  }
160 
161  if ( nPoints < 1 )
162  continue;
163 
164  //clip close to view extent, if needed
165  QRectF ptsRect = poly.boundingRect();
166  if ( clipToExtent && !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );
167 
168  //transform the QPolygonF to screen coordinates
169  if ( ct )
170  {
171  ct->transformPolygon( poly );
172  }
173 
174 
175  ptr = poly.data();
176  for ( int i = 0; i < poly.size(); ++i, ++ptr )
177  {
178  mtp.transformInPlace( ptr->rx(), ptr->ry() );
179  }
180 
181  if ( idx == 0 )
182  pts = poly;
183  else
184  holes.append( poly );
185  }
186 
187  return wkbPtr;
188 }
189 
191 {
192  if ( symbol )
193  {
194  if ( symbol->type() == QgsSymbolV2::Marker )
195  {
196  QgsMarkerSymbolV2* ms = static_cast<QgsMarkerSymbolV2*>( symbol );
197  if ( ms )
198  {
199  ms->setScaleMethod(( QgsSymbolV2::ScaleMethod )scaleMethod );
200  }
201  }
202  }
203 }
204 
206 {
207  if ( !destRenderer || !mPaintEffect )
208  return;
209 
210  destRenderer->setPaintEffect( mPaintEffect->clone() );
211 }
212 
213 
215  : mType( type )
216  , mUsingSymbolLevels( false )
217  , mCurrentVertexMarkerType( QgsVectorLayer::Cross )
218  , mCurrentVertexMarkerSize( 3 )
219  , mPaintEffect( 0 )
220  , mForceRaster( false )
221 {
223  mPaintEffect->setEnabled( false );
224 }
225 
227 {
228  delete mPaintEffect;
229 }
230 
232 {
233  return new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geomType ) );
234 }
235 
237 {
238  QgsRenderContext context;
240  return symbolForFeature( feature, context );
241 }
242 
244 {
245  Q_UNUSED( context );
246  // base method calls deprecated symbolForFeature to maintain API
248  return symbolForFeature( feature );
250 }
251 
253 {
255  return symbolForFeature( feature );
257 }
258 
260 {
261  return symbolForFeature( feature, context );
262 }
263 
265 {
266  startRender( context, vlayer->fields() );
267 }
268 
269 bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
270 {
271  QgsSymbolV2* symbol = symbolForFeature( feature, context );
272  if ( symbol == NULL )
273  return false;
274 
275  renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
276  return true;
277 }
278 
279 void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
280 {
281  QgsSymbolV2::SymbolType symbolType = symbol->type();
282 
283 
284  const QgsGeometry* geom = feature.constGeometry();
285  if ( !geom || !geom->geometry() )
286  {
287  return;
288  }
289 
290  const QgsGeometry* segmentizedGeometry = geom;
291  bool deleteSegmentizedGeometry = false;
292  context.setGeometry( geom->geometry() );
293 
294  //convert curve types to normal point/line/polygon ones
295  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
296  {
302  {
303  QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
304  if ( !g )
305  {
306  return;
307  }
308  segmentizedGeometry = new QgsGeometry( g );
309  deleteSegmentizedGeometry = true;
310  }
311  default:
312  break;
313  }
314 
315  switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
316  {
317  case QgsWKBTypes::Point:
318  {
319  if ( symbolType != QgsSymbolV2::Marker )
320  {
321  QgsDebugMsg( "point can be drawn only with marker symbol!" );
322  break;
323  }
324  QPointF pt;
325  _getPoint( pt, context, segmentizedGeometry->asWkb() );
326  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
327  }
328  break;
330  {
331  if ( symbolType != QgsSymbolV2::Line )
332  {
333  QgsDebugMsg( "linestring can be drawn only with line symbol!" );
334  break;
335  }
336  QPolygonF pts;
337  _getLineString( pts, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
338  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
339  }
340  break;
342  {
343  if ( symbolType != QgsSymbolV2::Fill )
344  {
345  QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
346  break;
347  }
348  QPolygonF pts;
349  QList<QPolygonF> holes;
350  _getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
351  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
352  }
353  break;
354 
356  {
357  if ( symbolType != QgsSymbolV2::Marker )
358  {
359  QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
360  break;
361  }
362 
363  QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
364  unsigned int num;
365  wkbPtr >> num;
366  const unsigned char* ptr = wkbPtr;
367  QPointF pt;
368 
369  for ( unsigned int i = 0; i < num; ++i )
370  {
371  ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
372  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
373  }
374  }
375  break;
376 
379  {
380  if ( symbolType != QgsSymbolV2::Line )
381  {
382  QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
383  break;
384  }
385 
386  QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
387  unsigned int num;
388  wkbPtr >> num;
389  const unsigned char* ptr = wkbPtr;
390  QPolygonF pts;
391 
392  const QgsGeometryCollectionV2* geomCollection = dynamic_cast<const QgsGeometryCollectionV2*>( geom->geometry() );
393 
394  for ( unsigned int i = 0; i < num; ++i )
395  {
396  if ( geomCollection )
397  {
398  context.setGeometry( geomCollection->geometryN( i ) );
399  }
400  ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
401  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
402  }
403  }
404  break;
405 
408  {
409  if ( symbolType != QgsSymbolV2::Fill )
410  {
411  QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
412  break;
413  }
414 
415  QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
416  unsigned int num;
417  wkbPtr >> num;
418  const unsigned char* ptr = wkbPtr;
419  QPolygonF pts;
420  QList<QPolygonF> holes;
421 
422  const QgsGeometryCollectionV2* geomCollection = dynamic_cast<const QgsGeometryCollectionV2*>( geom->geometry() );
423 
424  for ( unsigned int i = 0; i < num; ++i )
425  {
426  if ( geomCollection )
427  {
428  context.setGeometry( geomCollection->geometryN( i ) );
429  }
430  ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
431  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
432  }
433  break;
434  }
435  default:
436  QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
437  }
438 
439  if ( drawVertexMarker )
440  {
441  const QgsCoordinateTransform* ct = context.coordinateTransform();
442  const QgsMapToPixel& mtp = context.mapToPixel();
443 
444  QgsPointV2 vertexPoint;
445  QgsVertexId vertexId;
446  double x, y, z;
447  QPointF mapPoint;
448  while ( geom->geometry()->nextVertex( vertexId, vertexPoint ) )
449  {
450  //transform
451  x = vertexPoint.x(); y = vertexPoint.y(); z = vertexPoint.z();
452  if ( ct )
453  {
454  ct->transformInPlace( x, y, z );
455  }
456  mapPoint.setX( x ); mapPoint.setY( y );
457  mtp.transformInPlace( mapPoint.rx(), mapPoint.ry() );
458  renderVertexMarker( mapPoint, context );
459  }
460  }
461 
462  if ( deleteSegmentizedGeometry )
463  {
464  delete segmentizedGeometry;
465  }
466 }
467 
469 {
470  return "UNKNOWN RENDERER\n";
471 }
472 
474 {
475  QgsRenderContext context;
476  return symbols( context );
477 }
478 
480 {
481  Q_UNUSED( context );
482 
483  //base implementation calls deprecated method to maintain API
485  return symbols();
487 }
488 
489 
491 {
492  // <renderer-v2 type=""> ... </renderer-v2>
493 
494  if ( element.isNull() )
495  return NULL;
496 
497  // load renderer
498  QString rendererType = element.attribute( "type" );
499 
501  if ( m == NULL )
502  return NULL;
503 
504  QgsFeatureRendererV2* r = m->createRenderer( element );
505  if ( r )
506  {
507  r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
508  r->setForceRasterRender( element.attribute( "forceraster", "0" ).toInt() );
509 
510  //restore layer effect
511  QDomElement effectElem = element.firstChildElement( "effect" );
512  if ( !effectElem.isNull() )
513  {
514  r->setPaintEffect( QgsPaintEffectRegistry::instance()->createEffect( effectElem ) );
515  }
516  }
517  return r;
518 }
519 
521 {
522  // create empty renderer element
523  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
524  rendererElem.setAttribute( "forceraster", ( mForceRaster ? "1" : "0" ) );
525 
527  mPaintEffect->saveProperties( doc, rendererElem );
528 
529  return rendererElem;
530 }
531 
533 {
534  QDomElement element = node.toElement();
535  if ( element.isNull() )
536  return NULL;
537 
538  // get the UserStyle element
539  QDomElement userStyleElem = element.firstChildElement( "UserStyle" );
540  if ( userStyleElem.isNull() )
541  {
542  // UserStyle element not found, nothing will be rendered
543  errorMessage = "Info: UserStyle element not found.";
544  return NULL;
545  }
546 
547  // get the FeatureTypeStyle element
548  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( "FeatureTypeStyle" );
549  if ( featTypeStyleElem.isNull() )
550  {
551  errorMessage = "Info: FeatureTypeStyle element not found.";
552  return NULL;
553  }
554 
555  // use the RuleRenderer when more rules are present or the rule
556  // has filters or min/max scale denominators set,
557  // otherwise use the SingleSymbol renderer
558  bool needRuleRenderer = false;
559  int ruleCount = 0;
560 
561  QDomElement ruleElem = featTypeStyleElem.firstChildElement( "Rule" );
562  while ( !ruleElem.isNull() )
563  {
564  ruleCount++;
565 
566  // more rules present, use the RuleRenderer
567  if ( ruleCount > 1 )
568  {
569  QgsDebugMsg( "more Rule elements found: need a RuleRenderer" );
570  needRuleRenderer = true;
571  break;
572  }
573 
574  QDomElement ruleChildElem = ruleElem.firstChildElement();
575  while ( !ruleChildElem.isNull() )
576  {
577  // rule has filter or min/max scale denominator, use the RuleRenderer
578  if ( ruleChildElem.localName() == "Filter" ||
579  ruleChildElem.localName() == "MinScaleDenominator" ||
580  ruleChildElem.localName() == "MaxScaleDenominator" )
581  {
582  QgsDebugMsg( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
583  needRuleRenderer = true;
584  break;
585  }
586 
587  ruleChildElem = ruleChildElem.nextSiblingElement();
588  }
589 
590  if ( needRuleRenderer )
591  {
592  break;
593  }
594 
595  ruleElem = ruleElem.nextSiblingElement( "Rule" );
596  }
597 
598  QString rendererType;
599  if ( needRuleRenderer )
600  {
601  rendererType = "RuleRenderer";
602  }
603  else
604  {
605  rendererType = "singleSymbol";
606  }
607  QgsDebugMsg( QString( "Instantiating a '%1' renderer..." ).arg( rendererType ) );
608 
609  // create the renderer and return it
611  if ( m == NULL )
612  {
613  errorMessage = QString( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
614  return NULL;
615  }
616 
617  QgsFeatureRendererV2* r = m->createRendererFromSld( featTypeStyleElem, geomType );
618  return r;
619 }
620 
622 {
623  return writeSld( doc, layer.name() );
624 }
625 
627 {
628  QDomElement userStyleElem = doc.createElement( "UserStyle" );
629 
630  QDomElement nameElem = doc.createElement( "se:Name" );
631  nameElem.appendChild( doc.createTextNode( styleName ) );
632  userStyleElem.appendChild( nameElem );
633 
634  QDomElement featureTypeStyleElem = doc.createElement( "se:FeatureTypeStyle" );
635  toSld( doc, featureTypeStyleElem );
636  userStyleElem.appendChild( featureTypeStyleElem );
637 
638  return userStyleElem;
639 }
640 
642 {
643  Q_UNUSED( iconSize );
644  // empty list by default
645  return QgsLegendSymbologyList();
646 }
647 
649 {
650  return false;
651 }
652 
654 {
655  Q_UNUSED( key );
656  return false;
657 }
658 
660 {
661  Q_UNUSED( key );
662  Q_UNUSED( state );
663 }
664 
666 {
667  Q_UNUSED( scaleDenominator );
668  Q_UNUSED( rule );
669  return QgsLegendSymbolList();
670 }
671 
673 {
674  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
676  int i = 0;
677  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
678  {
679  lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
680  }
681  return lst2;
682 }
683 
685 {
688 }
689 
691 {
693  return symbolForFeature( feat ) != NULL;
695 }
696 
698 {
699  return symbolForFeature( feat, context ) != NULL;
700 }
701 
703 {
704  QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
707 }
708 
710 {
711  Q_FOREACH ( const QPointF& pt, pts )
712  renderVertexMarker( pt, context );
713 }
714 
716 {
717  Q_FOREACH ( const QPointF& pt, pts )
718  renderVertexMarker( pt, context );
719 
720  if ( rings )
721  {
722  Q_FOREACH ( const QPolygonF& ring, *rings )
723  {
724  Q_FOREACH ( const QPointF& pt, ring )
725  renderVertexMarker( pt, context );
726  }
727  }
728 }
729 
731 {
732  QgsSymbolV2List lst;
734  QgsSymbolV2* s = symbolForFeature( feat );
736  if ( s ) lst.append( s );
737  return lst;
738 }
739 
741 {
742  QgsSymbolV2List lst;
743  QgsSymbolV2* s = symbolForFeature( feat, context );
744  if ( s ) lst.append( s );
745  return lst;
746 }
747 
749 {
750  QgsSymbolV2List lst;
754  if ( s ) lst.append( s );
755  return lst;
756 }
757 
759 {
760  QgsSymbolV2List lst;
761  QgsSymbolV2* s = originalSymbolForFeature( feat, context );
762  if ( s ) lst.append( s );
763  return lst;
764 }
765 
767 {
768  return mPaintEffect;
769 }
770 
772 {
773  delete mPaintEffect;
774  mPaintEffect = effect;
775 }
776 
778 {
779  if ( symbol->type() == QgsSymbolV2::Marker )
780  {
781  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
783  {
784  const QgsDataDefined dd( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" );
785  s->setDataDefinedSize( dd );
786  }
787  else
788  {
789  const QgsDataDefined dd( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" );
790  s->setDataDefinedSize( dd );
791  }
793  }
794  else if ( symbol->type() == QgsSymbolV2::Line )
795  {
796  QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
797  const QgsDataDefined dd( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" );
798  s->setDataDefinedWidth( dd );
799  }
800 }
801 
803 {
804  if ( symbol->type() == QgsSymbolV2::Marker )
805  {
806  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
807  const QgsDataDefined dd(( s->angle()
808  ? QString::number( s->angle() ) + " + "
809  : QString() ) + field );
810  s->setDataDefinedAngle( dd );
811  }
812 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:53
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
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
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.
QgsFeatureRendererV2(const QString &type)
QDomNode appendChild(const QDomNode &newChild)
double x() const
Definition: qgspointv2.h:42
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:95
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:196
#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).
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
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
Calculate scale by the diameter.
Definition: qgssymbolv2.h:81
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:390
Base class for visual effects which can be applied to QPicture drawings.
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:76
Stores metadata about one renderer class.
Line symbol.
Definition: qgssymbolv2.h:71
virtual ~QgsFeatureRendererV2()
GeometryType
Definition: qgis.h:104
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:176
const QgsCoordinateTransform * coordinateTransform() const
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
QgsRendererV2AbstractMetadata * rendererMetadata(const QString &rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
QgsPaintEffect * mPaintEffect
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
Marker symbol.
Definition: qgssymbolv2.h:70
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.
double y() const
Definition: qgspointv2.h:43
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 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)
Tests whether a WKB type contains m values.
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:201
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:186
Utility class for identifying a unique vertex within a geometry.
static QgsPaintEffectRegistry * instance()
double z() const
Definition: qgspointv2.h:44
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, const QString &rule="")
return a list of item text / symbol
int mCurrentVertexMarkerSize
The current size of editing marker.
void setAttribute(const QString &name, const QString &value)
VertexMarkerType
Editing vertex markers.
Point geometry type.
Definition: qgspointv2.h:29
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)
Tests whether a WKB type contains the z-dimension.
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.
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const =0
Returns next vertex id and coordinates.
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()
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 renderVertexMarker(const QPointF &pt, QgsRenderContext &context)
render editing vertex marker at specified point
SymbolType
Type of the symbol.
Definition: qgssymbolv2.h:68
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:391
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
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:78
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 setX(qreal x)
void setY(qreal y)
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)
Fill symbol.
Definition: qgssymbolv2.h:72
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:70
qreal & rx()
qreal & ry()
Class for doing transforms between two map coordinate systems.
const QgsAbstractGeometryV2 * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
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)
Calculate scale by the area.
Definition: qgssymbolv2.h:80
QDomElement createElement(const QString &tagName)
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:206
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
Definition: qgsclipper.h:178
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
int size() const
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
Definition: qgssymbolv2.h:216
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:191
iterator begin()
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
void setGeometry(const QgsAbstractGeometryV2 *geometry)
Sets pointer to original (unsegmentized) geometry.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:211
static void convertSymbolRotation(QgsSymbolV2 *symbol, const QString &field)