Skip to content

Commit 3d03128

Browse files
committedJan 5, 2018
Restore some more atlas related tests
1 parent 1b93231 commit 3d03128

File tree

3 files changed

+56
-65
lines changed

3 files changed

+56
-65
lines changed
 

‎tests/src/core/testqgslayouthtml.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ void TestQgsLayoutHtml::javascriptSetFeature()
268268

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

271-
#if 0 //TODO
272271
//atlas
273-
mComposition->atlasComposition().setCoverageLayer( parentLayer );
274-
mComposition->atlasComposition().setEnabled( true );
272+
QgsLayout l( QgsProject::instance() );
273+
l.initializeDefaults();
274+
l.context().setLayer( parentLayer );
275275

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

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

301-
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
302-
QVERIFY( mComposition->atlasComposition().beginRender() );
303-
QVERIFY( mComposition->atlasComposition().prepareForFeature( 0 ) );
299+
QgsFeature f;
300+
QgsFeatureIterator it = parentLayer->getFeatures();
301+
it.nextFeature( f );
302+
l.context().setFeature( f );
304303

305304
htmlItem->loadHtml();
306305

307-
QgsLayoutChecker checker( QStringLiteral( "composerhtml_setfeature" ), mComposition );
306+
QgsLayoutChecker checker( QStringLiteral( "composerhtml_setfeature" ), &l );
308307
checker.setControlPathPrefix( QStringLiteral( "composer_html" ) );
309308
bool result = checker.testLayout( mReport );
310-
mComposition->removeMultiFrame( htmlItem );
311-
delete htmlItem;
312309
QVERIFY( result );
313310

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

318314

‎tests/src/core/testqgslayoutmap.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ void TestQgsLayoutMap::dataDefinedLayers()
340340
result = map->layersToRender();
341341
QVERIFY( result.isEmpty() );
342342

343-
344343
//test with atlas feature evaluation
345344
QgsVectorLayer *atlasLayer = new QgsVectorLayer( QStringLiteral( "Point?field=col1:string" ), QStringLiteral( "atlas" ), QStringLiteral( "memory" ) );
346345
QVERIFY( atlasLayer->isValid() );
@@ -349,23 +348,24 @@ void TestQgsLayoutMap::dataDefinedLayers()
349348
QgsFeature f2( atlasLayer->dataProvider()->fields(), 1 );
350349
f2.setAttribute( QStringLiteral( "col1" ), mPointsLayer->name() );
351350
atlasLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 );
352-
#if 0 //TODO
353-
mComposition->atlasComposition().setCoverageLayer( atlasLayer );
354-
mComposition->atlasComposition().setEnabled( true );
355-
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
356-
mComposition->atlasComposition().beginRender();
357-
mComposition->atlasComposition().prepareForFeature( 0 );
351+
352+
l.context().setLayer( atlasLayer );
353+
QgsFeature f;
354+
QgsFeatureIterator it = atlasLayer->getFeatures();
355+
it.nextFeature( f );
356+
l.context().setFeature( f );
358357

359358
map->dataDefinedProperties().setProperty( QgsLayoutObject::MapLayers, QgsProperty::fromField( QStringLiteral( "col1" ) ) );
360359
result = map->layersToRender();
361360
QCOMPARE( result.count(), 1 );
362361
QCOMPARE( result.at( 0 ), mLinesLayer );
363-
mComposition->atlasComposition().prepareForFeature( 1 );
362+
it.nextFeature( f );
363+
l.context().setFeature( f );
364364
result = map->layersToRender();
365365
QCOMPARE( result.count(), 1 );
366366
QCOMPARE( result.at( 0 ), mPointsLayer );
367-
mComposition->atlasComposition().setEnabled( false );
368-
#endif
367+
it.nextFeature( f );
368+
l.context().setFeature( f );
369369

370370
delete atlasLayer;
371371

‎tests/src/core/testqgslayouttable.cpp

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,8 @@ void TestQgsLayoutTable::attributeTableRepeat()
521521

522522
void TestQgsLayoutTable::attributeTableAtlasSource()
523523
{
524-
#if 0 //TODO
525-
QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( mComposition, false );
526-
524+
QgsLayout l( QgsProject::instance() );
525+
QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( &l );
527526

528527
table->setSource( QgsLayoutItemAttributeTable::AtlasFeature );
529528

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

541-
QVERIFY( mComposition->atlasComposition().prepareForFeature( 0 ) );
542-
QCOMPARE( table->contents()->length(), 1 );
543-
QgsComposerTableRow row = table->contents()->at( 0 );
538+
QgsFeature f;
539+
QgsFeatureIterator it = vectorLayer->getFeatures();
540+
it.nextFeature( f );
541+
l.context().setFeature( f );
542+
543+
QCOMPARE( table->contents().length(), 1 );
544+
QgsLayoutTableRow row = table->contents().at( 0 );
544545

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

553554
//next atlas feature
554-
QVERIFY( mComposition->atlasComposition().prepareForFeature( 1 ) );
555-
QCOMPARE( table->contents()->length(), 1 );
556-
row = table->contents()->at( 0 );
555+
it.nextFeature( f );
556+
l.context().setFeature( f );
557+
558+
QCOMPARE( table->contents().length(), 1 );
559+
row = table->contents().at( 0 );
557560
QCOMPARE( row.at( 0 ), QVariant( "Biplane" ) );
558561
QCOMPARE( row.at( 1 ), QVariant( 0 ) );
559562
QCOMPARE( row.at( 2 ), QVariant( 1 ) );
@@ -562,25 +565,22 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
562565
QCOMPARE( row.at( 5 ), QVariant( 6 ) );
563566

564567
//next atlas feature
565-
QVERIFY( mComposition->atlasComposition().prepareForFeature( 2 ) );
566-
QCOMPARE( table->contents()->length(), 1 );
567-
row = table->contents()->at( 0 );
568+
it.nextFeature( f );
569+
l.context().setFeature( f );
570+
571+
QCOMPARE( table->contents().length(), 1 );
572+
row = table->contents().at( 0 );
568573
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
569574
QCOMPARE( row.at( 1 ), QVariant( 85 ) );
570575
QCOMPARE( row.at( 2 ), QVariant( 3 ) );
571576
QCOMPARE( row.at( 3 ), QVariant( 1 ) );
572577
QCOMPARE( row.at( 4 ), QVariant( 1 ) );
573578
QCOMPARE( row.at( 5 ), QVariant( 2 ) );
574579

575-
mComposition->atlasComposition().endRender();
576-
577580
//try for a crash when removing current atlas layer
578581
QgsProject::instance()->removeMapLayer( vectorLayer->id() );
579582
table->refreshAttributes();
580583

581-
mComposition->removeMultiFrame( table );
582-
delete table;
583-
#endif
584584
}
585585

