21 const QString &description,
22 const QString &meshLayerParameterName,
23 const QSet<int> supportedDataType,
26 mMeshLayerParameterName( meshLayerParameterName ),
27 mSupportedDataType( supportedDataType )
52 for (
const int g : groups )
53 parts.append( QString::number( g ) );
55 return parts.join(
',' ).prepend(
'[' ).append(
']' );
64 QString code = QStringLiteral(
"QgsProcessingParameterMeshDatasetGroups('%1', %2" )
66 if ( !mMeshLayerParameterName.isEmpty() )
71 dt.append( QStringLiteral(
"QgsMeshDatasetGroupMetadata.DataOnFaces" ) );
73 dt.append( QStringLiteral(
"QgsMeshDatasetGroupMetadata.DataOnVertices" ) );
75 dt.append( QStringLiteral(
"QgsMeshDatasetGroupMetadata.DataOnVolumes" ) );
77 dt.append( QStringLiteral(
"QgsMeshDatasetGroupMetadata.DataOnEdges" ) );
80 code += QLatin1String(
", supportedDataType=[" );
81 code += dt.join(
',' );
86 code += QLatin1String(
", optional=True" );
96 if ( mMeshLayerParameterName.isEmpty() )
99 return QStringList() << mMeshLayerParameterName;
104 return mMeshLayerParameterName;
109 return mSupportedDataType.contains( dataType );
114 if ( !valueIsAcceptable( value,
true ) )
120 if ( !value.isValid() )
124 if ( value.type() == QVariant::List )
126 const QVariantList varList = value.toList();
127 if ( varList.isEmpty() )
130 for (
const QVariant &v : varList )
135 ret << value.toInt();
142 bool QgsProcessingParameterMeshDatasetGroups::valueIsAcceptable(
const QVariant &input,
bool allowEmpty )
144 if ( !input.isValid() )
147 if ( input.type() != QVariant::List )
153 const QVariantList list = input.toList();
155 if ( !allowEmpty && list.isEmpty() )
158 for (
const QVariant &var : list )
170 const QString &description,
171 const QString &meshLayerParameterName,
172 const QString &datasetGroupParameterName )
174 , mMeshLayerParameterName( meshLayerParameterName )
175 , mDatasetGroupParameterName( datasetGroupParameterName )
201 parts << QStringLiteral(
"'type': " ) +
type;
203 if ( value.toDateTime().isValid() )
205 QDateTime dateTime = value.toDateTime();
206 dateTime.setTimeSpec( Qt::UTC );
211 const QVariantMap variantTimeDataset = value.toMap();
212 if ( variantTimeDataset.value( QStringLiteral(
"type" ) ) == QLatin1String(
"dataset-time-step" ) )
214 const QVariantList datasetIndex = variantTimeDataset.value( QStringLiteral(
"value" ) ).toList();
215 parts << QStringLiteral(
"'value': " ) + QString(
"[%1,%2]" ).arg( datasetIndex.at( 0 ).toString(), datasetIndex.at( 1 ).toString() );
217 else if ( variantTimeDataset.value( QStringLiteral(
"type" ) ) == QLatin1String(
"defined-date-time" ) )
223 return parts.join(
',' ).prepend(
'{' ).append(
'}' );
228 switch ( outputType )
232 QString code = QStringLiteral(
"QgsProcessingParameterMeshDatasetTime('%1', '%2'" )
234 if ( !mMeshLayerParameterName.isEmpty() )
237 if ( !mDatasetGroupParameterName.isEmpty() )
241 code += QLatin1String(
", optional=True" );
251 QStringList otherParameters;
252 if ( !mMeshLayerParameterName.isEmpty() )
253 otherParameters << mMeshLayerParameterName;
255 if ( !mDatasetGroupParameterName.isEmpty() )
256 otherParameters << mMeshLayerParameterName << mDatasetGroupParameterName;
258 return otherParameters;
263 return mMeshLayerParameterName;
268 return mDatasetGroupParameterName;
273 if ( !valueIsAcceptable( value,
false ) )
276 if ( value.toDateTime().isValid() )
277 return QStringLiteral(
"defined-date-time" );
279 return value.toMap().value( QStringLiteral(
"type" ) ).toString();
284 if ( !valueIsAcceptable( value,
false ) ||
valueAsTimeType( value ) != QLatin1String(
"dataset-time-step" ) )
287 const QVariantList list = value.toMap().value( QStringLiteral(
"value" ) ).toList();
293 if ( value.toDateTime().isValid() )
295 QDateTime dateTime = value.toDateTime();
296 dateTime.setTimeSpec( Qt::UTC );
300 if ( !valueIsAcceptable( value,
false ) &&
valueAsTimeType( value ) != QLatin1String(
"defined-date-time" ) )
303 return value.toMap().value( QStringLiteral(
"value" ) ).toDateTime();
306 bool QgsProcessingParameterMeshDatasetTime::valueIsAcceptable(
const QVariant &input,
bool allowEmpty )
308 if ( !input.isValid() )
311 if ( input.toDateTime().isValid() )
314 if ( input.type() != QVariant::Map )
317 const QVariantMap map = input.toMap();
322 if ( ! map.contains( QStringLiteral(
"type" ) ) )
325 const QString
type = map.value( QStringLiteral(
"type" ) ).toString();
326 const QVariant value = map.value( QStringLiteral(
"value" ) );
328 if (
type == QLatin1String(
"static" ) ||
type == QLatin1String(
"current-context-time" ) )
331 if (
type == QLatin1String(
"dataset-time-step" ) )
333 if ( value.type() != QVariant::List )
335 const QVariantList list = value.toList();
336 if ( value.toList().count() != 2 )
338 if ( list.at( 0 ).type() != QVariant::Int || list.at( 1 ).type() != QVariant::Int )
341 else if (
type == QLatin1String(
"defined-date-time" ) )
343 if ( value.type() != QVariant::DateTime )
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Contains information about the context in which a processing algorithm is executed.
Base class for the definition of processing parameters.
Flags mFlags
Parameter flags.
QString description() const
Returns the description for the parameter.
@ FlagOptional
Parameter is optional.
QString name() const
Returns the name of the parameter.
QgsProcessingParameterMeshDatasetGroups(const QString &name, const QString &description=QString(), const QString &meshLayerParameterName=QString(), QSet< int > supportedDataType=QSet< int >(), bool optional=false)
Constructor.
static QString typeName()
Returns the type name for the parameter class.
static QList< int > valueAsDatasetGroup(const QVariant &value)
Returns the value as a list if dataset group indexes.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
QString type() const override
Unique parameter type name.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString meshLayerParameterName() const
Returns the name of the mesh layer parameter.
bool isDataTypeSupported(QgsMeshDatasetGroupMetadata::DataType dataType) const
Returns whether the data type is supported by the parameter.
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
QgsProcessingParameterMeshDatasetTime(const QString &name, const QString &description=QString(), const QString &meshLayerParameterName=QString(), const QString &datasetGroupParameterName=QString())
Constructor.
QString valueAsPythonString(const QVariant &value, QgsProcessingContext &context) const override
Returns a string version of the parameter input value, which is suitable for use as an input paramete...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
static QString valueAsTimeType(const QVariant &value)
Returns the dataset value time type as a string : current-context-time : the time is store in the pro...
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QString datasetGroupParameterName() const
Returns the name of the dataset groups parameter.
QString meshLayerParameterName() const
Returns the name of the mesh layer parameter.
static QgsMeshDatasetIndex timeValueAsDatasetIndex(const QVariant &value)
Returns the value as a QgsMeshDatasetIndex if the value has "dataset-time-step" type.
QStringList dependsOnOtherParameters() const override
Returns a list of other parameter names on which this parameter is dependent (e.g.
static QString typeName()
Returns the type name for the parameter class.
bool checkValueIsAcceptable(const QVariant &input, QgsProcessingContext *context=nullptr) const override
Checks whether the specified input value is acceptable for the parameter.
static QDateTime timeValueAsDefinedDateTime(const QVariant &value)
Returns the value as a QDateTime if the value has "defined-date-time" type.
QString type() const override
Unique parameter type name.
static QString stringToPythonLiteral(const QString &string)
Converts a string to a Python string literal.
static QString variantToPythonLiteral(const QVariant &value)
Converts a variant to a Python literal.
PythonOutputType
Available Python output types.
@ PythonQgsProcessingAlgorithmSubclass
Full Python QgsProcessingAlgorithm subclass.