QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
numericformats
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
#include <QString>
24
25
#include "moc_qgsnumericformat.cpp"
26
27
using namespace
Qt::StringLiterals;
28
29
QgsNumericFormatContext::QgsNumericFormatContext
()
30
{
31
const
QLocale l;
32
// With Qt6, these methods return strings to be prepared
33
// for utf-16 surrogates
34
// Do we care? If yes, we need to switch all members of QgsNumericFormatContext to QString
35
mThousandsSep = l.groupSeparator().at( 0 );
36
mDecimalSep = l.decimalPoint().at( 0 );
37
mPercent = l.percent().at( 0 );
38
mZeroDigit = l.zeroDigit().at( 0 );
39
mNegativeSign = l.negativeSign().at( 0 );
40
mPositiveSign = l.positiveSign().at( 0 );
41
mExponential = l.exponential().at( 0 );
42
}
43
44
QgsExpressionContext
QgsNumericFormatContext::expressionContext
()
const
45
{
46
return
mExpressionContext;
47
}
48
49
void
QgsNumericFormatContext::setExpressionContext
(
const
QgsExpressionContext
&context )
50
{
51
mExpressionContext = context;
52
}
53
54
int
QgsNumericFormat::sortKey
()
55
{
56
return
DEFAULT_SORT_KEY
;
57
}
58
59
double
QgsNumericFormat::suggestSampleValue
()
const
60
{
61
return
1234.56789123456;
62
}
63
64
void
QgsNumericFormat::writeXml
( QDomElement &element, QDomDocument &document,
const
QgsReadWriteContext
&context )
const
65
{
66
const
QVariantMap config =
configuration
( context );
67
const
QDomElement configElement =
QgsXmlUtils::writeVariant
( config, document );
68
element.appendChild( configElement );
69
element.setAttribute( u
"id"
_s,
id
() );
70
}
71
72
bool
QgsNumericFormat::operator==
(
const
QgsNumericFormat
&other )
const
73
{
74
return
id
() == other.
id
() &&
configuration
(
QgsReadWriteContext
() ) == other.
configuration
(
QgsReadWriteContext
() );
75
}
76
77
bool
QgsNumericFormat::operator!=
(
const
QgsNumericFormat
&other )
const
78
{
79
return
!
operator==
( other );
80
}
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition
qgsexpressioncontext.h:491
QgsNumericFormatContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context to use when evaluating QgsExpressions.
Definition
qgsnumericformat.cpp:49
QgsNumericFormatContext::QgsNumericFormatContext
QgsNumericFormatContext()
Constructor for QgsNumericFormatContext.
Definition
qgsnumericformat.cpp:29
QgsNumericFormatContext::expressionContext
QgsExpressionContext expressionContext() const
Returns the expression context to use when evaluating QgsExpressions.
Definition
qgsnumericformat.cpp:44
QgsNumericFormat::DEFAULT_SORT_KEY
static constexpr int DEFAULT_SORT_KEY
Definition
qgsnumericformat.h:323
QgsNumericFormat::sortKey
virtual int sortKey()
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
Definition
qgsnumericformat.cpp:54
QgsNumericFormat::operator!=
bool operator!=(const QgsNumericFormat &other) const
Definition
qgsnumericformat.cpp:77
QgsNumericFormat::QgsNumericFormat
QgsNumericFormat()=default
QgsNumericFormat::id
virtual QString id() const =0
Returns a unique id for this numeric format.
QgsNumericFormat::writeXml
void writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes the format to an XML element.
Definition
qgsnumericformat.cpp:64
QgsNumericFormat::operator==
bool operator==(const QgsNumericFormat &other) const
Definition
qgsnumericformat.cpp:72
QgsNumericFormat::suggestSampleValue
virtual double suggestSampleValue() const
Returns a suggested sample value which nicely represents the current format configuration.
Definition
qgsnumericformat.cpp:59
QgsNumericFormat::configuration
virtual QVariantMap configuration(const QgsReadWriteContext &context) const =0
Returns the current configuration of the formatter.
QgsReadWriteContext
A container for the context for various read/write operations on objects.
Definition
qgsreadwritecontext.h:38
QgsXmlUtils::writeVariant
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
Definition
qgsxmlutils.cpp:146
qgsnumericformat.h
qgsreadwritecontext.h
qgsxmlutils.h
Generated on
for QGIS API Documentation by
1.17.0