QGIS API Documentation 3.43.0-Master (b60ef06885e)
qgsinterpolatedlinerenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsinterpolatedlinerenderer.h
3 --------------------------------------
4 Date : April 2020
5 Copyright : (C) 2020 by Vincent Cloarec
6 Email : vcloarec 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 QGSINTERPOLATEDLINERENDERER_H
17#define QGSINTERPOLATEDLINERENDERER_H
18
19#include <QDebug>
20
21#include "qgis.h"
22#include "qgscolorrampshader.h"
23#include "qgsreadwritecontext.h"
24#include "qgssymbollayer.h"
25
28
38class CORE_EXPORT QgsInterpolatedLineColor
39{
40 public:
41
46 {
48 SingleColor = 0,
50 ColorRamp
51 };
52
56 QgsInterpolatedLineColor( const QgsColorRampShader &colorRampShader );
58 QgsInterpolatedLineColor( const QColor &color );
59
61 void setColor( const QgsColorRampShader &colorRampShader );
62
64 void setColor( const QColor &color );
65
67 QColor color( double magnitude ) const;
68
73 void setColoringMethod( ColoringMethod coloringMethod );
74
76 QgsInterpolatedLineColor::ColoringMethod coloringMethod() const;
77
79 QgsColorRampShader colorRampShader() const;
80
85 QColor singleColor() const;
86
88 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
90 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
91
101 void graduatedColors( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
102
103 private:
104 QgsColorRampShader mColorRampShader;
105 QColor mSingleColor = Qt::black;
106
107 QgsInterpolatedLineColor::ColoringMethod mColoringMethod = SingleColor;
108
109 QLinearGradient makeSimpleLinearGradient( const QColor &color1, const QColor &color2 ) const;
110
112 int itemColorIndexInf( double value ) const;
113
114 void graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, const QList<QLinearGradient> &gradients ) const;
115 void graduatedColorsInterpolated( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
116 void graduatedColorsDiscrete( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
117};
118
127{
128 public:
130 double minimumValue() const;
132 void setMinimumValue( double minimumValue );
133
135 double maximumValue() const;
137 void setMaximumValue( double maximumValue );
138
140 double minimumWidth() const;
142 void setMinimumWidth( double minimumWidth );
143
145 double maximumWidth() const;
147 void setMaximumWidth( double maximumWidth );
148
150 bool ignoreOutOfRange() const;
152 void setIgnoreOutOfRange( bool ignoreOutOfRange );
153
155 bool useAbsoluteValue() const;
157 void setUseAbsoluteValue( bool useAbsoluteValue );
158
160 bool isVariableWidth() const;
162 void setIsVariableWidth( bool isVariableWidth );
163
165 double fixedStrokeWidth() const;
167 void setFixedStrokeWidth( double fixedWidth );
168
170 double strokeWidth( double value ) const;
171
173 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
175 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
176
177 private:
178 bool mIsWidthVariable = false;
179
180 double mFixedWidth = Qgis::DEFAULT_LINE_WIDTH;
181
182 double mMinimumValue = 0;
183 double mMaximumValue = 10;
184 double mMinimumWidth = Qgis::DEFAULT_LINE_WIDTH;
185 double mMaximumWidth = 3;
186 bool mIgnoreOutOfRange = false;
187 bool mUseAbsoluteValue = false;
188
189 mutable double mLinearCoef = 1;
190 mutable bool mNeedUpdateFormula = true;
191 void updateLinearFormula() const;
192};
193
201{
202 public:
203
205 void setInterpolatedWidth( const QgsInterpolatedLineWidth &strokeWidth );
206
211 QgsInterpolatedLineWidth interpolatedLineWidth() const;
212
214 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit );
215
220 Qgis::RenderUnit widthUnit() const;
221
223 void setInterpolatedColor( const QgsInterpolatedLineColor &strokeColoring );
224
229 QgsInterpolatedLineColor interpolatedColor() const;
230
238 void render( double value1, double value2, const QgsPointXY &point1, const QgsPointXY &point2, QgsRenderContext &context ) const;
239
249 void render( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, const QgsPointXY &point1, const QgsPointXY &point2, QgsRenderContext &context ) const;
250
257 void renderInDeviceCoordinates( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, QPointF point1, QPointF point2, QgsRenderContext &context ) const;
258
264 void setSelected( bool selected );
265
266 private:
267
268 QgsInterpolatedLineWidth mStrokeWidth;
269 QgsInterpolatedLineColor mStrokeColoring;
271 void adjustLine( double value, double value1, double value2, double &width, double &adjusting ) const;
272 bool mSelected = false;
273
274
276};
277
287{
288 public:
289
291
293 static QgsSymbolLayer *create( const QVariantMap &properties ) SIP_FACTORY;
294
295 Qgis::SymbolLayerFlags flags() const override;
296 QString layerType() const override;
297 void startRender( QgsSymbolRenderContext &context ) override;
298 void stopRender( QgsSymbolRenderContext &context ) override;
299 QgsInterpolatedLineSymbolLayer *clone() const override SIP_FACTORY;
300 QVariantMap properties() const override;
301 void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
302 QColor color() const override;
303
304 void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
305 void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
306 void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
307 bool canCauseArtifactsBetweenAdjacentTiles() const override;
308
314 Q_DECL_DEPRECATED void setExpressionsStringForWidth( const QString &start, const QString &end ) SIP_DEPRECATED;
315
321 Q_DECL_DEPRECATED QString startValueExpressionForWidth() const SIP_DEPRECATED;
322
328 Q_DECL_DEPRECATED QString endValueExpressionForWidth() const SIP_DEPRECATED;
329
330 // TODO QGIS 4.0 -- rename to avoid collision with base class methods
331
337 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit ); // cppcheck-suppress duplInheritedMember
338
344 Qgis::RenderUnit widthUnit() const; // cppcheck-suppress duplInheritedMember
345
351 void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
352
358 QgsInterpolatedLineWidth interpolatedWidth() const;
359
365 Q_DECL_DEPRECATED void setExpressionsStringForColor( const QString &start, const QString &end ) SIP_DEPRECATED;
366
372 Q_DECL_DEPRECATED QString startValueExpressionForColor() const SIP_DEPRECATED;
373
379 Q_DECL_DEPRECATED QString endValueExpressionForColor() const SIP_DEPRECATED;
380
386 void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
387
393 QgsInterpolatedLineColor interpolatedColor() const;
394
395 private:
396#ifdef SIP_RUN
398#endif
399
400 QgsInterpolatedLineRenderer mLineRender;
401
402 QVector< QPolygonF > mLineParts;
403 bool mRenderingFeature = false;
404
405 void render( const QVector< QPolygonF > &parts, QgsRenderContext &context );
406
407 QVariant colorRampShaderProperties() const;
408 static QgsColorRampShader createColorRampShaderFromProperties( const QVariant &properties );
409};
410
411
412#endif // QGSINTERPOLATEDLINERENDERER_H
static const double DEFAULT_LINE_WIDTH
The default width (in millimeters) for line symbols.
Definition qgis.h:5953
QFlags< SymbolLayerFlag > SymbolLayerFlags
Symbol layer flags.
Definition qgis.h:851
RenderUnit
Rendering size units.
Definition qgis.h:5013
@ Millimeters
Millimeters.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Defines color interpolation for rendering mesh datasets.
ColoringMethod
Defines how the color is defined.
Represents a simple line renderer with width and color varying depending on values.
A symbol layer that represents vector layer line features as interpolated lines.
Represents a width that can vary depending on values.
Layer tree node points to a map layer.
Abstract base class for line symbol layers.
Represents a 2D point.
Definition qgspointxy.h:60
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
Abstract base class for symbol layers.
Encapsulates the context in which a symbol is being rendered.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_FACTORY
Definition qgis_sip.h:76