QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgscolorramplegendnodesettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorramplegendnode.h
3 --------------------------------------
4 Date : December 2020
5 Copyright : (C) 2020 by Nyall Dawson
6 Email : nyall dot dawson 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
17
18#include "qgis.h"
19#include "qgsapplication.h"
21#include "qgsnumericformat.h"
23
24#include <QString>
25
26using namespace Qt::StringLiterals;
27
32
34//****** IMPORTANT! editing this? make sure you update the move constructor too! *****
35 : mUseContinuousLegend( other.mUseContinuousLegend )
36 , mMinimumLabel( other.mMinimumLabel )
37 , mMaximumLabel( other.mMaximumLabel )
38 , mPrefix( other.mPrefix )
39 , mSuffix( other.mSuffix )
40 , mDirection( other.mDirection )
41 , mNumericFormat( other.numericFormat()->clone() )
42 , mTextFormat( other.textFormat() )
43 , mOrientation( other.mOrientation )
44 //****** IMPORTANT! editing this? make sure you update the move constructor too! *****
45{
46
47}
48
50 : mUseContinuousLegend( other.mUseContinuousLegend )
51 , mMinimumLabel( std::move( other.mMinimumLabel ) )
52 , mMaximumLabel( std::move( other.mMaximumLabel ) )
53 , mPrefix( std::move( other.mPrefix ) )
54 , mSuffix( std::move( other.mSuffix ) )
55 , mDirection( other.mDirection )
56 , mNumericFormat( std::move( other.mNumericFormat ) )
57 , mTextFormat( std::move( other.mTextFormat ) )
58 , mOrientation( other.mOrientation )
59{
60
61}
62
64{
65 if ( &other == this )
66 return *this;
67
68 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
69 mUseContinuousLegend = other.mUseContinuousLegend;
70 mMinimumLabel = other.mMinimumLabel;
71 mMaximumLabel = other.mMaximumLabel;
72 mPrefix = other.mPrefix;
73 mSuffix = other.mSuffix;
74 mDirection = other.mDirection;
75 mNumericFormat.reset( other.numericFormat()->clone() );
76 mTextFormat = other.mTextFormat;
77 mOrientation = other.mOrientation;
78 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
79 return *this;
80}
81
83{
84 if ( &other == this )
85 return *this;
86
87 mUseContinuousLegend = other.mUseContinuousLegend;
88 mMinimumLabel = std::move( other.mMinimumLabel );
89 mMaximumLabel = std::move( other.mMaximumLabel );
90 mPrefix = std::move( other.mPrefix );
91 mSuffix = std::move( other.mSuffix );
92 mDirection = other.mDirection;
93 mNumericFormat = std::move( other.mNumericFormat );
94 mTextFormat = std::move( other.mTextFormat );
95 mOrientation = other.mOrientation;
96 return *this;
97}
98
100
105
110
112{
113 return mMinimumLabel;
114}
115
117{
118 mMinimumLabel = label;
119}
120
122{
123 return mMaximumLabel;
124}
125
127{
128 mMaximumLabel = label;
129}
130
132{
133 return mNumericFormat.get();
134}
135
137{
138 mNumericFormat.reset( format );
139}
140
141void QgsColorRampLegendNodeSettings::writeXml( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context ) const
142{
143 QDomElement settingsElement = doc.createElement( u"rampLegendSettings"_s );
144
145 settingsElement.setAttribute( u"useContinuousLegend"_s, mUseContinuousLegend );
146 settingsElement.setAttribute( u"minimumLabel"_s, mMinimumLabel );
147 settingsElement.setAttribute( u"maximumLabel"_s, mMaximumLabel );
148 settingsElement.setAttribute( u"prefix"_s, mPrefix );
149 settingsElement.setAttribute( u"suffix"_s, mSuffix );
150 settingsElement.setAttribute( u"direction"_s, static_cast< int >( mDirection ) );
151 settingsElement.setAttribute( u"orientation"_s, static_cast< int >( mOrientation ) );
152
153 QDomElement numericFormatElem = doc.createElement( u"numericFormat"_s );
154 mNumericFormat->writeXml( numericFormatElem, doc, context );
155 settingsElement.appendChild( numericFormatElem );
156
157 if ( mTextFormat.isValid() )
158 {
159 settingsElement.appendChild( mTextFormat.writeXml( doc, context ) );
160 }
161
162 element.appendChild( settingsElement );
163}
164
165void QgsColorRampLegendNodeSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
166{
167 const QDomElement settingsElement = element.firstChildElement( u"rampLegendSettings"_s );
168 if ( !settingsElement.isNull() )
169 {
170 mUseContinuousLegend = settingsElement.attribute( u"useContinuousLegend"_s, u"1"_s ).toInt( );
171 mMinimumLabel = settingsElement.attribute( u"minimumLabel"_s );
172 mMaximumLabel = settingsElement.attribute( u"maximumLabel"_s );
173 mPrefix = settingsElement.attribute( u"prefix"_s );
174 mSuffix = settingsElement.attribute( u"suffix"_s );
175 mDirection = static_cast< QgsColorRampLegendNodeSettings::Direction >( settingsElement.attribute( u"direction"_s ).toInt() );
176 mOrientation = static_cast< Qt::Orientation >( settingsElement.attribute( u"orientation"_s, QString::number( Qt::Vertical ) ).toInt() );
177
178 const QDomNodeList numericFormatNodeList = settingsElement.elementsByTagName( u"numericFormat"_s );
179 if ( !numericFormatNodeList.isEmpty() )
180 {
181 const QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
182 mNumericFormat.reset( QgsApplication::numericFormatRegistry()->createFromXml( numericFormatElem, context ) );
183 }
184
185 if ( !settingsElement.firstChildElement( u"text-style"_s ).isNull() )
186 {
187 mTextFormat.readXml( settingsElement, context );
188 }
189 else
190 {
191 mTextFormat = QgsTextFormat();
192 }
193 }
194}
195
197{
198 return mPrefix;
199}
200
202{
203 mPrefix = prefix;
204}
205
207{
208 return mSuffix;
209}
210
212{
213 mSuffix = suffix;
214}
215
217{
218 return mTextFormat;
219}
220
222{
223 mTextFormat = format;
224}
225
227{
228 return mOrientation;
229}
230
232{
233 mOrientation = orientation;
234}
235
237{
238 return mUseContinuousLegend;
239}
240
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
A numeric formatter which returns a simple text representation of a value.
void setDirection(QgsColorRampLegendNodeSettings::Direction direction)
Sets the direction of the ramp.
QgsColorRampLegendNodeSettings & operator=(const QgsColorRampLegendNodeSettings &other)
void setMaximumLabel(const QString &label)
Sets the label for the maximum value on the ramp.
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
bool useContinuousLegend() const
Returns true if a continuous gradient legend will be used.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from an XML element.
void writeXml(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to an XML element.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
QString maximumLabel() const
Returns the label for the maximum value on the ramp.
QString suffix() const
Returns the suffix to show after legend text.
void setPrefix(const QString &prefix)
Sets the prefix to show before legend text.
void setUseContinuousLegend(bool useContinuousLegend)
Sets the flag to use a continuous gradient legend to useContinuousLegend.
void setOrientation(Qt::Orientation orientation)
Sets the ramp orientation (i.e.
void setSuffix(const QString &suffix)
Sets the suffix to show after legend text.
QString prefix() const
Returns the prefix to show before legend text.
Qt::Orientation orientation() const
Returns the ramp orientation (i.e.
QgsColorRampLegendNodeSettings::Direction direction() const
Returns the direction of the ramp.
QgsTextFormat textFormat() const
Returns the text format used to render text in the legend item.
void setMinimumLabel(const QString &label)
Sets the label for the minimum value on the ramp.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used to render text in the legend item.
QString minimumLabel() const
Returns the label for the minimum value on the ramp.
Abstract base class for numeric formatters, which allow for formatting a numeric value for display.
virtual QgsNumericFormat * clone() const =0
Clones the format, returning a new object.
void writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the format to an XML element.
A container for the context for various read/write operations on objects.
Container for all settings relating to text rendering.