Skip to content
Permalink
Browse files

fix tests for mesh layer

  • Loading branch information
PeterPetrik authored and nyalldawson committed Aug 29, 2018
1 parent 99a6f12 commit 199f4effb6118b2155e7975a7a000aa77610cae7
@@ -334,9 +334,9 @@ QModelIndex QgsMeshDatasetGroupTreeModel::groupIndexToModelIndex( int groupIndex
QgsMeshDatasetGroupTreeItemDelagate::QgsMeshDatasetGroupTreeItemDelagate( QObject *parent )
: QStyledItemDelegate( parent )
, mScalarSelectedPixmap( QStringLiteral( ":/images/themes/default/propertyicons/meshcontours.svg" ) )
, mScalarUnselectedPixmap( QStringLiteral( ":/images/themes/default/propertyicons/meshcontoursoff.svg" ) )
, mScalarDeselectedPixmap( QStringLiteral( ":/images/themes/default/propertyicons/meshcontoursoff.svg" ) )
, mVectorSelectedPixmap( QStringLiteral( ":/images/themes/default/propertyicons/meshvectors.svg" ) )
, mVectorUnselectedPixmap( QStringLiteral( ":/images/themes/default/propertyicons/meshvectorsoff.svg" ) )
, mVectorDeselectedPixmap( QStringLiteral( ":/images/themes/default/propertyicons/meshvectorsoff.svg" ) )
{
}

@@ -350,10 +350,10 @@ void QgsMeshDatasetGroupTreeItemDelagate::paint( QPainter *painter, const QStyle
if ( isVector )
{
bool isActive = index.data( QgsMeshDatasetGroupTreeModel::IsActiveVectorDatasetGroup ).toBool();
painter->drawPixmap( iconRect( option.rect, true ), isActive ? mVectorSelectedPixmap : mVectorUnselectedPixmap );
painter->drawPixmap( iconRect( option.rect, true ), isActive ? mVectorSelectedPixmap : mVectorDeselectedPixmap );
}
bool isActive = index.data( QgsMeshDatasetGroupTreeModel::IsActiveScalarDatasetGroup ).toBool();
painter->drawPixmap( iconRect( option.rect, false ), isActive ? mScalarSelectedPixmap : mScalarUnselectedPixmap );
painter->drawPixmap( iconRect( option.rect, false ), isActive ? mScalarSelectedPixmap : mScalarDeselectedPixmap );
}

QRect QgsMeshDatasetGroupTreeItemDelagate::iconRect( const QRect rect, bool isVector ) const
@@ -147,9 +147,9 @@ class APP_EXPORT QgsMeshDatasetGroupTreeItemDelagate: public QStyledItemDelegate
const QModelIndex &index ) const override;
private:
const QPixmap mScalarSelectedPixmap;
const QPixmap mScalarUnselectedPixmap;
const QPixmap mScalarDeselectedPixmap;
const QPixmap mVectorSelectedPixmap;
const QPixmap mVectorUnselectedPixmap;
const QPixmap mVectorDeselectedPixmap;
};

