QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgis.h"
20#include "qgscolorrampshader.h"
21#include "qgsreadwritecontext.h"
22#include "qgssymbollayer.h"
23
24#include <QDebug>
25
28
38class CORE_EXPORT QgsInterpolatedLineColor
39{
40 public:
41
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;
153
155 bool useAbsoluteValue() const;
158
160 bool isVariableWidth() const;
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
212
214 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit );
215
221
223 void setInterpolatedColor( const QgsInterpolatedLineColor &strokeColoring );
224
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;
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
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
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:6243
QFlags< SymbolLayerFlag > SymbolLayerFlags
Symbol layer flags.
Definition qgis.h:887
RenderUnit
Rendering size units.
Definition qgis.h:5183
@ Millimeters
Millimeters.
Definition qgis.h:5184
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.
QgsInterpolatedLineColor()
Default constructor.
ColoringMethod
Defines how the color is defined.
@ ColorRamp
Render with a color ramp.
@ SingleColor
Render with a single color.
Represents a simple line renderer with width and color varying depending on values.
void setInterpolatedColor(const QgsInterpolatedLineColor &strokeColoring)
Sets the stroke color used to render.
void renderInDeviceCoordinates(double valueColor1, double valueColor2, double valueWidth1, double valueWidth2, QPointF point1, QPointF point2, QgsRenderContext &context) const
Renders a line in the context between point1 and point2 in device (painter) coordinates with color th...
Qgis::RenderUnit widthUnit() const
Returns the unit of the stroke width.
void setInterpolatedWidth(const QgsInterpolatedLineWidth &strokeWidth)
Sets the stroke width used to render.
void setSelected(bool selected)
Sets if the rendering must be done as the element is selected.
void render(double value1, double value2, const QgsPointXY &point1, const QgsPointXY &point2, QgsRenderContext &context) const
Renders a line in the context between point1 and point2 with color and width that vary depending on v...
QgsInterpolatedLineWidth interpolatedLineWidth() const
Returns the stroke width used to render.
QgsInterpolatedLineColor interpolatedColor() const
Returns the stroke color used to render.
void setWidthUnit(Qgis::RenderUnit strokeWidthUnit)
Sets the unit of the stroke width.
Q_DECL_DEPRECATED QString endValueExpressionForWidth() const
Returns the expression related to the end extremity value for width.
QColor color() const override
Returns the "representative" color of the symbol layer.
Q_DECL_DEPRECATED QString endValueExpressionForColor() const
Returns the expression related to the end extremity value for width for color.
Q_DECL_DEPRECATED void setExpressionsStringForColor(const QString &start, const QString &end)
Sets the expressions (as string) that define the extremety values af the line feature for color.
Qgis::RenderUnit widthUnit() const
Returns the width unit.
Qgis::SymbolLayerFlags flags() const override
Returns flags which control the symbol layer's behavior.
QgsInterpolatedLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
bool canCauseArtifactsBetweenAdjacentTiles() const override
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context) override
Renders the line symbol layer along the line joining points, using the given render context.
QgsInterpolatedLineColor interpolatedColor() const
Returns the interpolated color used to render the colors of lines, see QgsInterpolatedLineColor.
Q_DECL_DEPRECATED QString startValueExpressionForColor() const
Returns the epression related to the start extremity value for width for color.
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
QString layerType() const override
Returns a string that represents this layer type.
Q_DECL_DEPRECATED void setExpressionsStringForWidth(const QString &start, const QString &end)
Sets the expressions (as string) that define the extremety values af the line feature for width.
void setInterpolatedWidth(const QgsInterpolatedLineWidth &interpolatedLineWidth)
Sets the interpolated width used to render the width of lines, see QgsInterpolatedLineWidth.
void setInterpolatedColor(const QgsInterpolatedLineColor &interpolatedLineColor)
Sets the interpolated color used to render the colors of lines, see QgsInterpolatedLineColor.
Q_DECL_DEPRECATED QString startValueExpressionForWidth() const
Returns the epression related to the start extremity value for width.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
QgsInterpolatedLineWidth interpolatedWidth() const
Returns the interpolated width used to render the width of lines, see QgsInterpolatedLineWidth.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
void setWidthUnit(Qgis::RenderUnit strokeWidthUnit)
Sets the width unit.
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
Represents a width that can vary depending on values.
void setFixedStrokeWidth(double fixedWidth)
Sets the fixed width.
double strokeWidth(double value) const
Returns the variable width depending on value, if not varying returns the fixed width.
void setUseAbsoluteValue(bool useAbsoluteValue)
Sets whether absolute value are used as input.
double minimumValue() const
Returns the minimum value used to defined the variable width.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from the given DOM element.
void setIgnoreOutOfRange(bool ignoreOutOfRange)
Sets whether the variable width ignores out of range value.
void setMaximumValue(double maximumValue)
Sets the maximum value used to defined the variable width.
bool useAbsoluteValue() const
Returns whether absolute value are used as input.
void setIsVariableWidth(bool isVariableWidth)
Returns whether the width is variable.
void setMinimumValue(double minimumValue)
Sets the minimum value used to defined the variable width.
double maximumWidth() const
Returns the maximum width used to defined the variable width.
void setMaximumWidth(double maximumWidth)
Sets the maximum width used to defined the variable width.
double maximumValue() const
Returns the maximum value used to defined the variable width.
void setMinimumWidth(double minimumWidth)
Sets the minimum width used to defined the variable width.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a new DOM element.
bool ignoreOutOfRange() const
Returns whether the variable width ignores out of range value.
double minimumWidth() const
Returns the minimum width used to defined the variable width.
double fixedStrokeWidth() const
Returns the fixed width.
bool isVariableWidth() const
Returns whether the width is variable.
Layer tree node points to a map layer.
QgsLineSymbolLayer(const QgsLineSymbolLayer &other)=delete
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.
QgsSymbolLayer(const QgsSymbolLayer &other)
Encapsulates the context in which a symbol is being rendered.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_FACTORY
Definition qgis_sip.h:84