QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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
24class QgsSymbolLayer;
28
29typedef QList<QgsSymbolLayer *> QgsSymbolLayerList;
30
40{
41 public:
42
52 void setIsAnimated( bool animated ) { mIsAnimated = animated; }
53
63 bool isAnimated() const { return mIsAnimated; }
64
70 void setFrameRate( double rate ) { mFrameRate = rate; }
71
77 double frameRate() const { return mFrameRate; }
78
79 private:
80
81 bool mIsAnimated = false;
82 double mFrameRate = 10;
83
84};
85
92class CORE_EXPORT QgsSymbol
93{
94
95#ifdef SIP_RUN
97 switch ( sipCpp->type() )
98 {
99 case Qgis::SymbolType::Marker: sipType = sipType_QgsMarkerSymbol; break;
100 case Qgis::SymbolType::Line: sipType = sipType_QgsLineSymbol; break;
101 case Qgis::SymbolType::Fill: sipType = sipType_QgsFillSymbol; break;
102 default: sipType = 0; break;
103 }
104 SIP_END
105#endif
106
107 friend class QgsFeatureRenderer;
108
109 public:
110
116 static QString symbolTypeToString( Qgis::SymbolType type );
117
123 static Qgis::SymbolType symbolTypeForGeometryType( QgsWkbTypes::GeometryType type );
124
130 {
132 };
133
138 static const QgsPropertiesDefinition &propertyDefinitions();
139
140 virtual ~QgsSymbol();
141
147 static QgsSymbol *defaultSymbol( QgsWkbTypes::GeometryType geomType ) SIP_FACTORY;
148
152 Qgis::SymbolType type() const { return mType; }
153
154 // symbol layers handling
155
163 QgsSymbolLayerList symbolLayers() { return mLayers; }
164
165#ifndef SIP_RUN
166
173 QgsSymbolLayer *symbolLayer( int layer );
174
181 const QgsSymbolLayer *symbolLayer( int layer ) const;
182#else
183
193 SIP_PYOBJECT symbolLayer( int layer ) SIP_TYPEHINT( QgsSymbolLayer );
194 % MethodCode
195 const int count = sipCpp->symbolLayerCount();
196 if ( a0 < 0 || a0 >= count )
197 {
198 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
199 sipIsErr = 1;
200 }
201 else
202 {
203 sipRes = sipConvertFromType( sipCpp->symbolLayer( a0 ), sipType_QgsSymbolLayer, NULL );
204 }
205 % End
206#endif
207
215 int symbolLayerCount() const { return mLayers.count(); }
216
217#ifdef SIP_RUN
218
222 int __len__() const;
223 % MethodCode
224 sipRes = sipCpp->symbolLayerCount();
225 % End
226
228 int __bool__() const;
229 % MethodCode
230 sipRes = true;
231 % End
232
243 SIP_PYOBJECT __getitem__( int index ) SIP_TYPEHINT( QgsSymbolLayer );
244 % MethodCode
245 const int count = sipCpp->symbolLayerCount();
246 if ( a0 < -count || a0 >= count )
247 {
248 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
249 sipIsErr = 1;
250 }
251 else if ( a0 >= 0 )
252 {
253 return sipConvertFromType( sipCpp->symbolLayer( a0 ), sipType_QgsSymbolLayer, NULL );
254 }
255 else
256 {
257 return sipConvertFromType( sipCpp->symbolLayer( count + a0 ), sipType_QgsSymbolLayer, NULL );
258 }
259 % End
260
271 void __delitem__( int index );
272 % MethodCode
273 const int count = sipCpp->symbolLayerCount();
274 if ( a0 >= 0 && a0 < count )
275 sipCpp->deleteSymbolLayer( a0 );
276 else if ( a0 < 0 && a0 >= -count )
277 sipCpp->deleteSymbolLayer( count + a0 );
278 else
279 {
280 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
281 sipIsErr = 1;
282 }
283 % End
284#endif
285
293 bool insertSymbolLayer( int index, QgsSymbolLayer *layer SIP_TRANSFER );
294
301 bool appendSymbolLayer( QgsSymbolLayer *layer SIP_TRANSFER );
302
306 bool deleteSymbolLayer( int index );
307
314 QgsSymbolLayer *takeSymbolLayer( int index ) SIP_TRANSFERBACK;
315
323 bool changeSymbolLayer( int index, QgsSymbolLayer *layer SIP_TRANSFER );
324
334 void startRender( QgsRenderContext &context, const QgsFields &fields = QgsFields() );
335
342 void stopRender( QgsRenderContext &context );
343
354 void setColor( const QColor &color ) const;
355
364 QColor color() const;
365
383 void drawPreviewIcon( QPainter *painter, QSize size, QgsRenderContext *customContext = nullptr, bool selected = false, const QgsExpressionContext *expressionContext = nullptr,
384 const QgsLegendPatchShape *patchShape = nullptr );
385
395 void exportImage( const QString &path, const QString &format, QSize size );
396
406 QImage asImage( QSize size, QgsRenderContext *customContext = nullptr );
407
418 QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = nullptr, Qgis::SymbolPreviewFlags flags = Qgis::SymbolPreviewFlag::FlagIncludeCrosshairsForMarkerSymbols ) SIP_PYNAME( bigSymbolPreviewImageV2 );
419
423 Q_DECL_DEPRECATED QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = nullptr, int flags = static_cast< int >( Qgis::SymbolPreviewFlag::FlagIncludeCrosshairsForMarkerSymbols ) ) SIP_DEPRECATED;
424
428 QString dump() const;
429
435 virtual QgsSymbol *clone() const = 0 SIP_FACTORY;
436
440 void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props ) const;
441
450 QgsUnitTypes::RenderUnit outputUnit() const;
451
457 bool usesMapUnits() const;
458
467 void setOutputUnit( QgsUnitTypes::RenderUnit unit ) const;
468
478 QgsMapUnitScale mapUnitScale() const;
479
488 void setMapUnitScale( const QgsMapUnitScale &scale ) const;
489
495 qreal opacity() const { return mOpacity; }
496
502 void setOpacity( qreal opacity ) { mOpacity = opacity; }
503
508 void setRenderHints( Qgis::SymbolRenderHints hints ) { mRenderHints = hints; }
509
514 Qgis::SymbolRenderHints renderHints() const { return mRenderHints; }
515
522 void setFlags( Qgis::SymbolFlags flags ) { mSymbolFlags = flags; }
523
530 Qgis::SymbolFlags flags() const { return mSymbolFlags; }
531
541 void setClipFeaturesToExtent( bool clipFeaturesToExtent ) { mClipFeaturesToExtent = clipFeaturesToExtent; }
542
552 bool clipFeaturesToExtent() const { return mClipFeaturesToExtent; }
553
563 void setForceRHR( bool force ) { mForceRHR = force; }
564
574 bool forceRHR() const { return mForceRHR; }
575
582 QgsSymbolAnimationSettings &animationSettings();
583
590 const QgsSymbolAnimationSettings &animationSettings() const SIP_SKIP;
591
598 void setAnimationSettings( const QgsSymbolAnimationSettings &settings );
599
605 QSet<QString> usedAttributes( const QgsRenderContext &context ) const;
606
614 void setDataDefinedProperty( Property key, const QgsProperty &property );
615
622 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
623
629 const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
630
637 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
638
643 bool hasDataDefinedProperties() const;
644
654 bool canCauseArtifactsBetweenAdjacentTiles() const;
655
660 Q_DECL_DEPRECATED void setLayer( const QgsVectorLayer *layer ) SIP_DEPRECATED;
661
665 Q_DECL_DEPRECATED const QgsVectorLayer *layer() const SIP_DEPRECATED;
666
671 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 );
672
678 QgsSymbolRenderContext *symbolRenderContext();
679
691 void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context, int layer = -1 );
692
704 void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context, int layer = -1 );
705
706 protected:
707
713 QgsSymbol( Qgis::SymbolType type, const QgsSymbolLayerList &layers SIP_TRANSFER ); // can't be instantiated
714
718 static inline QPointF _getPoint( QgsRenderContext &context, const QgsPoint &point )
719 {
720 QPointF pt;
721 if ( context.coordinateTransform().isValid() )
722 {
723 double x = point.x();
724 double y = point.y();
725 double z = 0.0;
726 context.coordinateTransform().transformInPlace( x, y, z );
727 pt = QPointF( x, y );
728
729 }
730 else
731 pt = point.toQPointF();
732
733 context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );
734 return pt;
735 }
736
740 static QPolygonF _getLineString( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent = true );
741
748 static QPolygonF _getPolygonRing( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing = false, bool correctRingOrientation = false );
749
757 static void _getPolygon( QPolygonF &pts, QVector<QPolygonF> &holes, QgsRenderContext &context, const QgsPolygon &polygon, bool clipToExtent = true, bool correctRingOrientation = false );
758
763 QgsSymbolLayerList cloneLayers() const SIP_FACTORY;
764
777 void renderUsingLayer( QgsSymbolLayer *layer, QgsSymbolRenderContext &context, QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::GeometryType::UnknownGeometry, const QPolygonF *points = nullptr, const QVector<QPolygonF> *rings = nullptr );
778
783 void renderVertexMarker( QPointF pt, QgsRenderContext &context, Qgis::VertexMarkerType currentVertexMarkerType, double currentVertexMarkerSize );
784
785 Qgis::SymbolType mType;
787
789 qreal mOpacity = 1.0;
790
791 Qgis::SymbolRenderHints mRenderHints;
792
798 Qgis::SymbolFlags mSymbolFlags = Qgis::SymbolFlags();
799
800 bool mClipFeaturesToExtent = true;
801 bool mForceRHR = false;
802
803 QgsSymbolAnimationSettings mAnimationSettings;
804
805 Q_DECL_DEPRECATED const QgsVectorLayer *mLayer = nullptr; //current vectorlayer
806
807 private:
808#ifdef SIP_RUN
809 QgsSymbol( const QgsSymbol & );
810#endif
811
812 static void initPropertyDefinitions();
813
815 static QgsPropertiesDefinition sPropertyDefinitions;
816
821 bool mStarted = false;
822
824 std::unique_ptr< QgsSymbolRenderContext > mSymbolRenderContext;
825
826 QgsPropertyCollection mDataDefinedProperties;
827
831 static QPolygonF _getLineString2d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent = true );
832
836 static QPolygonF _getLineString3d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent = true );
837
844 static QPolygonF _getPolygonRing2d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing = false, bool correctRingOrientation = false );
845
852 static QPolygonF _getPolygonRing3d( QgsRenderContext &context, const QgsCurve &curve, bool clipToExtent, bool isExteriorRing = false, bool correctRingOrientation = false );
853
854 Q_DISABLE_COPY( QgsSymbol )
855
856};
857
858#endif
859
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:72
@ FlagIncludeCrosshairsForMarkerSymbols
Include a crosshairs reference image in the background of marker symbol previews.
SymbolType
Symbol types.
Definition: qgis.h:206
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a wkb string in map coordinates.
Definition: qgsrenderer.cpp:47
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
virtual void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrenderer.h:326
QString type() const
Definition: qgsrenderer.h:142
virtual QString dump() const
Returns debug information about this renderer.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
void renderVertexMarker(QPointF pt, QgsRenderContext &context)
render editing vertex marker at specified point
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:96
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Container of fields for a vector layer.
Definition: qgsfields.h:45
Represents a patch shape for use in map legends.
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:34
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A store for object properties.
Definition: qgsproperty.h:231
Contains information about the context of a rendering operation.
Contains settings relating to symbol animation.
Definition: qgssymbol.h:40
bool isAnimated() const
Returns true if the symbol is animated.
Definition: qgssymbol.h:63
void setIsAnimated(bool animated)
Sets whether the symbol is animated.
Definition: qgssymbol.h:52
void setFrameRate(double rate)
Sets the symbol animation frame rate (in frames per second).
Definition: qgssymbol.h:70
double frameRate() const
Returns the symbol animation frame rate (in frames per second).
Definition: qgssymbol.h:77
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the symbol's property collection, used for data defined overrides.
Definition: qgssymbol.h:637
void setRenderHints(Qgis::SymbolRenderHints hints)
Sets rendering hint flags for the symbol.
Definition: qgssymbol.h:508
Qgis::SymbolRenderHints renderHints() const
Returns the rendering hint flags for the symbol.
Definition: qgssymbol.h:514
Property
Data definable properties.
Definition: qgssymbol.h:130
@ PropertyOpacity
Opacity.
Definition: qgssymbol.h:131
Qgis::SymbolFlags flags() const
Returns flags for the symbol.
Definition: qgssymbol.h:530
qreal opacity() const
Returns the opacity for the symbol.
Definition: qgssymbol.h:495
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
Definition: qgssymbol.h:552
void setFlags(Qgis::SymbolFlags flags)
Sets flags for the symbol.
Definition: qgssymbol.h:522
QgsSymbolLayerList symbolLayers()
Returns the list of symbol layers contained in the symbol.
Definition: qgssymbol.h:163
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition: qgssymbol.h:502
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:215
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:152
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition: qgssymbol.h:629
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
Definition: qgssymbol.h:574
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
Definition: qgssymbol.h:541
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Definition: qgssymbol.h:563
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
Represents a vector layer which manages a vector based data sets.
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:42
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_THROW(name)
Definition: qgis_sip.h:198
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:227
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#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_END
Definition: qgis_sip.h:203
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition: qgssymbol.h:29