Skip to content

Commit

Permalink
fix: set initial map extent when in development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vaahtokarkki committed Aug 7, 2023
1 parent 35d5803 commit f58c1a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@
# along with quality-result-gui. If not, see <https://www.gnu.org/licenses/>.

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
)
20 changes: 19 additions & 1 deletion src/quality_result_gui/quality_error_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@
# You should have received a copy of the GNU General Public License
# along with quality-result-gui. If not, see <https://www.gnu.org/licenses/>.

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__)


Expand Down Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions src/quality_result_gui_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit f58c1a4

Please sign in to comment.