@@ -73,6 +73,11 @@ void TestQgsRubberband::initTestCase()
73
73
myPolygonFileInfo.completeBaseName (), QStringLiteral ( " ogr" ) );
74
74
75
75
mCanvas = new QgsMapCanvas ();
76
+ mCanvas ->setFrameStyle ( QFrame::NoFrame );
77
+ mCanvas ->resize ( 512 , 512 );
78
+ mCanvas ->show (); // to make the canvas resize
79
+ mCanvas ->hide ();
80
+
76
81
mRubberband = 0 ;
77
82
}
78
83
@@ -111,13 +116,9 @@ void TestQgsRubberband::testAddSingleMultiGeometries()
111
116
112
117
void TestQgsRubberband::testBoundingRect ()
113
118
{
114
- QSizeF mapSize = mCanvas ->mapSettings ().outputSize ();
115
-
116
119
// Set extent to match canvas size.
117
120
// This is to ensure a 1:1 scale
118
- mCanvas ->setExtent ( QgsRectangle ( QRectF (
119
- QPointF ( 0 , 0 ), mapSize
120
- ) ) );
121
+ mCanvas ->setExtent ( QgsRectangle ( 0 , 0 , 512 , 512 ) );
121
122
QCOMPARE ( mCanvas ->mapUnitsPerPixel (), 1.0 );
122
123
123
124
// Polygon extent is 10,10 to 30,30
@@ -129,26 +130,24 @@ void TestQgsRubberband::testBoundingRect()
129
130
mRubberband ->setWidth ( 1 ); // default, but better be explicit
130
131
mRubberband ->addGeometry ( geom, mPolygonLayer );
131
132
132
- // 20 pixels for the extent + 3 for pen & icon per side + 2 of padding
133
+ // 20 pixels for the extent + 3 for pen & icon per side + 2 of extra padding from setRect()
133
134
QCOMPARE ( mRubberband ->boundingRect (), QRectF ( QPointF ( -1 , -1 ), QSizeF ( 28 , 28 ) ) );
134
135
QCOMPARE ( mRubberband ->pos (), QPointF (
135
136
// 10 for extent minx - 3 for pen & icon
136
- 7 ,
137
+ 10 - 3 ,
137
138
// 30 for extent maxy - 3 for pen & icon
138
- mapSize. height () - 30 - 3
139
+ 512 - 30 - 3
139
140
) );
140
141
141
- mCanvas ->setExtent ( QgsRectangle ( QRectF (
142
- QPointF ( 0 , 0 ), mapSize / 2
143
- ) ) );
142
+ mCanvas ->setExtent ( QgsRectangle ( 0 , 0 , 256 , 256 ) );
144
143
145
- // 40 pixels for the extent + 6 for pen & icon per side + 2 of padding
146
- QCOMPARE ( mRubberband ->boundingRect (), QRectF ( QPointF ( -1 , -1 ), QSizeF ( 54 , 54 ) ) );
144
+ // 40 pixels for the extent + 3 for pen & icon per side + 2 of extra padding from setRect()
145
+ QCOMPARE ( mRubberband ->boundingRect (), QRectF ( QPointF ( -1 , -1 ), QSizeF ( 48 , 48 ) ) );
147
146
QCOMPARE ( mRubberband ->pos (), QPointF (
148
147
// 10 for extent minx - 3 for pen & icon
149
- 7 * 2 ,
148
+ 10 * 2 - 3 ,
150
149
// 30 for extent maxy - 3 for pen & icon
151
- mapSize. height () - ( 30 + 3 ) * 2
150
+ 512 - 30 * 2 - 3
152
151
) );
153
152
154
153
}
0 commit comments