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