QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
numericformats
qgsexpressionbasednumericformat.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsexpressionbasednumericformat.cpp
3
--------------------------
4
begin : August 2024
5
copyright : (C) 2024 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
16
#include "
qgsexpressionbasednumericformat.h
"
17
18
#include "
qgis.h
"
19
20
#include <QString>
21
22
using namespace
Qt::StringLiterals;
23
24
QgsExpressionBasedNumericFormat::QgsExpressionBasedNumericFormat
()
25
{
26
setExpression
( u
"@value"
_s );
27
}
28
29
QString
QgsExpressionBasedNumericFormat::id
()
const
30
{
31
return
u
"expression"
_s;
32
}
33
34
QString
QgsExpressionBasedNumericFormat::visibleName
()
const
35
{
36
return
QObject::tr(
"Custom Expression"
);
37
}
38
39
int
QgsExpressionBasedNumericFormat::sortKey
()
40
{
41
return
1;
42
}
43
44
QString
QgsExpressionBasedNumericFormat::formatDouble
(
double
value,
const
QgsNumericFormatContext
&context )
const
45
{
46
QgsExpressionContext
expContext = context.
expressionContext
();
47
expContext.
setOriginalValueVariable
( value );
48
49
return
mExpression.evaluate( &expContext ).toString();
50
}
51
52
QgsNumericFormat
*
QgsExpressionBasedNumericFormat::clone
()
const
53
{
54
return
new
QgsExpressionBasedNumericFormat
( *
this
);
55
}
56
57
QgsNumericFormat
*
QgsExpressionBasedNumericFormat::create
(
const
QVariantMap &
configuration
,
const
QgsReadWriteContext
& )
const
58
{
59
auto
res = std::make_unique< QgsExpressionBasedNumericFormat >();
60
res->mExpression =
QgsExpression
(
configuration
.value( u
"expression"
_s, u
"@value"
_s ).toString() );
61
return
res.release();
62
}
63
64
QVariantMap
QgsExpressionBasedNumericFormat::configuration
(
const
QgsReadWriteContext
& )
const
65
{
66
QVariantMap res;
67
res.insert( u
"expression"
_s, mExpression.expression() );
68
return
res;
69
}
70
71
void
QgsExpressionBasedNumericFormat::setExpression
(
const
QString &
expression
)
72
{
73
mExpression =
QgsExpression
(
expression
);
74
}
QgsExpressionBasedNumericFormat::expression
QString expression() const
Returns the expression used to calculate the text representation of a value.
Definition
qgsexpressionbasednumericformat.h:56
QgsExpressionBasedNumericFormat::configuration
QVariantMap configuration(const QgsReadWriteContext &context) const override
Returns the current configuration of the formatter.
Definition
qgsexpressionbasednumericformat.cpp:64
QgsExpressionBasedNumericFormat::QgsExpressionBasedNumericFormat
QgsExpressionBasedNumericFormat()
Definition
qgsexpressionbasednumericformat.cpp:24
QgsExpressionBasedNumericFormat::visibleName
QString visibleName() const override
Returns the translated, user-visible name for this format.
Definition
qgsexpressionbasednumericformat.cpp:34
QgsExpressionBasedNumericFormat::setExpression
void setExpression(const QString &expression)
Sets the expression used to calculate the text representation of a value.
Definition
qgsexpressionbasednumericformat.cpp:71
QgsExpressionBasedNumericFormat::sortKey
int sortKey() override
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
Definition
qgsexpressionbasednumericformat.cpp:39
QgsExpressionBasedNumericFormat::formatDouble
QString formatDouble(double value, const QgsNumericFormatContext &context) const override
Returns a formatted string representation of a numeric double value.
Definition
qgsexpressionbasednumericformat.cpp:44
QgsExpressionBasedNumericFormat::id
QString id() const override
Returns a unique id for this numeric format.
Definition
qgsexpressionbasednumericformat.cpp:29
QgsExpressionBasedNumericFormat::create
QgsNumericFormat * create(const QVariantMap &configuration, const QgsReadWriteContext &context) const override
Creates a new copy of the format, using the supplied configuration.
Definition
qgsexpressionbasednumericformat.cpp:57
QgsExpressionBasedNumericFormat::clone
QgsNumericFormat * clone() const override
Clones the format, returning a new object.
Definition
qgsexpressionbasednumericformat.cpp:52
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition
qgsexpressioncontext.h:491
QgsExpressionContext::setOriginalValueVariable
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Definition
qgsexpressioncontext.cpp:754
QgsExpression
Handles parsing and evaluation of expressions (formerly called "search strings").
Definition
qgsexpression.h:198
QgsNumericFormatContext
A context for numeric formats.
Definition
qgsnumericformat.h:35
QgsNumericFormatContext::expressionContext
QgsExpressionContext expressionContext() const
Returns the expression context to use when evaluating QgsExpressions.
Definition
qgsnumericformat.cpp:44
QgsNumericFormat::QgsNumericFormat
QgsNumericFormat()=default
QgsReadWriteContext
A container for the context for various read/write operations on objects.
Definition
qgsreadwritecontext.h:38
qgis.h
qgsexpressionbasednumericformat.h
Generated on
for QGIS API Documentation by
1.17.0