Skip to content

Commit

Permalink
Allow changing the map extent properly when showing the map
Browse files Browse the repository at this point in the history
  • Loading branch information
Joonalai committed May 10, 2024
1 parent d5227a4 commit a71e5d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Fixes

* Allow using MagicMocks to mock layers without problems
* [#53](https://github.com/GispoCoding/pytest-qgis/pull/53) Allow using MagicMocks to mock layers without problems
* [#62](https://github.com/GispoCoding/pytest-qgis/pull/62) Allow changing the map extent properly when showing the map

# Version 2.0.0 (29-11-2023)

Expand Down
5 changes: 5 additions & 0 deletions src/pytest_qgis/pytest_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ def _show_qgis_dlg(common_settings: Settings, qgis_parent: QWidget) -> None:
if not common_settings.qgis_init_disabled:
qgis_parent.setWindowTitle("Test QGIS dialog opened by Pytest-qgis")
qgis_parent.show()

# Process events each time layer a visible layer is added to
# be able to change the extent properly
assert _APP
QgsProject.instance().legendLayersAdded.connect(_APP.processEvents)
elif common_settings.qgis_init_disabled:
warnings.warn(
"Cannot show QGIS map because QGIS is not initialized. "
Expand Down
12 changes: 12 additions & 0 deletions tests/visual/test_show_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,15 @@ def test_show_map_crs_change_to_4326_2(layer_polygon, layer_points, layer_polygo
QgsProject.instance().addMapLayers(
[layer_points, layer_polygon_3067, layer_polygon]
)


@pytest.mark.qgis_show_map(timeout=DEFAULT_TIMEOUT, zoom_to_common_extent=False)
def test_show_map_should_not_keep_the_set_extent(
layer_polygon_3067, qgis_canvas, qgis_app
):
QgsProject.instance().addMapLayer(layer_polygon_3067)
qgis_canvas.setExtent(QgsRectangle(475804, 7145949.5, 549226, 7219371.5))
# This triggers the map to set the extent based on the layer
# if events are not processed after adding the layer
qgis_app.processEvents()
assert qgis_canvas.extent().area() == pytest.approx(5390790084, abs=1e5)

0 comments on commit a71e5d9

Please sign in to comment.