QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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{
36}
37
38QString QgsSetProjectVariableAlgorithm::displayName() const
39{
40 return QObject::tr( "Set project variable" );
41}
42
43QStringList QgsSetProjectVariableAlgorithm::tags() const
44{
45 return QObject::tr( "expression" ).split( ',' );
46}
47
48QString QgsSetProjectVariableAlgorithm::group() const
49{
50 return QObject::tr( "Modeler tools" );
51}
52
53QString QgsSetProjectVariableAlgorithm::groupId() const
54{
55 return u"modelertools"_s;
56}
57
58QString QgsSetProjectVariableAlgorithm::shortDescription() const
59{
60 return QObject::tr( "Sets an expression variable for the current project." );
61}
62
63QString QgsSetProjectVariableAlgorithm::shortHelpString() const
64{
65 return QObject::tr( "This algorithm sets an expression variable for the current project." );
66}
67
68QgsSetProjectVariableAlgorithm *QgsSetProjectVariableAlgorithm::createInstance() const
69{
70 return new QgsSetProjectVariableAlgorithm();
71}
72
73bool QgsSetProjectVariableAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
74{
75 // this is all nice and quick, we can (and should) do it in the main thread without issue
76 const QString name = parameterAsString( parameters, u"NAME"_s, context );
77 const QString value = parameterAsString( parameters, u"VALUE"_s, context );
78
79 if ( name.isEmpty() )
80 throw QgsProcessingException( QObject::tr( "Variable name cannot be empty" ) );
81
83 feedback->pushInfo( QObject::tr( "Set variable \'%1\' to \'%2\'" ).arg( name, value ) );
84
85 return true;
86}
87
88void QgsSetProjectVariableAlgorithm::initAlgorithm( const QVariantMap & )
89{
90 addParameter( new QgsProcessingParameterString( u"NAME"_s, QObject::tr( "Variable name" ) ) );
91 addParameter( new QgsProcessingParameterString( u"VALUE"_s, QObject::tr( "Variable value" ) ) );
92}
93
94QVariantMap QgsSetProjectVariableAlgorithm::processAlgorithm( const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * )
95{
96 return QVariantMap();
97}
98
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3724
@ NotAvailableInStandaloneTool
Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms wh...
Definition qgis.h:3710
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
Definition qgis.h:3698
@ SkipGenericModelLogging
When running as part of a model, the generic algorithm setup and results logging should be skipped.
Definition qgis.h:3709
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.