QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#include "qgsnumericformat.h"
19#include "qgsapplication.h"
21#include "qgis.h"
22
27
29 : mUseContinuousLegend( other.mUseContinuousLegend )
30 , mMinimumLabel( other.mMinimumLabel )
31 , mMaximumLabel( other.mMaximumLabel )
32 , mPrefix( other.mPrefix )
33 , mSuffix( other.mSuffix )
34 , mDirection( other.mDirection )
35 , mNumericFormat( other.numericFormat()->clone() )
36 , mTextFormat( other.textFormat() )
37 , mOrientation( other.mOrientation )
38{
39
40}
41
43{
44 mUseContinuousLegend = other.mUseContinuousLegend;
45 mMinimumLabel = other.mMinimumLabel;
46 mMaximumLabel = other.mMaximumLabel;
47 mPrefix = other.mPrefix;
48 mSuffix = other.mSuffix;
49 mDirection = other.mDirection;
50 mNumericFormat.reset( other.numericFormat()->clone() );
51 mTextFormat = other.mTextFormat;
52 mOrientation = other.mOrientation;
53 return *this;
54}
55
57
62
67
69{
70 return mMinimumLabel;
71}
72
74{
75 mMinimumLabel = label;
76}
77
79{
80 return mMaximumLabel;
81}
82
84{
85 mMaximumLabel = label;
86}
87
89{
90 return mNumericFormat.get();
91}
92
94{
95 mNumericFormat.reset( format );
96}
97
98void QgsColorRampLegendNodeSettings::writeXml( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context ) const
99{
100 QDomElement settingsElement = doc.createElement( QStringLiteral( "rampLegendSettings" ) );
101
102 settingsElement.setAttribute( QStringLiteral( "useContinuousLegend" ), mUseContinuousLegend );
103 settingsElement.setAttribute( QStringLiteral( "minimumLabel" ), mMinimumLabel );
104 settingsElement.setAttribute( QStringLiteral( "maximumLabel" ), mMaximumLabel );
105 settingsElement.setAttribute( QStringLiteral( "prefix" ), mPrefix );
106 settingsElement.setAttribute( QStringLiteral( "suffix" ), mSuffix );
107 settingsElement.setAttribute( QStringLiteral( "direction" ), static_cast< int >( mDirection ) );
108 settingsElement.setAttribute( QStringLiteral( "orientation" ), static_cast< int >( mOrientation ) );
109
110 QDomElement numericFormatElem = doc.createElement( QStringLiteral( "numericFormat" ) );
111 mNumericFormat->writeXml( numericFormatElem, doc, context );
112 settingsElement.appendChild( numericFormatElem );
113
114 if ( mTextFormat.isValid() )
115 {
116 settingsElement.appendChild( mTextFormat.writeXml( doc, context ) );
117 }
118
119 element.appendChild( settingsElement );
120}
121
122void QgsColorRampLegendNodeSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
123{
124 const QDomElement settingsElement = element.firstChildElement( QStringLiteral( "rampLegendSettings" ) );
125 if ( !settingsElement.isNull() )
126 {
127 mUseContinuousLegend = settingsElement.attribute( QStringLiteral( "useContinuousLegend" ), QStringLiteral( "1" ) ).toInt( );
128 mMinimumLabel = settingsElement.attribute( QStringLiteral( "minimumLabel" ) );
129 mMaximumLabel = settingsElement.attribute( QStringLiteral( "maximumLabel" ) );
130 mPrefix = settingsElement.attribute( QStringLiteral( "prefix" ) );
131 mSuffix = settingsElement.attribute( QStringLiteral( "suffix" ) );
132 mDirection = static_cast< QgsColorRampLegendNodeSettings::Direction >( settingsElement.attribute( QStringLiteral( "direction" ) ).toInt() );
133 mOrientation = static_cast< Qt::Orientation >( settingsElement.attribute( QStringLiteral( "orientation" ), QString::number( Qt::Vertical ) ).toInt() );
134
135 const QDomNodeList numericFormatNodeList = settingsElement.elementsByTagName( QStringLiteral( "numericFormat" ) );
136 if ( !numericFormatNodeList.isEmpty() )
137 {
138 const QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
139 mNumericFormat.reset( QgsApplication::numericFormatRegistry()->createFromXml( numericFormatElem, context ) );
140 }
141
142 if ( !settingsElement.firstChildElement( QStringLiteral( "text-style" ) ).isNull() )
143 {
144 mTextFormat.readXml( settingsElement, context );
145 }
146 else
147 {
148 mTextFormat = QgsTextFormat();
149 }
150 }
151}
152
154{
155 return mPrefix;
156}
157
158void QgsColorRampLegendNodeSettings::setPrefix( const QString &prefix )
159{
160 mPrefix = prefix;
161}
162
164{
165 return mSuffix;
166}
167
168void QgsColorRampLegendNodeSettings::setSuffix( const QString &suffix )
169{
170 mSuffix = suffix;
171}
172
174{
175 return mTextFormat;
176}
177
179{
180 mTextFormat = format;
181}
182
184{
185 return mOrientation;
186}
187
188void QgsColorRampLegendNodeSettings::setOrientation( Qt::Orientation orientation )
189{
190 mOrientation = orientation;
191}
192
194{
195 return mUseContinuousLegend;
196}
197
199{
200 mUseContinuousLegend = useContinuousLegend;
201}
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
A numeric formatter which returns a simple text representation of a value.
Settings for a color ramp legend node.
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.
QgsNumericFormat * createFromXml(const QDomElement &element, const QgsReadWriteContext &context) const
Creates a new numeric format from an XML element.
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
virtual QgsNumericFormat * clone() const =0
Clones the format, returning a new object.
The class is used as a container of context for various read/write operations on other objects.
Container for all settings relating to text rendering.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool isValid() const
Returns true if the format is valid.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.