@@ -48,7 +48,9 @@ class TestQgsLayoutItemGroup : public QObject
48
48
void deleteGroup (); // test deleting group works
49
49
void groupVisibility ();
50
50
void moveGroup ();
51
+ void moveGroupReferencePos ();
51
52
void resizeGroup ();
53
+ void resizeGroupReferencePos ();
52
54
void undoRedo (); // test that group/ungroup undo/redo commands don't crash
53
55
54
56
private:
@@ -354,6 +356,69 @@ void TestQgsLayoutItemGroup::moveGroup()
354
356
QCOMPARE ( item2->positionWithUnits ().units (), QgsUnitTypes::LayoutInches );
355
357
}
356
358
359
+ void TestQgsLayoutItemGroup::moveGroupReferencePos ()
360
+ {
361
+ QgsProject proj;
362
+ QgsLayout l ( &proj );
363
+
364
+ QgsLayoutItemRectangularShape *item = new QgsLayoutItemRectangularShape ( &l );
365
+ l.addLayoutItem ( item );
366
+ item->attemptMove ( QgsLayoutPoint ( 5 , 9 ) );
367
+ item->attemptResize ( QgsLayoutSize ( 4 , 7 ) );
368
+ item->setReferencePoint ( QgsLayoutItem::UpperRight );
369
+
370
+ QCOMPARE ( item->positionWithUnits ().x (), 9.0 );
371
+ QCOMPARE ( item->positionWithUnits ().y (), 9.0 );
372
+ QCOMPARE ( item->scenePos ().x (), 5.0 );
373
+ QCOMPARE ( item->scenePos ().y (), 9.0 );
374
+
375
+ QgsLayoutItemRectangularShape *item2 = new QgsLayoutItemRectangularShape ( &l );
376
+ l.addLayoutItem ( item2 );
377
+ item2->attemptMove ( QgsLayoutPoint ( 15 , 19 ) );
378
+ item2->attemptResize ( QgsLayoutSize ( 6 , 3 ) );
379
+ item2->setReferencePoint ( QgsLayoutItem::LowerLeft );
380
+
381
+ QCOMPARE ( item2->positionWithUnits ().x (), 15.0 );
382
+ QCOMPARE ( item2->positionWithUnits ().y (), 22.0 );
383
+ QCOMPARE ( item2->scenePos ().x (), 15.0 );
384
+ QCOMPARE ( item2->scenePos ().y (), 19.0 );
385
+
386
+ // group items
387
+ QList<QgsLayoutItem *> groupItems;
388
+ groupItems << item << item2;
389
+ QgsLayoutItemGroup *group = l.groupItems ( groupItems );
390
+
391
+ QCOMPARE ( group->positionWithUnits ().x (), 5.0 );
392
+ QCOMPARE ( group->positionWithUnits ().y (), 9.0 );
393
+ QCOMPARE ( group->positionWithUnits ().units (), QgsUnitTypes::LayoutMillimeters );
394
+ QCOMPARE ( group->sizeWithUnits ().width (), 16.0 );
395
+ QCOMPARE ( group->sizeWithUnits ().height (), 13.0 );
396
+ QCOMPARE ( group->scenePos ().x (), 5.0 );
397
+ QCOMPARE ( group->scenePos ().y (), 9.0 );
398
+ QCOMPARE ( group->rect ().width (), 16.0 );
399
+ QCOMPARE ( group->rect ().height (), 13.0 );
400
+
401
+ group->attemptMove ( QgsLayoutPoint ( 2 , 4 ) );
402
+ QCOMPARE ( group->positionWithUnits ().x (), 2.0 );
403
+ QCOMPARE ( group->positionWithUnits ().y (), 4.0 );
404
+ QCOMPARE ( group->scenePos ().x (), 2.0 );
405
+ QCOMPARE ( group->scenePos ().y (), 4.0 );
406
+ QCOMPARE ( group->sizeWithUnits ().width (), 16.0 );
407
+ QCOMPARE ( group->sizeWithUnits ().height (), 13.0 );
408
+ QCOMPARE ( group->rect ().width (), 16.0 );
409
+ QCOMPARE ( group->rect ().height (), 13.0 );
410
+
411
+ QCOMPARE ( item->pos ().x (), 2.0 );
412
+ QCOMPARE ( item->pos ().y (), 4.0 );
413
+ QCOMPARE ( item->positionWithUnits ().x (), 6.0 );
414
+ QCOMPARE ( item->positionWithUnits ().y (), 4.0 );
415
+
416
+ QCOMPARE ( item2->pos ().x (), 12.0 );
417
+ QCOMPARE ( item2->pos ().y (), 14.0 );
418
+ QCOMPARE ( item2->positionWithUnits ().x (), 12.0 );
419
+ QCOMPARE ( item2->positionWithUnits ().y (), 17.0 );
420
+ }
421
+
357
422
void TestQgsLayoutItemGroup::resizeGroup ()
358
423
{
359
424
QgsProject proj;
@@ -402,6 +467,77 @@ void TestQgsLayoutItemGroup::resizeGroup()
402
467
QCOMPARE ( item2->sizeWithUnits ().units (), QgsUnitTypes::LayoutInches );
403
468
}
404
469
470
+ void TestQgsLayoutItemGroup::resizeGroupReferencePos ()
471
+ {
472
+ QgsProject proj;
473
+ QgsLayout l ( &proj );
474
+
475
+ QgsLayoutItemRectangularShape *item = new QgsLayoutItemRectangularShape ( &l );
476
+ l.addLayoutItem ( item );
477
+ item->attemptMove ( QgsLayoutPoint ( 5 , 9 ) );
478
+ item->attemptResize ( QgsLayoutSize ( 4 , 7 ) );
479
+ item->setReferencePoint ( QgsLayoutItem::UpperRight );
480
+
481
+ QCOMPARE ( item->positionWithUnits ().x (), 9.0 );
482
+ QCOMPARE ( item->positionWithUnits ().y (), 9.0 );
483
+ QCOMPARE ( item->scenePos ().x (), 5.0 );
484
+ QCOMPARE ( item->scenePos ().y (), 9.0 );
485
+
486
+ QgsLayoutItemRectangularShape *item2 = new QgsLayoutItemRectangularShape ( &l );
487
+ l.addLayoutItem ( item2 );
488
+ item2->attemptMove ( QgsLayoutPoint ( 15 , 19 ) );
489
+ item2->attemptResize ( QgsLayoutSize ( 6 , 3 ) );
490
+ item2->setReferencePoint ( QgsLayoutItem::LowerLeft );
491
+
492
+ QCOMPARE ( item2->positionWithUnits ().x (), 15.0 );
493
+ QCOMPARE ( item2->positionWithUnits ().y (), 22.0 );
494
+ QCOMPARE ( item2->scenePos ().x (), 15.0 );
495
+ QCOMPARE ( item2->scenePos ().y (), 19.0 );
496
+
497
+ // group items
498
+ QList<QgsLayoutItem *> groupItems;
499
+ groupItems << item << item2;
500
+ QgsLayoutItemGroup *group = l.groupItems ( groupItems );
501
+
502
+ QCOMPARE ( group->positionWithUnits ().x (), 5.0 );
503
+ QCOMPARE ( group->positionWithUnits ().y (), 9.0 );
504
+ QCOMPARE ( group->positionWithUnits ().units (), QgsUnitTypes::LayoutMillimeters );
505
+ QCOMPARE ( group->sizeWithUnits ().width (), 16.0 );
506
+ QCOMPARE ( group->sizeWithUnits ().height (), 13.0 );
507
+ QCOMPARE ( group->scenePos ().x (), 5.0 );
508
+ QCOMPARE ( group->scenePos ().y (), 9.0 );
509
+ QCOMPARE ( group->rect ().width (), 16.0 );
510
+ QCOMPARE ( group->rect ().height (), 13.0 );
511
+
512
+ group->attemptResize ( QgsLayoutSize ( 32.0 , 26.0 ) );
513
+ QCOMPARE ( group->positionWithUnits ().x (), 5.0 );
514
+ QCOMPARE ( group->positionWithUnits ().y (), 9.0 );
515
+ QCOMPARE ( group->scenePos ().x (), 5.0 );
516
+ QCOMPARE ( group->scenePos ().y (), 9.0 );
517
+ QCOMPARE ( group->sizeWithUnits ().width (), 32.0 );
518
+ QCOMPARE ( group->sizeWithUnits ().height (), 26.0 );
519
+ QCOMPARE ( group->rect ().width (), 32.0 );
520
+ QCOMPARE ( group->rect ().height (), 26.0 );
521
+
522
+ QCOMPARE ( item->pos ().x (), 5.0 );
523
+ QCOMPARE ( item->pos ().y (), 9.0 );
524
+ QCOMPARE ( item->positionWithUnits ().x (), 13.0 );
525
+ QCOMPARE ( item->positionWithUnits ().y (), 9.0 );
526
+ QCOMPARE ( item->sizeWithUnits ().width (), 8.0 );
527
+ QCOMPARE ( item->sizeWithUnits ().height (), 14.0 );
528
+ QCOMPARE ( item->rect ().width (), 8.0 );
529
+ QCOMPARE ( item->rect ().height (), 14.0 );
530
+
531
+ QCOMPARE ( item2->pos ().x (), 25.0 );
532
+ QCOMPARE ( item2->pos ().y (), 29.0 );
533
+ QCOMPARE ( item2->positionWithUnits ().x (), 25.0 );
534
+ QCOMPARE ( item2->positionWithUnits ().y (), 35.0 );
535
+ QCOMPARE ( item2->sizeWithUnits ().width (), 12.0 );
536
+ QCOMPARE ( item2->sizeWithUnits ().height (), 6.0 );
537
+ QCOMPARE ( item2->rect ().width (), 12.0 );
538
+ QCOMPARE ( item2->rect ().height (), 6.0 );
539
+ }
540
+
405
541
Q_DECLARE_METATYPE ( QgsLayoutItemGroup * )
406
542
Q_DECLARE_METATYPE( QgsLayoutItemRectangularShape * )
407
543
Q_DECLARE_METATYPE( QgsLayoutItem * )
0 commit comments