20using namespace Qt::StringLiterals;
25 const QString &description,
26 const QString &meshLayerParameterName,
27 const QSet<int> supportedDataType,
30 mMeshLayerParameterName( meshLayerParameterName ),
31 mSupportedDataType( supportedDataType )
56 for (
const int g : groups )
57 parts.append( QString::number( g ) );
59 return parts.join(
',' ).prepend(
'[' ).append(
']' );
68 QString code = u
"QgsProcessingParameterMeshDatasetGroups('%1', %2"_s
70 if ( !mMeshLayerParameterName.isEmpty() )
75 dt.append( u
"QgsMeshDatasetGroupMetadata.DataOnFaces"_s );
77 dt.append( u
"QgsMeshDatasetGroupMetadata.DataOnVertices"_s );
79 dt.append( u
"QgsMeshDatasetGroupMetadata.DataOnVolumes"_s );
81 dt.append( u
"QgsMeshDatasetGroupMetadata.DataOnEdges"_s );
84 code +=
", supportedDataType=["_L1;
85 code += dt.join(
',' );
90 code +=
", optional=True"_L1;
100 if ( mMeshLayerParameterName.isEmpty() )
101 return QStringList();
103 return QStringList() << mMeshLayerParameterName;
108 return mMeshLayerParameterName;
113 return mSupportedDataType.contains( dataType );
118 if ( !valueIsAcceptable( value,
true ) )
123 if ( value.isValid() )
125 if ( value.userType() == QMetaType::Type::QVariantList )
127 const QVariantList varList = value.toList();
128 for (
const QVariant &v : varList )
133 ret << value.toInt();
143 map.insert( u
"mesh_layer"_s, mMeshLayerParameterName );
144 QVariantList dataType;
145 for (
int v : mSupportedDataType )
146 dataType.append( v );
147 map.insert( u
"supported_data_type"_s, dataType );
154 mMeshLayerParameterName = map.value( u
"mesh_layer"_s ).toString();
155 const QVariantList dataType = map.value( u
"supported_data_type"_s ).toList();
156 mSupportedDataType.clear();
157 for (
const QVariant &var : dataType )
158 mSupportedDataType.insert( var.toInt() );
162bool QgsProcessingParameterMeshDatasetGroups::valueIsAcceptable(
const QVariant &input,
bool allowEmpty )
164 if ( !input.isValid() )
167 if ( input.userType() != QMetaType::Type::QVariantList )
173 const QVariantList list = input.toList();
175 if ( !allowEmpty && list.isEmpty() )
178 for (
const QVariant &var : list )
190 const QString &description,
191 const QString &meshLayerParameterName,
192 const QString &datasetGroupParameterName )
194 , mMeshLayerParameterName( meshLayerParameterName )
195 , mDatasetGroupParameterName( datasetGroupParameterName )
221 parts << u
"'type': "_s +
type;
223 if ( value.toDateTime().isValid() )
225 QDateTime dateTime = value.toDateTime();
226 dateTime.setTimeSpec( Qt::UTC );
231 const QVariantMap variantTimeDataset = value.toMap();
232 if ( variantTimeDataset.value( u
"type"_s ) ==
"dataset-time-step"_L1 )
234 const QVariantList datasetIndex = variantTimeDataset.value( u
"value"_s ).toList();
235 parts << u
"'value': "_s + QString(
"[%1,%2]" ).arg( datasetIndex.at( 0 ).toString(), datasetIndex.at( 1 ).toString() );
237 else if ( variantTimeDataset.value( u
"type"_s ) ==
"defined-date-time"_L1 )
243 return parts.join(
',' ).prepend(
'{' ).append(
'}' );
248 switch ( outputType )
252 QString code = u
"QgsProcessingParameterMeshDatasetTime('%1', '%2'"_s
254 if ( !mMeshLayerParameterName.isEmpty() )
257 if ( !mDatasetGroupParameterName.isEmpty() )
261 code +=
", optional=True"_L1;
271 QStringList otherParameters;
272 if ( !mMeshLayerParameterName.isEmpty() )
273 otherParameters << mMeshLayerParameterName;
275 if ( !mDatasetGroupParameterName.isEmpty() )
276 otherParameters << mMeshLayerParameterName << mDatasetGroupParameterName;
278 return otherParameters;
284 map.insert( u
"mesh_layer"_s, mMeshLayerParameterName );
285 map.insert( u
"dataset_groups"_s, mDatasetGroupParameterName );
292 mMeshLayerParameterName = map.value( u
"mesh_layer"_s ).toString();
293 mDatasetGroupParameterName = map.value( u
"dataset_groups"_s ).toString();
299 return mMeshLayerParameterName;
304 return mDatasetGroupParameterName;
309 if ( !valueIsAcceptable( value,
false ) )
312 if ( value.toDateTime().isValid() )
313 return u
"defined-date-time"_s;
315 return value.toMap().value( u
"type"_s ).toString();
320 if ( !valueIsAcceptable( value,
false ) ||
valueAsTimeType( value ) !=
"dataset-time-step"_L1 )
321 return QgsMeshDatasetIndex( -1, -1 );
323 const QVariantList list = value.toMap().value( u
"value"_s ).toList();
324 return QgsMeshDatasetIndex( list.at( 0 ).toInt(), list.at( 1 ).toInt() );
329 if ( value.toDateTime().isValid() )
331 QDateTime dateTime = value.toDateTime();
332 dateTime.setTimeSpec( Qt::UTC );
336 if ( !valueIsAcceptable( value,
false ) &&
valueAsTimeType( value ) !=
"defined-date-time"_L1 )
339 return value.toMap().value( u
"value"_s ).toDateTime();
342bool QgsProcessingParameterMeshDatasetTime::valueIsAcceptable(
const QVariant &input,
bool allowEmpty )
344 if ( !input.isValid() )
347 if ( input.toDateTime().isValid() )
350 if ( input.userType() != QMetaType::Type::QVariantMap )
353 const QVariantMap map = input.toMap();
358 if ( ! map.contains( u
"type"_s ) )
361 const QString
type = map.value( u
"type"_s ).toString();
362 const QVariant value = map.value( u
"value"_s );
364 if (
type ==
"static"_L1 ||
type ==
"current-context-time"_L1 )
367 if (
type ==
"dataset-time-step"_L1 )
369 if ( value.userType() != QMetaType::Type::QVariantList )
371 const QVariantList list = value.toList();
372 if ( value.toList().count() != 2 )
374 if ( list.at( 0 ).userType() != QMetaType::Type::Int || list.at( 1 ).userType() != QMetaType::Type::Int )
377 else if (
type ==
"defined-date-time"_L1 )
379 if ( value.userType() != QMetaType::Type::QDateTime )
@ Optional
Parameter is optional.
An 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.
Qgis::ProcessingParameterFlags mFlags
Parameter flags.
QString description() const
Returns the description for the parameter.
virtual QVariantMap toVariantMap() const
Saves this parameter to a QVariantMap.
QString name() const
Returns the name of the parameter.
virtual bool fromVariantMap(const QVariantMap &map)
Restores this parameter to a QVariantMap.
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...
QgsProcessingParameterDefinition * clone() const override
Creates a clone of the parameter definition.
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.
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
QString meshLayerParameterName() const
Returns the name of the mesh layer parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
bool isDataTypeSupported(QgsMeshDatasetGroupMetadata::DataType dataType) const
Returns whether the data type is supported by the parameter.
QString asPythonString(QgsProcessing::PythonOutputType outputType=QgsProcessing::PythonOutputType::PythonQgsProcessingAlgorithmSubclass) const override
Returns the parameter definition as a Python command which can be used within a Python Processing scr...
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...
bool fromVariantMap(const QVariantMap &map) override
Restores this parameter to a QVariantMap.
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.
QVariantMap toVariantMap() const override
Saves this parameter to a QVariantMap.
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.