QGIS API Documentation  3.21.0-Master (5b68dc587e)
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;
299  QgsInterpolatedLineSymbolLayer *clone() const override SIP_FACTORY;
300  QVariantMap properties() const override;
301  void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
302 
303  void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
304  void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
305  void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override;
306  bool isCompatibleWithSymbol( QgsSymbol *symbol ) const 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 
335  void setWidthUnit( QgsUnitTypes::RenderUnit strokeWidthUnit );
336 
342  QgsUnitTypes::RenderUnit widthUnit() const;
343 
349  void setInterpolatedWidth( const QgsInterpolatedLineWidth &interpolatedLineWidth );
350 
356  QgsInterpolatedLineWidth interpolatedWidth() const;
357 
363  Q_DECL_DEPRECATED void setExpressionsStringForColor( const QString &start, const QString &end ) SIP_DEPRECATED;
364 
370  Q_DECL_DEPRECATED QString startValueExpressionForColor() const SIP_DEPRECATED;
371 
377  Q_DECL_DEPRECATED QString endValueExpressionForColor() const SIP_DEPRECATED;
378 
384  void setInterpolatedColor( const QgsInterpolatedLineColor &interpolatedLineColor );
385 
391  QgsInterpolatedLineColor interpolatedColor() const;
392 
393  private:
394 #ifdef SIP_RUN
396 #endif
397 
398  QgsInterpolatedLineRenderer mLineRender;
399 
400  QVector< QPolygonF > mLineParts;
401  bool mRenderingFeature = false;
402 
403  void render( const QVector< QPolygonF > &parts, QgsRenderContext &context );
404 
405  QVariant colorRampShaderProperties() const;
406  static QgsColorRampShader createColorRampShaderFromProperties( const QVariant &properties );
407 };
408 
409 
410 #endif // QGSINTERPOLATEDLINERENDERER_H
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:56
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.
A class to represent a 2D point.
Definition: qgspointxy.h:59
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.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:1686
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_FACTORY
Definition: qgis_sip.h:76