Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix temporal unit
  • Loading branch information
vcloarec authored and nyalldawson committed May 20, 2021
1 parent 406f3f4 commit 389569f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/mesh/qgsmeshlayer.cpp
Expand Up @@ -924,7 +924,6 @@ void QgsMeshLayer::setDataSourcePrivate( const QString &dataSource, const QStrin
if ( ok )
{
mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );
mDataProvider->setTemporalUnit( mTemporalUnit );
}
}

Expand Down Expand Up @@ -1191,6 +1190,9 @@ bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &con
}
}

if ( pkeyNode.toElement().hasAttribute( QStringLiteral( "time-unit" ) ) )
mTemporalUnit = static_cast<QgsUnitTypes::TemporalUnit>( pkeyNode.toElement().attribute( QStringLiteral( "time-unit" ) ).toInt() );

// read dataset group store
QDomElement elemDatasetGroupsStore = layer_node.firstChildElement( QStringLiteral( "mesh-dataset-groups-store" ) );
if ( elemDatasetGroupsStore.isNull() )
Expand Down Expand Up @@ -1419,8 +1421,8 @@ bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvid
return false;
}

mDataProvider->setTemporalUnit( mTemporalUnit );
mDatasetGroupStore->setPersistentProvider( mDataProvider, mExtraDatasetUri );

setCrs( mDataProvider->crs() );

if ( provider == QLatin1String( "mesh_memory" ) )
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsmeshlayer.cpp
Expand Up @@ -1523,6 +1523,8 @@ void TestQgsMeshLayer::test_setDataSource()
QCOMPARE( firstLayer->dataProvider()->extraDatasets().count(), 3 );
QCOMPARE( firstLayer->datasetGroupTreeRootItem()->childCount(), 5 );

firstLayer->dataProvider()->temporalCapabilities()->setTemporalUnit( QgsUnitTypes::TemporalMinutes );

QgsReadWriteContext readWriteContext;
QDomDocument doc( "savedLayer" );
QDomElement layerElement = doc.createElement( "maplayer" );
Expand All @@ -1537,6 +1539,7 @@ void TestQgsMeshLayer::test_setDataSource()
QCOMPARE( layerWithGoodDataSource.datasetGroupTreeRootItem()->child( 1 )->description(), mDataDir + "/quad_and_triangle_vertex_scalar.dat" );
QCOMPARE( layerWithGoodDataSource.datasetGroupTreeRootItem()->child( 2 )->description(), mDataDir + "/quad_and_triangle_vertex_vector.dat" );
QCOMPARE( layerWithGoodDataSource.datasetGroupTreeRootItem()->child( 3 )->description(), mDataDir + "/quad_and_triangle_els_face_scalar.dat" );
QCOMPARE( layerWithGoodDataSource.dataProvider()->temporalCapabilities()->temporalUnit(), QgsUnitTypes::TemporalMinutes );

QCOMPARE( QgsMeshDatasetValue( 30.0 ), layerWithGoodDataSource.datasetValue( QgsMeshDatasetIndex( 0, 0 ), 1 ) );
QCOMPARE( QgsMeshDatasetValue( 2.0 ), layerWithGoodDataSource.datasetValue( QgsMeshDatasetIndex( 1, 0 ), 1 ) );
Expand Down Expand Up @@ -1571,6 +1574,7 @@ void TestQgsMeshLayer::test_setDataSource()
QCOMPARE( layerWithBadDataSource.datasetGroupTreeRootItem()->child( 1 )->description(), mDataDir + "/quad_and_triangle_vertex_scalar.dat" );
QCOMPARE( layerWithBadDataSource.datasetGroupTreeRootItem()->child( 2 )->description(), mDataDir + "/quad_and_triangle_vertex_vector.dat" );
QCOMPARE( layerWithBadDataSource.datasetGroupTreeRootItem()->child( 3 )->description(), mDataDir + "/quad_and_triangle_els_face_scalar.dat" );
QCOMPARE( layerWithGoodDataSource.dataProvider()->temporalCapabilities()->temporalUnit(), QgsUnitTypes::TemporalMinutes );

QCOMPARE( QgsMeshDatasetValue( 30.0 ), layerWithBadDataSource.datasetValue( QgsMeshDatasetIndex( 0, 0 ), 1 ) );
QCOMPARE( QgsMeshDatasetValue( 2.0 ), layerWithBadDataSource.datasetValue( QgsMeshDatasetIndex( 1, 0 ), 1 ) );
Expand Down

0 comments on commit 389569f

Please sign in to comment.