QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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
24
26{
27 return QStringLiteral( "expression" );
28}
29
31{
32 return QObject::tr( "Custom Expression" );
33}
34
39
41{
42 QgsExpressionContext expContext = context.expressionContext();
43 expContext.setOriginalValueVariable( value );
44
45 return mExpression.evaluate( &expContext ).toString();
46}
47
52
54{
55 auto res = std::make_unique< QgsExpressionBasedNumericFormat >();
56 res->mExpression = QgsExpression( configuration.value( QStringLiteral( "expression" ), QStringLiteral( "@value" ) ).toString() );
57 return res.release();
58}
59
61{
62 QVariantMap res;
63 res.insert( QStringLiteral( "expression" ), mExpression.expression() );
64 return res;
65}
66
68{
69 mExpression = QgsExpression( expression );
70}
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.