diff --git a/src/quality_result_gui_plugin/env.py b/src/quality_result_gui/env.py
similarity index 79%
rename from src/quality_result_gui_plugin/env.py
rename to src/quality_result_gui/env.py
index 23ff99e..cb67d85 100644
--- a/src/quality_result_gui_plugin/env.py
+++ b/src/quality_result_gui/env.py
@@ -18,9 +18,21 @@
# along with quality-result-gui. If not, see .
import os
+from pathlib import Path
IS_DEVELOPMENT_MODE = os.environ.get("IS_DEVELOPMENT_MODE", "0").lower() in (
"1",
"true",
"yes",
)
+
+TEST_JSON_FILE_PATH = (
+ str(
+ (
+ Path(__file__).parent
+ / "dev_tools/example_quality_errors/quality_errors.json"
+ ).resolve()
+ )
+ if IS_DEVELOPMENT_MODE
+ else None
+)
diff --git a/src/quality_result_gui/quality_error_visualizer.py b/src/quality_result_gui/quality_error_visualizer.py
index dfcf406..11d21ce 100644
--- a/src/quality_result_gui/quality_error_visualizer.py
+++ b/src/quality_result_gui/quality_error_visualizer.py
@@ -17,17 +17,24 @@
# You should have received a copy of the GNU General Public License
# along with quality-result-gui. If not, see .
+import json
import logging
-from typing import Iterable, List, Optional
+from pathlib import Path
+from typing import Iterable, List, Optional, cast
from qgis.core import QgsAnnotationLayer, QgsCoordinateReferenceSystem, QgsProject
+from qgis.gui import QgisInterface
+from qgis.utils import iface as utils_iface
from quality_result_gui.api.types.quality_error import QualityError
from quality_result_gui.configuration import QualityLayerStyleConfig
+from quality_result_gui.env import IS_DEVELOPMENT_MODE, TEST_JSON_FILE_PATH
from quality_result_gui.quality_layer import QualityErrorLayer
from quality_result_gui.ui.quality_error_tree_view import SelectionType
from quality_result_gui.utils import layer_utils
+iface = cast(QgisInterface, utils_iface)
+
LOGGER = logging.getLogger(__name__)
@@ -62,6 +69,17 @@ def add_new_errors(self, quality_errors: Iterable[QualityError]) -> None:
quality_error, use_highlighted_style=False
)
+ # In dev mode define map extent when all errors are added to layer
+ if IS_DEVELOPMENT_MODE and TEST_JSON_FILE_PATH:
+ layer = self._quality_error_layer.find_layer_from_project()
+ amount_of_added_errors = len(layer.items().keys()) if layer else 0
+ if (
+ len(json.loads(Path(TEST_JSON_FILE_PATH).read_text()))
+ == amount_of_added_errors
+ and layer
+ ):
+ iface.mapCanvas().setExtent(layer.extent())
+
def remove_errors(self, quality_errors: Iterable[QualityError]) -> None:
errors = list(quality_errors)
self._quality_error_layer.remove_annotations(errors)
diff --git a/src/quality_result_gui_plugin/plugin.py b/src/quality_result_gui_plugin/plugin.py
index 1e7aa30..aa8fc66 100644
--- a/src/quality_result_gui_plugin/plugin.py
+++ b/src/quality_result_gui_plugin/plugin.py
@@ -34,10 +34,10 @@
import quality_result_gui
import quality_result_gui_plugin
+from quality_result_gui.env import IS_DEVELOPMENT_MODE, TEST_JSON_FILE_PATH
from quality_result_gui.quality_error_manager import QualityResultManager
from quality_result_gui_plugin.dev_tools.dev_tools_dialog import DevToolsDialog
from quality_result_gui_plugin.dev_tools.mock_api_client import MockQualityResultClient
-from quality_result_gui_plugin.env import IS_DEVELOPMENT_MODE
LOGGER = logging.getLogger(__name__)
@@ -86,13 +86,7 @@ def initGui(self) -> None: # noqa: N802 (qgis naming)
# Add shortcut action to open qulity results form example json when in dev mode
if IS_DEVELOPMENT_MODE and self.dev_tool_action is None:
-
- self._test_json_file_path = str(
- (
- Path(__file__).parent
- / "dev_tools/example_quality_errors/quality_errors.json"
- ).resolve()
- )
+ self._test_json_file_path = TEST_JSON_FILE_PATH or ""
self.dev_tool_action = QAction(
QIcon(resources_path("icons/quality_result_gui.svg")),
"Test quality result GUI",
@@ -122,7 +116,6 @@ def _unload_quality_error_manager_if_exists(self) -> None:
self.quality_error_manager = None
def _on_open_dev_tools_called(self) -> None:
-
dialog = DevToolsDialog(iface.mainWindow())
if dialog.exec_():
self._test_json_file_path = (