QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
51
55 QgsInterpolatedLineColor( const QgsColorRampShader &colorRampShader );
57 QgsInterpolatedLineColor( const QColor &color );
58
60 void setColor( const QgsColorRampShader &colorRampShader );
61
63 void setColor( const QColor &color );
64
66 QColor color( double magnitude ) const;
67
72 void setColoringMethod( ColoringMethod coloringMethod );
73
75 QgsInterpolatedLineColor::ColoringMethod coloringMethod() const;
76
78 QgsColorRampShader colorRampShader() const;
79
84 QColor singleColor() const;
85
87 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
89 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
90
100 void graduatedColors( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
101
102 private:
103 QgsColorRampShader mColorRampShader;
104 QColor mSingleColor = Qt::black;
105
106 QgsInterpolatedLineColor::ColoringMethod mColoringMethod = SingleColor;
107
108 QLinearGradient makeSimpleLinearGradient( const QColor &color1, const QColor &color2 ) const;
109
111 int itemColorIndexInf( double value ) const;
112
113 void graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, const QList<QLinearGradient> &gradients ) const;
114 void graduatedColorsInterpolated( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
115 void graduatedColorsDiscrete( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
116};
117
126{
127 public:
129 double minimumValue() const;
131 void setMinimumValue( double minimumValue );
132
134 double maximumValue() const;
136 void setMaximumValue( double maximumValue );
137
139 double minimumWidth() const;
141 void setMinimumWidth( double minimumWidth );
142
144 double maximumWidth() const;
146 void setMaximumWidth( double maximumWidth );
147
149 bool ignoreOutOfRange() const;
152
154 bool useAbsoluteValue() const;
157
159 bool isVariableWidth() const;
162
164 double fixedStrokeWidth() const;
166 void setFixedStrokeWidth( double fixedWidth );
167
169 double strokeWidth( double value ) const;
170
172 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
174 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
175
176 private:
177 bool mIsWidthVariable = false;
178
179 double mFixedWidth = Qgis::DEFAULT_LINE_WIDTH;
180
181 double mMinimumValue = 0;
182 double mMaximumValue = 10;
183 double mMinimumWidth = Qgis::DEFAULT_LINE_WIDTH;
184 double mMaximumWidth = 3;
185 bool mIgnoreOutOfRange = false;
186 bool mUseAbsoluteValue = false;
187
188 mutable double mLinearCoef = 1;
189 mutable bool mNeedUpdateFormula = true;
190 void updateLinearFormula() const;
191};
192
200{
201 public:
203 void setInterpolatedWidth( const QgsInterpolatedLineWidth &strokeWidth );
204
210
212 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit );
213
219
221 void setInterpolatedColor( const QgsInterpolatedLineColor &strokeColoring );
222
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 QgsInterpolatedLineWidth mStrokeWidth;
266 QgsInterpolatedLineColor mStrokeColoring;
268 void adjustLine( double value, double value1, double value2, double &width, double &adjusting ) const;
269 bool mSelected = false;
270
271
273};
274
284{
285 public:
287
289 static QgsSymbolLayer *create( const QVariantMap &properties ) SIP_FACTORY;
290
291 Qgis::SymbolLayerFlags flags() const override;
292 QString layerType() const override;
293 void startRender( QgsSymbolRenderContext &context ) override;
294 void stopRender( QgsSymbolRenderContext &context ) override;
296 QVariantMap properties() const override;
297 void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
298 QColor color() const override;
299
300 void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
301 void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
302 void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
303 bool canCauseArtifactsBetweenAdjacentTiles() const override;
304
310 Q_DECL_DEPRECATED void setExpressionsStringForWidth( const QString &start, const QString &end ) SIP_DEPRECATED;
311
317 Q_DECL_DEPRECATED QString startValueExpressionForWidth() const SIP_DEPRECATED;
318
324 Q_DECL_DEPRECATED QString endValueExpressionForWidth() const SIP_DEPRECATED;
325
326 // TODO QGIS 5.0 -- rename to avoid collision with base class methods
327
333 void setWidthUnit( Qgis::RenderUnit strokeWidthUnit ); // cppcheck-suppress duplInheritedMember
334
340 Qgis::RenderUnit widthUnit() const; // cppcheck-suppress duplInheritedMember
341
347 void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
348
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
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
static const double DEFAULT_LINE_WIDTH
The default width (in millimeters) for line symbols.
Definition qgis.h:6612
QFlags< SymbolLayerFlag > SymbolLayerFlags
Symbol layer flags.
Definition qgis.h:913
RenderUnit
Rendering size units.
Definition qgis.h:5340
@ Millimeters
Millimeters.
Definition qgis.h:5341
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:60
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:62
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:113
#define SIP_FACTORY
Definition qgis_sip.h:83