Skip to content
Permalink
Browse files
fix temporal unit
  • Loading branch information
vcloarec authored and nyalldawson committed May 20, 2021
1 parent 406f3f4 commit 389569f54faa92bf149fd303e31907638f1773f2
Showing with 8 additions and 2 deletions.
  1. +4 −2 src/core/mesh/qgsmeshlayer.cpp
  2. +4 −0 tests/src/core/testqgsmeshlayer.cpp
@@ -924,7 +924,6 @@ void QgsMeshLayer::setDataSourcePrivate( const QString &dataSource, const QStrin
if ( ok )
{
mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );
mDataProvider->setTemporalUnit( mTemporalUnit );
}
}

@@ -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() )
@@ -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" ) )
@@ -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" );
@@ -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 ) );
@@ -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 ) );

0 comments on commit 389569f

Please sign in to comment.