@@ -28,6 +28,7 @@ class TestQgsLayout: public QObject
28
28
void init ();// will be called before each testfunction is executed.
29
29
void cleanup ();// will be called after every testfunction.
30
30
void creation (); // test creation of QgsLayout
31
+ void units ();
31
32
32
33
private:
33
34
QString mReport ;
@@ -68,6 +69,54 @@ void TestQgsLayout::creation()
68
69
delete layout;
69
70
}
70
71
72
+ void TestQgsLayout::units ()
73
+ {
74
+ QgsLayout layout;
75
+ layout.setUnits ( QgsUnitTypes::LayoutCentimeters );
76
+ QCOMPARE ( layout.units (), QgsUnitTypes::LayoutCentimeters );
77
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutMeasurement ( 10.0 , QgsUnitTypes::LayoutMillimeters ) ), 1.0 );
78
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutSize ( 10.0 , 20.0 , QgsUnitTypes::LayoutMillimeters ) ), QSizeF ( 1.0 , 2.0 ) );
79
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutPoint ( 10.0 , 20.0 , QgsUnitTypes::LayoutMillimeters ) ), QPointF ( 1.0 , 2.0 ) );
80
+ QCOMPARE ( layout.convertFromLayoutUnits ( 1.0 , QgsUnitTypes::LayoutMillimeters ), QgsLayoutMeasurement ( 10.0 , QgsUnitTypes::LayoutMillimeters ) );
81
+ QCOMPARE ( layout.convertFromLayoutUnits ( QSizeF ( 1.0 , 2.0 ), QgsUnitTypes::LayoutMillimeters ), QgsLayoutSize ( 10.0 , 20.0 , QgsUnitTypes::LayoutMillimeters ) );
82
+ QCOMPARE ( layout.convertFromLayoutUnits ( QPointF ( 1.0 , 2.0 ), QgsUnitTypes::LayoutMillimeters ), QgsLayoutPoint ( 10.0 , 20.0 , QgsUnitTypes::LayoutMillimeters ) );
83
+
84
+ // check with dpi conversion
85
+ layout.setUnits ( QgsUnitTypes::LayoutInches );
86
+ layout.context ().setDpi ( 96.0 );
87
+ QCOMPARE ( layout.context ().dpi (), 96.0 );
88
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutMeasurement ( 96 , QgsUnitTypes::LayoutPixels ) ), 1.0 );
89
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutSize ( 96 , 96 , QgsUnitTypes::LayoutPixels ) ), QSizeF ( 1.0 , 1.0 ) );
90
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutPoint ( 96 , 96 , QgsUnitTypes::LayoutPixels ) ), QPointF ( 1.0 , 1.0 ) );
91
+ QgsLayoutMeasurement result = layout.convertFromLayoutUnits ( 1.0 , QgsUnitTypes::LayoutPixels );
92
+ QCOMPARE ( result.units (), QgsUnitTypes::LayoutPixels );
93
+ QCOMPARE ( result.length (), 96.0 );
94
+ QgsLayoutSize sizeResult = layout.convertFromLayoutUnits ( QSizeF ( 1.0 , 1.0 ), QgsUnitTypes::LayoutPixels );
95
+ QCOMPARE ( sizeResult.units (), QgsUnitTypes::LayoutPixels );
96
+ QCOMPARE ( sizeResult.width (), 96.0 );
97
+ QCOMPARE ( sizeResult.height (), 96.0 );
98
+ QgsLayoutPoint pointResult = layout.convertFromLayoutUnits ( QPointF ( 1.0 , 1.0 ), QgsUnitTypes::LayoutPixels );
99
+ QCOMPARE ( pointResult.units (), QgsUnitTypes::LayoutPixels );
100
+ QCOMPARE ( pointResult.x (), 96.0 );
101
+ QCOMPARE ( pointResult.y (), 96.0 );
102
+
103
+ layout.setUnits ( QgsUnitTypes::LayoutPixels );
104
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutMeasurement ( 1 , QgsUnitTypes::LayoutInches ) ), 96.0 );
105
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutSize ( 1 , 2 , QgsUnitTypes::LayoutInches ) ), QSizeF ( 96.0 , 192.0 ) );
106
+ QCOMPARE ( layout.convertToLayoutUnits ( QgsLayoutPoint ( 1 , 2 , QgsUnitTypes::LayoutInches ) ), QPointF ( 96.0 , 192.0 ) );
107
+ result = layout.convertFromLayoutUnits ( 96.0 , QgsUnitTypes::LayoutInches );
108
+ QCOMPARE ( result.units (), QgsUnitTypes::LayoutInches );
109
+ QCOMPARE ( result.length (), 1.0 );
110
+ sizeResult = layout.convertFromLayoutUnits ( QSizeF ( 96.0 , 192.0 ), QgsUnitTypes::LayoutInches );
111
+ QCOMPARE ( sizeResult.units (), QgsUnitTypes::LayoutInches );
112
+ QCOMPARE ( sizeResult.width (), 1.0 );
113
+ QCOMPARE ( sizeResult.height (), 2.0 );
114
+ pointResult = layout.convertFromLayoutUnits ( QPointF ( 96.0 , 192.0 ), QgsUnitTypes::LayoutInches );
115
+ QCOMPARE ( pointResult.units (), QgsUnitTypes::LayoutInches );
116
+ QCOMPARE ( pointResult.x (), 1.0 );
117
+ QCOMPARE ( pointResult.y (), 2.0 );
118
+ }
119
+
71
120
72
121
QGSTEST_MAIN ( TestQgsLayout )
73
122
#include " testqgslayout.moc"
0 commit comments