24
24
#include " qgslayoutundostack.h"
25
25
#include " qgslayoutitemlabel.h"
26
26
#include " qgslayoutitempolyline.h"
27
+ #include " qgslayoutitemhtml.h"
28
+ #include " qgslayoutframe.h"
27
29
28
30
class TestQgsLayout : public QObject
29
31
{
@@ -47,6 +49,7 @@ class TestQgsLayout: public QObject
47
49
void layoutItemByUuid ();
48
50
void undoRedoOccurred ();
49
51
void itemsOnPage (); // test fetching matching items on a set page
52
+ void shouldExportPage ();
50
53
void pageIsEmpty ();
51
54
void clear ();
52
55
@@ -614,6 +617,50 @@ void TestQgsLayout::itemsOnPage()
614
617
QCOMPARE ( labels.length (), 0 );
615
618
}
616
619
620
+ void TestQgsLayout::shouldExportPage ()
621
+ {
622
+ QgsProject proj;
623
+ QgsLayout l ( &proj );
624
+ QgsLayoutItemPage *page = new QgsLayoutItemPage ( &l );
625
+ page->setPageSize ( " A4" );
626
+ l.pageCollection ()->addPage ( page );
627
+ QgsLayoutItemPage *page2 = new QgsLayoutItemPage ( &l );
628
+ page2->setPageSize ( " A4" );
629
+ l.pageCollection ()->addPage ( page2 );
630
+
631
+ QgsLayoutItemHtml *htmlItem = new QgsLayoutItemHtml ( &l );
632
+ // frame on page 1
633
+ QgsLayoutFrame *frame1 = new QgsLayoutFrame ( &l, htmlItem );
634
+ frame1->attemptSetSceneRect ( QRectF ( 0 , 0 , 100 , 100 ) );
635
+ // frame on page 2
636
+ QgsLayoutFrame *frame2 = new QgsLayoutFrame ( &l, htmlItem );
637
+ frame2->attemptSetSceneRect ( QRectF ( 0 , 320 , 100 , 100 ) );
638
+ frame2->setHidePageIfEmpty ( true );
639
+ htmlItem->addFrame ( frame1 );
640
+ htmlItem->addFrame ( frame2 );
641
+ htmlItem->setContentMode ( QgsLayoutItemHtml::ManualHtml );
642
+ // short content, so frame 2 should be empty
643
+ htmlItem->setHtml ( QStringLiteral ( " <p><i>Test manual <b>html</b></i></p>" ) );
644
+ htmlItem->loadHtml ();
645
+
646
+ QVERIFY ( l.pageCollection ()->shouldExportPage ( 0 ) );
647
+ QVERIFY ( !l.pageCollection ()->shouldExportPage ( 1 ) );
648
+
649
+ // long content, so frame 2 should not be empty
650
+ htmlItem->setHtml ( QStringLiteral ( " <p style=\" height: 10000px\" ><i>Test manual <b>html</b></i></p>" ) );
651
+ htmlItem->loadHtml ();
652
+
653
+ QVERIFY ( l.pageCollection ()->shouldExportPage ( 0 ) );
654
+ QVERIFY ( l.pageCollection ()->shouldExportPage ( 1 ) );
655
+
656
+ // ...and back again...
657
+ htmlItem->setHtml ( QStringLiteral ( " <p><i>Test manual <b>html</b></i></p>" ) );
658
+ htmlItem->loadHtml ();
659
+
660
+ QVERIFY ( l.pageCollection ()->shouldExportPage ( 0 ) );
661
+ QVERIFY ( !l.pageCollection ()->shouldExportPage ( 1 ) );
662
+ }
663
+
617
664
void TestQgsLayout::pageIsEmpty ()
618
665
{
619
666
QgsProject proj;
0 commit comments