QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsprocessingoutputs.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingoutputs.cpp
3 -------------------------
4 begin : May 2017
5 copyright : (C) 2017 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 "qgsvariantutils.h"
21
22#include <QDir>
23#include <QString>
24#include <QUrl>
25
26using namespace Qt::StringLiterals;
27
32
33QString QgsProcessingOutputDefinition::valueAsString( const QVariant &value, QgsProcessingContext &, bool &ok ) const
34{
35 if ( QgsVariantUtils::isNull( value ) )
36 {
37 ok = true;
38 return QObject::tr( "NULL" );
39 }
40
41 if ( value.userType() == QMetaType::Type::QString )
42 {
43 ok = true;
44 return value.toString();
45 }
46 ok = false;
47 return QString();
48}
49
50QString QgsProcessingOutputDefinition::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
51{
52 return valueAsString( value, context, ok );
53}
54
56{
57 return QColor( 128, 128, 128 ); /* mid gray */
58}
59
64
69
74
76{
77 return QColor( 122, 0, 47 ); /* burgundy */
78}
79
83
85{
86 return QColor( 0, 180, 180 ); /* turquoise */
87}
88
92
96
98{
99 return QColor( 137, 150, 171 ); /* cold gray */
100}
101
105
106QString QgsProcessingOutputHtml::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
107{
108 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
109 {
110 ok = true;
111 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
112 }
113
114 return valueAsString( value, context, ok );
115}
116
118{
119 return QColor( 255, 131, 23 ); /* orange */
120}
121
125
126QString QgsProcessingOutputNumber::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
127{
128 ok = false;
129 switch ( value.userType() )
130 {
131 case QMetaType::Type::Int:
132 case QMetaType::Type::UInt:
133 case QMetaType::Type::LongLong:
134 case QMetaType::Type::ULongLong:
135 case QMetaType::Type::Double:
136 ok = true;
137 return value.toString();
138 default:
139 break;
140 }
141 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
142}
143
145{
146 return QColor( 34, 157, 214 ); /* blue */
147}
148
152
154{
155 return QColor( 255, 131, 23 ); /* orange */
156}
157
161
162QString QgsProcessingOutputBoolean::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
163{
164 ok = false;
165 if ( value.userType() == QMetaType::Type::Bool )
166 {
167 ok = true;
168 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
169 }
170 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
171}
172
174{
175 return QColor( 51, 201, 28 ); /* green */
176}
177
181
182QString QgsProcessingOutputFolder::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
183{
184 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
185 {
186 ok = true;
187 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
188 }
189
190 return valueAsString( value, context, ok );
191}
192
194{
195 return QColor( 80, 80, 80 ); /* dark gray */
196}
197
201
202QString QgsProcessingOutputFile::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
203{
204 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
205 {
206 ok = true;
207 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
208 }
209
210 return valueAsString( value, context, ok );
211}
212
214{
215 return QColor( 80, 80, 80 ); /* dark gray */
216}
217
221
223{
224 return typeName();
225}
226
228{
229 return QColor( 137, 150, 171 ); /* cold gray */
230}
231
235
237{
238 return typeName();
239}
240
241QString QgsProcessingOutputMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
242{
243 ok = false;
244 switch ( value.userType() )
245 {
246 case QMetaType::Type::QVariantList:
247 {
248 ok = true;
249 const QVariantList list = value.toList();
250
251 QStringList layerNames;
252 for ( const QVariant &v : list )
253 {
254 layerNames << v.toString();
255 }
256 return layerNames.join( ", "_L1 );
257 }
258
259 case QMetaType::Type::QStringList:
260 {
261 ok = true;
262 const QStringList list = value.toStringList();
263 return list.join( ", "_L1 );
264 }
265
266 default:
267 break;
268 }
269 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
270}
271
273{
274 return QColor( 137, 150, 171 ); /* cold gray */
275}
276
280
286
288{
289 return typeName();
290}
291
292QString QgsProcessingOutputVariant::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
293{
294 ok = false;
295 switch ( value.userType() )
296 {
297 case QMetaType::Type::Int:
298 case QMetaType::Type::UInt:
299 case QMetaType::Type::LongLong:
300 case QMetaType::Type::ULongLong:
301 case QMetaType::Type::Double:
302 ok = true;
303 return value.toString();
304 case QMetaType::Type::Bool:
305 ok = true;
306 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
307
308 case QMetaType::Type::QVariantList:
309 {
310 ok = true;
311 const QVariantList list = value.toList();
312
313 QStringList names;
314 for ( const QVariant &v : list )
315 {
316 names << v.toString();
317 }
318 return names.join( ", "_L1 );
319 }
320
321 case QMetaType::Type::QStringList:
322 {
323 ok = true;
324 const QStringList list = value.toStringList();
325 return list.join( ", "_L1 );
326 }
327
328 default:
329 break;
330 }
331 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
332}
333
ProcessingSourceType
Processing data source types.
Definition qgis.h:3590
Contains information about the context in which a processing algorithm is executed.
QgsProcessingOutputBoolean(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputNumber.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter output value (if possible).
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputConditionalBranch(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputConditionalBranch.
QString name() const
Returns the name of the output.
virtual QString valueAsFormattedString(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a HTML string version of the parameter output value (if possible).
virtual QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const
Returns a string version of the parameter output value (if possible).
QgsProcessingOutputDefinition(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputDefinition.
virtual QColor modelColor() const
Returns the color to use for the output in the model designer canvas.
QString mDescription
Output description.
QString description() const
Returns the description for the output.
QString valueAsFormattedString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a HTML string version of the parameter output value (if possible).
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputFile(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputFile.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputFolder(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputFolder.
QString valueAsFormattedString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a HTML string version of the parameter output value (if possible).
QgsProcessingOutputHtml(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputHtml.
QString valueAsFormattedString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a HTML string version of the parameter output value (if possible).
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
static QString typeName()
Returns the type name for the output class.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputMapLayer(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputMapLayer.
QString type() const override
Unique output type name.
static QString typeName()
Returns the type name for the output class.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputMultipleLayers(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputMultipleLayers.
QString type() const override
Unique output type name.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter output value (if possible).
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter output value (if possible).
QgsProcessingOutputNumber(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputNumber.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputPointCloudLayer(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputPointCloudLayer.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputRasterLayer(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputRasterLayer.
QgsProcessingOutputString(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputString.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
static QString typeName()
Returns the type name for the output class.
QgsProcessingOutputVariant(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputVariant.
QString type() const override
Unique output type name.
QString valueAsString(const QVariant &value, QgsProcessingContext &context, bool &ok) const override
Returns a string version of the parameter output value (if possible).
QgsProcessingOutputVectorLayer(const QString &name, const QString &description=QString(), Qgis::ProcessingSourceType type=Qgis::ProcessingSourceType::VectorAnyGeometry)
Constructor for QgsProcessingOutputVectorLayer.
QString type() const override
Unique output type name.
void setDataType(Qgis::ProcessingSourceType type)
Sets the layer type for the output layer.
Qgis::ProcessingSourceType dataType() const
Returns the layer type for the output layer.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
QgsProcessingOutputVectorTileLayer(const QString &name, const QString &description=QString())
Constructor for QgsProcessingOutputVectorTileLayer.
QColor modelColor() const override
Returns the color to use for the output in the model designer canvas.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.