Skip to content
Permalink
Browse files

Restore some more atlas related tests

  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 1b93231 commit 3d03128e4aa78d0989aa817ff88b46503553ff4a
Showing with 56 additions and 65 deletions.
  1. +8 −12 tests/src/core/testqgslayouthtml.cpp
  2. +10 −10 tests/src/core/testqgslayoutmap.cpp
  3. +38 −43 tests/src/core/testqgslayouttable.cpp
@@ -268,10 +268,10 @@ void TestQgsLayoutHtml::javascriptSetFeature()

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

#if 0 //TODO
//atlas
mComposition->atlasComposition().setCoverageLayer( parentLayer );
mComposition->atlasComposition().setEnabled( true );
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
l.context().setLayer( parentLayer );

QgsRelation rel;
rel.setId( QStringLiteral( "rel1" ) );
@@ -281,8 +281,6 @@ void TestQgsLayoutHtml::javascriptSetFeature()
rel.addFieldPair( QStringLiteral( "y" ), QStringLiteral( "foreignkey" ) );
QgsProject::instance()->relationManager()->addRelation( rel );

QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemHtml *htmlItem = new QgsLayoutItemHtml( &l );
QgsLayoutFrame *htmlFrame = new QgsLayoutFrame( &l, htmlItem );
htmlFrame->attemptSetSceneRect( QRectF( 0, 0, 100, 200 ) );
@@ -298,21 +296,19 @@ void TestQgsLayoutHtml::javascriptSetFeature()
" feature.properties['relation one'][0].z + ',' + feature.properties['relation one'][1].z;}"
"</script></body>" ) );

mComposition->setAtlasMode( QgsComposition::ExportAtlas );
QVERIFY( mComposition->atlasComposition().beginRender() );
QVERIFY( mComposition->atlasComposition().prepareForFeature( 0 ) );
QgsFeature f;
QgsFeatureIterator it = parentLayer->getFeatures();
it.nextFeature( f );
l.context().setFeature( f );

htmlItem->loadHtml();

QgsLayoutChecker checker( QStringLiteral( "composerhtml_setfeature" ), mComposition );
QgsLayoutChecker checker( QStringLiteral( "composerhtml_setfeature" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
bool result = checker.testLayout( mReport );
mComposition->removeMultiFrame( htmlItem );
delete htmlItem;
QVERIFY( result );

QgsProject::instance()->removeMapLayers( QList<QgsMapLayer *>() << childLayer << parentLayer );
#endif
}


@@ -340,7 +340,6 @@ void TestQgsLayoutMap::dataDefinedLayers()
result = map->layersToRender();
QVERIFY( result.isEmpty() );


//test with atlas feature evaluation
QgsVectorLayer *atlasLayer = new QgsVectorLayer( QStringLiteral( "Point?field=col1:string" ), QStringLiteral( "atlas" ), QStringLiteral( "memory" ) );
QVERIFY( atlasLayer->isValid() );
@@ -349,23 +348,24 @@ void TestQgsLayoutMap::dataDefinedLayers()
QgsFeature f2( atlasLayer->dataProvider()->fields(), 1 );
f2.setAttribute( QStringLiteral( "col1" ), mPointsLayer->name() );
atlasLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 );
#if 0 //TODO
mComposition->atlasComposition().setCoverageLayer( atlasLayer );
mComposition->atlasComposition().setEnabled( true );
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
mComposition->atlasComposition().beginRender();
mComposition->atlasComposition().prepareForFeature( 0 );

l.context().setLayer( atlasLayer );
QgsFeature f;
QgsFeatureIterator it = atlasLayer->getFeatures();
it.nextFeature( f );
l.context().setFeature( f );

map->dataDefinedProperties().setProperty( QgsLayoutObject::MapLayers, QgsProperty::fromField( QStringLiteral( "col1" ) ) );
result = map->layersToRender();
QCOMPARE( result.count(), 1 );
QCOMPARE( result.at( 0 ), mLinesLayer );
mComposition->atlasComposition().prepareForFeature( 1 );
it.nextFeature( f );
l.context().setFeature( f );
result = map->layersToRender();
QCOMPARE( result.count(), 1 );
QCOMPARE( result.at( 0 ), mPointsLayer );
mComposition->atlasComposition().setEnabled( false );
#endif
it.nextFeature( f );
l.context().setFeature( f );

