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