QGIS API Documentation 4.1.0-Master (31622b25bb0)
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
86{
87 return true;
88}
89
93
95{
96 return QColor( 0, 180, 180 ); /* turquoise */
97}
98
100{
101 return true;
102}
103
107
109{
110 return true;
111}
112
116
118{
119 return QColor( 137, 150, 171 ); /* cold gray */
120}
121
123{
124 return true;
125}
126
130
131QString QgsProcessingOutputHtml::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
132{
133 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
134 {
135 ok = true;
136 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
137 }
138
139 return valueAsString( value, context, ok );
140}
141
143{
144 return QColor( 255, 131, 23 ); /* orange */
145}
146
150
151QString QgsProcessingOutputNumber::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
152{
153 ok = false;
154 switch ( value.userType() )
155 {
156 case QMetaType::Type::Int:
157 case QMetaType::Type::UInt:
158 case QMetaType::Type::LongLong:
159 case QMetaType::Type::ULongLong:
160 case QMetaType::Type::Double:
161 ok = true;
162 return value.toString();
163 default:
164 break;
165 }
166 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
167}
168
170{
171 return QColor( 34, 157, 214 ); /* blue */
172}
173
177
179{
180 return QColor( 255, 131, 23 ); /* orange */
181}
182
186
187QString QgsProcessingOutputBoolean::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
188{
189 ok = false;
190 if ( value.userType() == QMetaType::Type::Bool )
191 {
192 ok = true;
193 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
194 }
195 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
196}
197
199{
200 return QColor( 51, 201, 28 ); /* green */
201}
202
206
207QString QgsProcessingOutputFolder::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
208{
209 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
210 {
211 ok = true;
212 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
213 }
214
215 return valueAsString( value, context, ok );
216}
217
219{
220 return QColor( 80, 80, 80 ); /* dark gray */
221}
222
226
227QString QgsProcessingOutputFile::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
228{
229 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
230 {
231 ok = true;
232 return u"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
233 }
234
235 return valueAsString( value, context, ok );
236}
237
239{
240 return QColor( 80, 80, 80 ); /* dark gray */
241}
242
246
248{
249 return typeName();
250}
251
253{
254 return true;
255}
256
258{
259 return QColor( 137, 150, 171 ); /* cold gray */
260}
261
265
267{
268 return typeName();
269}
270
271QString QgsProcessingOutputMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
272{
273 ok = false;
274 switch ( value.userType() )
275 {
276 case QMetaType::Type::QVariantList:
277 {
278 ok = true;
279 const QVariantList list = value.toList();
280
281 QStringList layerNames;
282 for ( const QVariant &v : list )
283 {
284 layerNames << v.toString();
285 }
286 return layerNames.join( ", "_L1 );
287 }
288
289 case QMetaType::Type::QStringList:
290 {
291 ok = true;
292 const QStringList list = value.toStringList();
293 return list.join( ", "_L1 );
294 }
295
296 default:
297 break;
298 }
299 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
300}
301
303{
304 return true;
305}
306
308{
309 return QColor( 137, 150, 171 ); /* cold gray */
310}
311
315
319
321{
322 return typeName();
323}
324
325QString QgsProcessingOutputVariant::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
326{
327 ok = false;
328 switch ( value.userType() )
329 {
330 case QMetaType::Type::Int:
331 case QMetaType::Type::UInt:
332 case QMetaType::Type::LongLong:
333 case QMetaType::Type::ULongLong:
334 case QMetaType::Type::Double:
335 ok = true;
336 return value.toString();
337 case QMetaType::Type::Bool:
338 ok = true;
339 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
340
341 case QMetaType::Type::QVariantList:
342 {
343 ok = true;
344 const QVariantList list = value.toList();
345
346 QStringList names;
347 for ( const QVariant &v : list )
348 {
349 names << v.toString();
350 }
351 return names.join( ", "_L1 );
352 }
353
354 case QMetaType::Type::QStringList:
355 {
356 ok = true;
357 const QStringList list = value.toStringList();
358 return list.join( ", "_L1 );
359 }
360
361 default:
362 break;
363 }
364 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
365}
ProcessingSourceType
Processing data source types.
Definition qgis.h:3712
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).
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).
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.
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.
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.
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.
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.
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.
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.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.