QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
qgssymbol.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbol.h
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#ifndef QGSSYMBOL_H
17#define QGSSYMBOL_H
18
19#include "qgis_core.h"
20#include "qgis.h"
22#include "qgsrendercontext.h"
23#include "qgsscreenproperties.h"
24
25class QgsSymbolLayer;
29
30typedef QList<QgsSymbolLayer *> QgsSymbolLayerList;
31
41{
42 public:
43
53 void setIsAnimated( bool animated ) { mIsAnimated = animated; }
54
64 bool isAnimated() const { return mIsAnimated; }
65
71 void setFrameRate( double rate ) { mFrameRate = rate; }
72
78 double frameRate() const { return mFrameRate; }
79
80 private:
81
82 bool mIsAnimated = false;
83 double mFrameRate = 10;
84
85};
86
87
96class CORE_EXPORT QgsSymbolBufferSettings
97{
98 public:
99
102
105
110 bool enabled() const { return mEnabled; }
111
116 void setEnabled( bool enabled ) { mEnabled = enabled; }
117
123 double size() const { return mSize; }
124
133 void setSize( double size ) { mSize = size; }
134
141 Qgis::RenderUnit sizeUnit() const { return mSizeUnit; }
142
149 void setSizeUnit( Qgis::RenderUnit unit ) { mSizeUnit = unit; }
150
158 QgsMapUnitScale sizeMapUnitScale() const { return mSizeMapUnitScale; }
159
168 void setSizeMapUnitScale( const QgsMapUnitScale &scale ) { mSizeMapUnitScale = scale; }
169
174 Qt::PenJoinStyle joinStyle() const { return mJoinStyle; }
175
180 void setJoinStyle( Qt::PenJoinStyle style ) { mJoinStyle = style; }
181
189 QgsFillSymbol *fillSymbol() const;
190
197 void setFillSymbol( QgsFillSymbol *symbol SIP_TRANSFER );
198
199
205 void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const;
206
212 void readXml( const QDomElement &element, const QgsReadWriteContext &context );
213
214 private:
215 bool mEnabled = false;
216 double mSize = 1;
218 QgsMapUnitScale mSizeMapUnitScale;
219 Qt::PenJoinStyle mJoinStyle = Qt::RoundJoin;
220 std::unique_ptr< QgsFillSymbol > mFillSymbol;
221};
222
223
230class CORE_EXPORT QgsSymbol
231{
232
233#ifdef SIP_RUN
235 switch ( sipCpp->type() )
236 {
237 case Qgis::SymbolType::Marker: sipType = sipType_QgsMarkerSymbol; break;
238 case Qgis::SymbolType::Line: sipType = sipType_QgsLineSymbol; break;
239 case Qgis::SymbolType::Fill: sipType = sipType_QgsFillSymbol; break;
240 default: sipType = 0; break;
241 }
242 SIP_END
243#endif
244
245 friend class QgsFeatureRenderer;
246
247 public:
248
254 static QString symbolTypeToString( Qgis::SymbolType type );
255
261 static Qgis::SymbolType symbolTypeForGeometryType( Qgis::GeometryType type );
262
263 // *INDENT-OFF*
264
270 {
271 Opacity SIP_MONKEYPATCH_COMPAT_NAME( PropertyOpacity ),
272 };
273 // *INDENT-ON*
274
279 static const QgsPropertiesDefinition &propertyDefinitions();
280
281 virtual ~QgsSymbol();
282
288 static QgsSymbol *defaultSymbol( Qgis::GeometryType geomType ) SIP_FACTORY;
289
293 Qgis::SymbolType type() const { return mType; }
294
295 // symbol layers handling
296
303 QgsSymbolLayerList symbolLayers() const { return mLayers; }
304
305#ifndef SIP_RUN
306
312 QgsSymbolLayer *symbolLayer( int layer );
313
320 const QgsSymbolLayer *symbolLayer( int layer ) const;
321#else
322
331 SIP_PYOBJECT symbolLayer( int layer ) SIP_TYPEHINT( QgsSymbolLayer );
332 % MethodCode
333 const int count = sipCpp->symbolLayerCount();
334 if ( a0 < 0 || a0 >= count )
335 {
336 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
337 sipIsErr = 1;
338 }
339 else
340 {
341 sipRes = sipConvertFromType( sipCpp->symbolLayer( a0 ), sipType_QgsSymbolLayer, NULL );
342 }
343 % End
344#endif
345
352 int symbolLayerCount() const { return mLayers.count(); }
353
354#ifdef SIP_RUN
355
359 int __len__() const;
360 % MethodCode
361 sipRes = sipCpp->symbolLayerCount();
362 % End
363
365 int __bool__() const;
366 % MethodCode
367 sipRes = true;
368 % End
369
380 SIP_PYOBJECT __getitem__( int index ) SIP_TYPEHINT( QgsSymbolLayer );
381 % MethodCode
382 const int count = sipCpp->symbolLayerCount();
383 if ( a0 < -count || a0 >= count )
384 {
385 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
386 sipIsErr = 1;
387 }
388 else if ( a0 >= 0 )
389 {
390 return sipConvertFromType( sipCpp->symbolLayer( a0 ), sipType_QgsSymbolLayer, NULL );
391 }
392 else
393 {
394 return sipConvertFromType( sipCpp->symbolLayer( count + a0 ), sipType_QgsSymbolLayer, NULL );
395 }
396 % End
397
408 void __delitem__( int index );
409 % MethodCode
410 const int count = sipCpp->symbolLayerCount();
411 if ( a0 >= 0 && a0 < count )
412 sipCpp->deleteSymbolLayer( a0 );
413 else if ( a0 < 0 && a0 >= -count )
414 sipCpp->deleteSymbolLayer( count + a0 );
415 else
416 {
417 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
418 sipIsErr = 1;
419 }
420 % End
421#endif
422
430 bool insertSymbolLayer( int index, QgsSymbolLayer *layer SIP_TRANSFER );
431
438 bool appendSymbolLayer( QgsSymbolLayer *layer SIP_TRANSFER );
439
443 bool deleteSymbolLayer( int index );
444
451 QgsSymbolLayer *takeSymbolLayer( int index ) SIP_TRANSFERBACK;
452
460 bool changeSymbolLayer( int index, QgsSymbolLayer *layer SIP_TRANSFER );
461
471 void startRender( QgsRenderContext &context, const QgsFields &fields = QgsFields() );
472
479 void stopRender( QgsRenderContext &context );
480
491 void setColor( const QColor &color ) const;
492
501 QColor color() const;
502
519 void drawPreviewIcon( QPainter *painter, QSize size, QgsRenderContext *customContext = nullptr, bool selected = false, const QgsExpressionContext *expressionContext = nullptr,
520 const QgsLegendPatchShape *patchShape = nullptr, const QgsScreenProperties &screen = QgsScreenProperties() );
521
531 void exportImage( const QString &path, const QString &format, QSize size );
532
542 QImage asImage( QSize size, QgsRenderContext *customContext = nullptr );
543
555 QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = nullptr, Qgis::SymbolPreviewFlags flags = Qgis::SymbolPreviewFlag::FlagIncludeCrosshairsForMarkerSymbols, const QgsScreenProperties &screen = QgsScreenProperties() ) SIP_PYNAME( bigSymbolPreviewImageV2 );
556
560 Q_DECL_DEPRECATED QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = nullptr, int flags = static_cast< int >( Qgis::SymbolPreviewFlag::FlagIncludeCrosshairsForMarkerSymbols ) ) SIP_DEPRECATED;
561
565 QString dump() const;
566
572 virtual QgsSymbol *clone() const = 0 SIP_FACTORY;
573
577 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props ) const;
578
587 Qgis::RenderUnit outputUnit() const;
588
594 bool usesMapUnits() const;
595
604 void setOutputUnit( Qgis::RenderUnit unit ) const;
605
615 QgsMapUnitScale mapUnitScale() const;
616
625 void setMapUnitScale( const QgsMapUnitScale &scale ) const;
626
632 qreal opacity() const { return mOpacity; }
633
639 void setOpacity( qreal opacity ) { mOpacity = opacity; }
640
645 void setRenderHints( Qgis::SymbolRenderHints hints ) { mRenderHints = hints; }
646
651 Qgis::SymbolRenderHints renderHints() const;
652
659 void setFlags( Qgis::SymbolFlags flags ) { mSymbolFlags = flags; }
660
667 Qgis::SymbolFlags flags() const;
668
677 void setClipFeaturesToExtent( bool clipFeaturesToExtent ) { mClipFeaturesToExtent = clipFeaturesToExtent; }
678
687 bool clipFeaturesToExtent() const { return mClipFeaturesToExtent; }
688
698 void setForceRHR( bool force ) { mForceRHR = force; }
699
709 bool forceRHR() const { return mForceRHR; }
710
719 QgsSymbolBufferSettings *bufferSettings();
720
729 const QgsSymbolBufferSettings *bufferSettings() const SIP_SKIP;
730
739 void setBufferSettings( QgsSymbolBufferSettings *settings SIP_TRANSFER );
740
747 QgsSymbolAnimationSettings &animationSettings();
748
755 const QgsSymbolAnimationSettings &animationSettings() const SIP_SKIP;
756
763 void setAnimationSettings( const QgsSymbolAnimationSettings &settings );
764
770 QSet<QString> usedAttributes( const QgsRenderContext &context ) const;
771
779 void setDataDefinedProperty( Property key, const QgsProperty &property );
780
787 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
788
794 const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
795
802 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
803
807 bool hasDataDefinedProperties() const;
808
818 bool canCauseArtifactsBetweenAdjacentTiles() const;
819
824 Q_DECL_DEPRECATED void setLayer( const QgsVectorLayer *layer ) SIP_DEPRECATED;
825
829 Q_DECL_DEPRECATED const QgsVectorLayer *layer() const SIP_DEPRECATED;
830
835 void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, Qgis::VertexMarkerType currentVertexMarkerType = Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize = 0.0 ) SIP_THROW( QgsCsException );
836
842 QgsSymbolRenderContext *symbolRenderContext();
843
855 void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context, int layer = -1 );
856
868 void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context, int layer = -1 );
869
870 protected:
871
877 QgsSymbol( Qgis::SymbolType type, const QgsSymbolLayerList &layers SIP_TRANSFER ); // can't be instantiated
878
882 static inline QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point )
883 {
884 QPointF pt;
885 if ( context.coordinateTransform().isValid() )
886 {
887 double x = point.x();
888 double y = point.y();
889 double z = 0.0;
890 context.coordinateTransform().transformInPlace( x, y, z );
891 pt = QPointF( x, y );
892
893 }
894 else
895 pt = point.toQPointF();
896
897 context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
898 return pt;
899 }
900
904 static QPolygonF _getLineString( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent = true );
905
912 static QPolygonF _getPolygonRing( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing = false, bool correctRingOrientation = false );
913
921 static void _getPolygon( QPolygonF &pts, QVector<QPolygonF> &holes, QgsRenderContext &context, const QgsPolygon &polygon, bool clipToExtent = true, bool correctRingOrientation = false );
922
927 QgsSymbolLayerList cloneLayers() const SIP_FACTORY;
928
934 void copyCommonProperties( const QgsSymbol *other );
935
948 void renderUsingLayer( QgsSymbolLayer *layer, QgsSymbolRenderContext &context, Qgis::GeometryType geometryType = Qgis::GeometryType::Unknown, const QPolygonF *points = nullptr, const QVector<QPolygonF> *rings = nullptr );
949
953 void renderVertexMarker( QPointF pt, QgsRenderContext &context, Qgis::VertexMarkerType currentVertexMarkerType, double currentVertexMarkerSize );
954
955 Qgis::SymbolType mType;
957
959 qreal mOpacity = 1.0;
960
961 Qgis::SymbolRenderHints mRenderHints;
962
968 Qgis::SymbolFlags mSymbolFlags = Qgis::SymbolFlags();
969
970 bool mClipFeaturesToExtent = true;
971 bool mForceRHR = false;
972
973 std::unique_ptr< QgsSymbolBufferSettings > mBufferSettings;
974 QgsSymbolAnimationSettings mAnimationSettings;
975
976 Q_DECL_DEPRECATED const QgsVectorLayer *mLayer = nullptr; //current vectorlayer
977
978 private:
979#ifdef SIP_RUN
980 QgsSymbol( const QgsSymbol & );
981#endif
982
983 static void initPropertyDefinitions();
984
986 static QgsPropertiesDefinition sPropertyDefinitions;
987
992 bool mStarted = false;
993
995 std::unique_ptr< QgsSymbolRenderContext > mSymbolRenderContext;
996
997 QgsPropertyCollection mDataDefinedProperties;
998
1002 static QPolygonF _getLineString2d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent = true );
1003
1007 static QPolygonF _getLineString3d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent = true );
1008
1015 static QPolygonF _getPolygonRing2d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing = false, bool correctRingOrientation = false );
1016
1023 static QPolygonF _getPolygonRing3d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing = false, bool correctRingOrientation = false );
1024
1025 Q_DISABLE_COPY( QgsSymbol )
1026
1027};
1028
1029#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< SymbolPreviewFlag > SymbolPreviewFlags
Symbol preview flags.
Definition qgis.h:801
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
RenderUnit
Rendering size units.
Definition qgis.h:4795
@ Millimeters
Millimeters.
@ FlagIncludeCrosshairsForMarkerSymbols
Include a crosshairs reference image in the background of marker symbol previews.
QFlags< SymbolRenderHint > SymbolRenderHints
Symbol render hints.
Definition qgis.h:741
QFlags< SymbolFlag > SymbolFlags
Symbol flags.
Definition qgis.h:787
SymbolType
Symbol types.
Definition qgis.h:574
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Definition qgscurve.h:35
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all 2D vector feature renderers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Container of fields for a vector layer.
Definition qgsfields.h:46
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Represents a patch shape for use in map legends.
Abstract base class for line symbol layers.
Struct for storing maximum and minimum scales for measurements in map units.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A store for object properties.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
Stores properties relating to a screen.
Contains settings relating to symbol animation.
Definition qgssymbol.h:41
bool isAnimated() const
Returns true if the symbol is animated.
Definition qgssymbol.h:64
void setIsAnimated(bool animated)
Sets whether the symbol is animated.
Definition qgssymbol.h:53
void setFrameRate(double rate)
Sets the symbol animation frame rate (in frames per second).
Definition qgssymbol.h:71
double frameRate() const
Returns the symbol animation frame rate (in frames per second).
Definition qgssymbol.h:78
Contains settings relating to symbol buffers, which draw a "halo" effect around the symbol.
Definition qgssymbol.h:97
void setEnabled(bool enabled)
Sets whether the symbol buffer will be drawn.
Definition qgssymbol.h:116
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the buffer size.
Definition qgssymbol.h:168
bool enabled() const
Returns whether the buffer is enabled.
Definition qgssymbol.h:110
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
Definition qgssymbol.h:158
void setSize(double size)
Sets the size of the buffer.
Definition qgssymbol.h:133
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
Definition qgssymbol.h:180
void setSizeUnit(Qgis::RenderUnit unit)
Sets the unit used for the buffer size.
Definition qgssymbol.h:149
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
Definition qgssymbol.h:174
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
Definition qgssymbol.h:141
double size() const
Returns the size of the buffer.
Definition qgssymbol.h:123
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the symbol's property collection, used for data defined overrides.
Definition qgssymbol.h:802
Property
Data definable properties.
Definition qgssymbol.h:270
void setRenderHints(Qgis::SymbolRenderHints hints)
Sets rendering hint flags for the symbol.
Definition qgssymbol.h:645
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
Definition qgssymbol.h:687
void setFlags(Qgis::SymbolFlags flags)
Sets flags for the symbol.
Definition qgssymbol.h:659
QgsSymbolLayerList symbolLayers() const
Returns the list of symbol layers contained in the symbol.
Definition qgssymbol.h:303
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition qgssymbol.h:639
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition qgssymbol.h:352
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:293
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition qgssymbol.h:794
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
Definition qgssymbol.h:709
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
Definition qgssymbol.h:677
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Definition qgssymbol.h:698
Represents a vector layer which manages a vector based data sets.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:232
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
#define SIP_END
Definition qgis_sip.h:208
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition qgssymbol.h:30