QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsnumericformat.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsnumericformat.cpp
3 -------------------
4 begin : January 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include "qgsnumericformat.h"
18
19#include "qgsreadwritecontext.h"
20#include "qgsxmlutils.h"
21
22#include <QLocale>
23
24#include "moc_qgsnumericformat.cpp"
25
27{
28 const QLocale l;
29#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
30 mThousandsSep = l.groupSeparator();
31 mDecimalSep = l.decimalPoint();
32 mPercent = l.percent();
33 mZeroDigit = l.zeroDigit();
34 mNegativeSign = l.negativeSign();
35 mPositiveSign = l.positiveSign();
36 mExponential = l.exponential();
37#else
38 // With Qt6, these methods return strings to be prepared
39 // for utf-16 surrogates
40 // Do we care? If yes, we need to switch all members of QgsNumericFormatContext to QString
41 mThousandsSep = l.groupSeparator().at( 0 );
42 mDecimalSep = l.decimalPoint().at( 0 );
43 mPercent = l.percent().at( 0 );
44 mZeroDigit = l.zeroDigit().at( 0 );
45 mNegativeSign = l.negativeSign().at( 0 );
46 mPositiveSign = l.positiveSign().at( 0 );
47 mExponential = l.exponential().at( 0 );
48#endif
49}
50
52{
53 return mExpressionContext;
54}
55
57{
58 mExpressionContext = context;
59}
60
65
67{
68 return 1234.56789123456;
69}
70
71void QgsNumericFormat::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const
72{
73 const QVariantMap config = configuration( context );
74 const QDomElement configElement = QgsXmlUtils::writeVariant( config, document );
75 element.appendChild( configElement );
76 element.setAttribute( QStringLiteral( "id" ), id() );
77}
78
80{
81 return id() == other.id() && configuration( QgsReadWriteContext() ) == other.configuration( QgsReadWriteContext() );
82}
83
85{
86 return !operator==( other );
87}
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context to use when evaluating QgsExpressions.
QgsNumericFormatContext()
Constructor for QgsNumericFormatContext.
QgsExpressionContext expressionContext() const
Returns the expression context to use when evaluating QgsExpressions.
static constexpr int DEFAULT_SORT_KEY
virtual int sortKey()
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
bool operator!=(const QgsNumericFormat &other) const
QgsNumericFormat()=default
virtual QString id() const =0
Returns a unique id for this numeric format.
void writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the format to an XML element.
bool operator==(const QgsNumericFormat &other) const
virtual double suggestSampleValue() const
Returns a suggested sample value which nicely represents the current format configuration.
virtual QVariantMap configuration(const QgsReadWriteContext &context) const =0
Returns the current configuration of the formatter.
A container for the context for various read/write operations on objects.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.