QGIS API Documentation  2.9.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 )
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;
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 );
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 {
213  QgsEffectStack* stack = new QgsEffectStack();
214  stack->appendEffect( new QgsDrawSourceEffect() );
215  mPaintEffect = stack;
216  mPaintEffect->setEnabled( false );
217 }
218 
220 {
221  delete mPaintEffect;
222 }
223 
225 {
226  return new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geomType ) );
227 }
228 
230 {
231  startRender( context, vlayer->pendingFields() );
232 }
233 
234 bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
235 {
236  QgsSymbolV2* symbol = symbolForFeature( feature );
237  if ( symbol == NULL )
238  return false;
239 
240  renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
241  return true;
242 }
243 
244 void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
245 {
246  QgsSymbolV2::SymbolType symbolType = symbol->type();
247 
248  const QgsGeometry* geom = feature.constGeometry();
249  if ( !geom )
250  {
251  return;
252  }
253 
254  if ( geom->requiresConversionToStraightSegments() )
255  {
256  //geometry requires conversion to straight segments
257  QgsGeometry* straightGeom = new QgsGeometry( *geom );
258  straightGeom->convertToStraightSegment();
259  feature.setGeometry( straightGeom );
260  geom = feature.constGeometry();
261  }
262 
263  switch ( geom->wkbType() )
264  {
265  case QGis::WKBPoint:
266  case QGis::WKBPoint25D:
267  {
268  if ( symbolType != QgsSymbolV2::Marker )
269  {
270  QgsDebugMsg( "point can be drawn only with marker symbol!" );
271  break;
272  }
273  QPointF pt;
274  _getPoint( pt, context, geom->asWkb() );
275  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
276 
277  //if ( drawVertexMarker )
278  // renderVertexMarker( pt, context );
279  }
280  break;
281 
282  case QGis::WKBLineString:
284  {
285  if ( symbolType != QgsSymbolV2::Line )
286  {
287  QgsDebugMsg( "linestring can be drawn only with line symbol!" );
288  break;
289  }
290  QPolygonF pts;
291  _getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
292  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
293 
294  if ( drawVertexMarker )
295  renderVertexMarkerPolyline( pts, context );
296  }
297  break;
298 
299  case QGis::WKBPolygon:
300  case QGis::WKBPolygon25D:
301  {
302  if ( symbolType != QgsSymbolV2::Fill )
303  {
304  QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
305  break;
306  }
307  QPolygonF pts;
308  QList<QPolygonF> holes;
309  _getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
310  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
311 
312  if ( drawVertexMarker )
313  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
314  }
315  break;
316 
317  case QGis::WKBMultiPoint:
319  {
320  if ( symbolType != QgsSymbolV2::Marker )
321  {
322  QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
323  break;
324  }
325 
326  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
327  unsigned int num;
328  wkbPtr >> num;
329  const unsigned char* ptr = wkbPtr;
330  QPointF pt;
331 
332  for ( unsigned int i = 0; i < num; ++i )
333  {
334  ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
335  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
336 
337  //if ( drawVertexMarker )
338  // renderVertexMarker( pt, context );
339  }
340  }
341  break;
342 
345  {
346  if ( symbolType != QgsSymbolV2::Line )
347  {
348  QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
349  break;
350  }
351 
352  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
353  unsigned int num;
354  wkbPtr >> num;
355  const unsigned char* ptr = wkbPtr;
356  QPolygonF pts;
357 
358  for ( unsigned int i = 0; i < num; ++i )
359  {
360  ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
361  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
362 
363  if ( drawVertexMarker )
364  renderVertexMarkerPolyline( pts, context );
365  }
366  }
367  break;
368 
371  {
372  if ( symbolType != QgsSymbolV2::Fill )
373  {
374  QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
375  break;
376  }
377 
378  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
379  unsigned int num;
380  wkbPtr >> num;
381  const unsigned char* ptr = wkbPtr;
382  QPolygonF pts;
383  QList<QPolygonF> holes;
384 
385  for ( unsigned int i = 0; i < num; ++i )
386  {
387  ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
388  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
389 
390  if ( drawVertexMarker )
391  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
392  }
393  }
394  break;
395 
396  default:
397  QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
398  }
399 }
400 
402 {
403  return "UNKNOWN RENDERER\n";
404 }
405 
406 
408 {
409  // <renderer-v2 type=""> ... </renderer-v2>
410 
411  if ( element.isNull() )
412  return NULL;
413 
414  // load renderer
415  QString rendererType = element.attribute( "type" );
416 
418  if ( m == NULL )
419  return NULL;
420 
421  QgsFeatureRendererV2* r = m->createRenderer( element );
422  if ( r )
423  {
424  r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
425 
426  //restore layer effect
427  QDomElement effectElem = element.firstChildElement( "effect" );
428  if ( !effectElem.isNull() )
429  {
430  r->setPaintEffect( QgsPaintEffectRegistry::instance()->createEffect( effectElem ) );
431  }
432  }
433  return r;
434 }
435 
436 QDomElement QgsFeatureRendererV2::save( QDomDocument& doc )
437 {
438  // create empty renderer element
439  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
440 
441  if ( mPaintEffect )
442  mPaintEffect->saveProperties( doc, rendererElem );
443 
444  return rendererElem;
445 }
446 
447 QgsFeatureRendererV2* QgsFeatureRendererV2::loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage )
448 {
449  QDomElement element = node.toElement();
450  if ( element.isNull() )
451  return NULL;
452 
453  // get the UserStyle element
454  QDomElement userStyleElem = element.firstChildElement( "UserStyle" );
455  if ( userStyleElem.isNull() )
456  {
457  // UserStyle element not found, nothing will be rendered
458  errorMessage = "Info: UserStyle element not found.";
459  return NULL;
460  }
461 
462  // get the FeatureTypeStyle element
463  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( "FeatureTypeStyle" );
464  if ( featTypeStyleElem.isNull() )
465  {
466  errorMessage = "Info: FeatureTypeStyle element not found.";
467  return NULL;
468  }
469 
470  // use the RuleRenderer when more rules are present or the rule
471  // has filters or min/max scale denominators set,
472  // otherwise use the SingleSymbol renderer
473  bool needRuleRenderer = false;
474  int ruleCount = 0;
475 
476  QDomElement ruleElem = featTypeStyleElem.firstChildElement( "Rule" );
477  while ( !ruleElem.isNull() )
478  {
479  ruleCount++;
480 
481  // more rules present, use the RuleRenderer
482  if ( ruleCount > 1 )
483  {
484  QgsDebugMsg( "more Rule elements found: need a RuleRenderer" );
485  needRuleRenderer = true;
486  break;
487  }
488 
489  QDomElement ruleChildElem = ruleElem.firstChildElement();
490  while ( !ruleChildElem.isNull() )
491  {
492  // rule has filter or min/max scale denominator, use the RuleRenderer
493  if ( ruleChildElem.localName() == "Filter" ||
494  ruleChildElem.localName() == "MinScaleDenominator" ||
495  ruleChildElem.localName() == "MaxScaleDenominator" )
496  {
497  QgsDebugMsg( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
498  needRuleRenderer = true;
499  break;
500  }
501 
502  ruleChildElem = ruleChildElem.nextSiblingElement();
503  }
504 
505  if ( needRuleRenderer )
506  {
507  break;
508  }
509 
510  ruleElem = ruleElem.nextSiblingElement( "Rule" );
511  }
512 
513  QString rendererType;
514  if ( needRuleRenderer )
515  {
516  rendererType = "RuleRenderer";
517  }
518  else
519  {
520  rendererType = "singleSymbol";
521  }
522  QgsDebugMsg( QString( "Instantiating a '%1' renderer..." ).arg( rendererType ) );
523 
524  // create the renderer and return it
526  if ( m == NULL )
527  {
528  errorMessage = QString( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
529  return NULL;
530  }
531 
532  QgsFeatureRendererV2* r = m->createRendererFromSld( featTypeStyleElem, geomType );
533  return r;
534 }
535 
536 QDomElement QgsFeatureRendererV2::writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const
537 {
538  return writeSld( doc, layer.name() );
539 }
540 
541 QDomElement QgsFeatureRendererV2::writeSld( QDomDocument& doc, const QString& styleName ) const
542 {
543  QDomElement userStyleElem = doc.createElement( "UserStyle" );
544 
545  QDomElement nameElem = doc.createElement( "se:Name" );
546  nameElem.appendChild( doc.createTextNode( styleName ) );
547  userStyleElem.appendChild( nameElem );
548 
549  QDomElement featureTypeStyleElem = doc.createElement( "se:FeatureTypeStyle" );
550  toSld( doc, featureTypeStyleElem );
551  userStyleElem.appendChild( featureTypeStyleElem );
552 
553  return userStyleElem;
554 }
555 
557 {
558  Q_UNUSED( iconSize );
559  // empty list by default
560  return QgsLegendSymbologyList();
561 }
562 
564 {
565  return false;
566 }
567 
569 {
570  Q_UNUSED( key );
571  return false;
572 }
573 
574 void QgsFeatureRendererV2::checkLegendSymbolItem( QString key, bool state )
575 {
576  Q_UNUSED( key );
577  Q_UNUSED( state );
578 }
579 
580 QgsLegendSymbolList QgsFeatureRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
581 {
582  Q_UNUSED( scaleDenominator );
583  Q_UNUSED( rule );
584  return QgsLegendSymbolList();
585 }
586 
588 {
589  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
591  int i = 0;
592  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
593  {
594  lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
595  }
596  return lst2;
597 }
598 
600 {
603 }
604 
606 {
607  QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
610 }
611 
613 {
614  foreach ( QPointF pt, pts )
615  renderVertexMarker( pt, context );
616 }
617 
618 void QgsFeatureRendererV2::renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context )
619 {
620  foreach ( QPointF pt, pts )
621  renderVertexMarker( pt, context );
622 
623  if ( rings )
624  {
625  foreach ( QPolygonF ring, *rings )
626  {
627  foreach ( QPointF pt, ring )
628  renderVertexMarker( pt, context );
629  }
630  }
631 }
632 
634 {
635  QgsSymbolV2List lst;
636  QgsSymbolV2* s = symbolForFeature( feat );
637  if ( s ) lst.append( s );
638  return lst;
639 }
640 
642 {
643  QgsSymbolV2List lst;
645  if ( s ) lst.append( s );
646  return lst;
647 }
648 
650 {
651  return mPaintEffect;
652 }
653 
655 {
656  delete mPaintEffect;
657  mPaintEffect = effect;
658 }
659 
661 {
662  if ( symbol->type() == QgsSymbolV2::Marker )
663  {
664  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
666  {
667  const QgsDataDefined dd( "sqrt(" + QString::number( s->size() ) + " * (" + field + "))" );
668  s->setDataDefinedSize( dd );
669  }
670  else
671  {
672  const QgsDataDefined dd( QString::number( s->size() ) + " * (" + field + ")" );
673  s->setDataDefinedSize( dd );
674  }
675  }
676  else if ( symbol->type() == QgsSymbolV2::Line )
677  {
678  QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
679  const QgsDataDefined dd( QString::number( s->width() ) + " * (" + field + ")" );
680  s->setDataDefinedWidth( dd );
681  }
682 }
683 
684 void QgsFeatureRendererV2::convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field )
685 {
686  if ( symbol->type() == QgsSymbolV2::Marker )
687  {
688  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
689  const QgsDataDefined dd(( s->angle()
690  ? QString::number( s->angle() ) + " + "
691  : QString() ) + field );
692  s->setDataDefinedAngle( dd );
693  }
694 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:51
static QgsRendererV2Registry * instance()
#define RENDERER_TAG_NAME
Definition: qgsrendererv2.h:48
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.
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.
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:39
QgsRendererV2AbstractMetadata * rendererMetadata(QString rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
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
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
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
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
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...
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)
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
double width() const
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 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.
A paint effect which consists of a stack of other chained paint effects.
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
void appendEffect(QgsPaintEffect *effect)
Appends an effect to the end of the stack.
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
QgsFeatureRendererV2(QString type)
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
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.
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
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
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)
QList< QgsLegendSymbolItemV2 > QgsLegendSymbolListV2
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
A paint effect which draws the source picture with minor or no alterations.
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)
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
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...
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:187
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)