QGIS API Documentation 4.3.0-Master (0cfde48c85b)
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 false;
58}
59
61{
62 return QColor( 128, 128, 128 ); /* mid gray */
63}
64
69
74
79
81{
82 return QColor( 122, 0, 47 ); /* burgundy */
83}
84
89
91{
92 return true;
93}
94
98
100{
101 return QColor( 0, 180, 180 ); /* turquoise */
102}
103
108
110{
111 return true;
112}
113
117
122
124{
125 return true;
126}
127
131
133{
134 return QColor( 137, 150, 171 ); /* cold gray */
135}
136
141
143{
144 return true;
145}
146
150
151QString QgsProcessingOutputHtml::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
152{
153 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
154 {
155 ok = true;
156 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
157 }
158
159 return valueAsString( value, context, ok );
160}
161
163{
164 return QColor( 255, 131, 23 ); /* orange */
165}
166
171
175
176QString QgsProcessingOutputNumber::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
177{
178 ok = false;
179 switch ( value.userType() )
180 {
181 case QMetaType::Type::Int:
182 case QMetaType::Type::UInt:
183 case QMetaType::Type::LongLong:
184 case QMetaType::Type::ULongLong:
185 case QMetaType::Type::Double:
186 ok = true;
187 return value.toString();
188 default:
189 break;
190 }
191 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
192}
193
195{
196 return QColor( 34, 157, 214 ); /* blue */
197}
198
203
207
209{
210 return QColor( 255, 131, 23 ); /* orange */
211}
212
217
221
222QString QgsProcessingOutputBoolean::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
223{
224 ok = false;
225 if ( value.userType() == QMetaType::Type::Bool )
226 {
227 ok = true;
228 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
229 }
230 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
231}
232
234{
235 return QColor( 51, 201, 28 ); /* green */
236}
237
242
246
247QString QgsProcessingOutputFolder::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
248{
249 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
250 {
251 ok = true;
252 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
253 }
254
255 return valueAsString( value, context, ok );
256}
257
259{
260 return QColor( 80, 80, 80 ); /* dark gray */
261}
262
267
271
272QString QgsProcessingOutputFile::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
273{
274 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
275 {
276 ok = true;
277 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
278 }
279
280 return valueAsString( value, context, ok );
281}
282
284{
285 return QColor( 80, 80, 80 ); /* dark gray */
286}
287
292
296
298{
299 return typeName();
300}
301
303{
304 return true;
305}
306
308{
309 return QColor( 137, 150, 171 ); /* cold gray */
310}
311
316
320
325
327{
328 return typeName();
329}
330
331QString QgsProcessingOutputMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
332{
333 ok = false;
334 switch ( value.userType() )
335 {
336 case QMetaType::Type::QVariantList:
337 {
338 ok = true;
339 const QVariantList list = value.toList();
340
341 QStringList layerNames;
342 for ( const QVariant &v : list )
343 {
344 layerNames << v.toString();
345 }
346 return layerNames.join( ", "_L1 );
347 }
348
349 case QMetaType::Type::QStringList:
350 {
351 ok = true;
352 const QStringList list = value.toStringList();
353 return list.join( ", "_L1 );
354 }
355
356 default:
357 break;
358 }
359 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
360}
361
363{
364 return true;
365}
366
368{
369 return QColor( 137, 150, 171 ); /* cold gray */
370}
371
375
380
384
389
391{
392 return typeName();
393}
394
395QString QgsProcessingOutputVariant::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
396{
397 ok = false;
398 switch ( value.userType() )
399 {
400 case QMetaType::Type::Int:
401 case QMetaType::Type::UInt:
402 case QMetaType::Type::LongLong:
403 case QMetaType::Type::ULongLong:
404 case QMetaType::Type::Double:
405 ok = true;
406 return value.toString();
407 case QMetaType::Type::Bool:
408 ok = true;
409 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
410
411 case QMetaType::Type::QVariantList:
412 {
413 ok = true;
414 const QVariantList list = value.toList();
415
416 QStringList names;
417 for ( const QVariant &v : list )
418 {
419 names << v.toString();
420 }
421 return names.join( ", "_L1 );
422 }
423
424 case QMetaType::Type::QStringList:
425 {
426 ok = true;
427 const QStringList list = value.toStringList();
428 return list.join( ", "_L1 );
429 }
430
431 default:
432 break;
433 }
434 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
435}
ProcessingSourceType
Processing data source types.
Definition qgis.h:3769
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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).
virtual bool isMapLayer() const
Returns true if the output is a map layer type.
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).
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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).
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
bool isMapLayer() const override
Returns true if the output is a map layer type.
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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).
bool isMapLayer() const override
Returns true if the output is a map layer type.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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.
bool isMapLayer() const override
Returns true if the output is a map layer type.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
bool isMapLayer() const override
Returns true if the output is a map layer type.
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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).
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
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.
bool isMapLayer() const override
Returns true if the output is a map layer type.
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.
bool isMapLayer() const override
Returns true if the output is a map layer type.
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.
QgsProcessingOutputDefinition * clone() const override
Creates a clone of the output definition.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.