@@ -521,9 +521,8 @@ void TestQgsLayoutTable::attributeTableRepeat()
521
521
522
522
void TestQgsLayoutTable::attributeTableAtlasSource ()
523
523
{
524
- #if 0 //TODO
525
- QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( mComposition, false );
526
-
524
+ QgsLayout l ( QgsProject::instance () );
525
+ QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable ( &l );
527
526
528
527
table->setSource ( QgsLayoutItemAttributeTable::AtlasFeature );
529
528
@@ -534,13 +533,15 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
534
533
vectorFileInfo.completeBaseName (),
535
534
QStringLiteral ( " ogr" ) );
536
535
QgsProject::instance ()->addMapLayer ( vectorLayer );
537
- mComposition->atlasComposition().setCoverageLayer( vectorLayer );
538
- mComposition->atlasComposition().setEnabled( true );
539
- QVERIFY( mComposition->atlasComposition().beginRender() );
536
+ l.context ().setLayer ( vectorLayer );
540
537
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 );
544
545
545
546
// check a couple of results
546
547
QCOMPARE ( row.at ( 0 ), QVariant ( " Jet" ) );
@@ -551,9 +552,11 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
551
552
QCOMPARE ( row.at ( 5 ), QVariant ( 2 ) );
552
553
553
554
// 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 );
557
560
QCOMPARE ( row.at ( 0 ), QVariant ( " Biplane" ) );
558
561
QCOMPARE ( row.at ( 1 ), QVariant ( 0 ) );
559
562
QCOMPARE ( row.at ( 2 ), QVariant ( 1 ) );
@@ -562,25 +565,22 @@ void TestQgsLayoutTable::attributeTableAtlasSource()
562
565
QCOMPARE ( row.at ( 5 ), QVariant ( 6 ) );
563
566
564
567
// 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 );
568
573
QCOMPARE ( row.at ( 0 ), QVariant ( " Jet" ) );
569
574
QCOMPARE ( row.at ( 1 ), QVariant ( 85 ) );
570
575
QCOMPARE ( row.at ( 2 ), QVariant ( 3 ) );
571
576
QCOMPARE ( row.at ( 3 ), QVariant ( 1 ) );
572
577
QCOMPARE ( row.at ( 4 ), QVariant ( 1 ) );
573
578
QCOMPARE ( row.at ( 5 ), QVariant ( 2 ) );
574
579
575
- mComposition->atlasComposition().endRender();
576
-
577
580
// try for a crash when removing current atlas layer
578
581
QgsProject::instance ()->removeMapLayer ( vectorLayer->id () );
579
582
table->refreshAttributes ();
580
583
581
- mComposition->removeMultiFrame( table );
582
- delete table;
583
- #endif
584
584
}
585
585
586
586
@@ -611,10 +611,13 @@ void TestQgsLayoutTable::attributeTableRelationSource()
611
611
612
612
QgsProject::instance ()->addMapLayer ( atlasLayer );
613
613
614
- #if 0 //TODO
615
614
// 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 );
618
621
619
622
// create a relation
620
623
QgsRelation relation;
@@ -624,18 +627,15 @@ void TestQgsLayoutTable::attributeTableRelationSource()
624
627
relation.addFieldPair ( QStringLiteral ( " Class" ), QStringLiteral ( " Class" ) );
625
628
QgsProject::instance ()->relationManager ()->addRelation ( relation );
626
629
627
- QgsLayoutItemAttributeTable * table = new QgsLayoutItemAttributeTable( mComposition, false );
630
+ table = new QgsLayoutItemAttributeTable ( &l );
628
631
table->setMaximumNumberOfFeatures ( 50 );
629
632
table->setSource ( QgsLayoutItemAttributeTable::RelationChildren );
630
633
table->setRelationId ( relation.id () );
631
634
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 );
634
637
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 );
639
639
640
640
// check a couple of results
641
641
QCOMPARE ( row.at ( 0 ), QVariant ( " Jet" ) );
@@ -644,14 +644,14 @@ void TestQgsLayoutTable::attributeTableRelationSource()
644
644
QCOMPARE ( row.at ( 3 ), QVariant ( 2 ) );
645
645
QCOMPARE ( row.at ( 4 ), QVariant ( 0 ) );
646
646
QCOMPARE ( row.at ( 5 ), QVariant ( 2 ) );
647
- row = table->contents()-> at( 1 );
647
+ row = table->contents (). at ( 1 );
648
648
QCOMPARE ( row.at ( 0 ), QVariant ( " Jet" ) );
649
649
QCOMPARE ( row.at ( 1 ), QVariant ( 85 ) );
650
650
QCOMPARE ( row.at ( 2 ), QVariant ( 3 ) );
651
651
QCOMPARE ( row.at ( 3 ), QVariant ( 1 ) );
652
652
QCOMPARE ( row.at ( 4 ), QVariant ( 1 ) );
653
653
QCOMPARE ( row.at ( 5 ), QVariant ( 2 ) );
654
- row = table->contents()-> at( 2 );
654
+ row = table->contents (). at ( 2 );
655
655
QCOMPARE ( row.at ( 0 ), QVariant ( " Jet" ) );
656
656
QCOMPARE ( row.at ( 1 ), QVariant ( 95 ) );
657
657
QCOMPARE ( row.at ( 2 ), QVariant ( 3 ) );
@@ -660,34 +660,29 @@ void TestQgsLayoutTable::attributeTableRelationSource()
660
660
QCOMPARE ( row.at ( 5 ), QVariant ( 2 ) );
661
661
662
662
// 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 );
667
668
QCOMPARE ( row.at ( 0 ), QVariant ( " Biplane" ) );
668
669
QCOMPARE ( row.at ( 1 ), QVariant ( 0 ) );
669
670
QCOMPARE ( row.at ( 2 ), QVariant ( 1 ) );
670
671
QCOMPARE ( row.at ( 3 ), QVariant ( 3 ) );
671
672
QCOMPARE ( row.at ( 4 ), QVariant ( 3 ) );
672
673
QCOMPARE ( row.at ( 5 ), QVariant ( 6 ) );
673
- row = table->contents()-> at( 1 );
674
+ row = table->contents (). at ( 1 );
674
675
QCOMPARE ( row.at ( 0 ), QVariant ( " Biplane" ) );
675
676
QCOMPARE ( row.at ( 1 ), QVariant ( 340 ) );
676
677
QCOMPARE ( row.at ( 2 ), QVariant ( 1 ) );
677
678
QCOMPARE ( row.at ( 3 ), QVariant ( 3 ) );
678
679
QCOMPARE ( row.at ( 4 ), QVariant ( 3 ) );
679
680
QCOMPARE ( row.at ( 5 ), QVariant ( 6 ) );
680
681
681
- mComposition->atlasComposition().endRender();
682
-
683
682
// try for a crash when removing current atlas layer
684
683
QgsProject::instance ()->removeMapLayer ( atlasLayer->id () );
685
684
686
685
table->refreshAttributes ();
687
-
688
- mComposition->removeMultiFrame( table );
689
- delete table;
690
- #endif
691
686
}
692
687
693
688
void TestQgsLayoutTable::contentsContainsRow ()
0 commit comments