QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
36class CORE_EXPORT QgsInterpolatedLineColor
37{
38 public:
39
44 {
46 SingleColor = 0,
48 ColorRamp
49 };
50
54 QgsInterpolatedLineColor( const QgsColorRampShader &colorRampShader );
56 QgsInterpolatedLineColor( const QColor &color );
57
59 void setColor( const QgsColorRampShader &colorRampShader );
60
62 void setColor( const QColor &color );
63
65 QColor color( double magnitude ) const;
66
71 void setColoringMethod( ColoringMethod coloringMethod );
72
74 QgsInterpolatedLineColor::ColoringMethod coloringMethod() const;
75
77 QgsColorRampShader colorRampShader() const;
78
83 QColor singleColor() const;
84
86 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
88 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
89
99 void graduatedColors( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
100
101 private:
102 QgsColorRampShader mColorRampShader;
103 QColor mSingleColor = Qt::black;
104
105 QgsInterpolatedLineColor::ColoringMethod mColoringMethod = SingleColor;
106
107 QLinearGradient makeSimpleLinearGradient( const QColor &color1, const QColor &color2 ) const;
108
110 int itemColorIndexInf( double value ) const;
111
112 void graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, const QList<QLinearGradient> &gradients ) const;
113 void graduatedColorsInterpolated( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
114 void graduatedColorsDiscrete( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
115};
116
125{
126 public:
128 double minimumValue() const;
130 void setMinimumValue( double minimumValue );
131
133 double maximumValue() const;
135 void setMaximumValue( double maximumValue );
136
138 double minimumWidth() const;
140 void setMinimumWidth( double minimumWidth );
141
143 double maximumWidth() const;
145 void setMaximumWidth( double maximumWidth );
146
148 bool ignoreOutOfRange() const;
150 void setIgnoreOutOfRange( bool ignoreOutOfRange );
151
153 bool useAbsoluteValue() const;
155 void setUseAbsoluteValue( bool useAbsoluteValue );
156
158 bool isVariableWidth() const;
160 void setIsVariableWidth( bool isVariableWidth );
161
163 double fixedStrokeWidth() const;
165 void setFixedStrokeWidth( double fixedWidth );
166
168 double strokeWidth( double value ) const;
169
171 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
173 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
174
175 private:
176 bool mIsWidthVariable = false;
177
178 double mFixedWidth = DEFAULT_LINE_WIDTH;
179
180 double mMinimumValue = 0;
181 double mMaximumValue = 10;
182 double mMinimumWidth = DEFAULT_LINE_WIDTH;
183 double mMaximumWidth = 3;
184 bool mIgnoreOutOfRange = false;
185 bool mUseAbsoluteValue = false;
186
187 mutable double mLinearCoef = 1;
188 mutable bool mNeedUpdateFormula = true;
189 void updateLinearFormula() const;
190};
191
199{
200 public:
201
203 void setInterpolatedWidth( const QgsInterpolatedLineWidth &strokeWidth );
204
209 QgsInterpolatedLineWidth interpolatedLineWidth() const;
210
212 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit );
213
218 Qgis::RenderUnit widthUnit() const;
219
221 void setInterpolatedColor( const QgsInterpolatedLineColor &strokeColoring );
222
227 QgsInterpolatedLineColor interpolatedColor() const;
228
236 void render( double value1, double value2, const QgsPointXY &point1, const QgsPointXY &point2, QgsRenderContext &context ) const;
237
247 void render( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, const QgsPointXY &point1, const QgsPointXY &point2, QgsRenderContext &context ) const;
248
255 void renderInDeviceCoordinates( double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, QPointF point1, QPointF point2, QgsRenderContext &context ) const;
256
262 void setSelected( bool selected );
263
264 private:
265
266 QgsInterpolatedLineWidth mStrokeWidth;
267 QgsInterpolatedLineColor mStrokeColoring;
268 Qgis::RenderUnit mStrokeWidthUnit = Qgis::RenderUnit::Millimeters;
269 void adjustLine( double value, double value1, double value2, double &width, double &adjusting ) const;
270 bool mSelected = false;
271
272
274};
275
284{
285 public:
286
289
291 static QgsSymbolLayer *create( const QVariantMap &properties ) SIP_FACTORY;
292
293 Qgis::SymbolLayerFlags flags() const override;
294 QString layerType() const override;
295 void startRender( QgsSymbolRenderContext &context ) override;
296 void stopRender( QgsSymbolRenderContext &context ) override;
297 QgsInterpolatedLineSymbolLayer *clone() const override SIP_FACTORY;
298 QVariantMap properties() const override;
299 void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
300 QColor color() const override;
301
302 void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
303 void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
304 void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
305 bool canCauseArtifactsBetweenAdjacentTiles() const override;
306
312 Q_DECL_DEPRECATED void setExpressionsStringForWidth( const QString &start, const QString &end ) SIP_DEPRECATED;
313
319 Q_DECL_DEPRECATED QString startValueExpressionForWidth() const SIP_DEPRECATED;
320
326 Q_DECL_DEPRECATED QString endValueExpressionForWidth() const SIP_DEPRECATED;
327
333 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit );
334
340 Qgis::RenderUnit widthUnit() const;
341
347 void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
348
354 QgsInterpolatedLineWidth interpolatedWidth() const;
355
361 Q_DECL_DEPRECATED void setExpressionsStringForColor( const QString &start, const QString &end ) SIP_DEPRECATED;
362
368 Q_DECL_DEPRECATED QString startValueExpressionForColor() const SIP_DEPRECATED;
369
375 Q_DECL_DEPRECATED QString endValueExpressionForColor() const SIP_DEPRECATED;
376
382 void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
383
389 QgsInterpolatedLineColor interpolatedColor() const;
390
391 private:
392#ifdef SIP_RUN
394#endif
395
396 QgsInterpolatedLineRenderer mLineRender;
397
398 QVector< QPolygonF > mLineParts;
399 bool mRenderingFeature = false;
400
401 void render( const QVector< QPolygonF > &parts, QgsRenderContext &context );
402
403 QVariant colorRampShaderProperties() const;
404 static QgsColorRampShader createColorRampShaderFromProperties( const QVariant &properties );
405};
406
407
408#endif // QGSINTERPOLATEDLINERENDERER_H
RenderUnit
Rendering size units.
Definition: qgis.h:3176
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:56
Class defining color to render 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 feature as interpolated line The interpolation is do...
Represents a width than can vary depending on values.
Layer tree node points to a map layer.
A class to represent a 2D point.
Definition: qgspointxy.h:59
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.
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:4049
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_FACTORY
Definition: qgis_sip.h:76