QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
31
33 //****** IMPORTANT! editing this? make sure you update the move constructor too! *****
34 : mUseContinuousLegend( other.mUseContinuousLegend )
35 , mMinimumLabel( other.mMinimumLabel )
36 , mMaximumLabel( other.mMaximumLabel )
37 , mPrefix( other.mPrefix )
38 , mSuffix( other.mSuffix )
39 , mDirection( other.mDirection )
40 , mNumericFormat( other.numericFormat()->clone() )
41 , mTextFormat( other.textFormat() )
42 , mOrientation( other.mOrientation )
43//****** IMPORTANT! editing this? make sure you update the move constructor too! *****
44{}
45
47 : mUseContinuousLegend( other.mUseContinuousLegend )
48 , mMinimumLabel( std::move( other.mMinimumLabel ) )
49 , mMaximumLabel( std::move( other.mMaximumLabel ) )
50 , mPrefix( std::move( other.mPrefix ) )
51 , mSuffix( std::move( other.mSuffix ) )
52 , mDirection( other.mDirection )
53 , mNumericFormat( std::move( other.mNumericFormat ) )
54 , mTextFormat( std::move( other.mTextFormat ) )
55 , mOrientation( other.mOrientation )
56{}
57
59{
60 if ( &other == this )
61 return *this;
62
63 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
64 mUseContinuousLegend = other.mUseContinuousLegend;
65 mMinimumLabel = other.mMinimumLabel;
66 mMaximumLabel = other.mMaximumLabel;
67 mPrefix = other.mPrefix;
68 mSuffix = other.mSuffix;
69 mDirection = other.mDirection;
70 mNumericFormat.reset( other.numericFormat()->clone() );
71 mTextFormat = other.mTextFormat;
72 mOrientation = other.mOrientation;
73 //****** IMPORTANT! editing this? make sure you update the move assignment operator too! *****
74 return *this;
75}
76
78{
79 if ( &other == this )
80 return *this;
81
82 mUseContinuousLegend = other.mUseContinuousLegend;
83 mMinimumLabel = std::move( other.mMinimumLabel );
84 mMaximumLabel = std::move( other.mMaximumLabel );
85 mPrefix = std::move( other.mPrefix );
86 mSuffix = std::move( other.mSuffix );
87 mDirection = other.mDirection;
88 mNumericFormat = std::move( other.mNumericFormat );
89 mTextFormat = std::move( other.mTextFormat );
90 mOrientation = other.mOrientation;
91 return *this;
92}
93
95
100
105
107{
108 return mMinimumLabel;
109}
110
112{
113 mMinimumLabel = label;
114}
115
117{
118 return mMaximumLabel;
119}
120
122{
123 mMaximumLabel = label;
124}
125
127{
128 return mNumericFormat.get();
129}
130
132{
133 mNumericFormat.reset( format );
134}
135
136void QgsColorRampLegendNodeSettings::writeXml( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context ) const
137{
138 QDomElement settingsElement = doc.createElement( u"rampLegendSettings"_s );
139
140 settingsElement.setAttribute( u"useContinuousLegend"_s, mUseContinuousLegend );
141 settingsElement.setAttribute( u"minimumLabel"_s, mMinimumLabel );
142 settingsElement.setAttribute( u"maximumLabel"_s, mMaximumLabel );
143 settingsElement.setAttribute( u"prefix"_s, mPrefix );
144 settingsElement.setAttribute( u"suffix"_s, mSuffix );
145 settingsElement.setAttribute( u"direction"_s, static_cast< int >( mDirection ) );
146 settingsElement.setAttribute( u"orientation"_s, static_cast< int >( mOrientation ) );
147
148 QDomElement numericFormatElem = doc.createElement( u"numericFormat"_s );
149 mNumericFormat->writeXml( numericFormatElem, doc, context );
150 settingsElement.appendChild( numericFormatElem );
151
152 if ( mTextFormat.isValid() )
153 {
154 settingsElement.appendChild( mTextFormat.writeXml( doc, context ) );
155 }
156
157 element.appendChild( settingsElement );
158}
159
160void QgsColorRampLegendNodeSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
161{
162 const QDomElement settingsElement = element.firstChildElement( u"rampLegendSettings"_s );
163 if ( !settingsElement.isNull() )
164 {
165 mUseContinuousLegend = settingsElement.attribute( u"useContinuousLegend"_s, u"1"_s ).toInt();
166 mMinimumLabel = settingsElement.attribute( u"minimumLabel"_s );
167 mMaximumLabel = settingsElement.attribute( u"maximumLabel"_s );
168 mPrefix = settingsElement.attribute( u"prefix"_s );
169 mSuffix = settingsElement.attribute( u"suffix"_s );
170 mDirection = static_cast< QgsColorRampLegendNodeSettings::Direction >( settingsElement.attribute( u"direction"_s ).toInt() );
171 mOrientation = static_cast< Qt::Orientation >( settingsElement.attribute( u"orientation"_s, QString::number( Qt::Vertical ) ).toInt() );
172
173 const QDomNodeList numericFormatNodeList = settingsElement.elementsByTagName( u"numericFormat"_s );
174 if ( !numericFormatNodeList.isEmpty() )
175 {
176 const QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
177 mNumericFormat.reset( QgsApplication::numericFormatRegistry()->createFromXml( numericFormatElem, context ) );
178 }
179
180 if ( !settingsElement.firstChildElement( u"text-style"_s ).isNull() )
181 {
182 mTextFormat.readXml( settingsElement, context );
183 }
184 else
185 {
186 mTextFormat = QgsTextFormat();
187 }
188 }
189}
190
192{
193 return mPrefix;
194}
195
197{
198 mPrefix = prefix;
199}
200
202{
203 return mSuffix;
204}
205
207{
208 mSuffix = suffix;
209}
210
212{
213 return mTextFormat;
214}
215
217{
218 mTextFormat = format;
219}
220
222{
223 return mOrientation;
224}
225
227{
228 mOrientation = orientation;
229}
230
232{
233 return mUseContinuousLegend;
234}
235
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.