QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 <QRegExp>
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgssymbollayerutils.h"
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;
44 
51  QgsRendererRange( const QgsClassificationRange &range, QgsSymbol *symbol SIP_TRANSFER, bool render = true );
52  QgsRendererRange( double lowerValue, double upperValue, QgsSymbol *symbol SIP_TRANSFER, const QString &label, bool render = true );
53  QgsRendererRange( const QgsRendererRange &range );
54 
55  // default dtor is OK
56  QgsRendererRange &operator=( QgsRendererRange range );
57 
58  bool operator<( const QgsRendererRange &other ) const;
59 
60  double lowerValue() const;
61  double upperValue() const;
62 
63  QgsSymbol *symbol() const;
64  QString label() const;
65 
66  void setSymbol( QgsSymbol *s SIP_TRANSFER );
67  void setLabel( const QString &label );
68  void setLowerValue( double lowerValue );
69  void setUpperValue( double upperValue );
70 
71  // \since QGIS 2.5
72  bool renderState() const;
73  void setRenderState( bool render );
74 
75  // debugging
76  QString dump() const;
77 
86  void toSld( QDomDocument &doc, QDomElement &element, QVariantMap props, bool firstRange = false ) const;
87 
88  protected:
89  double mLowerValue = 0, mUpperValue = 0;
90  std::unique_ptr<QgsSymbol> mSymbol;
91  QString mLabel;
92  bool mRender = true;
93 
94  // for cpy+swap idiom
95  void swap( QgsRendererRange &other );
96 };
97 
98 typedef QList<QgsRendererRange> QgsRangeList;
99 
100 
107 class Q_DECL_DEPRECATED CORE_EXPORT QgsRendererRangeLabelFormat SIP_DEPRECATED
108 {
109  public:
111  QgsRendererRangeLabelFormat( const QString &format, int precision = 4, bool trimTrailingZeroes = false );
112 
113  bool operator==( const QgsRendererRangeLabelFormat &other ) const;
114  bool operator!=( const QgsRendererRangeLabelFormat &other ) const;
115 
116  QString format() const { return mFormat; }
117  void setFormat( const QString &format ) { mFormat = format; }
118 
119  int precision() const { return mPrecision; }
120  void setPrecision( int precision );
121 
122  bool trimTrailingZeroes() const { return mTrimTrailingZeroes; }
123  void setTrimTrailingZeroes( bool trimTrailingZeroes ) { mTrimTrailingZeroes = trimTrailingZeroes; }
124 
126  QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );
127  QString labelForRange( const QgsRendererRange &range ) const;
128  QString formatNumber( double value ) const;
129 
130  void setFromDomElement( QDomElement &element );
131  void saveToDomElement( QDomElement &element );
132 
133  static const int MAX_PRECISION;
134  static const int MIN_PRECISION;
135 
136  protected:
137  QString mFormat;
138  int mPrecision = 4;
139  bool mTrimTrailingZeroes = false;
140  // values used to manage number formatting - precision and trailing zeroes
141  double mNumberScale = 1.0;
142  QString mNumberSuffix;
145 };
146 
147 
148 #endif // QGSRENDERERRANGE_H
QgsClassificationRange contains the information about a classification range.
void setFormat(const QString &format)
void setTrimTrailingZeroes(bool trimTrailingZeroes)
QgsRendererRange()=default
Constructor for QgsRendererRange.
std::unique_ptr< QgsSymbol > mSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:407
#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