Skip to content

Commit 14a00b7

Browse files
committedMar 29, 2017
Fix rubber band unit tests
1 parent d4852ca commit 14a00b7

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed
 

‎tests/src/gui/testqgsrubberband.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ void TestQgsRubberband::initTestCase()
7373
myPolygonFileInfo.completeBaseName(), QStringLiteral( "ogr" ) );
7474

7575
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+
7681
mRubberband = 0;
7782
}
7883

@@ -111,13 +116,9 @@ void TestQgsRubberband::testAddSingleMultiGeometries()
111116

112117
void TestQgsRubberband::testBoundingRect()
113118
{
114-
QSizeF mapSize = mCanvas->mapSettings().outputSize();
115-
116119
// Set extent to match canvas size.
117120
// 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 ) );
121122
QCOMPARE( mCanvas->mapUnitsPerPixel(), 1.0 );
122123

123124
// Polygon extent is 10,10 to 30,30
@@ -129,26 +130,24 @@ void TestQgsRubberband::testBoundingRect()
129130
mRubberband->setWidth( 1 ); // default, but better be explicit
130131
mRubberband->addGeometry( geom, mPolygonLayer );
131132

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()
133134
QCOMPARE( mRubberband->boundingRect(), QRectF( QPointF( -1, -1 ), QSizeF( 28, 28 ) ) );
134135
QCOMPARE( mRubberband->pos(), QPointF(
135136
// 10 for extent minx - 3 for pen & icon
136-
7,
137+
10 - 3,
137138
// 30 for extent maxy - 3 for pen & icon
138-
mapSize.height() - 30 - 3
139+
512 - 30 - 3
139140
) );
140141

141-
mCanvas->setExtent( QgsRectangle( QRectF(
142-
QPointF( 0, 0 ), mapSize / 2
143-
) ) );
142+
mCanvas->setExtent( QgsRectangle( 0, 0, 256, 256 ) );
144143

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 ) ) );
147146
QCOMPARE( mRubberband->pos(), QPointF(
148147
// 10 for extent minx - 3 for pen & icon
149-
7 * 2,
148+
10 * 2 - 3,
150149
// 30 for extent maxy - 3 for pen & icon
151-
mapSize.height() - ( 30 + 3 ) * 2
150+
512 - 30 * 2 - 3
152151
) );
153152

154153
}

0 commit comments

Comments
 (0)
Please sign in to comment.