QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
17
18#include "qgis.h"
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
28
30{
31 return u"expression"_s;
32}
33
35{
36 return QObject::tr( "Custom Expression" );
37}
38
43
45{
46 QgsExpressionContext expContext = context.expressionContext();
47 expContext.setOriginalValueVariable( value );
48
49 return mExpression.evaluate( &expContext ).toString();
50}
51
56
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
65{
66 QVariantMap res;
67 res.insert( u"expression"_s, mExpression.expression() );
68 return res;
69}
70
72{
73 mExpression = QgsExpression( expression );
74}
QString expression() const
Returns the expression used to calculate the text representation of a value.
QVariantMap configuration(const QgsReadWriteContext &context) const override
Returns the current configuration of the formatter.
QString visibleName() const override
Returns the translated, user-visible name for this format.
void setExpression(const QString &expression)
Sets the expression used to calculate the text representation of a value.
int sortKey() override
Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
QString formatDouble(double value, const QgsNumericFormatContext &context) const override
Returns a formatted string representation of a numeric double value.
QString id() const override
Returns a unique id for this numeric format.
QgsNumericFormat * create(const QVariantMap &configuration, const QgsReadWriteContext &context) const override
Creates a new copy of the format, using the supplied configuration.
QgsNumericFormat * clone() const override
Clones the format, returning a new object.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
A context for numeric formats.
QgsExpressionContext expressionContext() const
Returns the expression context to use when evaluating QgsExpressions.
QgsNumericFormat()=default
A container for the context for various read/write operations on objects.