@@ -58,13 +58,10 @@ def testDeferredUpdate(self):
58
58
canvas .setLayers ([layer ])
59
59
canvas .setExtent (QgsRectangle (10 , 30 , 20 , 35 ))
60
60
canvas .show ()
61
-
62
61
# need to wait until first redraw can occur (note that we first need to wait till drawing starts!)
63
62
while not canvas .isDrawing ():
64
63
app .processEvents ()
65
- while canvas .isDrawing ():
66
- app .processEvents ()
67
-
64
+ canvas .waitWhileRendering ()
68
65
self .assertTrue (self .canvasImageCheck ('empty_canvas' , 'empty_canvas' , canvas ))
69
66
70
67
# add polygon to layer
@@ -83,10 +80,7 @@ def testDeferredUpdate(self):
83
80
84
81
# refresh canvas
85
82
canvas .refresh ()
86
- while not canvas .isDrawing ():
87
- app .processEvents ()
88
- while canvas .isDrawing ():
89
- app .processEvents ()
83
+ canvas .waitWhileRendering ()
90
84
91
85
# now we expect the canvas check to fail (since they'll be a new polygon rendered over it)
92
86
self .assertFalse (self .canvasImageCheck ('empty_canvas' , 'empty_canvas' , canvas ))
@@ -110,9 +104,7 @@ def testRefreshOnTimer(self):
110
104
# need to wait until first redraw can occur (note that we first need to wait till drawing starts!)
111
105
while not canvas .isDrawing ():
112
106
app .processEvents ()
113
- while canvas .isDrawing ():
114
- app .processEvents ()
115
-
107
+ canvas .waitWhileRendering ()
116
108
self .assertTrue (self .canvasImageCheck ('empty_canvas' , 'empty_canvas' , canvas ))
117
109
118
110
# add polygon to layer
@@ -210,9 +202,7 @@ def testMapTheme(self):
210
202
# need to wait until first redraw can occur (note that we first need to wait till drawing starts!)
211
203
while not canvas .isDrawing ():
212
204
app .processEvents ()
213
- while canvas .isDrawing ():
214
- app .processEvents ()
215
-
205
+ canvas .waitWhileRendering ()
216
206
self .assertTrue (self .canvasImageCheck ('theme1' , 'theme1' , canvas ))
217
207
218
208
# add some styles
@@ -223,18 +213,12 @@ def testMapTheme(self):
223
213
layer .styleManager ().addStyleFromLayer ('style2' )
224
214
225
215
canvas .refresh ()
226
- while not canvas .isDrawing ():
227
- app .processEvents ()
228
- while canvas .isDrawing ():
229
- app .processEvents ()
216
+ canvas .waitWhileRendering ()
230
217
self .assertTrue (self .canvasImageCheck ('theme2' , 'theme2' , canvas ))
231
218
232
219
layer .styleManager ().setCurrentStyle ('style1' )
233
220
canvas .refresh ()
234
- while not canvas .isDrawing ():
235
- app .processEvents ()
236
- while canvas .isDrawing ():
237
- app .processEvents ()
221
+ canvas .waitWhileRendering ()
238
222
self .assertTrue (self .canvasImageCheck ('theme1' , 'theme1' , canvas ))
239
223
240
224
# ok, so all good with setting/rendering map styles
@@ -258,18 +242,12 @@ def testMapTheme(self):
258
242
259
243
canvas .setTheme ('theme2' )
260
244
canvas .refresh ()
261
- while not canvas .isDrawing ():
262
- app .processEvents ()
263
- while canvas .isDrawing ():
264
- app .processEvents ()
245
+ canvas .waitWhileRendering ()
265
246
self .assertTrue (self .canvasImageCheck ('theme2' , 'theme2' , canvas ))
266
247
267
248
canvas .setTheme ('theme1' )
268
249
canvas .refresh ()
269
- while not canvas .isDrawing ():
270
- app .processEvents ()
271
- while canvas .isDrawing ():
272
- app .processEvents ()
250
+ canvas .waitWhileRendering ()
273
251
self .assertTrue (self .canvasImageCheck ('theme1' , 'theme1' , canvas ))
274
252
275
253
# add another layer
@@ -286,17 +264,11 @@ def testMapTheme(self):
286
264
287
265
# rerender canvas - should NOT show new layer
288
266
canvas .refresh ()
289
- while not canvas .isDrawing ():
290
- app .processEvents ()
291
- while canvas .isDrawing ():
292
- app .processEvents ()
267
+ canvas .waitWhileRendering ()
293
268
self .assertTrue (self .canvasImageCheck ('theme1' , 'theme1' , canvas ))
294
269
# test again - this time refresh all layers
295
270
canvas .refreshAllLayers ()
296
- while not canvas .isDrawing ():
297
- app .processEvents ()
298
- while canvas .isDrawing ():
299
- app .processEvents ()
271
+ canvas .waitWhileRendering ()
300
272
self .assertTrue (self .canvasImageCheck ('theme1' , 'theme1' , canvas ))
301
273
302
274
# add layer 2 to theme1
@@ -305,10 +277,7 @@ def testMapTheme(self):
305
277
QgsProject .instance ().mapThemeCollection ().update ('theme1' , theme1 )
306
278
307
279
canvas .refresh ()
308
- while not canvas .isDrawing ():
309
- app .processEvents ()
310
- while canvas .isDrawing ():
311
- app .processEvents ()
280
+ canvas .waitWhileRendering ()
312
281
self .assertTrue (self .canvasImageCheck ('theme3' , 'theme3' , canvas ))
313
282
314
283
# change the appearance of an active style
@@ -320,42 +289,29 @@ def testMapTheme(self):
320
289
QgsProject .instance ().mapThemeCollection ().update ('theme1' , theme1 )
321
290
322
291
canvas .refresh ()
323
- while not canvas .isDrawing ():
324
- app .processEvents ()
325
- while canvas .isDrawing ():
326
- app .processEvents ()
292
+ canvas .waitWhileRendering ()
327
293
self .assertTrue (self .canvasImageCheck ('theme3' , 'theme3' , canvas ))
328
294
329
295
layer2 .styleManager ().setCurrentStyle ('style4' )
330
296
sym3 = QgsFillSymbol .createSimple ({'color' : '#b200b2' })
331
297
layer2 .renderer ().setSymbol (sym3 )
332
298
canvas .refresh ()
333
-
334
- while not canvas .isDrawing ():
335
- app .processEvents ()
336
- while canvas .isDrawing ():
337
- app .processEvents ()
299
+ canvas .waitWhileRendering ()
338
300
self .assertTrue (self .canvasImageCheck ('theme4' , 'theme4' , canvas ))
339
301
340
302
# try setting layers while a theme is in place
341
303
canvas .setLayers ([layer ])
342
304
canvas .refresh ()
343
305
344
306
# should be no change... setLayers should be ignored if canvas is following a theme!
345
- while not canvas .isDrawing ():
346
- app .processEvents ()
347
- while canvas .isDrawing ():
348
- app .processEvents ()
307
+ canvas .waitWhileRendering ()
349
308
self .assertTrue (self .canvasImageCheck ('theme4' , 'theme4' , canvas ))
350
309
351
310
# setLayerStyleOverrides while theme is in place
352
311
canvas .setLayerStyleOverrides ({layer2 .id (): 'original' })
353
312
# should be no change... setLayerStyleOverrides should be ignored if canvas is following a theme!
354
313
canvas .refresh ()
355
- while not canvas .isDrawing ():
356
- app .processEvents ()
357
- while canvas .isDrawing ():
358
- app .processEvents ()
314
+ canvas .waitWhileRendering ()
359
315
self .assertTrue (self .canvasImageCheck ('theme4' , 'theme4' , canvas ))
360
316
361
317
def canvasImageCheck (self , name , reference_image , canvas ):
0 commit comments