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  feature.setGeometry( straightGeom );
259  geom = feature.constGeometry();
260  }
261 
262  switch ( geom->wkbType() )
263  {
264  case QGis::WKBPoint:
265  case QGis::WKBPoint25D:
266  {
267  if ( symbolType != QgsSymbolV2::Marker )
268  {
269  QgsDebugMsg( "point can be drawn only with marker symbol!" );
270  break;
271  }
272  QPointF pt;
273  _getPoint( pt, context, geom->asWkb() );
274  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
275 
276  //if ( drawVertexMarker )
277  // renderVertexMarker( pt, context );
278  }
279  break;
280 
281  case QGis::WKBLineString:
283  {
284  if ( symbolType != QgsSymbolV2::Line )
285  {
286  QgsDebugMsg( "linestring can be drawn only with line symbol!" );
287  break;
288  }
289  QPolygonF pts;
290  _getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
291  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
292 
293  if ( drawVertexMarker )
294  renderVertexMarkerPolyline( pts, context );
295  }
296  break;
297 
298  case QGis::WKBPolygon:
299  case QGis::WKBPolygon25D:
300  {
301  if ( symbolType != QgsSymbolV2::Fill )
302  {
303  QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
304  break;
305  }
306  QPolygonF pts;
307  QList<QPolygonF> holes;
308  _getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
309  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
310 
311  if ( drawVertexMarker )
312  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
313  }
314  break;
315 
316  case QGis::WKBMultiPoint:
318  {
319  if ( symbolType != QgsSymbolV2::Marker )
320  {
321  QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
322  break;
323  }
324 
325  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
326  unsigned int num;
327  wkbPtr >> num;
328  const unsigned char* ptr = wkbPtr;
329  QPointF pt;
330 
331  for ( unsigned int i = 0; i < num; ++i )
332  {
333  ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
334  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
335 
336  //if ( drawVertexMarker )
337  // renderVertexMarker( pt, context );
338  }
339  }
340  break;
341 
344  {
345  if ( symbolType != QgsSymbolV2::Line )
346  {
347  QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
348  break;
349  }
350 
351  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
352  unsigned int num;
353  wkbPtr >> num;
354  const unsigned char* ptr = wkbPtr;
355  QPolygonF pts;
356 
357  for ( unsigned int i = 0; i < num; ++i )
358  {
359  ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
360  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
361 
362  if ( drawVertexMarker )
363  renderVertexMarkerPolyline( pts, context );
364  }
365  }
366  break;
367 
370  {
371  if ( symbolType != QgsSymbolV2::Fill )
372  {
373  QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
374  break;
375  }
376 
377  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
378  unsigned int num;
379  wkbPtr >> num;
380  const unsigned char* ptr = wkbPtr;
381  QPolygonF pts;
382  QList<QPolygonF> holes;
383 
384  for ( unsigned int i = 0; i < num; ++i )
385  {
386  ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
387  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
388 
389  if ( drawVertexMarker )
390  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
391  }
392  }
393  break;
394 
395  default:
396  QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
397  }
398 }
399 
401 {
402  return "UNKNOWN RENDERER\n";
403 }
404 
405 
407 {
408  // <renderer-v2 type=""> ... </renderer-v2>
409 
410  if ( element.isNull() )
411  return NULL;
412 
413  // load renderer
414  QString rendererType = element.attribute( "type" );
415 
417  if ( m == NULL )
418  return NULL;
419 
420  QgsFeatureRendererV2* r = m->createRenderer( element );
421  if ( r )
422  {
423  r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
424 
425  //restore layer effect
426  QDomElement effectElem = element.firstChildElement( "effect" );
427  if ( !effectElem.isNull() )
428  {
429  r->setPaintEffect( QgsPaintEffectRegistry::instance()->createEffect( effectElem ) );
430  }
431  }
432  return r;
433 }
434 
435 QDomElement QgsFeatureRendererV2::save( QDomDocument& doc )
436 {
437  // create empty renderer element
438  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
439 
440  if ( mPaintEffect )
441  mPaintEffect->saveProperties( doc, rendererElem );
442 
443  return rendererElem;
444 }
445 
446 QgsFeatureRendererV2* QgsFeatureRendererV2::loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage )
447 {
448  QDomElement element = node.toElement();
449  if ( element.isNull() )
450  return NULL;
451 
452  // get the UserStyle element
453  QDomElement userStyleElem = element.firstChildElement( "UserStyle" );
454  if ( userStyleElem.isNull() )
455  {
456  // UserStyle element not found, nothing will be rendered
457  errorMessage = "Info: UserStyle element not found.";
458  return NULL;
459  }
460 
461  // get the FeatureTypeStyle element
462  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( "FeatureTypeStyle" );
463  if ( featTypeStyleElem.isNull() )
464  {
465  errorMessage = "Info: FeatureTypeStyle element not found.";
466  return NULL;
467  }
468 
469  // use the RuleRenderer when more rules are present or the rule
470  // has filters or min/max scale denominators set,
471  // otherwise use the SingleSymbol renderer
472  bool needRuleRenderer = false;
473  int ruleCount = 0;
474 
475  QDomElement ruleElem = featTypeStyleElem.firstChildElement( "Rule" );
476  while ( !ruleElem.isNull() )
477  {
478  ruleCount++;
479 
480  // more rules present, use the RuleRenderer
481  if ( ruleCount > 1 )
482  {
483  QgsDebugMsg( "more Rule elements found: need a RuleRenderer" );
484  needRuleRenderer = true;
485  break;
486  }
487 
488  QDomElement ruleChildElem = ruleElem.firstChildElement();
489  while ( !ruleChildElem.isNull() )
490  {
491  // rule has filter or min/max scale denominator, use the RuleRenderer
492  if ( ruleChildElem.localName() == "Filter" ||
493  ruleChildElem.localName() == "MinScaleDenominator" ||
494  ruleChildElem.localName() == "MaxScaleDenominator" )
495  {
496  QgsDebugMsg( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
497  needRuleRenderer = true;
498  break;
499  }
500 
501  ruleChildElem = ruleChildElem.nextSiblingElement();
502  }
503 
504  if ( needRuleRenderer )
505  {
506  break;
507  }
508 
509  ruleElem = ruleElem.nextSiblingElement( "Rule" );
510  }
511 
512  QString rendererType;
513  if ( needRuleRenderer )
514  {
515  rendererType = "RuleRenderer";
516  }
517  else
518  {
519  rendererType = "singleSymbol";
520  }
521  QgsDebugMsg( QString( "Instantiating a '%1' renderer..." ).arg( rendererType ) );
522 
523  // create the renderer and return it
525  if ( m == NULL )
526  {
527  errorMessage = QString( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
528  return NULL;
529  }
530 
531  QgsFeatureRendererV2* r = m->createRendererFromSld( featTypeStyleElem, geomType );
532  return r;
533 }
534 
535 QDomElement QgsFeatureRendererV2::writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const
536 {
537  return writeSld( doc, layer.name() );
538 }
539 
540 QDomElement QgsFeatureRendererV2::writeSld( QDomDocument& doc, const QString& styleName ) const
541 {
542  QDomElement userStyleElem = doc.createElement( "UserStyle" );
543 
544  QDomElement nameElem = doc.createElement( "se:Name" );
545  nameElem.appendChild( doc.createTextNode( styleName ) );
546  userStyleElem.appendChild( nameElem );
547 
548  QDomElement featureTypeStyleElem = doc.createElement( "se:FeatureTypeStyle" );
549  toSld( doc, featureTypeStyleElem );
550  userStyleElem.appendChild( featureTypeStyleElem );
551 
552  return userStyleElem;
553 }
554 
556 {
557  Q_UNUSED( iconSize );
558  // empty list by default
559  return QgsLegendSymbologyList();
560 }
561 
563 {
564  return false;
565 }
566 
568 {
569  Q_UNUSED( key );
570  return false;
571 }
572 
573 void QgsFeatureRendererV2::checkLegendSymbolItem( QString key, bool state )
574 {
575  Q_UNUSED( key );
576  Q_UNUSED( state );
577 }
578 
579 QgsLegendSymbolList QgsFeatureRendererV2::legendSymbolItems( double scaleDenominator, QString rule )
580 {
581  Q_UNUSED( scaleDenominator );
582  Q_UNUSED( rule );
583  return QgsLegendSymbolList();
584 }
585 
587 {
588  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
590  int i = 0;
591  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
592  {
593  lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
594  }
595  return lst2;
596 }
597 
599 {
602 }
603 
605 {
606  QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
609 }
610 
612 {
613  foreach ( QPointF pt, pts )
614  renderVertexMarker( pt, context );
615 }
616 
617 void QgsFeatureRendererV2::renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context )
618 {
619  foreach ( QPointF pt, pts )
620  renderVertexMarker( pt, context );
621 
622  if ( rings )
623  {
624  foreach ( QPolygonF ring, *rings )
625  {
626  foreach ( QPointF pt, ring )
627  renderVertexMarker( pt, context );
628  }
629  }
630 }
631 
633 {
634  QgsSymbolV2List lst;
635  QgsSymbolV2* s = symbolForFeature( feat );
636  if ( s ) lst.append( s );
637  return lst;
638 }
639 
641 {
642  QgsSymbolV2List lst;
644  if ( s ) lst.append( s );
645  return lst;
646 }
647 
649 {
650  return mPaintEffect;
651 }
652 
654 {
655  delete mPaintEffect;
656  mPaintEffect = effect;
657 }
658 
660 {
661  if ( symbol->type() == QgsSymbolV2::Marker )
662  {
663  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
665  {
666  const QgsDataDefined dd( "sqrt(" + QString::number( s->size() ) + " * (" + field + "))" );
667  s->setDataDefinedSize( dd );
668  }
669  else
670  {
671  const QgsDataDefined dd( QString::number( s->size() ) + " * (" + field + ")" );
672  s->setDataDefinedSize( dd );
673  }
674  }
675  else if ( symbol->type() == QgsSymbolV2::Line )
676  {
677  QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
678  const QgsDataDefined dd( QString::number( s->width() ) + " * (" + field + ")" );
679  s->setDataDefinedWidth( dd );
680  }
681 }
682 
683 void QgsFeatureRendererV2::convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field )
684 {
685  if ( symbol->type() == QgsSymbolV2::Marker )
686  {
687  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
688  const QgsDataDefined dd(( s->angle()
689  ? QString::number( s->angle() ) + " + "
690  : QString() ) + field );
691  s->setDataDefinedAngle( dd );
692  }
693 }
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)