Skip to content
Permalink
Browse files
fixes for mesh layer processing
  • Loading branch information
vcloarec authored and nyalldawson committed Jun 10, 2021
1 parent 59be24f commit 8fd40802bee77eb1e593e258d9f0df80a5ed8818
@@ -354,7 +354,7 @@ QVariantMap QgsExportMeshOnElement::processAlgorithm( const QVariantMap &paramet
for ( int i = 0; i < mElementCount; ++i )
{
QgsAttributes attributes;
for ( const DataGroup &dataGroup : mDataPerGroup )
for ( const DataGroup &dataGroup : std::as_const( mDataPerGroup ) )
{
const QgsMeshDatasetValue &value = dataGroup.datasetValues.value( i );
addAttributes( value, attributes, dataGroup.metadata.isVector(), mExportVectorOption );
@@ -592,7 +592,7 @@ QVariantMap QgsExportMeshOnGridAlgorithm::processAlgorithm( const QVariantMap &p

QList<QgsMeshDatasetGroupMetadata> metaList;
metaList.reserve( mDataPerGroup.size() );
for ( const DataGroup &dataGroup : mDataPerGroup )
for ( const DataGroup &dataGroup : std::as_const( mDataPerGroup ) )
metaList.append( dataGroup.metadata );
QgsFields fields = createFields( metaList, mExportVectorOption );

@@ -738,7 +738,8 @@ void QgsMeshRasterizeAlgorithm::initAlgorithm( const QVariantMap &configuration
QStringLiteral( "DATASET_GROUPS" ),
QObject::tr( "Dataset groups" ),
QStringLiteral( "INPUT" ),
supportedDataType() ) );
supportedDataType(),
true ) );

addParameter( new QgsProcessingParameterMeshDatasetTime(
QStringLiteral( "DATASET_TIME" ),
@@ -1108,7 +1109,7 @@ QVariantMap QgsMeshContoursAlgorithm::processAlgorithm( const QVariantMap &param
firstAttributes.append( dataGroup.metadata.name() );
firstAttributes.append( mDateTimeString );

for ( double level : mLevels )
for ( double level : std::as_const( mLevels ) )
{
QgsGeometry line = contoursExported.exportLines( level, feedback );
if ( feedback->isCanceled() )
@@ -1285,7 +1286,7 @@ QVariantMap QgsMeshExportCrossSection::processAlgorithm( const QVariantMap &para
#endif
QStringList header;
header << QStringLiteral( "fid" ) << QStringLiteral( "x" ) << QStringLiteral( "y" ) << QObject::tr( "offset" );
for ( const DataGroup &datagroup : mDataPerGroup )
for ( const DataGroup &datagroup : std::as_const( mDataPerGroup ) )
header << datagroup.metadata.name();
textStream << header.join( ',' ) << QStringLiteral( "\n" );

@@ -1494,7 +1495,7 @@ bool QgsMeshExportTimeSeries::prepareAlgorithm( const QVariantMap &parameters, Q
while ( mRelativeTimeSteps.last() < relativeEndTime.seconds() * 1000 )
mRelativeTimeSteps.append( mRelativeTimeSteps.last() + timeStepInterval );

for ( qint64 relativeTimeStep : mRelativeTimeSteps )
for ( qint64 relativeTimeStep : std::as_const( mRelativeTimeSteps ) )
{
mTimeStepString.append( meshLayer->formatTime( relativeTimeStep / 3600.0 / 1000.0 ) );
}
@@ -1601,7 +1602,7 @@ QVariantMap QgsMeshExportTimeSeries::processAlgorithm( const QVariantMap &parame
QStringList header;
header << QStringLiteral( "fid" ) << QStringLiteral( "x" ) << QStringLiteral( "y" ) << QObject::tr( "time" );

for ( int gi : mGroupIndexes )
for ( int gi : std::as_const( mGroupIndexes ) )
header << mGroupsMetadata.value( gi ).name();

textStream << header.join( ',' ) << QStringLiteral( "\n" );
@@ -1647,7 +1648,7 @@ QVariantMap QgsMeshExportTimeSeries::processAlgorithm( const QVariantMap &parame
if ( mRelativeTimeToData.contains( timeStep ) )
{
const QMap<int, int> &groupToData = mRelativeTimeToData.value( timeStep );
for ( int groupIndex : mGroupIndexes )
for ( int groupIndex : std::as_const( mGroupIndexes ) )
{
if ( !groupToData.contains( groupIndex ) )
continue;
@@ -1680,7 +1681,7 @@ QVariantMap QgsMeshExportTimeSeries::processAlgorithm( const QVariantMap &parame
<< QString::number( point.y(), 'f', coordDigits )
<< QObject::tr( "static dataset" );
const QMap<int, int> &groupToData = mRelativeTimeToData.value( 0 );
for ( int groupIndex : mGroupIndexes )
for ( int groupIndex : std::as_const( mGroupIndexes ) )
{
if ( !groupToData.contains( groupIndex ) )
continue;
@@ -22,7 +22,7 @@ QgsProcessingParameterMeshDatasetGroups::QgsProcessingParameterMeshDatasetGroups
const QString &meshLayerParameterName,
const QSet<int> supportedDataType,
bool optional ):
QgsProcessingParameterDefinition( name, description, QVariant(), optional, QString() ),
QgsProcessingParameterDefinition( name, description, QVariantList(), optional, QString() ),
mMeshLayerParameterName( meshLayerParameterName ),
mSupportedDataType( supportedDataType )
{
@@ -48,9 +48,9 @@ QString QgsProcessingParameterMeshDatasetGroups::valueAsPythonString( const QVar
{
Q_UNUSED( context );
QStringList parts;
const QVariantList variantDatasetGroupIndexes = value.toList();
for ( const QVariant &variantIndex : variantDatasetGroupIndexes )
parts.append( QString::number( variantIndex.toInt() ) );
const QList<int> groups = valueAsDatasetGroup( value );
for ( const int g : groups )
parts.append( QString::number( g ) );

return parts.join( ',' ).prepend( '[' ).append( ']' );
}
@@ -113,10 +113,20 @@ QList<int> QgsProcessingParameterMeshDatasetGroups::valueAsDatasetGroup( const Q
{
if ( !valueIsAcceptable( value, true ) )
return QList<int>();
QVariantList list = value.toList();

QList<int> ret;
for ( const QVariant &v : list )
ret.append( v.toInt() );

// if invalid or empty, return only the group 0
if ( !value.isValid() )
ret << 0;
else
{
QVariantList list = value.toList();
if ( list.isEmpty() )
ret << 0;
for ( const QVariant &v : list )
ret.append( v.toInt() );
}

return ret;
}
@@ -177,7 +187,7 @@ QString QgsProcessingParameterMeshDatasetTime::valueAsPythonString( const QVaria
if ( variantTimeDataset.value( QStringLiteral( "type" ) ) == QLatin1String( "dataset-time-step" ) )
{
QVariantList datasetIndex = variantTimeDataset.value( QStringLiteral( "value" ) ).toList();
parts << QStringLiteral( "'value': " ) + QString( "QgsMeshDatasetIndex(%1,%2)" ).arg( datasetIndex.at( 0 ).toString() ).arg( datasetIndex.at( 1 ).toString() );
parts << QStringLiteral( "'value': " ) + QString( "[%1,%2]" ).arg( datasetIndex.at( 0 ).toString(), datasetIndex.at( 1 ).toString() );
}
else if ( variantTimeDataset.value( QStringLiteral( "type" ) ) == QLatin1String( "defined-date-time" ) )
{
@@ -264,7 +274,12 @@ bool QgsProcessingParameterMeshDatasetTime::valueIsAcceptable( const QVariant &i

if ( input.type() != QVariant::Map )
return false;

const QVariantMap map = input.toMap();

if ( map.isEmpty() )
return allowEmpty;

if ( ! map.contains( QStringLiteral( "type" ) ) )
return false;

@@ -118,7 +118,7 @@ void QgsProcessingMeshDatasetGroupsWidget::showDialog()
if ( mMeshLayer )
{
datasetGroupsIndexes = mMeshLayer->datasetGroupsIndexes();
for ( int i : datasetGroupsIndexes )
for ( int i : std::as_const( datasetGroupsIndexes ) )
{
QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( i );
if ( mParam->isDataTypeSupported( meta.dataType() ) )
@@ -265,6 +265,11 @@ void QgsProcessingMeshDatasetGroupsWidgetWrapper::setMeshLayerWrapperValue( cons
mWidget->setMeshLayer( meshLayer, layerFromProject );
}

QStringList QgsProcessingMeshDatasetGroupsWidgetWrapper::compatibleParameterTypes() const
{
return QStringList() << QgsProcessingParameterMeshDatasetGroups::typeName();
}

QWidget *QgsProcessingMeshDatasetGroupsWidgetWrapper::createWidget() SIP_FACTORY
{
mWidget = new QgsProcessingMeshDatasetGroupsWidget( nullptr, static_cast<const QgsProcessingParameterMeshDatasetGroups *>( parameterDefinition() ) );
@@ -350,7 +355,7 @@ void QgsProcessingMeshDatasetTimeWidgetWrapper::postInitialize( const QList<QgsA

void QgsProcessingMeshDatasetTimeWidgetWrapper::setMeshLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper )
{
if ( !mWidget )
if ( !mWidget || !wrapper )
return;

// evaluate value to layer
@@ -377,7 +382,7 @@ void QgsProcessingMeshDatasetTimeWidgetWrapper::setMeshLayerWrapperValue( const

void QgsProcessingMeshDatasetTimeWidgetWrapper::setDatasetGroupIndexesWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper )
{
if ( !mWidget )
if ( !mWidget || !wrapper )
return;

QVariant datasetGroupsVariant = wrapper->parameterValue();
@@ -395,6 +400,11 @@ void QgsProcessingMeshDatasetTimeWidgetWrapper::setDatasetGroupIndexesWrapperVal

}

QStringList QgsProcessingMeshDatasetTimeWidgetWrapper::compatibleParameterTypes() const
{
return QStringList() << QgsProcessingParameterMeshDatasetTime::typeName();
}

QWidget *QgsProcessingMeshDatasetTimeWidgetWrapper::createWidget()
{
mWidget = new QgsProcessingMeshDatasetTimeWidget( nullptr, static_cast<const QgsProcessingParameterMeshDatasetTime *>( parameterDefinition() ), widgetContext() );
@@ -434,6 +444,8 @@ QgsProcessingMeshDatasetTimeWidget::QgsProcessingMeshDatasetTimeWidget( QWidget
{
setupUi( this );

mValue.insert( QStringLiteral( "type" ), QStringLiteral( "static" ) );

dateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );

mCanvas = context.mapCanvas();
@@ -453,6 +465,8 @@ void QgsProcessingMeshDatasetTimeWidget::setMeshLayer( QgsMeshLayer *layer, bool
if ( mMeshLayer == layer )
return;

mReferenceTime = QDateTime();

if ( layerFromProject )
{
mMeshLayer = layer;
@@ -461,7 +475,8 @@ void QgsProcessingMeshDatasetTimeWidget::setMeshLayer( QgsMeshLayer *layer, bool
else
{
mMeshLayer = nullptr;
mReferenceTime = layer->dataProvider()->temporalCapabilities()->referenceTime();
if ( layer )
mReferenceTime = layer->dataProvider()->temporalCapabilities()->referenceTime();
storeTimeStepsFromLayer( layer );
}

@@ -500,9 +515,10 @@ void QgsProcessingMeshDatasetTimeWidget::setValue( const QVariant &value )
else if ( type == QLatin1String( "dataset-time-step" ) )
{
whileBlocking( radioButtonDatasetGroupTimeStep )->setChecked( true );
whileBlocking( comboBoxDatasetTimeStep )->setCurrentIndex( comboBoxDatasetTimeStep->findData( mValue.value( QStringLiteral( "value" ) ) ) );
QVariantList dataset = mValue.value( QStringLiteral( "value" ) ).toList();
whileBlocking( comboBoxDatasetTimeStep )->setCurrentIndex( comboBoxDatasetTimeStep->findData( dataset ) );
}
else if ( type == QLatin1String( "dataset-time-step" ) )
else if ( type == QLatin1String( "defined-date-time" ) )
{
radioButtonDefinedDateTime->setChecked( true );
whileBlocking( dateTimeEdit )->setDate( mValue.value( QStringLiteral( "value" ) ).toDate() );
@@ -604,7 +620,7 @@ void QgsProcessingMeshDatasetTimeWidget::populateTimeStepsFromLayer()
return;

QMap<quint64, QgsMeshDatasetIndex> timeStep;
for ( int groupIndex : mDatasetGroupIndexes )
for ( int groupIndex : std::as_const( mDatasetGroupIndexes ) )
{
QgsMeshDatasetGroupMetadata meta = mMeshLayer->datasetGroupMetadata( groupIndex );
if ( !meta.isTemporal() )
@@ -84,7 +84,7 @@ class GUI_EXPORT QgsProcessingMeshDatasetGroupsWidgetWrapper : public QgsAbstra
void setMeshLayerWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper );

protected:
QStringList compatibleParameterTypes() const override {return QStringList();}
QStringList compatibleParameterTypes() const override;
QStringList compatibleOutputTypes() const override {return QStringList();}
QWidget *createWidget() override;
void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
@@ -167,7 +167,7 @@ class GUI_EXPORT QgsProcessingMeshDatasetTimeWidgetWrapper : public QgsAbstract
void setDatasetGroupIndexesWrapperValue( const QgsAbstractProcessingParameterWidgetWrapper *wrapper );

protected:
QStringList compatibleParameterTypes() const override {return QStringList();}
QStringList compatibleParameterTypes() const override;
QStringList compatibleOutputTypes() const override {return QStringList();}
QWidget *createWidget() override;
void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
@@ -354,7 +354,11 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingTinInputLayersWidgetWr
return new QgsProcessingTinInputLayersWidgetWrapper( parameter, type );
}

QStringList QgsProcessingTinInputLayersWidgetWrapper::compatibleParameterTypes() const {return QStringList();}
QStringList QgsProcessingTinInputLayersWidgetWrapper::compatibleParameterTypes() const
{
return QStringList()
<< QgsProcessingParameterTinInputLayers::typeName();
}

QStringList QgsProcessingTinInputLayersWidgetWrapper::compatibleOutputTypes() const {return QStringList();}

@@ -9419,7 +9419,7 @@ void TestProcessingGui::testMeshDatasetWrapperLayerInProject()
QVariantMap timeValueMap = timeValue.toMap();
QCOMPARE( timeValueMap[QStringLiteral( "type" )].toString(), QStringLiteral( "dataset-time-step" ) );
pythonString = timeDefinition.valueAsPythonString( timeWrapper.widgetValue(), context );
QCOMPARE( pythonString, QStringLiteral( "{'type': 'dataset-time-step','value': QgsMeshDatasetIndex(1,0)}" ) );
QCOMPARE( pythonString, QStringLiteral( "{'type': 'dataset-time-step','value': [1,0]}" ) );
QVERIFY( timeDefinition.checkValueIsAcceptable( timeValue ) );
QCOMPARE( QgsProcessingParameterMeshDatasetTime::valueAsTimeType( timeValue ), QStringLiteral( "dataset-time-step" ) );
QVERIFY( QgsProcessingParameterMeshDatasetTime::timeValueAsDatasetIndex( timeValue ) == QgsMeshDatasetIndex( 1, 0 ) );

0 comments on commit 8fd4080

Please sign in to comment.