1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************
qgsellipsesymbollayer.h
---------------------
begin : June 2011
copyright : (C) 2011 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSELLIPSESYMBOLLAYER_H
#define QGSELLIPSESYMBOLLAYER_H
#define DEFAULT_ELLIPSE_JOINSTYLE Qt::MiterJoin
#include "qgis_core.h"
#include "qgis.h"
#include "qgsmarkersymbollayer.h"
#include <QPainterPath>
class QgsExpression;
/**
* \ingroup core
* A symbol layer for rendering objects with major and minor axis (e.g. ellipse, rectangle )*/
class CORE_EXPORT QgsEllipseSymbolLayer: public QgsMarkerSymbolLayer
{
public:
QgsEllipseSymbolLayer();
static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) SIP_FACTORY;
static QgsSymbolLayer *createFromSld( QDomElement &element ) SIP_FACTORY;
void renderPoint( QPointF point, QgsSymbolRenderContext &context ) override;
QString layerType() const override;
void startRender( QgsSymbolRenderContext &context ) override;
void stopRender( QgsSymbolRenderContext &context ) override;
QgsEllipseSymbolLayer *clone() const override SIP_FACTORY;
QgsStringMap properties() const override;
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const override;
bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
void setSymbolName( const QString &name ) { mSymbolName = name; }
QString symbolName() const { return mSymbolName; }
void setSize( double size ) override;
void setSymbolWidth( double w );
double symbolWidth() const { return mSymbolWidth; }
void setSymbolHeight( double h );
double symbolHeight() const { return mSymbolHeight; }
Qt::PenStyle strokeStyle() const { return mStrokeStyle; }
void setStrokeStyle( Qt::PenStyle strokeStyle ) { mStrokeStyle = strokeStyle; }
/**
* Gets stroke join style.
* \since QGIS 2.16 */
Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
/**
* Set stroke join style.
* \since QGIS 2.16 */
void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
void setStrokeWidth( double w ) { mStrokeWidth = w; }
double strokeWidth() const { return mStrokeWidth; }
void setFillColor( const QColor &c ) override { setColor( c ); }
QColor fillColor() const override { return color(); }
void setStrokeColor( const QColor &c ) override { mStrokeColor = c; }
QColor strokeColor() const override { return mStrokeColor; }
/**
* Sets the units for the symbol's width.
* \param unit symbol units
* \see symbolWidthUnit()
* \see setSymbolHeightUnit()
*/
void setSymbolWidthUnit( QgsUnitTypes::RenderUnit unit ) { mSymbolWidthUnit = unit; }
/**
* Returns the units for the symbol's width.
* \see setSymbolWidthUnit()
* \see symbolHeightUnit()
*/
QgsUnitTypes::RenderUnit symbolWidthUnit() const { return mSymbolWidthUnit; }
void setSymbolWidthMapUnitScale( const QgsMapUnitScale &scale ) { mSymbolWidthMapUnitScale = scale; }
const QgsMapUnitScale &symbolWidthMapUnitScale() const { return mSymbolWidthMapUnitScale; }
/**
* Sets the units for the symbol's height.
* \param unit symbol units
* \see symbolHeightUnit()
* \see setSymbolWidthUnit()
*/
void setSymbolHeightUnit( QgsUnitTypes::RenderUnit unit ) { mSymbolHeightUnit = unit; }
/**
* Returns the units for the symbol's height.
* \see setSymbolHeightUnit()
* \see symbolWidthUnit()
*/
QgsUnitTypes::RenderUnit symbolHeightUnit() const { return mSymbolHeightUnit; }
void setSymbolHeightMapUnitScale( const QgsMapUnitScale &scale ) { mSymbolHeightMapUnitScale = scale; }
const QgsMapUnitScale &symbolHeightMapUnitScale() const { return mSymbolHeightMapUnitScale; }
/**
* Sets the units for the symbol's stroke width.
* \param unit symbol units
* \see strokeWidthUnit()
*/
void setStrokeWidthUnit( QgsUnitTypes::RenderUnit unit ) { mStrokeWidthUnit = unit; }
/**
* Returns the units for the symbol's stroke width.
* \see setStrokeWidthUnit()
*/
QgsUnitTypes::RenderUnit strokeWidthUnit() const { return mStrokeWidthUnit; }
void setStrokeWidthMapUnitScale( const QgsMapUnitScale &scale ) { mStrokeWidthMapUnitScale = scale; }
const QgsMapUnitScale &strokeWidthMapUnitScale() const { return mStrokeWidthMapUnitScale; }
void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
QgsUnitTypes::RenderUnit outputUnit() const override;
void setMapUnitScale( const QgsMapUnitScale &scale ) override;
QgsMapUnitScale mapUnitScale() const override;
QRectF bounds( QPointF point, QgsSymbolRenderContext &context ) override;
private:
QString mSymbolName;
double mSymbolWidth = 4;
QgsUnitTypes::RenderUnit mSymbolWidthUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mSymbolWidthMapUnitScale;
double mSymbolHeight = 3;
QgsUnitTypes::RenderUnit mSymbolHeightUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mSymbolHeightMapUnitScale;
QColor mStrokeColor;
Qt::PenStyle mStrokeStyle = Qt::SolidLine;
Qt::PenJoinStyle mPenJoinStyle = DEFAULT_ELLIPSE_JOINSTYLE;
double mStrokeWidth = 0;
QgsUnitTypes::RenderUnit mStrokeWidthUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mStrokeWidthMapUnitScale;
QPainterPath mPainterPath;
QPen mPen;
QBrush mBrush;
/**
* Setup mPainterPath
\param symbolName name of symbol
\param context render context
\param scaledWidth optional width
\param scaledHeight optional height
\param f optional feature to render (0 if no data defined rendering)
*/
void preparePath( const QString &symbolName, QgsSymbolRenderContext &context, double *scaledWidth = nullptr, double *scaledHeight = nullptr, const QgsFeature *f = nullptr );
QSizeF calculateSize( QgsSymbolRenderContext &context, double *scaledWidth = nullptr, double *scaledHeight = nullptr );
void calculateOffsetAndRotation( QgsSymbolRenderContext &context, double scaledWidth, double scaledHeight, bool &hasDataDefinedRotation, QPointF &offset, double &angle ) const;
};
// clazy:excludeall=qstring-allocations
#endif // QGSELLIPSESYMBOLLAYER_H