/**
@@ -51,6 +51,7 @@ class TestQgsMeshLayer : public QObject

void test_write_read_project();
void test_read_mesh();
void test_read_bed_elevation_dataset();
void test_read_vertex_scalar_dataset();
void test_read_vertex_vector_dataset();
void test_read_face_scalar_dataset();
@@ -82,19 +83,20 @@ void TestQgsMeshLayer::initTestCase()
mMemoryLayer = new QgsMeshLayer( readFile( "/quad_and_triangle.txt" ), "Triangle and Quad Memory", "mesh_memory" );
QVERIFY( mMemoryLayer->isValid() );
QCOMPARE( mMemoryLayer->dataProvider()->extraDatasets().count(), 0 );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_bed_elevation.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_vertex_scalar.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_vertex_vector.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_face_scalar.txt" ) );
mMemoryLayer->dataProvider()->addDataset( readFile( "/quad_and_triangle_face_vector.txt" ) );
QCOMPARE( mMemoryLayer->dataProvider()->extraDatasets().count(), 4 );
QCOMPARE( mMemoryLayer->dataProvider()->extraDatasets().count(), 5 );

QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mMemoryLayer );

// MDAL Layer
QString uri( mDataDir + "/quad_and_triangle.2dm" );
mMdalLayer = new QgsMeshLayer( uri, "Triangle and Quad MDAL", "mdal" );
QCOMPARE( mMdalLayer->dataProvider()->extraDatasets().count(), 0 );
QCOMPARE( mMdalLayer->dataProvider()->datasetGroupCount(), 1 ); //bed elevation is already in the 2dm
mMdalLayer->dataProvider()->addDataset( mDataDir + "/quad_and_triangle_vertex_scalar.dat" );
mMdalLayer->dataProvider()->addDataset( mDataDir + "/quad_and_triangle_vertex_vector.dat" );
QCOMPARE( mMdalLayer->dataProvider()->extraDatasets().count(), 2 );
@@ -142,6 +144,41 @@ void TestQgsMeshLayer::test_read_mesh()
}
}

void TestQgsMeshLayer::test_read_bed_elevation_dataset()
{
QList<const QgsMeshDataProvider *> dataProviders;
dataProviders.append( mMemoryLayer->dataProvider() );
dataProviders.append( mMdalLayer->dataProvider() );

foreach ( auto dp, dataProviders )
{
QVERIFY( dp != nullptr );
QVERIFY( dp->isValid() );

QCOMPARE( 5, dp->datasetGroupCount() );

QgsMeshDatasetIndex ds( 0, 0 );

const QgsMeshDatasetGroupMetadata meta = dp->datasetGroupMetadata( ds );
QVERIFY( meta.name().contains( "Elevation" ) );
QVERIFY( meta.isScalar() );
QVERIFY( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnVertices );

const QgsMeshDatasetMetadata dmeta = dp->datasetMetadata( ds );
QVERIFY( qgsDoubleNear( dmeta.time(), 0 ) );
QVERIFY( dmeta.isValid() );

// We have 5 values, since dp->vertexCount() = 5
QCOMPARE( QgsMeshDatasetValue( 20 ), dp->datasetValue( ds, 0 ) );
QCOMPARE( QgsMeshDatasetValue( 30 ), dp->datasetValue( ds, 1 ) );
QCOMPARE( QgsMeshDatasetValue( 40 ), dp->datasetValue( ds, 2 ) );
QCOMPARE( QgsMeshDatasetValue( 50 ), dp->datasetValue( ds, 3 ) );
QCOMPARE( QgsMeshDatasetValue( 10 ), dp->datasetValue( ds, 4 ) );

QVERIFY( dp->isFaceActive( ds, 0 ) );
}
}

void TestQgsMeshLayer::test_read_vertex_scalar_dataset()
{
QList<const QgsMeshDataProvider *> dataProviders;
@@ -153,11 +190,11 @@ void TestQgsMeshLayer::test_read_vertex_scalar_dataset()
QVERIFY( dp != nullptr );
QVERIFY( dp->isValid() );

QCOMPARE( 4, dp->datasetGroupCount() );
QCOMPARE( 5, dp->datasetGroupCount() );

for ( int i = 0; i < 2 ; ++i )
{
QgsMeshDatasetIndex ds( 0, i );
QgsMeshDatasetIndex ds( 1, i );

const QgsMeshDatasetGroupMetadata meta = dp->datasetGroupMetadata( ds );
if ( meta.extraOptions().count() == 2 )
@@ -196,11 +233,11 @@ void TestQgsMeshLayer::test_read_vertex_vector_dataset()
QVERIFY( dp != nullptr );
QVERIFY( dp->isValid() );

QCOMPARE( 4, dp->datasetGroupCount() );
QCOMPARE( 5, dp->datasetGroupCount() );

for ( int i = 0; i < 2 ; ++i )
{
QgsMeshDatasetIndex ds( 1, i );
QgsMeshDatasetIndex ds( 2, i );

const QgsMeshDatasetGroupMetadata meta = dp->datasetGroupMetadata( ds );
if ( meta.extraOptions().count() == 2 )
@@ -236,11 +273,11 @@ void TestQgsMeshLayer::test_read_face_scalar_dataset()
QVERIFY( dp != nullptr );
QVERIFY( dp->isValid() );

QCOMPARE( 4, dp->datasetGroupCount() );
QCOMPARE( 5, dp->datasetGroupCount() );

for ( int i = 0; i < 2 ; ++i )
{
QgsMeshDatasetIndex ds( 2, i );
QgsMeshDatasetIndex ds( 3, i );

const QgsMeshDatasetGroupMetadata meta = dp->datasetGroupMetadata( ds );
if ( meta.extraOptions().count() == 2 )
@@ -274,11 +311,11 @@ void TestQgsMeshLayer::test_read_face_vector_dataset()
QVERIFY( dp != nullptr );
QVERIFY( dp->isValid() );

QCOMPARE( 4, dp->datasetGroupCount() );
QCOMPARE( 5, dp->datasetGroupCount() );

for ( int i = 0; i < 2 ; ++i )
{
QgsMeshDatasetIndex ds( 3, i );
QgsMeshDatasetIndex ds( 4, i );

const QgsMeshDatasetGroupMetadata meta = dp->datasetGroupMetadata( ds );
if ( meta.extraOptions().count() == 2 )
@@ -308,11 +345,11 @@ void TestQgsMeshLayer::test_read_vertex_scalar_dataset_with_inactive_face()
QgsMeshDataProvider *dp = layer.dataProvider();
QVERIFY( dp != nullptr );
QVERIFY( dp->isValid() );
QCOMPARE( 1, dp->datasetGroupCount() );
QCOMPARE( 2, dp->datasetGroupCount() );

for ( int i = 0; i < 2 ; ++i )
{
QgsMeshDatasetIndex ds( 0, i );
QgsMeshDatasetIndex ds( 1, i );

const QgsMeshDatasetGroupMetadata meta = dp->datasetGroupMetadata( ds );
QCOMPARE( meta.name(), QString( "VertexScalarDatasetWithInactiveFace1" ) );
@@ -255,7 +255,7 @@ void TestQgsMeshRenderer::test_face_vector_dataset_rendering()

void TestQgsMeshRenderer::test_vertex_scalar_dataset_with_inactive_face_rendering()
{
QgsMeshDatasetIndex ds( 0, 1 );
QgsMeshDatasetIndex ds( 1, 1 );
const QgsMeshDatasetGroupMetadata metadata = mMdalLayer->dataProvider()->datasetGroupMetadata( ds );
QVERIFY( metadata.name() == "VertexScalarDatasetWithInactiveFace1" );

Binary file not shown.
@@ -0,0 +1,10 @@
Vertex Scalar BedElevation
---
description: Bed Elevation
---
0
20
30
40
50
10

0 comments on commit 199f4ef

Please sign in to comment.
You can’t perform that action at this time.