QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmsetvariable.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmsetvariable.cpp
3 ---------------------
4 begin : June 2020
5 copyright : (C) 2020 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
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27
28QString QgsSetProjectVariableAlgorithm::name() const
29{
30 return u"setprojectvariable"_s;
31}
32
33Qgis::ProcessingAlgorithmFlags QgsSetProjectVariableAlgorithm::flags() const
34{
38}
39
40QString QgsSetProjectVariableAlgorithm::displayName() const
41{
42 return QObject::tr( "Set project variable" );
43}
44
45QStringList QgsSetProjectVariableAlgorithm::tags() const
46{
47 return QObject::tr( "expression" ).split( ',' );
48}
49
50QString QgsSetProjectVariableAlgorithm::group() const
51{
52 return QObject::tr( "Modeler tools" );
53}
54
55QString QgsSetProjectVariableAlgorithm::groupId() const
56{
57 return u"modelertools"_s;
58}
59
60QString QgsSetProjectVariableAlgorithm::shortDescription() const
61{
62 return QObject::tr( "Sets an expression variable for the current project." );
63}
64
65QString QgsSetProjectVariableAlgorithm::shortHelpString() const
66{
67 return QObject::tr( "This algorithm sets an expression variable for the current project." );
68}
69
70QgsSetProjectVariableAlgorithm *QgsSetProjectVariableAlgorithm::createInstance() const
71{
72 return new QgsSetProjectVariableAlgorithm();
73}
74
75bool QgsSetProjectVariableAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
76{
77 // this is all nice and quick, we can (and should) do it in the main thread without issue
78 const QString name = parameterAsString( parameters, u"NAME"_s, context );
79 const QString value = parameterAsString( parameters, u"VALUE"_s, context );
80
81 if ( name.isEmpty() )
82 throw QgsProcessingException( QObject::tr( "Variable name cannot be empty" ) );
83
85 feedback->pushInfo( QObject::tr( "Set variable \'%1\' to \'%2\'" ).arg( name, value ) );
86
87 return true;
88}
89
90void QgsSetProjectVariableAlgorithm::initAlgorithm( const QVariantMap & )
91{
92 addParameter( new QgsProcessingParameterString( u"NAME"_s, QObject::tr( "Variable name" ) ) );
93 addParameter( new QgsProcessingParameterString( u"VALUE"_s, QObject::tr( "Variable value" ) ) );
94}
95
96QVariantMap QgsSetProjectVariableAlgorithm::processAlgorithm( const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * )
97{
98 return QVariantMap();
99}
100
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3680
@ NotAvailableInStandaloneTool
Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms wh...
Definition qgis.h:3666
@ 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
static void setProjectVariable(QgsProject *project, const QString &name, const QVariant &value)
Sets a project context variable.
Contains information about the context in which a processing algorithm is executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A string parameter for processing algorithms.