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();
145 map.insert( QStringLiteral(
"mesh_layer" ), mMeshLayerParameterName );
146 QVariantList dataType;
147 for (
int v : mSupportedDataType )
148 dataType.append( v );
149 map.insert( QStringLiteral(
"supported_data_type" ), dataType );
156 mMeshLayerParameterName = map.value( QStringLiteral(
"mesh_layer" ) ).toString();
157 const QVariantList dataType = map.value( QStringLiteral(
"supported_data_type" ) ).toList();
158 mSupportedDataType.clear();
159 for (
const QVariant &var : dataType )
160 mSupportedDataType.insert( var.toInt() );
164 bool QgsProcessingParameterMeshDatasetGroups::valueIsAcceptable(
const QVariant &input,
bool allowEmpty )
166 if ( !input.isValid() )
169 if ( input.type() != QVariant::List )
175 const QVariantList list = input.toList();
177 if ( !allowEmpty && list.isEmpty() )
180 for (
const QVariant &var : list )
192 const QString &description,
193 const QString &meshLayerParameterName,
194 const QString &datasetGroupParameterName )
196 , mMeshLayerParameterName( meshLayerParameterName )
197 , mDatasetGroupParameterName( datasetGroupParameterName )
223 parts << QStringLiteral(
"'type': " ) +
type;
225 if ( value.toDateTime().isValid() )
227 QDateTime dateTime = value.toDateTime();
228 dateTime.setTimeSpec( Qt::UTC );
233 const QVariantMap variantTimeDataset = value.toMap();
234 if ( variantTimeDataset.value( QStringLiteral(
"type" ) ) == QLatin1String(
"dataset-time-step" ) )
236 const QVariantList datasetIndex = variantTimeDataset.value( QStringLiteral(
"value" ) ).toList();
237 parts << QStringLiteral(
"'value': " ) + QString(
"[%1,%2]" ).arg( datasetIndex.at( 0 ).toString(), datasetIndex.at( 1 ).toString() );
239 else if ( variantTimeDataset.value( QStringLiteral(
"type" ) ) == QLatin1String(
"defined-date-time" ) )
245 return parts.join(
',' ).prepend(
'{' ).append(
'}' );
250 switch ( outputType )
254 QString code = QStringLiteral(
"QgsProcessingParameterMeshDatasetTime('%1', '%2'" )
256 if ( !mMeshLayerParameterName.isEmpty() )
259 if ( !mDatasetGroupParameterName.isEmpty() )
263 code += QLatin1String(
", optional=True" );
273 QStringList otherParameters;
274 if ( !mMeshLayerParameterName.isEmpty() )
275 otherParameters << mMeshLayerParameterName;
277 if ( !mDatasetGroupParameterName.isEmpty() )
278 otherParameters << mMeshLayerParameterName << mDatasetGroupParameterName;
280 return otherParameters;
286 map.insert( QStringLiteral(
"mesh_layer" ), mMeshLayerParameterName );
287 map.insert( QStringLiteral(
"dataset_groups" ), mDatasetGroupParameterName );
294 mMeshLayerParameterName = map.value( QStringLiteral(
"mesh_layer" ) ).toString();
295 mDatasetGroupParameterName = map.value( QStringLiteral(
"dataset_groups" ) ).toString();
301 return mMeshLayerParameterName;
306 return mDatasetGroupParameterName;
311 if ( !valueIsAcceptable( value,
false ) )
314 if ( value.toDateTime().isValid() )
315 return QStringLiteral(
"defined-date-time" );
317 return value.toMap().value( QStringLiteral(
"type" ) ).toString();
322 if ( !valueIsAcceptable( value,
false ) ||
valueAsTimeType( value ) != QLatin1String(
"dataset-time-step" ) )
325 const QVariantList list = value.toMap().value( QStringLiteral(
"value" ) ).toList();
331 if ( value.toDateTime().isValid() )
333 QDateTime dateTime = value.toDateTime();
334 dateTime.setTimeSpec( Qt::UTC );
338 if ( !valueIsAcceptable( value,
false ) &&
valueAsTimeType( value ) != QLatin1String(
"defined-date-time" ) )
341 return value.toMap().value( QStringLiteral(
"value" ) ).toDateTime();
344 bool QgsProcessingParameterMeshDatasetTime::valueIsAcceptable(
const QVariant &input,
bool allowEmpty )
346 if ( !input.isValid() )
349 if ( input.toDateTime().isValid() )
352 if ( input.type() != QVariant::Map )
355 const QVariantMap map = input.toMap();
360 if ( ! map.contains( QStringLiteral(
"type" ) ) )
363 const QString
type = map.value( QStringLiteral(
"type" ) ).toString();
364 const QVariant value = map.value( QStringLiteral(
"value" ) );
366 if (
type == QLatin1String(
"static" ) ||
type == QLatin1String(
"current-context-time" ) )
369 if (
type == QLatin1String(
"dataset-time-step" ) )
371 if ( value.type() != QVariant::List )
373 const QVariantList list = value.toList();
374 if ( value.toList().count() != 2 )
376 if ( list.at( 0 ).type() != QVariant::Int || list.at( 1 ).type() != QVariant::Int )
379 else if (
type == QLatin1String(
"defined-date-time" ) )
381 if ( value.type() != QVariant::DateTime )