QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmcalculateexpression.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmcalculateexpression.cpp
3 ---------------------
4 begin : August 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
25
26QString QgsCalculateExpressionAlgorithm::name() const
27{
28 return u"calculateexpression"_s;
29}
30
31Qgis::ProcessingAlgorithmFlags QgsCalculateExpressionAlgorithm::flags() const
32{
34}
35
36QString QgsCalculateExpressionAlgorithm::displayName() const
37{
38 return QObject::tr( "Calculate expression" );
39}
40
41QStringList QgsCalculateExpressionAlgorithm::tags() const
42{
43 return QObject::tr( "evaluate,variable,store" ).split( ',' );
44}
45
46QString QgsCalculateExpressionAlgorithm::group() const
47{
48 return QObject::tr( "Modeler tools" );
49}
50
51QString QgsCalculateExpressionAlgorithm::groupId() const
52{
53 return u"modelertools"_s;
54}
55
56QString QgsCalculateExpressionAlgorithm::shortHelpString() const
57{
58 return QObject::tr( "This algorithm calculates the result of a QGIS expression and makes it available for use in other parts of the model." );
59}
60
61QString QgsCalculateExpressionAlgorithm::shortDescription() const
62{
63 return QObject::tr( "Calculates the result of a QGIS expression and makes it available for use in other parts of the model." );
64}
65
66QgsCalculateExpressionAlgorithm *QgsCalculateExpressionAlgorithm::createInstance() const
67{
68 return new QgsCalculateExpressionAlgorithm();
69}
70
71void QgsCalculateExpressionAlgorithm::initAlgorithm( const QVariantMap & )
72{
73 // possibly this should be a new dedicated parameter type for "QgsProcessingParameterVariant", as the values specified for the parameter will
74 // be whatever the model calculates as the result of the expression. But this works for now...
75 auto inputParameter = std::make_unique<QgsProcessingParameterString>( u"INPUT"_s, QObject::tr( "Input" ), QVariant(), false, false );
76 // we limit the available sources for this parameter to just precalculated expressions -- otherwise it's confusing if we allow users
77 // to enter a literal value for this parameter, as they could enter an expression in there and expect it to be evaluated.
78 inputParameter->setMetadata(
79 { QVariantMap( { { u"model_widget"_s, QVariantMap( { { u"accepted_sources"_s, QVariantList { static_cast<int>( Qgis::ProcessingModelChildParameterSource::Expression ) } } } ) } } )
80 }
81 );
82 addParameter( inputParameter.release() );
83
84 addOutput( new QgsProcessingOutputVariant( u"OUTPUT"_s, QObject::tr( "Value" ) ) );
85}
86
87QVariantMap QgsCalculateExpressionAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &, QgsProcessingFeedback * )
88{
89 const QVariant res = parameters.value( u"INPUT"_s );
90
91 QVariantMap outputs;
92 outputs.insert( u"OUTPUT"_s, res );
93 return outputs;
94}
95
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3680
@ Expression
Parameter value is taken from an expression, evaluated just before the algorithm runs.
Definition qgis.h:3922
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
Definition qgis.h:3654
@ SkipGenericModelLogging
When running as part of a model, the generic algorithm setup and results logging should be skipped.
Definition qgis.h:3665
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
A variant output for processing algorithms, capable of storing any QVariant value.