QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 "qgsrendercontext.h"
25 #include "qgsunittypes.h"
26 
34 class CORE_EXPORT QgsInterpolatedLineColor
35 {
36  public:
37 
42  {
44  SingleColor = 0,
46  ColorRamp
47  };
48 
52  QgsInterpolatedLineColor( const QgsColorRampShader &colorRampShader );
54  QgsInterpolatedLineColor( const QColor &color );
55 
57  void setColor( const QgsColorRampShader &colorRampShader );
58 
60  void setColor( const QColor &color );
61 
63  QColor color( double magnitude ) const;
64 
66  QgsInterpolatedLineColor::ColoringMethod coloringMethod() const;
67 
69  QgsColorRampShader colorRampShader() const;
70 
72  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
74  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
75 
85  void graduatedColors( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
86 
87  private:
88  QgsColorRampShader mColorRampShader;
89  QColor mSingleColor = Qt::black;
90 
91  QgsInterpolatedLineColor::ColoringMethod mColoringMethod = SingleColor;
92 
93  QLinearGradient makeSimpleLinearGradient( const QColor &color1, const QColor &color2 ) const;
94 
96  int itemColorIndexInf( double value ) const;
97 
98  void graduatedColorsExact( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
99  void graduatedColorsInterpolated( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
100  void graduatedColorsDiscrete( double value1, double value2, QList<double> &breakValues, QList<QColor> &breakColors, QList<QLinearGradient> &gradients ) const;
101 };
102 
110 class CORE_EXPORT QgsInterpolatedLineWidth
111 {
112  public:
114  double minimumValue() const;
116  void setMinimumValue( double minimumValue );
117 
119  double maximumValue() const;
121  void setMaximumValue( double maximumValue );
122 
124  double minimumWidth() const;
126  void setMinimumWidth( double minimumWidth );
127 
129  double maximumWidth() const;
131  void setMaximumWidth( double maximumWidth );
132 
134  bool ignoreOutOfRange() const;
136  void setIgnoreOutOfRange( bool ignoreOutOfRange );
137 
139  bool useAbsoluteValue() const;
141  void setUseAbsoluteValue( bool useAbsoluteValue );
142 
144  bool isVariableWidth() const;
146  void setIsVariableWidth( bool isVariableWidth );
147 
149  double fixedStrokeWidth() const;
151  void setFixedStrokeWidth( double fixedWidth );
152 
154  double strokeWidth( double value ) const;
155 
157  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
159  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
160 
161  private:
162  bool mIsWidthVariable = false;
163 
164  double mFixedWidth = DEFAULT_LINE_WIDTH;
165 
166  double mMinimumValue = 0;
167  double mMaximumValue = 10;
168  double mMinimumWidth = DEFAULT_LINE_WIDTH;
169  double mMaximumWidth = 3;
170  bool mIgnoreOutOfRange = false;
171  bool mUseAbsoluteValue = false;
172 
173  mutable double mLinearCoef = 1;
174  mutable bool mNeedUpdateFormula = true;
175  void updateLinearFormula() const;
176 };
177 
185 {
186  public:
188  void setInterpolatedWidth( const QgsInterpolatedLineWidth &strokeWidth );
189 
191  void setWidthUnit( const QgsUnitTypes::RenderUnit &strokeWidthUnit );
192 
194  void setInterpolatedColor( const QgsInterpolatedLineColor &strokeColoring );
195 
200  void render( double value1, double value2, QgsPointXY point1, QgsPointXY point2, QgsRenderContext &context ) const;
201 
202  private:
203  QgsInterpolatedLineWidth mStrokeWidth;
204  QgsInterpolatedLineColor mStrokeColoring;
206 
207  QPolygonF varyingWidthLine( double value1, double value2, QPointF point1, QPointF point2, QgsRenderContext &context ) const;
208  void adjustLine( const double &value, const double &value1, const double &value2, double &width, double &adjusting ) const;
209 };
210 
211 #endif // QGSINTERPOLATEDLINERENDERER_H
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Class defining color to render mesh datasets.
QgsInterpolatedLineColor()=default
Default constructor.
ColoringMethod
Defines how the color is defined.
Represents a line with width and color varying depending on values.
Represents a width than can vary depending on values.
A class to represent a 2D point.
Definition: qgspointxy.h:44
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.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:754