Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Restore some more atlas related tests
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 1b93231 commit 3d03128
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 65 deletions.
20 changes: 8 additions & 12 deletions tests/src/core/testqgslayouthtml.cpp
Expand Up @@ -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" ) );
Expand All @@ -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 ) );
Expand All @@ -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
}


Expand Down
20 changes: 10 additions & 10 deletions tests/src/core/testqgslayoutmap.cpp
Expand Up @@ -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() );
Expand All @@ -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;

Expand Down
81 changes: 38 additions & 43 deletions tests/src/core/testqgslayouttable.cpp
Expand Up @@ -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 );

Expand All @@ -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" ) );
Expand All @@ -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 ) );
Expand All @@ -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
}


Expand Down Expand Up @@ -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;
Expand All @@ -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" ) );
Expand All @@ -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 ) );
Expand All @@ -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()
Expand Down

0 comments on commit 3d03128

Please sign in to comment.