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