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  startRender( context, vlayer->pendingFields() );
237 }
238 
239 bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
240 {
241  QgsSymbolV2* symbol = symbolForFeature( feature );
242  if ( symbol == NULL )
243  return false;
244 
245  renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
246  return true;
247 }
248 
249 void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
250 {
251  QgsSymbolV2::SymbolType symbolType = symbol->type();
252 
253  const QgsGeometry* geom = feature.constGeometry();
254  if ( !geom || !geom->geometry() )
255  {
256  return;
257  }
258 
259  //convert curve types to normal point/line/polygon ones
260  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
261  {
267  {
268  QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
269  if ( !g )
270  {
271  return;
272  }
273  feature.setGeometry( new QgsGeometry( g ) );
274  geom = feature.constGeometry();
275  }
276  default:
277  break;
278  }
279 
280  switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
281  {
282  case QgsWKBTypes::Point:
283  {
284  if ( symbolType != QgsSymbolV2::Marker )
285  {
286  QgsDebugMsg( "point can be drawn only with marker symbol!" );
287  break;
288  }
289  QPointF pt;
290  _getPoint( pt, context, geom->asWkb() );
291  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
292 
293  //if ( drawVertexMarker )
294  // renderVertexMarker( pt, context );
295  }
296  break;
298  {
299  if ( symbolType != QgsSymbolV2::Line )
300  {
301  QgsDebugMsg( "linestring can be drawn only with line symbol!" );
302  break;
303  }
304  QPolygonF pts;
305  _getLineString( pts, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
306  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
307 
308  if ( drawVertexMarker )
309  renderVertexMarkerPolyline( pts, context );
310  }
311  break;
313  {
314  if ( symbolType != QgsSymbolV2::Fill )
315  {
316  QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
317  break;
318  }
319  QPolygonF pts;
320  QList<QPolygonF> holes;
321  _getPolygon( pts, holes, context, geom->asWkb(), symbol->clipFeaturesToExtent() );
322  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
323 
324  if ( drawVertexMarker )
325  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
326  }
327  break;
328 
330  {
331  if ( symbolType != QgsSymbolV2::Marker )
332  {
333  QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
334  break;
335  }
336 
337  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
338  unsigned int num;
339  wkbPtr >> num;
340  const unsigned char* ptr = wkbPtr;
341  QPointF pt;
342 
343  for ( unsigned int i = 0; i < num; ++i )
344  {
345  ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
346  (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
347 
348  //if ( drawVertexMarker )
349  // renderVertexMarker( pt, context );
350  }
351  }
352  break;
353 
356  {
357  if ( symbolType != QgsSymbolV2::Line )
358  {
359  QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
360  break;
361  }
362 
363  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
364  unsigned int num;
365  wkbPtr >> num;
366  const unsigned char* ptr = wkbPtr;
367  QPolygonF pts;
368 
369  for ( unsigned int i = 0; i < num; ++i )
370  {
371  ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
372  (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
373 
374  if ( drawVertexMarker )
375  renderVertexMarkerPolyline( pts, context );
376  }
377  }
378  break;
379 
382  {
383  if ( symbolType != QgsSymbolV2::Fill )
384  {
385  QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
386  break;
387  }
388 
389  QgsConstWkbPtr wkbPtr( geom->asWkb() + 1 + sizeof( int ) );
390  unsigned int num;
391  wkbPtr >> num;
392  const unsigned char* ptr = wkbPtr;
393  QPolygonF pts;
394  QList<QPolygonF> holes;
395 
396  for ( unsigned int i = 0; i < num; ++i )
397  {
398  ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
399  (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
400 
401  if ( drawVertexMarker )
402  renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context );
403  }
404  break;
405  }
406  default:
407  QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
408  }
409 }
410 
412 {
413  return "UNKNOWN RENDERER\n";
414 }
415 
416 
418 {
419  // <renderer-v2 type=""> ... </renderer-v2>
420 
421  if ( element.isNull() )
422  return NULL;
423 
424  // load renderer
425  QString rendererType = element.attribute( "type" );
426 
428  if ( m == NULL )
429  return NULL;
430 
431  QgsFeatureRendererV2* r = m->createRenderer( element );
432  if ( r )
433  {
434  r->setUsingSymbolLevels( element.attribute( "symbollevels", "0" ).toInt() );
435  r->setForceRasterRender( element.attribute( "forceraster", "0" ).toInt() );
436 
437  //restore layer effect
438  QDomElement effectElem = element.firstChildElement( "effect" );
439  if ( !effectElem.isNull() )
440  {
441  r->setPaintEffect( QgsPaintEffectRegistry::instance()->createEffect( effectElem ) );
442  }
443  }
444  return r;
445 }
446 
448 {
449  // create empty renderer element
450  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
451  rendererElem.setAttribute( "forceraster", ( mForceRaster ? "1" : "0" ) );
452 
453  if ( mPaintEffect )
454  mPaintEffect->saveProperties( doc, rendererElem );
455 
456  return rendererElem;
457 }
458 
460 {
461  QDomElement element = node.toElement();
462  if ( element.isNull() )
463  return NULL;
464 
465  // get the UserStyle element
466  QDomElement userStyleElem = element.firstChildElement( "UserStyle" );
467  if ( userStyleElem.isNull() )
468  {
469  // UserStyle element not found, nothing will be rendered
470  errorMessage = "Info: UserStyle element not found.";
471  return NULL;
472  }
473 
474  // get the FeatureTypeStyle element
475  QDomElement featTypeStyleElem = userStyleElem.firstChildElement( "FeatureTypeStyle" );
476  if ( featTypeStyleElem.isNull() )
477  {
478  errorMessage = "Info: FeatureTypeStyle element not found.";
479  return NULL;
480  }
481 
482  // use the RuleRenderer when more rules are present or the rule
483  // has filters or min/max scale denominators set,
484  // otherwise use the SingleSymbol renderer
485  bool needRuleRenderer = false;
486  int ruleCount = 0;
487 
488  QDomElement ruleElem = featTypeStyleElem.firstChildElement( "Rule" );
489  while ( !ruleElem.isNull() )
490  {
491  ruleCount++;
492 
493  // more rules present, use the RuleRenderer
494  if ( ruleCount > 1 )
495  {
496  QgsDebugMsg( "more Rule elements found: need a RuleRenderer" );
497  needRuleRenderer = true;
498  break;
499  }
500 
501  QDomElement ruleChildElem = ruleElem.firstChildElement();
502  while ( !ruleChildElem.isNull() )
503  {
504  // rule has filter or min/max scale denominator, use the RuleRenderer
505  if ( ruleChildElem.localName() == "Filter" ||
506  ruleChildElem.localName() == "MinScaleDenominator" ||
507  ruleChildElem.localName() == "MaxScaleDenominator" )
508  {
509  QgsDebugMsg( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
510  needRuleRenderer = true;
511  break;
512  }
513 
514  ruleChildElem = ruleChildElem.nextSiblingElement();
515  }
516 
517  if ( needRuleRenderer )
518  {
519  break;
520  }
521 
522  ruleElem = ruleElem.nextSiblingElement( "Rule" );
523  }
524 
525  QString rendererType;
526  if ( needRuleRenderer )
527  {
528  rendererType = "RuleRenderer";
529  }
530  else
531  {
532  rendererType = "singleSymbol";
533  }
534  QgsDebugMsg( QString( "Instantiating a '%1' renderer..." ).arg( rendererType ) );
535 
536  // create the renderer and return it
538  if ( m == NULL )
539  {
540  errorMessage = QString( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
541  return NULL;
542  }
543 
544  QgsFeatureRendererV2* r = m->createRendererFromSld( featTypeStyleElem, geomType );
545  return r;
546 }
547 
549 {
550  return writeSld( doc, layer.name() );
551 }
552 
554 {
555  QDomElement userStyleElem = doc.createElement( "UserStyle" );
556 
557  QDomElement nameElem = doc.createElement( "se:Name" );
558  nameElem.appendChild( doc.createTextNode( styleName ) );
559  userStyleElem.appendChild( nameElem );
560 
561  QDomElement featureTypeStyleElem = doc.createElement( "se:FeatureTypeStyle" );
562  toSld( doc, featureTypeStyleElem );
563  userStyleElem.appendChild( featureTypeStyleElem );
564 
565  return userStyleElem;
566 }
567 
569 {
570  Q_UNUSED( iconSize );
571  // empty list by default
572  return QgsLegendSymbologyList();
573 }
574 
576 {
577  return false;
578 }
579 
581 {
582  Q_UNUSED( key );
583  return false;
584 }
585 
587 {
588  Q_UNUSED( key );
589  Q_UNUSED( state );
590 }
591 
593 {
594  Q_UNUSED( scaleDenominator );
595  Q_UNUSED( rule );
596  return QgsLegendSymbolList();
597 }
598 
600 {
601  QgsLegendSymbolList lst = const_cast<QgsFeatureRendererV2*>( this )->legendSymbolItems();
603  int i = 0;
604  for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
605  {
606  lst2 << QgsLegendSymbolItemV2( it->second, it->first, QString::number( i ), legendSymbolItemsCheckable() );
607  }
608  return lst2;
609 }
610 
612 {
615 }
616 
618 {
619  QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
622 }
623 
625 {
626  foreach ( QPointF pt, pts )
627  renderVertexMarker( pt, context );
628 }
629 
631 {
632  foreach ( QPointF pt, pts )
633  renderVertexMarker( pt, context );
634 
635  if ( rings )
636  {
637  foreach ( QPolygonF ring, *rings )
638  {
639  foreach ( QPointF pt, ring )
640  renderVertexMarker( pt, context );
641  }
642  }
643 }
644 
646 {
647  QgsSymbolV2List lst;
648  QgsSymbolV2* s = symbolForFeature( feat );
649  if ( s ) lst.append( s );
650  return lst;
651 }
652 
654 {
655  QgsSymbolV2List lst;
657  if ( s ) lst.append( s );
658  return lst;
659 }
660 
662 {
663  return mPaintEffect;
664 }
665 
667 {
668  delete mPaintEffect;
669  mPaintEffect = effect;
670 }
671 
673 {
674  if ( symbol->type() == QgsSymbolV2::Marker )
675  {
676  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
678  {
679  const QgsDataDefined dd( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" );
680  s->setDataDefinedSize( dd );
681  }
682  else
683  {
684  const QgsDataDefined dd( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" );
685  s->setDataDefinedSize( dd );
686  }
688  }
689  else if ( symbol->type() == QgsSymbolV2::Line )
690  {
691  QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
692  const QgsDataDefined dd( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" );
693  s->setDataDefinedWidth( dd );
694  }
695 }
696 
698 {
699  if ( symbol->type() == QgsSymbolV2::Marker )
700  {
701  QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
702  const QgsDataDefined dd(( s->angle()
703  ? QString::number( s->angle() ) + " + "
704  : QString() ) + field );
705  s->setDataDefinedAngle( dd );
706  }
707 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:51
void clear()
static QgsRendererV2Registry * instance()
#define RENDERER_TAG_NAME
Definition: qgsrendererv2.h:48
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:96
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
const QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
void setDataDefinedAngle(const QgsDataDefined &dd)
Set data defined angle for whole symbol (including all symbol layers).
A container class for data source field mapping or expression.
QgsRendererV2AbstractMetadata * rendererMetadata(QString rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
QDomNode appendChild(const QDomNode &newChild)
static QgsFeatureRendererV2 * loadSld(const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
SymbolType type() const
Definition: qgssymbolv2.h:86
static const unsigned char * _getPoint(QPointF &pt, QgsRenderContext &context, const unsigned char *wkb)
void transformPolygon(QPolygonF &poly, TransformDirection direction=ForwardTransform) const
QString attribute(const QString &name, const QString &defValue) const
virtual QString dump() const
for debugging
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
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
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
Base class for visual effects which can be applied to QPicture drawings.
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
QDomElement nextSiblingElement(const QString &tagName) const
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:75
Stores metadata about one renderer class.
virtual ~QgsFeatureRendererV2()
GeometryType
Definition: qgis.h:155
const QgsRectangle & extent() const
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
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
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 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
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
const QgsFields & pendingFields() const
Returns the list of fields of this layer.
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
static void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y.
static void convertSymbolSizeScale(QgsSymbolV2 *symbol, QgsSymbolV2::ScaleMethod method, const QString &field)
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
QDomText createTextNode(const QString &value)
iterator end()
QgsFeatureRendererV2(QString type)
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QgsAbstractGeometryV2 * segmentize() const
Returns a version of the geometry without curves.
bool isNull() const
void setDataDefinedWidth(const QgsDataDefined &dd)
Set data defined width for whole symbol (including all symbol layers).
void setUsingSymbolLevels(bool usingSymbolLevels)
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
Contains information about the context of a rendering operation.
QRectF boundingRect() const
QPainter * painter()
void copyPaintEffect(QgsFeatureRendererV2 *destRenderer) const
Copies paint effect of this renderer to another renderer.
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
virtual QgsSymbolV2List symbolsForFeature(QgsFeature &feat)
return list of symbols used for rendering the feature.
static QgsFeatureRendererV2 * load(QDomElement &symbologyElem)
create a renderer from XML element
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const
Return a list of symbology items for the legend.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
QDomElement firstChildElement(const QString &tagName) const
void setScaleMethodToSymbol(QgsSymbolV2 *symbol, int scaleMethod)
virtual Q_DECL_DEPRECATED QDomElement writeSld(QDomDocument &doc, const QgsVectorLayer &layer) const
create the SLD UserStyle element following the SLD v1.1 specs
void renderVertexMarkerPolygon(QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
render editing vertex marker for a polygon
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
Definition: qgsfeature.cpp:68
qreal & rx()
qreal & ry()
Class for doing transforms between two map coordinate systems.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
const QgsMapToPixel & mapToPixel() const
static const unsigned char * _getLineString(QPolygonF &pts, QgsRenderContext &context, const unsigned char *wkb, bool clipToExtent=true)
QDomElement createElement(const QString &tagName)
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:202
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
Definition: qgsclipper.h:178
virtual QgsFeatureRendererV2 * createRendererFromSld(QDomElement &elem, QGis::GeometryType geomType)
int size() const
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:43
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
To be overridden.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:187
iterator begin()
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
void renderVertexMarker(QPointF &pt, QgsRenderContext &context)
render editing vertex marker at specified point
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
static void convertSymbolRotation(QgsSymbolV2 *symbol, const QString &field)