delete atlasLayer;

@@ -521,9 +521,8 @@ void TestQgsLayoutTable::attributeTableRepeat()

void TestQgsLayoutTable::attributeTableAtlasSource()
{
#if 0 //TODO
QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( mComposition, false );

QgsLayout l( QgsProject::instance() );
QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( &l );

table->setSource( QgsLayoutItemAttributeTable::AtlasFeature );

@@ -534,13 +533,15 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
vectorFileInfo.completeBaseName(),
QStringLiteral( "ogr" ) );
QgsProject::instance()->addMapLayer( vectorLayer );
mComposition->atlasComposition().setCoverageLayer( vectorLayer );
mComposition->atlasComposition().setEnabled( true );
QVERIFY( mComposition->atlasComposition().beginRender() );
l.context().setLayer( vectorLayer );

QVERIFY( mComposition->atlasComposition().prepareForFeature( 0 ) );
QCOMPARE( table->contents()->length(), 1 );
QgsComposerTableRow row = table->contents()->at( 0 );
QgsFeature f;
QgsFeatureIterator it = vectorLayer->getFeatures();
it.nextFeature( f );
l.context().setFeature( f );

QCOMPARE( table->contents().length(), 1 );
QgsLayoutTableRow row = table->contents().at( 0 );

//check a couple of results
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
@@ -551,9 +552,11 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
QCOMPARE( row.at( 5 ), QVariant( 2 ) );

//next atlas feature
QVERIFY( mComposition->atlasComposition().prepareForFeature( 1 ) );
QCOMPARE( table->contents()->length(), 1 );
row = table->contents()->at( 0 );
it.nextFeature( f );
l.context().setFeature( f );

QCOMPARE( table->contents().length(), 1 );
row = table->contents().at( 0 );
QCOMPARE( row.at( 0 ), QVariant( "Biplane" ) );
QCOMPARE( row.at( 1 ), QVariant( 0 ) );
QCOMPARE( row.at( 2 ), QVariant( 1 ) );
@@ -562,25 +565,22 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
QCOMPARE( row.at( 5 ), QVariant( 6 ) );

//next atlas feature
QVERIFY( mComposition->atlasComposition().prepareForFeature( 2 ) );
QCOMPARE( table->contents()->length(), 1 );
row = table->contents()->at( 0 );
it.nextFeature( f );
l.context().setFeature( f );

QCOMPARE( table->contents().length(), 1 );
row = table->contents().at( 0 );
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
QCOMPARE( row.at( 1 ), QVariant( 85 ) );
QCOMPARE( row.at( 2 ), QVariant( 3 ) );
QCOMPARE( row.at( 3 ), QVariant( 1 ) );
QCOMPARE( row.at( 4 ), QVariant( 1 ) );
QCOMPARE( row.at( 5 ), QVariant( 2 ) );

mComposition->atlasComposition().endRender();

//try for a crash when removing current atlas layer
QgsProject::instance()->removeMapLayer( vectorLayer->id() );
table->refreshAttributes();

mComposition->removeMultiFrame( table );
delete table;
#endif
}


@@ -611,10 +611,13 @@ void TestQgsLayoutTable::attributeTableRelationSource()

QgsProject::instance()->addMapLayer( atlasLayer );

#if 0 //TODO
//setup atlas
mComposition->atlasComposition().setCoverageLayer( atlasLayer );
mComposition->atlasComposition().setEnabled( true );
l.context().setLayer( atlasLayer );

QgsFeature f;
QgsFeatureIterator it = atlasLayer->getFeatures();
it.nextFeature( f );
l.context().setFeature( f );

//create a relation
QgsRelation relation;
@@ -624,18 +627,15 @@ void TestQgsLayoutTable::attributeTableRelationSource()
relation.addFieldPair( QStringLiteral( "Class" ), QStringLiteral( "Class" ) );
QgsProject::instance()->relationManager()->addRelation( relation );

QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( mComposition, false );
table = new QgsLayoutItemAttributeTable( &l );
table->setMaximumNumberOfFeatures( 50 );
table->setSource( QgsLayoutItemAttributeTable::RelationChildren );
table->setRelationId( relation.id() );

QVERIFY( mComposition->atlasComposition().beginRender() );
QVERIFY( mComposition->atlasComposition().prepareForFeature( 0 ) );
QCOMPARE( f.attribute( "Class" ).toString(), QString( "Jet" ) );
QCOMPARE( table->contents().length(), 8 );

QCOMPARE( mComposition->atlasComposition().feature().attribute( "Class" ).toString(), QString( "Jet" ) );
QCOMPARE( table->contents()->length(), 8 );

QgsComposerTableRow row = table->contents()->at( 0 );
QgsLayoutTableRow row = table->contents().at( 0 );

//check a couple of results
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
@@ -644,14 +644,14 @@ void TestQgsLayoutTable::attributeTableRelationSource()
QCOMPARE( row.at( 3 ), QVariant( 2 ) );
QCOMPARE( row.at( 4 ), QVariant( 0 ) );
QCOMPARE( row.at( 5 ), QVariant( 2 ) );
row = table->contents()->at( 1 );
row = table->contents().at( 1 );
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
QCOMPARE( row.at( 1 ), QVariant( 85 ) );
QCOMPARE( row.at( 2 ), QVariant( 3 ) );
QCOMPARE( row.at( 3 ), QVariant( 1 ) );
QCOMPARE( row.at( 4 ), QVariant( 1 ) );
QCOMPARE( row.at( 5 ), QVariant( 2 ) );
row = table->contents()->at( 2 );
row = table->contents().at( 2 );
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
QCOMPARE( row.at( 1 ), QVariant( 95 ) );
QCOMPARE( row.at( 2 ), QVariant( 3 ) );
@@ -660,34 +660,29 @@ void TestQgsLayoutTable::attributeTableRelationSource()
QCOMPARE( row.at( 5 ), QVariant( 2 ) );

//next atlas feature
QVERIFY( mComposition->atlasComposition().prepareForFeature( 1 ) );
QCOMPARE( mComposition->atlasComposition().feature().attribute( "Class" ).toString(), QString( "Biplane" ) );
QCOMPARE( table->contents()->length(), 5 );
row = table->contents()->at( 0 );
it.nextFeature( f );
l.context().setFeature( f );
QCOMPARE( f.attribute( "Class" ).toString(), QString( "Biplane" ) );
QCOMPARE( table->contents().length(), 5 );
row = table->contents().at( 0 );
QCOMPARE( row.at( 0 ), QVariant( "Biplane" ) );
QCOMPARE( row.at( 1 ), QVariant( 0 ) );
QCOMPARE( row.at( 2 ), QVariant( 1 ) );
QCOMPARE( row.at( 3 ), QVariant( 3 ) );
QCOMPARE( row.at( 4 ), QVariant( 3 ) );
QCOMPARE( row.at( 5 ), QVariant( 6 ) );
row = table->contents()->at( 1 );
row = table->contents().at( 1 );
QCOMPARE( row.at( 0 ), QVariant( "Biplane" ) );
QCOMPARE( row.at( 1 ), QVariant( 340 ) );
QCOMPARE( row.at( 2 ), QVariant( 1 ) );
QCOMPARE( row.at( 3 ), QVariant( 3 ) );
QCOMPARE( row.at( 4 ), QVariant( 3 ) );
QCOMPARE( row.at( 5 ), QVariant( 6 ) );

mComposition->atlasComposition().endRender();

//try for a crash when removing current atlas layer
QgsProject::instance()->removeMapLayer( atlasLayer->id() );

table->refreshAttributes();

mComposition->removeMultiFrame( table );
delete table;
#endif
}

void TestQgsLayoutTable::contentsContainsRow()

0 comments on commit 3d03128

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