QGIS API Documentation  2.15.0-Master (5f66276)
qgssymbollayerv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2.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 "qgssymbollayerv2.h"
17 #include "qgsclipper.h"
18 #include "qgsexpression.h"
19 #include "qgsrendercontext.h"
20 #include "qgsvectorlayer.h"
21 #include "qgsdxfexport.h"
22 #include "qgsgeometrysimplifier.h"
23 #include "qgspainteffect.h"
24 #include "qgseffectstack.h"
25 #include "qgspainteffectregistry.h"
26 #include "qgsdatadefined.h"
27 #include "qgsexpressioncontext.h"
28 
29 #include <QSize>
30 #include <QPainter>
31 #include <QPointF>
32 #include <QPolygonF>
33 
34 const QString QgsSymbolLayerV2::EXPR_SIZE( "size" );
35 const QString QgsSymbolLayerV2::EXPR_ANGLE( "angle" );
36 const QString QgsSymbolLayerV2::EXPR_NAME( "name" );
37 const QString QgsSymbolLayerV2::EXPR_COLOR( "color" );
38 const QString QgsSymbolLayerV2::EXPR_COLOR_BORDER( "color_border" );
39 const QString QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH( "outline_width" );
40 const QString QgsSymbolLayerV2::EXPR_OUTLINE_STYLE( "outline_style" );
41 const QString QgsSymbolLayerV2::EXPR_FILL( "fill" );
42 const QString QgsSymbolLayerV2::EXPR_OUTLINE( "outline" );
43 const QString QgsSymbolLayerV2::EXPR_OFFSET( "offset" );
44 const QString QgsSymbolLayerV2::EXPR_CHAR( "char" );
45 const QString QgsSymbolLayerV2::EXPR_FILL_COLOR( "fill_color" );
46 const QString QgsSymbolLayerV2::EXPR_OUTLINE_COLOR( "outline_color" );
47 const QString QgsSymbolLayerV2::EXPR_WIDTH( "width" );
48 const QString QgsSymbolLayerV2::EXPR_HEIGHT( "height" );
49 const QString QgsSymbolLayerV2::EXPR_SYMBOL_NAME( "symbol_name" );
50 const QString QgsSymbolLayerV2::EXPR_ROTATION( "rotation" );
51 const QString QgsSymbolLayerV2::EXPR_FILL_STYLE( "fill_style" );
52 const QString QgsSymbolLayerV2::EXPR_WIDTH_BORDER( "width_border" );
53 const QString QgsSymbolLayerV2::EXPR_BORDER_STYLE( "border_style" );
54 const QString QgsSymbolLayerV2::EXPR_JOIN_STYLE( "join_style" );
55 const QString QgsSymbolLayerV2::EXPR_BORDER_COLOR( "border_color" );
56 const QString QgsSymbolLayerV2::EXPR_COLOR2( "color2" );
57 const QString QgsSymbolLayerV2::EXPR_LINEANGLE( "lineangle" );
58 const QString QgsSymbolLayerV2::EXPR_GRADIENT_TYPE( "gradient_type" );
59 const QString QgsSymbolLayerV2::EXPR_COORDINATE_MODE( "coordinate_mode" );
60 const QString QgsSymbolLayerV2::EXPR_SPREAD( "spread" );
61 const QString QgsSymbolLayerV2::EXPR_REFERENCE1_X( "reference1_x" );
62 const QString QgsSymbolLayerV2::EXPR_REFERENCE1_Y( "reference1_y" );
63 const QString QgsSymbolLayerV2::EXPR_REFERENCE2_X( "reference2_x" );
64 const QString QgsSymbolLayerV2::EXPR_REFERENCE2_Y( "reference2_y" );
65 const QString QgsSymbolLayerV2::EXPR_REFERENCE1_ISCENTROID( "reference1_iscentroid" );
66 const QString QgsSymbolLayerV2::EXPR_REFERENCE2_ISCENTROID( "reference2_iscentroid" );
67 const QString QgsSymbolLayerV2::EXPR_BLUR_RADIUS( "blur_radius" );
68 const QString QgsSymbolLayerV2::EXPR_DISTANCE( "distance" );
69 const QString QgsSymbolLayerV2::EXPR_USE_WHOLE_SHAPE( "use_whole_shape" );
70 const QString QgsSymbolLayerV2::EXPR_MAX_DISTANCE( "max_distance" );
71 const QString QgsSymbolLayerV2::EXPR_IGNORE_RINGS( "ignore_rings" );
72 const QString QgsSymbolLayerV2::EXPR_SVG_FILE( "svgFile" );
73 const QString QgsSymbolLayerV2::EXPR_SVG_FILL_COLOR( "svgFillColor" );
74 const QString QgsSymbolLayerV2::EXPR_SVG_OUTLINE_COLOR( "svgOutlineColor" );
75 const QString QgsSymbolLayerV2::EXPR_SVG_OUTLINE_WIDTH( "svgOutlineWidth" );
76 const QString QgsSymbolLayerV2::EXPR_LINEWIDTH( "linewidth" );
77 const QString QgsSymbolLayerV2::EXPR_DISTANCE_X( "distance_x" );
78 const QString QgsSymbolLayerV2::EXPR_DISTANCE_Y( "distance_y" );
79 const QString QgsSymbolLayerV2::EXPR_DISPLACEMENT_X( "displacement_x" );
80 const QString QgsSymbolLayerV2::EXPR_DISPLACEMENT_Y( "displacement_y" );
81 const QString QgsSymbolLayerV2::EXPR_FILE( "file" );
82 const QString QgsSymbolLayerV2::EXPR_ALPHA( "alpha" );
83 const QString QgsSymbolLayerV2::EXPR_CUSTOMDASH( "customdash" );
84 const QString QgsSymbolLayerV2::EXPR_LINE_STYLE( "line_style" );
85 const QString QgsSymbolLayerV2::EXPR_JOINSTYLE( "joinstyle" );
86 const QString QgsSymbolLayerV2::EXPR_CAPSTYLE( "capstyle" );
87 const QString QgsSymbolLayerV2::EXPR_PLACEMENT( "placement" );
88 const QString QgsSymbolLayerV2::EXPR_INTERVAL( "interval" );
89 const QString QgsSymbolLayerV2::EXPR_OFFSET_ALONG_LINE( "offset_along_line" );
90 const QString QgsSymbolLayerV2::EXPR_HORIZONTAL_ANCHOR_POINT( "horizontal_anchor_point" );
91 const QString QgsSymbolLayerV2::EXPR_VERTICAL_ANCHOR_POINT( "vertical_anchor_point" );
92 
94 {
96  return expression( property );
98 }
99 
101 {
103  return nullptr;
104 
106  if ( it != mDataDefinedProperties.constEnd() )
107  {
108  return it.value();
109  }
110  return nullptr;
111 }
112 
114 {
115  QgsDataDefined* dd = getDataDefinedProperty( property );
116  return dd ? dd->expression() : nullptr;
117 }
118 
120 {
121  const QgsDataDefined* dd = getDataDefinedProperty( property );
122  return dd ? dd->expressionString() : QString();
123 }
124 
125 void QgsSymbolLayerV2::setDataDefinedProperty( const QString& property, const QString& expressionString )
126 {
127  setDataDefinedProperty( property, new QgsDataDefined( expressionString ) );
128 }
129 
131 {
132  removeDataDefinedProperty( property );
133  mDataDefinedProperties.insert( property, dataDefined );
134 }
135 
137 {
139  if ( it != mDataDefinedProperties.end() )
140  {
141  delete( it.value() );
143  }
144 }
145 
147 {
148  qDeleteAll( mDataDefinedProperties );
150 }
151 
153 {
155  return false;
156 
158  for ( ; it != mDataDefinedProperties.constEnd(); ++it )
159  {
160  if ( hasDataDefinedProperty( it.key() ) )
161  return true;
162  }
163 
164  return false;
165 }
166 
168 {
170  return false;
171 
172  QgsDataDefined* dd = getDataDefinedProperty( property );
173  return dd && dd->isActive();
174 }
175 
176 QVariant QgsSymbolLayerV2::evaluateDataDefinedProperty( const QString &property, const QgsFeature* feature, const QVariant& defaultVal, bool *ok ) const
177 {
178  if ( ok )
179  *ok = false;
180 
181  QgsDataDefined* dd = getDataDefinedProperty( property );
182  if ( !dd || !dd->isActive() )
183  return defaultVal;
184 
185  if ( dd->useExpression() )
186  {
187  if ( dd->expression() )
188  {
190  QVariant result = dd->expression()->evaluate( &context );
191  if ( result.isValid() )
192  {
193  if ( ok )
194  *ok = true;
195  return result;
196  }
197  else
198  return defaultVal;
199  }
200  else
201  {
202  return defaultVal;
203  }
204  }
205  else if ( feature && !dd->field().isEmpty() && !mFields.isEmpty() )
206  {
207  int attributeIndex = mFields.fieldNameIndex( dd->field() );
208  if ( attributeIndex >= 0 )
209  {
210  if ( ok )
211  *ok = true;
212  return feature->attribute( attributeIndex );
213  }
214  }
215  return defaultVal;
216 }
217 
218 QVariant QgsSymbolLayerV2::evaluateDataDefinedProperty( const QString& property, const QgsSymbolV2RenderContext& context, const QVariant& defaultVal, bool* ok ) const
219 {
220  if ( ok )
221  *ok = false;
222 
223  QgsDataDefined* dd = getDataDefinedProperty( property );
224  if ( !dd || !dd->isActive() )
225  return defaultVal;
226 
227  if ( dd->useExpression() )
228  {
229  if ( dd->expression() )
230  {
231  QVariant result = dd->expression()->evaluate( &context.renderContext().expressionContext() );
232  if ( result.isValid() )
233  {
234  if ( ok )
235  *ok = true;
236  return result;
237  }
238  else
239  return defaultVal;
240  }
241  else
242  {
243  return defaultVal;
244  }
245  }
246  else if ( context.feature() && !dd->field().isEmpty() && !mFields.isEmpty() )
247  {
248  int attributeIndex = mFields.fieldNameIndex( dd->field() );
249  if ( attributeIndex >= 0 )
250  {
251  if ( ok )
252  *ok = true;
253  return context.feature()->attribute( attributeIndex );
254  }
255  }
256  return defaultVal;
257 }
258 
259 bool QgsSymbolLayerV2::writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
260 {
261  Q_UNUSED( e );
262  Q_UNUSED( mmMapUnitScaleFactor );
263  Q_UNUSED( layerName );
264  Q_UNUSED( context );
265  Q_UNUSED( shift );
266  return false;
267 }
268 
270 {
271  Q_UNUSED( e );
272  Q_UNUSED( context );
273  return 1.0;
274 }
275 
277 {
278  Q_UNUSED( e );
279  Q_UNUSED( context );
280  return 0.0;
281 }
282 
284 {
285  Q_UNUSED( context );
286  return color();
287 }
288 
290 {
291  Q_UNUSED( context );
292  return 0.0;
293 }
294 
296 {
297  Q_UNUSED( unit );
298  return QVector<qreal>();
299 }
300 
301 Qt::PenStyle QgsSymbolLayerV2::dxfPenStyle() const
302 {
303  return Qt::SolidLine;
304 }
305 
307 {
308  Q_UNUSED( context );
309  return color();
310 }
311 
312 Qt::BrushStyle QgsSymbolLayerV2::dxfBrushStyle() const
313 {
314  return Qt::NoBrush;
315 }
316 
318 {
319  return mPaintEffect;
320 }
321 
323 {
324  delete mPaintEffect;
325  mPaintEffect = effect;
326 }
327 
329  : mType( type )
330  , mLocked( locked )
331  , mRenderingPass( 0 )
332  , mPaintEffect( nullptr )
333 {
335  mPaintEffect->setEnabled( false );
336 }
337 
338 void QgsSymbolLayerV2::prepareExpressions( const QgsFields* fields, double scale )
339 {
341  for ( ; it != mDataDefinedProperties.constEnd(); ++it )
342  {
343  if ( it.value() )
344  {
346  if ( scale > 0 )
347  {
348  params.insert( "scale", scale );
349  }
350  it.value()->setExpressionParams( params );
351 
352  if ( fields )
353  {
354  it.value()->prepareExpression( QgsExpressionContextUtils::createFeatureBasedContext( QgsFeature(), *fields ) );
355  }
356  else
357  {
358  it.value()->prepareExpression();
359  }
360  }
361  }
362 
363  if ( fields )
364  {
365  //QgsFields is implicitly shared, so it's cheap to make a copy
366  mFields = *fields;
367  }
368 }
369 
371 {
373  for ( ; it != mDataDefinedProperties.constEnd(); ++it )
374  {
375  if ( it.value() )
376  {
378  if ( context.renderContext().rendererScale() > 0 )
379  {
380  params.insert( "scale", context.renderContext().rendererScale() );
381  }
382  it.value()->setExpressionParams( params );
383  it.value()->prepareExpression( context.renderContext().expressionContext() );
384  }
385  }
386 
387  if ( context.fields() )
388  {
389  //QgsFields is implicitly shared, so it's cheap to make a copy
390  mFields = *context.fields();
391  }
392 }
393 
395 {
397  delete mPaintEffect;
398 }
399 
401 {
402  if ( symbol->type() == QgsSymbolV2::Fill && mType == QgsSymbolV2::Line )
403  return true;
404 
405  return symbol->type() == mType;
406 }
407 
409 {
410  QStringList columns;
411 
413  for ( ; ddIt != mDataDefinedProperties.constEnd(); ++ddIt )
414  {
415  if ( ddIt.value() && ddIt.value()->isActive() )
416  {
417  columns.append( ddIt.value()->referencedColumns() );
418  }
419  }
420 
421  return columns.toSet();
422 }
423 
425 {
427  for ( ; ddIt != mDataDefinedProperties.constEnd(); ++ddIt )
428  {
429  if ( ddIt.value() )
430  {
431  stringMap.unite( ddIt.value()->toMap( ddIt.key() ) );
432  }
433  }
434 }
435 
437 {
438  QgsStringMap::const_iterator propIt = stringMap.constBegin();
439  for ( ; propIt != stringMap.constEnd(); ++propIt )
440  {
441  if ( propIt.key().endsWith( "_dd_expression" ) )
442  {
443  //found a data defined property
444 
445  //get data defined property name by stripping "_dd_expression" from property key
446  QString propertyName = propIt.key().left( propIt.key().length() - 14 );
447 
448  QgsDataDefined* dd = QgsDataDefined::fromMap( stringMap, propertyName );
449  if ( dd )
450  setDataDefinedProperty( propertyName, dd );
451  }
452  else if ( propIt.key().endsWith( "_expression" ) )
453  {
454  //old style data defined property, upgrade
455 
456  //get data defined property name by stripping "_expression" from property key
457  QString propertyName = propIt.key().left( propIt.key().length() - 11 );
458 
459  setDataDefinedProperty( propertyName, new QgsDataDefined( propIt.value() ) );
460  }
461  }
462 }
463 
465 {
466  if ( !destLayer )
467  return;
468 
469  destLayer->removeDataDefinedProperties();
470 
472  for ( ; ddIt != mDataDefinedProperties.constEnd(); ++ddIt )
473  {
474  if ( ddIt.value() )
475  {
476  destLayer->setDataDefinedProperty( ddIt.key(), new QgsDataDefined( *( ddIt.value() ) ) );
477  }
478  }
479 }
480 
482 {
483  if ( !destLayer || !mPaintEffect )
484  return;
485 
486  destLayer->setPaintEffect( mPaintEffect->clone() );
487 }
488 
490  : QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
491  , mAngle( 0 )
492  , mLineAngle( 0 )
493  , mSize( 2.0 )
494  , mSizeUnit( QgsSymbolV2::MM )
495  , mOffsetUnit( QgsSymbolV2::MM )
496  , mScaleMethod( QgsSymbolV2::ScaleDiameter )
497  , mHorizontalAnchorPoint( HCenter )
498  , mVerticalAnchorPoint( VCenter )
499 {
500 
501 }
502 
504  : QgsSymbolLayerV2( QgsSymbolV2::Line, locked )
505  , mWidth( 0 )
506  , mWidthUnit( QgsSymbolV2::MM )
507  , mOffset( 0 )
508  , mOffsetUnit( QgsSymbolV2::MM )
509 {
510 }
511 
513  : QgsSymbolLayerV2( QgsSymbolV2::Fill, locked )
514  , mAngle( 0.0 )
515 {
516 }
517 
519 {
520  Q_UNUSED( context );
521 }
522 
524 {
525  startRender( context );
526  renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
527  stopRender( context );
528 }
529 
530 void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const
531 {
532  markerOffset( context, mSize, mSize, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
533 }
534 
535 void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double width, double height, double& offsetX, double& offsetY ) const
536 {
537  markerOffset( context, width, height, mSizeUnit, mSizeUnit, offsetX, offsetY, mSizeMapUnitScale, mSizeMapUnitScale );
538 }
539 
540 void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double width, double height,
541  QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
542  double& offsetX, double& offsetY, const QgsMapUnitScale& widthMapUnitScale, const QgsMapUnitScale& heightMapUnitScale ) const
543 {
544  offsetX = mOffset.x();
545  offsetY = mOffset.y();
546 
548  {
551  offsetX = offset.x();
552  offsetY = offset.y();
553  }
554 
555  offsetX = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), offsetX, mOffsetUnit, mOffsetMapUnitScale );
556  offsetY = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), offsetY, mOffsetUnit, mOffsetMapUnitScale );
557 
558  HorizontalAnchorPoint horizontalAnchorPoint = mHorizontalAnchorPoint;
559  VerticalAnchorPoint verticalAnchorPoint = mVerticalAnchorPoint;
561  {
562  horizontalAnchorPoint = decodeHorizontalAnchorPoint( evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HORIZONTAL_ANCHOR_POINT , context ).toString() );
563  }
565  {
566  verticalAnchorPoint = decodeVerticalAnchorPoint( evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_VERTICAL_ANCHOR_POINT, context ).toString() );
567  }
568 
569  //correct horizontal position according to anchor point
570  if ( horizontalAnchorPoint == HCenter && verticalAnchorPoint == VCenter )
571  {
572  return;
573  }
574 
575  double anchorPointCorrectionX = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), width, widthUnit, widthMapUnitScale ) / 2.0;
576  double anchorPointCorrectionY = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), height, heightUnit, heightMapUnitScale ) / 2.0;
577  if ( horizontalAnchorPoint == Left )
578  {
579  offsetX += anchorPointCorrectionX;
580  }
581  else if ( horizontalAnchorPoint == Right )
582  {
583  offsetX -= anchorPointCorrectionX;
584  }
585 
586  //correct vertical position according to anchor point
587  if ( verticalAnchorPoint == Top )
588  {
589  offsetY += anchorPointCorrectionY;
590  }
591  else if ( verticalAnchorPoint == Bottom )
592  {
593  offsetY -= anchorPointCorrectionY;
594  }
595 }
596 
598 {
599  angle = DEG2RAD( angle );
600  double c = cos( angle ), s = sin( angle );
601  return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() * c );
602 }
603 
604 QgsMarkerSymbolLayerV2::HorizontalAnchorPoint QgsMarkerSymbolLayerV2::decodeHorizontalAnchorPoint( const QString& str )
605 {
606  if ( str.compare( "left", Qt::CaseInsensitive ) == 0 )
607  {
609  }
610  else if ( str.compare( "right", Qt::CaseInsensitive ) == 0 )
611  {
613  }
614  else
615  {
617  }
618 }
619 
620 QgsMarkerSymbolLayerV2::VerticalAnchorPoint QgsMarkerSymbolLayerV2::decodeVerticalAnchorPoint( const QString& str )
621 {
622  if ( str.compare( "top", Qt::CaseInsensitive ) == 0 )
623  {
625  }
626  else if ( str.compare( "bottom", Qt::CaseInsensitive ) == 0 )
627  {
629  }
630  else
631  {
633  }
634 }
635 
637 {
638  mSizeUnit = unit;
639  mOffsetUnit = unit;
640 }
641 
643 {
644  if ( mOffsetUnit != mSizeUnit )
645  {
646  return QgsSymbolV2::Mixed;
647  }
648  return mOffsetUnit;
649 }
650 
652 {
653  mSizeMapUnitScale = scale;
654  mOffsetMapUnitScale = scale;
655 }
656 
658 {
659  if ( mSizeMapUnitScale == mOffsetMapUnitScale )
660  {
661  return mSizeMapUnitScale;
662  }
663  return QgsMapUnitScale();
664 }
665 
667 {
668  mWidthUnit = unit;
669 }
670 
672 {
673  return mWidthUnit;
674 }
675 
677 {
678  mWidthMapUnitScale = scale;
679 }
680 
682 {
683  return mWidthMapUnitScale;
684 }
685 
686 
688 {
689  QPolygonF points;
690  // we're adding 0.5 to get rid of blurred preview:
691  // drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line
692  points << QPointF( 0, int( size.height() / 2 ) + 0.5 ) << QPointF( size.width(), int( size.height() / 2 ) + 0.5 );
693 
694  startRender( context );
695  renderPolyline( points, context );
696  stopRender( context );
697 }
698 
700 {
701  renderPolyline( points, context );
702  if ( rings )
703  {
704  Q_FOREACH ( const QPolygonF& ring, *rings )
705  renderPolyline( ring, context );
706  }
707 }
708 
710 {
711  Q_UNUSED( context );
712  return width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
713 }
714 
715 
717 {
718  QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) );
719  startRender( context );
720  renderPolygon( poly, nullptr, context );
721  stopRender( context );
722 }
723 
725 {
726  if ( !p )
727  {
728  return;
729  }
730 
731  // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points).
732  if ( points.size() <= 5 &&
735  ( p->renderHints() & QPainter::Antialiasing ) )
736  {
737  p->setRenderHint( QPainter::Antialiasing, false );
738  p->drawRect( points.boundingRect() );
739  p->setRenderHint( QPainter::Antialiasing, true );
740  return;
741  }
742 
743  // polygons outlines are sometimes rendered wrongly with drawPolygon, when
744  // clipped (see #13343), so use drawPath instead.
745  if ( !rings && p->pen().style() == Qt::NoPen )
746  {
747  // simple polygon without holes
748  p->drawPolygon( points );
749  }
750  else
751  {
752  // polygon with holes must be drawn using painter path
753  QPainterPath path;
754  QPolygonF outerRing = points;
755  path.addPolygon( outerRing );
756 
757  if ( rings )
758  {
760  for ( ; it != rings->constEnd(); ++it )
761  {
762  QPolygonF ring = *it;
763  path.addPolygon( ring );
764  }
765  }
766 
767  p->drawPath( path );
768  }
769 }
770 
771 void QgsMarkerSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const
772 {
773  QDomElement symbolizerElem = doc.createElement( "se:PointSymbolizer" );
774  if ( !props.value( "uom", "" ).isEmpty() )
775  symbolizerElem.setAttribute( "uom", props.value( "uom", "" ) );
776  element.appendChild( symbolizerElem );
777 
778  // <Geometry>
779  QgsSymbolLayerV2Utils::createGeometryElement( doc, symbolizerElem, props.value( "geom", "" ) );
780 
781  writeSldMarker( doc, symbolizerElem, props );
782 }
783 
784 
virtual QSet< QString > usedAttributes() const
Returns the set of attributes referenced by the layer.
static double mapUnitScaleFactor(double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits)
QgsSymbolV2::SymbolType mType
static const QString EXPR_DISTANCE_Y
Class for parsing and evaluation of expressions (formerly called "search strings").
static const QString EXPR_CHAR
static const QString EXPR_OUTLINE_COLOR
static const QString EXPR_DISPLACEMENT_Y
virtual void removeDataDefinedProperties()
Removes all data defined properties from the layer and deletes associated objects.
static const QString EXPR_JOINSTYLE
Qt::PenStyle style() const
QgsSymbolV2::OutputUnit outputUnit() const override
static QPointF _rotatedOffset(QPointF offset, double angle)
Adjusts a marker offset to account for rotation.
void setEnabled(const bool enabled)
Sets whether the effect is enabled.
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:62
float threshold() const
Gets the simplification threshold of the vector layer managed.
virtual Qt::PenStyle dxfPenStyle() const
get pen style
iterator erase(iterator pos)
int width() const
A container class for data source field mapping or expression.
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
static const QString EXPR_BORDER_COLOR
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
SymbolType type() const
Definition: qgssymbolv2.h:104
static const QString EXPR_USE_WHOLE_SHAPE
RenderHints renderHints() const
static const QString EXPR_REFERENCE2_Y
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
QMap< Key, T > & unite(const QMap< Key, T > &other)
virtual bool isCompatibleWithSymbol(QgsSymbolV2 *symbol) const
Returns if the layer can be used below the specified symbol.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
QString field() const
Get the field which this QgsDataDefined represents.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
static const QString EXPR_DISPLACEMENT_X
int fieldNameIndex(const QString &fieldName) const
Look up field&#39;s index from name also looks up case-insensitive if there is no match otherwise...
Definition: qgsfield.cpp:534
double rendererScale() const
QMap< QString, QgsDataDefined * > mDataDefinedProperties
static const QString EXPR_WIDTH
virtual bool writeDxf(QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift=QPointF(0.0, 0.0)) const
write as DXF
static const QString EXPR_CUSTOMDASH
QGis::UnitType mapUnits() const
Retrieve map units.
Definition: qgsdxfexport.h:93
const_iterator constBegin() const
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:514
#define DEG2RAD(x)
Base class for visual effects which can be applied to QPicture drawings.
QgsSymbolV2::OutputUnit outputUnit() const override
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
QgsPaintEffect * mPaintEffect
QgsExpression * expression()
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
Container of fields for a vector layer.
Definition: qgsfield.h:193
static const QString EXPR_BLUR_RADIUS
static const QString EXPR_COORDINATE_MODE
virtual void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)=0
Line symbol.
Definition: qgssymbolv2.h:79
static QPointF decodePoint(const QString &str)
QString expressionString() const
Returns the expression string of this QgsDataDefined.
static const QString EXPR_COLOR2
static QgsDataDefined * fromMap(const QgsStringMap &map, const QString &baseName=QString())
Creates a QgsDataDefined from a decoded QgsStringMap.
void copyPaintEffect(QgsSymbolLayerV2 *destLayer) const
Copies paint effect of this layer to another symbol layer.
QSet< T > toSet() const
QgsSymbolLayerV2(QgsSymbolV2::SymbolType type, bool locked=false)
static const QString EXPR_VERTICAL_ANCHOR_POINT
virtual bool hasDataDefinedProperty(const QString &property) const
Checks whether the layer has a matching data defined property and if that property is currently activ...
static const QString EXPR_OFFSET_ALONG_LINE
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const
get line width
void clear()
virtual void removeDataDefinedProperty(const QString &property)
Removes a data defined property from the layer.
static const QString EXPR_OFFSET
void setMapUnitScale(const QgsMapUnitScale &scale) override
static const QString EXPR_SIZE
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual Q_DECL_DEPRECATED QString dataDefinedPropertyString(const QString &property) const
Returns a data defined expression for a property, if set.
virtual void startRender(QgsSymbolV2RenderContext &context)=0
static const QString EXPR_JOIN_STYLE
virtual Q_DECL_DEPRECATED QgsExpression * expression(const QString &property) const
Returns the data defined expression associated with a property.
static const QString EXPR_FILL_STYLE
static const QString EXPR_REFERENCE1_Y
void drawRect(const QRectF &rectangle)
static const QString EXPR_BORDER_STYLE
static const QString EXPR_REFERENCE2_X
static const QString EXPR_REFERENCE2_ISCENTROID
Mixed units in symbol layers.
Definition: qgssymbolv2.h:66
static const QString EXPR_LINEWIDTH
static const QString EXPR_PLACEMENT
static const QString EXPR_FILL_COLOR
void markerOffset(QgsSymbolV2RenderContext &context, double &offsetX, double &offsetY) const
Calculates the required marker offset, including both the symbol offset and any displacement required...
qreal x() const
qreal y() const
void append(const T &value)
static const QString EXPR_SPREAD
void addPolygon(const QPolygonF &polygon)
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
const QgsFeature * feature() const
Current feature being rendered - may be null.
Definition: qgssymbolv2.h:378
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects. ...
static const QString EXPR_LINEANGLE
const Key & key() const
static QString encodePoint(QPointF point)
static double convertToPainterUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to painter units.
virtual QVector< qreal > dxfCustomDashPattern(QgsSymbolV2::OutputUnit &unit) const
get dash pattern
static const QString EXPR_ALPHA
The geometries can be rendered with &#39;AntiAliasing&#39; disabled because of it is &#39;1-pixel size&#39;...
QgsMarkerSymbolLayerV2(bool locked=false)
Constructor for QgsMarkerSymbolLayerV2.
void setAttribute(const QString &name, const QString &value)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isEmpty() const
const_iterator constEnd() const
const T & value() const
virtual QColor color() const
The fill color.
static const QString EXPR_FILL
virtual void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
iterator end()
virtual Q_DECL_DEPRECATED void prepareExpressions(const QgsFields *fields, double scale=-1.0)
Prepares all data defined property expressions for evaluation.
virtual double dxfAngle(QgsSymbolV2RenderContext &context) const
get angle
static const QString EXPR_FILE
virtual bool hasDataDefinedProperties() const
Checks whether the layer has any associated data defined properties.
static const QString EXPR_CAPSTYLE
static const QString EXPR_OUTLINE_STYLE
QgsSymbolV2::SymbolType type() const
bool useExpression() const
Returns if the field or the expression part is active.
static const QString EXPR_DISTANCE
static const QString EXPR_COLOR
static const QString EXPR_WIDTH_BORDER
static const QString EXPR_SVG_FILE
static const QString EXPR_ANGLE
QgsExpressionContext & expressionContext()
Gets the expression context.
double symbologyScaleDenominator() const
Retrieve reference scale for output.
Definition: qgsdxfexport.h:80
static const QString EXPR_DISTANCE_X
static const QString EXPR_REFERENCE1_X
void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size) override
QgsFillSymbolLayerV2(bool locked=false)
SymbolType
Type of the symbol.
Definition: qgssymbolv2.h:76
static const QString EXPR_GRADIENT_TYPE
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:515
const Key key(const T &value) const
void startRender(QgsSymbolV2RenderContext &context) override
static const QString EXPR_OUTLINE_WIDTH
QgsMapUnitScale mapUnitScale() const override
VerticalAnchorPoint
Symbol vertical anchor points.
virtual Qt::BrushStyle dxfBrushStyle() const
get brush/fill style
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props) const override
static const QString EXPR_SVG_FILL_COLOR
QRectF boundingRect() const
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:271
virtual QColor dxfBrushColor(QgsSymbolV2RenderContext &context) const
get brush/fill color
void setMapUnitScale(const QgsMapUnitScale &scale) override
void drawPath(const QPainterPath &path)
QgsLineSymbolLayerV2(bool locked=false)
Struct for storing maximum and minimum scales for measurements in map units.
QgsMapUnitScale mapUnitScale() const override
static const QString EXPR_SVG_OUTLINE_COLOR
static const QString EXPR_NAME
virtual Q_DECL_DEPRECATED const QgsExpression * dataDefinedProperty(const QString &property) const
Returns a data defined expression for a property, if set.
QgsRenderContext & renderContext()
Definition: qgssymbolv2.h:349
virtual QgsDataDefined * getDataDefinedProperty(const QString &property) const
Returns the data defined property corresponding to the specified property key.
void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size) override
static const QString EXPR_IGNORE_RINGS
int height() const
virtual QColor dxfColor(QgsSymbolV2RenderContext &context) const
get color
Fill symbol.
Definition: qgssymbolv2.h:80
static const QString EXPR_COLOR_BORDER
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
static const QString EXPR_REFERENCE1_ISCENTROID
static const QString EXPR_ROTATION
const QgsFields * fields() const
Fields of the layer.
Definition: qgssymbolv2.h:384
QgsSymbolV2::OutputUnit mOffsetUnit
Offset units.
bool isValid() const
iterator insert(const Key &key, const T &value)
virtual double dxfOffset(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const
get offset
bool isEmpty() const
static const QString EXPR_OUTLINE
HorizontalAnchorPoint
Symbol horizontal anchor points.
static const QString EXPR_SVG_OUTLINE_WIDTH
void restoreDataDefinedProperties(const QgsStringMap &stringMap)
Restores all data defined properties from string map.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size) override
static const QString EXPR_SYMBOL_NAME
virtual double dxfWidth(const QgsDxfExport &e, QgsSymbolV2RenderContext &context) const override
get line width
void _renderPolygon(QPainter *p, const QPolygonF &points, const QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
Default method to render polygon.
static bool isGeneralizableByDeviceBoundingBox(const QgsRectangle &envelope, float mapToPixelTol=1.0f)
Returns whether the device-envelope can be replaced by its BBOX when is applied the specified toleran...
int size() const
bool isEmpty() const
Check whether the container is empty.
Definition: qgsfield.cpp:360
int compare(const QString &other) const
static const QString EXPR_MAX_DISTANCE
const QPen & pen() const
static const QString EXPR_LINE_STYLE
void saveDataDefinedProperties(QgsStringMap &stringMap) const
Saves all data defined properties to a string map.
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
QPointF mOffset
Marker offset.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the layer.
bool isActive() const
double angle() const
void setOutputUnit(QgsSymbolV2::OutputUnit unit) override
static const QString EXPR_INTERVAL
iterator find(const Key &key)
void copyDataDefinedProperties(QgsSymbolLayerV2 *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
static const QString EXPR_HEIGHT
const T value(const Key &key) const
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.
virtual Q_DECL_DEPRECATED QVariant evaluateDataDefinedProperty(const QString &property, const QgsFeature *feature, const QVariant &defaultVal=QVariant(), bool *ok=nullptr) const
Evaluates the matching data defined property and returns the calculated value.
static const QString EXPR_HORIZONTAL_ANCHOR_POINT