QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
processing
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
18
#include "
qgsalgorithmcalculateexpression.h
"
19
20
#include <QString>
21
22
using namespace
Qt::StringLiterals;
23
25
26
QString QgsCalculateExpressionAlgorithm::name()
const
27
{
28
return
u
"calculateexpression"
_s;
29
}
30
31
Qgis::ProcessingAlgorithmFlags
QgsCalculateExpressionAlgorithm::flags()
const
32
{
33
return
Qgis::ProcessingAlgorithmFlag::HideFromToolbox
|
Qgis::ProcessingAlgorithmFlag::SkipGenericModelLogging
;
34
}
35
36
QString QgsCalculateExpressionAlgorithm::displayName()
const
37
{
38
return
QObject::tr(
"Calculate expression"
);
39
}
40
41
QStringList QgsCalculateExpressionAlgorithm::tags()
const
42
{
43
return
QObject::tr(
"evaluate,variable,store"
).split(
','
);
44
}
45
46
QString QgsCalculateExpressionAlgorithm::group()
const
47
{
48
return
QObject::tr(
"Modeler tools"
);
49
}
50
51
QString QgsCalculateExpressionAlgorithm::groupId()
const
52
{
53
return
u
"modelertools"
_s;
54
}
55
56
QString 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
61
QString 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
66
QgsCalculateExpressionAlgorithm *QgsCalculateExpressionAlgorithm::createInstance()
const
67
{
68
return
new
QgsCalculateExpressionAlgorithm();
69
}
70
71
void
QgsCalculateExpressionAlgorithm::initAlgorithm(
const
QVariantMap & )
72
{
73
QGS_MARK_ALGORITHM_SOURCE
74
75
// possibly this should be a new dedicated parameter type for "QgsProcessingParameterVariant", as the values specified for the parameter will
76
// be whatever the model calculates as the result of the expression. But this works for now...
77
auto
inputParameter = std::make_unique<QgsProcessingParameterString>( u
"INPUT"
_s, QObject::tr(
"Input"
), QVariant(),
false
,
false
);
78
// we limit the available sources for this parameter to just precalculated expressions -- otherwise it's confusing if we allow users
79
// to enter a literal value for this parameter, as they could enter an expression in there and expect it to be evaluated.
80
inputParameter->setMetadata(
81
{ QVariantMap( { { u
"model_widget"
_s, QVariantMap( { { u
"accepted_sources"
_s, QVariantList {
static_cast<
int
>
(
Qgis::ProcessingModelChildParameterSource::Expression
) } } } ) } } ) }
82
);
83
addParameter( inputParameter.release() );
84
85
addOutput(
new
QgsProcessingOutputVariant
( u
"OUTPUT"
_s, QObject::tr(
"Value"
) ) );
86
}
87
88
QVariantMap QgsCalculateExpressionAlgorithm::processAlgorithm(
const
QVariantMap ¶meters,
QgsProcessingContext
&,
QgsProcessingFeedback
* )
89
{
90
const
QVariant res = parameters.value( u
"INPUT"
_s );
91
92
QVariantMap outputs;
93
outputs.insert( u
"OUTPUT"
_s, res );
94
return
outputs;
95
}
96
Qgis::ProcessingAlgorithmFlags
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition
qgis.h:3848
Qgis::ProcessingModelChildParameterSource::Expression
@ Expression
Parameter value is taken from an expression, evaluated just before the algorithm runs.
Definition
qgis.h:4114
Qgis::ProcessingAlgorithmFlag::HideFromToolbox
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
Definition
qgis.h:3822
Qgis::ProcessingAlgorithmFlag::SkipGenericModelLogging
@ SkipGenericModelLogging
When running as part of a model, the generic algorithm setup and results logging should be skipped.
Definition
qgis.h:3833
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition
qgsprocessingcontext.h:45
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition
qgsprocessingfeedback.h:40
QgsProcessingOutputVariant
A variant output for processing algorithms, capable of storing any QVariant value.
Definition
qgsprocessingoutputs.h:381
qgsalgorithmcalculateexpression.h
Generated on
for QGIS API Documentation by
1.17.0