Skip to content

Commit 651b5c6

Browse files
committed
Add a unit test for destroying canvas while a job is canceling
1 parent 0a1517b commit 651b5c6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/src/python/test_qgsmapcanvas.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,34 @@ def testRefreshOnTimer(self):
154154
# messy, but only way to check that canvas redraw doesn't occur
155155
self.assertFalse(canvas.isDrawing())
156156

157+
def testCancelAndDestroy(self):
158+
""" test that nothing goes wrong if we destroy a canvas while a job is canceling """
159+
canvas = QgsMapCanvas()
160+
canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
161+
canvas.setFrameStyle(0)
162+
canvas.resize(600, 400)
163+
164+
layer = QgsVectorLayer("Polygon?crs=epsg:4326&field=fldtxt:string",
165+
"layer", "memory")
166+
167+
# add a ton of features
168+
for i in range(5000):
169+
f = QgsFeature()
170+
f.setGeometry(QgsGeometry.fromRect(QgsRectangle(5, 25, 25, 45)))
171+
self.assertTrue(layer.dataProvider().addFeatures([f]))
172+
173+
canvas.setLayers([layer])
174+
canvas.setExtent(QgsRectangle(10, 30, 20, 35))
175+
canvas.show()
176+
177+
# need to wait until first redraw can occur (note that we first need to wait till drawing starts!)
178+
while not canvas.isDrawing():
179+
app.processEvents()
180+
self.assertTrue(canvas.isDrawing())
181+
182+
canvas.stopRendering()
183+
del canvas
184+
157185
def canvasImageCheck(self, name, reference_image, canvas):
158186
self.report += "<h2>Render {}</h2>\n".format(name)
159187
temp_dir = QDir.tempPath() + '/'

0 commit comments

Comments
 (0)