QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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, QgsStringMap 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
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsRendererRangeLabelFormat
Definition: qgsrendererrange.h:107
QgsRendererRangeLabelFormat::mReTrailingZeroes
QRegExp mReTrailingZeroes
Definition: qgsrendererrange.h:143
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:399
qgssymbollayerutils.h
QgsRendererRange
Definition: qgsrendererrange.h:36
QgsRendererRangeLabelFormat::MAX_PRECISION
static const int MAX_PRECISION
Definition: qgsrendererrange.h:133
QgsSymbol
Definition: qgssymbol.h:63
MathUtils::lower
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:407
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:404
QgsRendererRangeLabelFormat::mNumberSuffix
QString mNumberSuffix
Definition: qgsrendererrange.h:142
QgsRendererRangeLabelFormat::trimTrailingZeroes
bool trimTrailingZeroes() const
Definition: qgsrendererrange.h:122
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsRendererRangeLabelFormat::mReNegativeZero
QRegExp mReNegativeZero
Definition: qgsrendererrange.h:144
QgsRangeList
QList< QgsRendererRange > QgsRangeList
Definition: qgsrendererrange.h:98
QgsRendererRange::mLabel
QString mLabel
Definition: qgsrendererrange.h:91
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsRendererRangeLabelFormat::format
QString format() const
Definition: qgsrendererrange.h:116
QgsRendererRangeLabelFormat::setTrimTrailingZeroes
void setTrimTrailingZeroes(bool trimTrailingZeroes)
Definition: qgsrendererrange.h:123
QgsClassificationRange
Definition: qgsclassificationmethod.h:48
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsRendererRangeLabelFormat::setFormat
void setFormat(const QString &format)
Definition: qgsrendererrange.h:117
QgsRendererRangeLabelFormat::mFormat
QString mFormat
Definition: qgsrendererrange.h:137
QgsRendererRange::mSymbol
std::unique_ptr< QgsSymbol > mSymbol
Definition: qgsrendererrange.h:90
QgsRendererRangeLabelFormat::MIN_PRECISION
static const int MIN_PRECISION
Definition: qgsrendererrange.h:134
QgsRendererRangeLabelFormat::precision
int precision() const
Definition: qgsrendererrange.h:119