22
22
#include " qgslayoutitemshape.h"
23
23
#include " qgslayoutpagecollection.h"
24
24
#include " qgslayoutundostack.h"
25
+ #include " qgslayoutitemlabel.h"
26
+ #include " qgslayoutitempolyline.h"
25
27
26
28
class TestQgsLayout : public QObject
27
29
{
@@ -521,13 +523,13 @@ void TestQgsLayout::itemsOnPage()
521
523
page3->setPageSize ( " A4" );
522
524
l.pageCollection ()->addPage ( page3 );
523
525
524
- QgsLayoutItemShape *label1 = new QgsLayoutItemShape ( &l );
526
+ QgsLayoutItemLabel *label1 = new QgsLayoutItemLabel ( &l );
525
527
l.addLayoutItem ( label1 );
526
528
label1->attemptMove ( QgsLayoutPoint ( 10 , 10 ), true , false , 0 );
527
- QgsLayoutItemShape *label2 = new QgsLayoutItemShape ( &l );
529
+ QgsLayoutItemLabel *label2 = new QgsLayoutItemLabel ( &l );
528
530
l.addLayoutItem ( label2 );
529
531
label2->attemptMove ( QgsLayoutPoint ( 10 , 10 ), true , false , 0 );
530
- QgsLayoutItemShape *label3 = new QgsLayoutItemShape ( &l );
532
+ QgsLayoutItemLabel *label3 = new QgsLayoutItemLabel ( &l );
531
533
l.addLayoutItem ( label3 );
532
534
label3->attemptMove ( QgsLayoutPoint ( 10 , 10 ), true , false , 1 );
533
535
QgsLayoutItemShape *shape1 = new QgsLayoutItemShape ( &l );
@@ -536,10 +538,10 @@ void TestQgsLayout::itemsOnPage()
536
538
QgsLayoutItemShape *shape2 = new QgsLayoutItemShape ( &l );
537
539
l.addLayoutItem ( shape2 );
538
540
shape2->attemptMove ( QgsLayoutPoint ( 10 , 10 ), true , false , 1 );
539
- QgsLayoutItemShape *arrow1 = new QgsLayoutItemShape ( &l );
541
+ QgsLayoutItemPolyline *arrow1 = new QgsLayoutItemPolyline ( &l );
540
542
l.addLayoutItem ( arrow1 );
541
543
arrow1->attemptMove ( QgsLayoutPoint ( 10 , 10 ), true , false , 2 );
542
- QgsLayoutItemShape *arrow2 = new QgsLayoutItemShape ( &l );
544
+ QgsLayoutItemPolyline *arrow2 = new QgsLayoutItemPolyline ( &l );
543
545
l.addLayoutItem ( arrow2 );
544
546
arrow2->attemptMove ( QgsLayoutPoint ( 10 , 10 ), true , false , 2 );
545
547
@@ -554,6 +556,40 @@ void TestQgsLayout::itemsOnPage()
554
556
// should be 3 items on page 3
555
557
QCOMPARE ( items.length (), 3 );
556
558
559
+ // check fetching specific item types
560
+ QList<QgsLayoutItemLabel *> labels;
561
+ l.pageCollection ()->itemsOnPage ( labels, 0 );
562
+ // should be 2 labels on page 1
563
+ QCOMPARE ( labels.length (), 2 );
564
+ l.pageCollection ()->itemsOnPage ( labels, 1 );
565
+ // should be 1 label on page 2
566
+ QCOMPARE ( labels.length (), 1 );
567
+ l.pageCollection ()->itemsOnPage ( labels, 2 );
568
+ // should be no label on page 3
569
+ QCOMPARE ( labels.length (), 0 );
570
+
571
+ QList<QgsLayoutItemShape *> shapes;
572
+ l.pageCollection ()->itemsOnPage ( shapes, 0 );
573
+ // should be 1 shapes on page 1
574
+ QCOMPARE ( shapes.length (), 1 );
575
+ l.pageCollection ()->itemsOnPage ( shapes, 1 );
576
+ // should be 1 shapes on page 2
577
+ QCOMPARE ( shapes.length (), 1 );
578
+ l.pageCollection ()->itemsOnPage ( shapes, 2 );
579
+ // should be no shapes on page 3
580
+ QCOMPARE ( shapes.length (), 0 );
581
+
582
+ QList<QgsLayoutItemPolyline *> arrows;
583
+ l.pageCollection ()->itemsOnPage ( arrows, 0 );
584
+ // should be no arrows on page 1
585
+ QCOMPARE ( arrows.length (), 0 );
586
+ l.pageCollection ()->itemsOnPage ( arrows, 1 );
587
+ // should be no arrows on page 2
588
+ QCOMPARE ( arrows.length (), 0 );
589
+ l.pageCollection ()->itemsOnPage ( arrows, 2 );
590
+ // should be 2 arrows on page 3
591
+ QCOMPARE ( arrows.length (), 2 );
592
+
557
593
l.removeLayoutItem ( label1 );
558
594
l.removeLayoutItem ( label2 );
559
595
l.removeLayoutItem ( label3 );
@@ -569,6 +605,13 @@ void TestQgsLayout::itemsOnPage()
569
605
QCOMPARE ( items.length (), 1 );
570
606
items = l.pageCollection ()->itemsOnPage ( 2 );
571
607
QCOMPARE ( items.length (), 1 );
608
+
609
+ l.pageCollection ()->itemsOnPage ( labels, 0 );
610
+ QCOMPARE ( labels.length (), 0 );
611
+ l.pageCollection ()->itemsOnPage ( labels, 1 );
612
+ QCOMPARE ( labels.length (), 0 );
613
+ l.pageCollection ()->itemsOnPage ( labels, 2 );
614
+ QCOMPARE ( labels.length (), 0 );
572
615
}
573
616
574
617
void TestQgsLayout::pageIsEmpty ()
0 commit comments