QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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 <QUrl>
24
29
30QString QgsProcessingOutputDefinition::valueAsString( const QVariant &value, QgsProcessingContext &, bool &ok ) const
31{
32 if ( QgsVariantUtils::isNull( value ) )
33 {
34 ok = true;
35 return QObject::tr( "NULL" );
36 }
37
38 if ( value.userType() == QMetaType::Type::QString )
39 {
40 ok = true;
41 return value.toString();
42 }
43 ok = false;
44 return QString();
45}
46
47QString QgsProcessingOutputDefinition::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
48{
49 return valueAsString( value, context, ok );
50}
51
53{
54 return QColor( 128, 128, 128 ); /* mid gray */
55}
56
61
66
71
73{
74 return QColor( 122, 0, 47 ); /* burgundy */
75}
76
80
82{
83 return QColor( 0, 180, 180 ); /* turquoise */
84}
85
89
93
95{
96 return QColor( 137, 150, 171 ); /* cold gray */
97}
98
102
103QString QgsProcessingOutputHtml::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
104{
105 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
106 {
107 ok = true;
108 return QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
109 }
110
111 return valueAsString( value, context, ok );
112}
113
115{
116 return QColor( 255, 131, 23 ); /* orange */
117}
118
122
123QString QgsProcessingOutputNumber::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
124{
125 ok = false;
126 switch ( value.userType() )
127 {
128 case QMetaType::Type::Int:
129 case QMetaType::Type::UInt:
130 case QMetaType::Type::LongLong:
131 case QMetaType::Type::ULongLong:
132 case QMetaType::Type::Double:
133 ok = true;
134 return value.toString();
135 default:
136 break;
137 }
138 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
139}
140
142{
143 return QColor( 34, 157, 214 ); /* blue */
144}
145
149
151{
152 return QColor( 255, 131, 23 ); /* orange */
153}
154
158
159QString QgsProcessingOutputBoolean::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
160{
161 ok = false;
162 if ( value.userType() == QMetaType::Type::Bool )
163 {
164 ok = true;
165 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
166 }
167 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
168}
169
171{
172 return QColor( 51, 201, 28 ); /* green */
173}
174
178
179QString QgsProcessingOutputFolder::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
180{
181 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
182 {
183 ok = true;
184 return QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
185 }
186
187 return valueAsString( value, context, ok );
188}
189
191{
192 return QColor( 80, 80, 80 ); /* dark gray */
193}
194
198
199QString QgsProcessingOutputFile::valueAsFormattedString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
200{
201 if ( value.userType() == QMetaType::Type::QString && !value.toString().isEmpty() )
202 {
203 ok = true;
204 return QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( value.toString() ).toString(), QDir::toNativeSeparators( value.toString() ) );
205 }
206
207 return valueAsString( value, context, ok );
208}
209
211{
212 return QColor( 80, 80, 80 ); /* dark gray */
213}
214
218
220{
221 return typeName();
222}
223
225{
226 return QColor( 137, 150, 171 ); /* cold gray */
227}
228
232
234{
235 return typeName();
236}
237
238QString QgsProcessingOutputMultipleLayers::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
239{
240 ok = false;
241 switch ( value.userType() )
242 {
243 case QMetaType::Type::QVariantList:
244 {
245 ok = true;
246 const QVariantList list = value.toList();
247
248 QStringList layerNames;
249 for ( const QVariant &v : list )
250 {
251 layerNames << v.toString();
252 }
253 return layerNames.join( QLatin1String( ", " ) );
254 }
255
256 case QMetaType::Type::QStringList:
257 {
258 ok = true;
259 const QStringList list = value.toStringList();
260 return list.join( QLatin1String( ", " ) );
261 }
262
263 default:
264 break;
265 }
266 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
267}
268
270{
271 return QColor( 137, 150, 171 ); /* cold gray */
272}
273
277
283
285{
286 return typeName();
287}
288
289QString QgsProcessingOutputVariant::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
290{
291 ok = false;
292 switch ( value.userType() )
293 {
294 case QMetaType::Type::Int:
295 case QMetaType::Type::UInt:
296 case QMetaType::Type::LongLong:
297 case QMetaType::Type::ULongLong:
298 case QMetaType::Type::Double:
299 ok = true;
300 return value.toString();
301 case QMetaType::Type::Bool:
302 ok = true;
303 return value.toBool() ? QObject::tr( "True" ) : QObject::tr( "False" );
304
305 case QMetaType::Type::QVariantList:
306 {
307 ok = true;
308 const QVariantList list = value.toList();
309
310 QStringList names;
311 for ( const QVariant &v : list )
312 {
313 names << v.toString();
314 }
315 return names.join( QLatin1String( ", " ) );
316 }
317
318 case QMetaType::Type::QStringList:
319 {
320 ok = true;
321 const QStringList list = value.toStringList();
322 return list.join( QLatin1String( ", " ) );
323 }
324
325 default:
326 break;
327 }
328 return QgsProcessingOutputDefinition::valueAsString( value, context, ok );
329}
330
ProcessingSourceType
Processing data source types.
Definition qgis.h:3531
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.