QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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;
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
288
290 static QgsSymbolLayer *create( const QVariantMap &properties ) SIP_FACTORY;
291
292 Qgis::SymbolLayerFlags flags() const override;
293 QString layerType() const override;
294 void startRender( QgsSymbolRenderContext &context ) override;
295 void stopRender( QgsSymbolRenderContext &context ) override;
296 QgsInterpolatedLineSymbolLayer *clone() const override SIP_FACTORY;
297 QVariantMap properties() const override;
298 void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
299 QColor color() const override;
300
301 void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
302 void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
303 void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
304 bool canCauseArtifactsBetweenAdjacentTiles() const override;
305
311 Q_DECL_DEPRECATED void setExpressionsStringForWidth( const QString &start, const QString &end ) SIP_DEPRECATED;
312
318 Q_DECL_DEPRECATED QString startValueExpressionForWidth() const SIP_DEPRECATED;
319
325 Q_DECL_DEPRECATED QString endValueExpressionForWidth() const SIP_DEPRECATED;
326
327 // TODO QGIS 4.0 -- rename to avoid collision with base class methods
328
334 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit ); // cppcheck-suppress duplInheritedMember
335
341 Qgis::RenderUnit widthUnit() const; // cppcheck-suppress duplInheritedMember
342
348 void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
349
355 QgsInterpolatedLineWidth interpolatedWidth() const;
356
362 Q_DECL_DEPRECATED void setExpressionsStringForColor( const QString &start, const QString &end ) SIP_DEPRECATED;
363
369 Q_DECL_DEPRECATED QString startValueExpressionForColor() const SIP_DEPRECATED;
370
376 Q_DECL_DEPRECATED QString endValueExpressionForColor() const SIP_DEPRECATED;
377
383 void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
384
390 QgsInterpolatedLineColor interpolatedColor() const;
391
392 private:
393#ifdef SIP_RUN
395#endif
396
397 QgsInterpolatedLineRenderer mLineRender;
398
399 QVector< QPolygonF > mLineParts;
400 bool mRenderingFeature = false;
401
402 void render( const QVector< QPolygonF > &parts, QgsRenderContext &context );
403
404 QVariant colorRampShaderProperties() const;
405 static QgsColorRampShader createColorRampShaderFromProperties( const QVariant &properties );
406};
407
408
409#endif // QGSINTERPOLATEDLINERENDERER_H
QFlags< SymbolLayerFlag > SymbolLayerFlags
Symbol layer flags.
Definition qgis.h:821
RenderUnit
Rendering size units.
Definition qgis.h:4892
@ 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
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.
Abstract base class for line symbol layers.
A class to represent a 2D point.
Definition qgspointxy.h:60
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:6557
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_FACTORY
Definition qgis_sip.h:76