@@ -365,6 +365,120 @@ def testReflow(self):
365
365
self .assertEqual (page3 .pos ().x (), 0 )
366
366
self .assertEqual (page3 .pos ().y (), 130 )
367
367
368
+ def testInsertPageWithItems (self ):
369
+ p = QgsProject ()
370
+ l = QgsLayout (p )
371
+ collection = l .pageCollection ()
372
+
373
+ # add a page
374
+ page = QgsLayoutItemPage (l )
375
+ page .setPageSize ('A4' )
376
+ collection .addPage (page )
377
+ page2 = QgsLayoutItemPage (l )
378
+ page2 .setPageSize ('A5' )
379
+ collection .addPage (page2 )
380
+
381
+ # item on pages
382
+ shape1 = QgsLayoutItemShape (l )
383
+ shape1 .attemptResize (QgsLayoutSize (90 , 50 ))
384
+ shape1 .attemptMove (QgsLayoutPoint (90 , 50 ), page = 0 )
385
+ l .addLayoutItem (shape1 )
386
+
387
+ shape2 = QgsLayoutItemShape (l )
388
+ shape2 .attemptResize (QgsLayoutSize (110 , 50 ))
389
+ shape2 .attemptMove (QgsLayoutPoint (100 , 150 ), page = 1 )
390
+ l .addLayoutItem (shape2 )
391
+
392
+ self .assertEqual (shape1 .page (), 0 )
393
+ self .assertEqual (shape2 .page (), 1 )
394
+
395
+ # third page, slotted in middle
396
+ page3 = QgsLayoutItemPage (l )
397
+ page3 .setPageSize ('A3' )
398
+ collection .insertPage (page3 , 0 )
399
+
400
+ # check item position
401
+ self .assertEqual (shape1 .page (), 1 )
402
+ self .assertEqual (shape1 .pagePositionWithUnits (), QgsLayoutPoint (90 , 50 ))
403
+ self .assertEqual (shape2 .page (), 2 )
404
+ self .assertEqual (shape2 .pagePositionWithUnits (), QgsLayoutPoint (100 , 150 ))
405
+
406
+ def testDeletePageWithItems (self ):
407
+ p = QgsProject ()
408
+ l = QgsLayout (p )
409
+ collection = l .pageCollection ()
410
+
411
+ # add a page
412
+ page = QgsLayoutItemPage (l )
413
+ page .setPageSize ('A4' )
414
+ collection .addPage (page )
415
+ page2 = QgsLayoutItemPage (l )
416
+ page2 .setPageSize ('A4' )
417
+ collection .addPage (page2 )
418
+ page3 = QgsLayoutItemPage (l )
419
+ page3 .setPageSize ('A4' )
420
+ collection .addPage (page3 )
421
+
422
+ # item on pages
423
+ shape1 = QgsLayoutItemShape (l )
424
+ shape1 .attemptResize (QgsLayoutSize (90 , 50 ))
425
+ shape1 .attemptMove (QgsLayoutPoint (90 , 50 ), page = 0 )
426
+ l .addLayoutItem (shape1 )
427
+
428
+ shape2 = QgsLayoutItemShape (l )
429
+ shape2 .attemptResize (QgsLayoutSize (110 , 50 ))
430
+ shape2 .attemptMove (QgsLayoutPoint (100 , 150 ), page = 2 )
431
+ l .addLayoutItem (shape2 )
432
+
433
+ self .assertEqual (shape1 .page (), 0 )
434
+ self .assertEqual (shape2 .page (), 2 )
435
+
436
+ collection .deletePage (1 )
437
+
438
+ # check item position
439
+ self .assertEqual (shape1 .page (), 0 )
440
+ self .assertEqual (shape1 .pagePositionWithUnits (), QgsLayoutPoint (90 , 50 ))
441
+ self .assertEqual (shape2 .page (), 1 )
442
+ self .assertEqual (shape2 .pagePositionWithUnits (), QgsLayoutPoint (100 , 150 ))
443
+
444
+ def testDeletePageWithItems2 (self ):
445
+ p = QgsProject ()
446
+ l = QgsLayout (p )
447
+ collection = l .pageCollection ()
448
+
449
+ # add a page
450
+ page = QgsLayoutItemPage (l )
451
+ page .setPageSize ('A4' )
452
+ collection .addPage (page )
453
+ page2 = QgsLayoutItemPage (l )
454
+ page2 .setPageSize ('A4' )
455
+ collection .addPage (page2 )
456
+ page3 = QgsLayoutItemPage (l )
457
+ page3 .setPageSize ('A4' )
458
+ collection .addPage (page3 )
459
+
460
+ # item on pages
461
+ shape1 = QgsLayoutItemShape (l )
462
+ shape1 .attemptResize (QgsLayoutSize (90 , 50 ))
463
+ shape1 .attemptMove (QgsLayoutPoint (90 , 50 ), page = 0 )
464
+ l .addLayoutItem (shape1 )
465
+
466
+ shape2 = QgsLayoutItemShape (l )
467
+ shape2 .attemptResize (QgsLayoutSize (110 , 50 ))
468
+ shape2 .attemptMove (QgsLayoutPoint (100 , 150 ), page = 2 )
469
+ l .addLayoutItem (shape2 )
470
+
471
+ self .assertEqual (shape1 .page (), 0 )
472
+ self .assertEqual (shape2 .page (), 2 )
473
+
474
+ collection .deletePage (page2 )
475
+
476
+ # check item position
477
+ self .assertEqual (shape1 .page (), 0 )
478
+ self .assertEqual (shape1 .pagePositionWithUnits (), QgsLayoutPoint (90 , 50 ))
479
+ self .assertEqual (shape2 .page (), 1 )
480
+ self .assertEqual (shape2 .pagePositionWithUnits (), QgsLayoutPoint (100 , 150 ))
481
+
368
482
def testDataDefinedSize (self ):
369
483
p = QgsProject ()
370
484
l = QgsLayout (p )
0 commit comments