QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsrenderer.h"
25 #include "qgsunittypes.h"
26 #include "qgssymbollayer.h"
27 
28 class QgsLayerTreeLayer;
29 class QgsRenderContext;
30 
38 class 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 
126 class CORE_EXPORT QgsInterpolatedLineWidth
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 = DEFAULT_LINE_WIDTH;
181 
182  double mMinimumValue = 0;
183  double mMaximumValue = 10;
184  double mMinimumWidth = 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( QgsUnitTypes::RenderUnit strokeWidthUnit );
215 
220  QgsUnitTypes::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 
286 {
287  public:
288 
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 isCompatibleWithSymbol( QgsSymbol *symbol ) const override;
308  bool canCauseArtifactsBetweenAdjacentTiles() const override;
309 
315  Q_DECL_DEPRECATED void setExpressionsStringForWidth( const QString &start, const QString &end ) SIP_DEPRECATED;
316 
322  Q_DECL_DEPRECATED QString startValueExpressionForWidth() const SIP_DEPRECATED;
323 
329  Q_DECL_DEPRECATED QString endValueExpressionForWidth() const SIP_DEPRECATED;
330 
336  void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );
337 
344 
350  void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
351 
357  QgsInterpolatedLineWidth interpolatedWidth() const;
358 
364  Q_DECL_DEPRECATED void setExpressionsStringForColor( const QString &start, const QString &end ) SIP_DEPRECATED;
365 
371  Q_DECL_DEPRECATED QString startValueExpressionForColor() const SIP_DEPRECATED;
372 
378  Q_DECL_DEPRECATED QString endValueExpressionForColor() const SIP_DEPRECATED;
379 
385  void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
386 
392  QgsInterpolatedLineColor interpolatedColor() const;
393 
394  private:
395 #ifdef SIP_RUN
397 #endif
398 
399  QgsInterpolatedLineRenderer mLineRender;
400 
401  QVector< QPolygonF > mLineParts;
402  bool mRenderingFeature = false;
403 
404  void render( const QVector< QPolygonF > &parts, QgsRenderContext &context );
405 
406  QVariant colorRampShaderProperties() const;
407  static QgsColorRampShader createColorRampShaderFromProperties( const QVariant &properties );
408 };
409 
410 
411 #endif // QGSINTERPOLATEDLINERENDERER_H
QgsLineSymbolLayer
Definition: qgssymbollayer.h:1024
QgsLineSymbolLayer::setWidthUnit
void setWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the line's width.
Definition: qgssymbollayer.h:1165
QgsSymbolLayer::startFeatureRender
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
Definition: qgssymbollayer.cpp:131
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsLineSymbolLayer::renderPolyline
virtual void renderPolyline(const QPolygonF &points, QgsSymbolRenderContext &context)=0
Renders the line symbol layer along the line joining points, using the given render context.
QgsSymbolLayer::isCompatibleWithSymbol
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
Definition: qgssymbollayer.cpp:300
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsSymbolLayer::flags
virtual Qgis::SymbolLayerFlags flags() const
Returns flags which control the symbol layer's behavior.
Definition: qgssymbollayer.cpp:242
qgsreadwritecontext.h
QgsInterpolatedLineColor::ColoringMethod
ColoringMethod
Defines how the color is defined.
Definition: qgsinterpolatedlinerenderer.h:45
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
qgscolorrampshader.h
qgsunittypes.h
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsColorRampShader
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:42
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsLineSymbolLayer::drawPreviewIcon
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
Definition: qgssymbollayer.cpp:743
QgsSymbolRenderContext
Definition: qgssymbolrendercontext.h:35
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsSymbolLayer::clone
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSymbolLayer
Definition: qgssymbollayer.h:54
QgsInterpolatedLineWidth
Represents a width than can vary depending on values.
Definition: qgsinterpolatedlinerenderer.h:126
QgsSymbolLayer::stopFeatureRender
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
Definition: qgssymbollayer.cpp:143
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
DEFAULT_LINE_WIDTH
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:2776
QgsInterpolatedLineColor
Class defining color to render mesh datasets. The color can vary depending on the dataset value.
Definition: qgsinterpolatedlinerenderer.h:38
QgsSymbolLayer::properties
virtual QVariantMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
qgssymbollayer.h
qgsrenderer.h
QgsSymbolLayer::canCauseArtifactsBetweenAdjacentTiles
virtual bool canCauseArtifactsBetweenAdjacentTiles() const
Returns true if the symbol layer rendering can cause visible artifacts across a single feature when t...
Definition: qgssymbollayer.cpp:308
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsInterpolatedLineSymbolLayer
A symbol layer that represents vector layer line feature as interpolated line The interpolation is do...
Definition: qgsinterpolatedlinerenderer.h:285
QgsSymbolLayer::stopRender
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
QgsSymbolLayer::layerType
virtual QString layerType() const =0
Returns a string that represents this layer type.
QgsSymbolLayer::color
virtual QColor color() const
Returns the "representative" color of the symbol layer.
Definition: qgssymbollayer.cpp:247
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsSymbolLayer::startRender
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
QgsInterpolatedLineRenderer
Represents a simple line renderer with width and color varying depending on values.
Definition: qgsinterpolatedlinerenderer.h:200
QgsLineSymbolLayer::widthUnit
QgsUnitTypes::RenderUnit widthUnit() const
Returns the units for the line's width.
Definition: qgssymbollayer.h:1171