QGIS API Documentation  3.23.0-Master (22c16f2067)
qgsrendererrange.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererrange.h
3  ---------------------
4  begin : September 2019
5  copyright : (C) 2019 by Denis Rouzaud
6  email : [email protected]
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 QGSRENDERERRANGE_H
17 #define QGSRENDERERRANGE_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgssymbollayerutils.h"
22 
23 #include <QRegularExpression>
24 
25 class QDomDocument;
26 class QDomElement;
27 
28 class QgsSymbol;
30 
31 
36 class CORE_EXPORT QgsRendererRange
37 {
38  public:
39 
43  QgsRendererRange() = default;
45 
52  QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true );
53  QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true );
54  QgsRendererRange( const QgsRendererRange &range );
55 
56  // default dtor is OK
57  QgsRendererRange &operator=( QgsRendererRange range );
58 
59  bool operator<( const QgsRendererRange &other ) const;
60 
61  double lowerValue() const;
62  double upperValue() const;
63 
64  QgsSymbol *symbol() const;
65  QString label() const;
66 
67  void setSymbol( QgsSymbol *s SIP_TRANSFER );
68  void setLabel( const QString &label );
69  void setLowerValue( double lowerValue );
70  void setUpperValue( double upperValue );
71 
72  // \since QGIS 2.5
73  bool renderState() const;
74  void setRenderState( bool render );
75 
76  // debugging
77  QString dump() const;
78 
87  void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
88 
89  protected:
90  double mLowerValue = 0, mUpperValue = 0;
91  std::unique_ptr<QgsSymbol> mSymbol;
92  QString mLabel;
93  bool mRender = true;
94 
95  // for cpy+swap idiom
96  void swap( QgsRendererRange &other );
97 };
98 
99 typedef QList<QgsRendererRange> QgsRangeList;
100 
101 
108 class CORE_EXPORT Q_DECL_DEPRECATED QgsRendererRangeLabelFormat SIP_DEPRECATED
109 {
110  public:
112  QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
113 
114  bool operator==( const QgsRendererRangeLabelFormat &other ) const;
115  bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
116 
117  QString format() const { return mFormat; }
118  void setFormat( const QString &format ) { mFormat = format; }
119 
120  int precision() const { return mPrecision; }
121  void setPrecision( int precision );
122 
123  bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
124  void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
125 
127  QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
128  QString labelForRange( const QgsRendererRange &range ) const;
129  QString formatNumber( double value ) const;
130 
131  void setFromDomElement( QDomElement &element );
132  void saveToDomElement( QDomElement &element );
133 
134  static const int MAX_PRECISION;
135  static const int MIN_PRECISION;
136 
137  protected:
138  QString mFormat;
139  int mPrecision = 4;
140  bool mTrimTrailingZeroes = false;
141  // values used to manage number formatting - precision and trailing zeroes
142  double mNumberScale = 1.0;
143  QString mNumberSuffix;
144  QRegularExpression mReTrailingZeroes;
145  QRegularExpression mReNegativeZero;
146 };
147 
148 
149 #endif // QGSRENDERERRANGE_H
QgsClassificationRange contains the information about a classification range.
void setFormat(const QString &format)
QRegularExpression mReTrailingZeroes
QRegularExpression mReNegativeZero
void setTrimTrailingZeroes(bool trimTrailingZeroes)
QgsRendererRange()=default
Constructor for QgsRendererRange.
std::unique_ptr< QgsSymbol > mSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:407
bool operator<(const QVariant &v1, const QVariant &v2)
Compares two QVariant values and returns whether the first is less than the second.
Definition: qgis.h:1802
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_TRANSFER
Definition: qgis_sip.h:36
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QList< QgsRendererRange > QgsRangeList
int precision