586586

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

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

614-
#if 0 //TODO
615614
//setup atlas
616-
mComposition->atlasComposition().setCoverageLayer( atlasLayer );
617-
mComposition->atlasComposition().setEnabled( true );
615+
l.context().setLayer( atlasLayer );
616+
617+
QgsFeature f;
618+
QgsFeatureIterator it = atlasLayer->getFeatures();
619+
it.nextFeature( f );
620+
l.context().setFeature( f );
618621

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

627-
QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( mComposition, false );
630+
table = new QgsLayoutItemAttributeTable( &l );
628631
table->setMaximumNumberOfFeatures( 50 );
629632
table->setSource( QgsLayoutItemAttributeTable::RelationChildren );
630633
table->setRelationId( relation.id() );
631634

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

635-
QCOMPARE( mComposition->atlasComposition().feature().attribute( "Class" ).toString(), QString( "Jet" ) );
636-
QCOMPARE( table->contents()->length(), 8 );
637-
638-
QgsComposerTableRow row = table->contents()->at( 0 );
638+
QgsLayoutTableRow row = table->contents().at( 0 );
639639

640640
//check a couple of results
641641
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
@@ -644,14 +644,14 @@ void TestQgsLayoutTable::attributeTableRelationSource()
644644
QCOMPARE( row.at( 3 ), QVariant( 2 ) );
645645
QCOMPARE( row.at( 4 ), QVariant( 0 ) );
646646
QCOMPARE( row.at( 5 ), QVariant( 2 ) );
647-
row = table->contents()->at( 1 );
647+
row = table->contents().at( 1 );
648648
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
649649
QCOMPARE( row.at( 1 ), QVariant( 85 ) );
650650
QCOMPARE( row.at( 2 ), QVariant( 3 ) );
651651
QCOMPARE( row.at( 3 ), QVariant( 1 ) );
652652
QCOMPARE( row.at( 4 ), QVariant( 1 ) );
653653
QCOMPARE( row.at( 5 ), QVariant( 2 ) );
654-
row = table->contents()->at( 2 );
654+
row = table->contents().at( 2 );
655655
QCOMPARE( row.at( 0 ), QVariant( "Jet" ) );
656656
QCOMPARE( row.at( 1 ), QVariant( 95 ) );
657657
QCOMPARE( row.at( 2 ), QVariant( 3 ) );
@@ -660,34 +660,29 @@ void TestQgsLayoutTable::attributeTableRelationSource()
660660
QCOMPARE( row.at( 5 ), QVariant( 2 ) );
661661

662662
//next atlas feature
663-
QVERIFY( mComposition->atlasComposition().prepareForFeature( 1 ) );
664-
QCOMPARE( mComposition->atlasComposition().feature().attribute( "Class" ).toString(), QString( "Biplane" ) );
665-
QCOMPARE( table->contents()->length(), 5 );
666-
row = table->contents()->at( 0 );
663+
it.nextFeature( f );
664+
l.context().setFeature( f );
665+
QCOMPARE( f.attribute( "Class" ).toString(), QString( "Biplane" ) );
666+
QCOMPARE( table->contents().length(), 5 );
667+
row = table->contents().at( 0 );
667668
QCOMPARE( row.at( 0 ), QVariant( "Biplane" ) );
668669
QCOMPARE( row.at( 1 ), QVariant( 0 ) );
669670
QCOMPARE( row.at( 2 ), QVariant( 1 ) );
670671
QCOMPARE( row.at( 3 ), QVariant( 3 ) );
671672
QCOMPARE( row.at( 4 ), QVariant( 3 ) );
672673
QCOMPARE( row.at( 5 ), QVariant( 6 ) );
673-
row = table->contents()->at( 1 );
674+
row = table->contents().at( 1 );
674675
QCOMPARE( row.at( 0 ), QVariant( "Biplane" ) );
675676
QCOMPARE( row.at( 1 ), QVariant( 340 ) );
676677
QCOMPARE( row.at( 2 ), QVariant( 1 ) );
677678
QCOMPARE( row.at( 3 ), QVariant( 3 ) );
678679
QCOMPARE( row.at( 4 ), QVariant( 3 ) );
679680
QCOMPARE( row.at( 5 ), QVariant( 6 ) );
680681

681-
mComposition->atlasComposition().endRender();
682-
683682
//try for a crash when removing current atlas layer
684683
QgsProject::instance()->removeMapLayer( atlasLayer->id() );
685684

686685
table->refreshAttributes();
687-
688-
mComposition->removeMultiFrame( table );
689-
delete table;
690-
#endif
691686
}
692687

693688
void TestQgsLayoutTable::contentsContainsRow()

0 commit comments

Comments
 (0)
Please sign in to comment.