Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dock widgettien napit eivät jää enää pohjaan #199

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arho_feature_template/core/plan_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def __init__(self):
self.regulation_group_libraries = []

# Initialize new feature dock
self.new_feature_dock = NewFeatureDock()
self.new_feature_dock = NewFeatureDock(iface.mainWindow())
self.new_feature_dock.tool_activated.connect(self.add_new_plan_feature)
self.new_feature_dock.hide()

# Initialize regulation groups dock
self.regulation_groups_dock = RegulationGroupsDock()
self.regulation_groups_dock = RegulationGroupsDock(iface.mainWindow())
self.regulation_groups_dock.new_regulation_group_requested.connect(self.create_new_regulation_group)
self.regulation_groups_dock.edit_regulation_group_requested.connect(self.edit_regulation_group)
self.regulation_groups_dock.delete_regulation_group_requested.connect(self.delete_regulation_group)
Expand Down
4 changes: 2 additions & 2 deletions arho_feature_template/gui/docks/new_feature_dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class NewFeatureDock(QgsDockWidget, DockClass): # type: ignore

tool_activated = pyqtSignal()

def __init__(self) -> None:
super().__init__()
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.setupUi(self)

# INIT
Expand Down
4 changes: 2 additions & 2 deletions arho_feature_template/gui/docks/regulation_groups_dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class RegulationGroupsDock(QgsDockWidget, DockClass): # type: ignore
edit_regulation_group_requested = pyqtSignal(RegulationGroup)
delete_regulation_group_requested = pyqtSignal(RegulationGroup)

def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)

self.new_btn.setIcon(QgsApplication.getThemeIcon("mActionAdd.svg"))
Expand Down
59 changes: 19 additions & 40 deletions arho_feature_template/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Callable
from typing import TYPE_CHECKING, Callable

from qgis.core import QgsApplication
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator
Expand All @@ -15,6 +15,9 @@
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name, resources_path
from arho_feature_template.utils.misc_utils import disconnect_signal, iface

if TYPE_CHECKING:
from qgis.gui import QgsDockWidget


class Plugin:
"""QGIS Plugin Implementation."""
Expand Down Expand Up @@ -120,33 +123,23 @@ def add_action(
return action

def initGui(self) -> None: # noqa N802
# Plan manager
self.plan_manager = PlanManager()
iface.mapCanvas().mapToolSet.connect(self.plan_manager.plan_digitize_map_tool.deactivate)

iface.addDockWidget(Qt.RightDockWidgetArea, self.plan_manager.new_feature_dock)
self.plan_manager.new_feature_dock.setUserVisible(False)

self.plan_manager.new_feature_dock.visibilityChanged.connect(self.new_feature_dock_visibility_changed)

# Docks
self.validation_dock = ValidationDock()
iface.addDockWidget(Qt.RightDockWidgetArea, self.validation_dock)
self.validation_dock.setUserVisible(False)
self.validation_dock.visibilityChanged.connect(self.validation_dock_visibility_changed)

iface.mapCanvas().mapToolSet.connect(self.plan_manager.plan_digitize_map_tool.deactivate)

# Regulation groups dock
iface.addDockWidget(Qt.RightDockWidgetArea, self.plan_manager.new_feature_dock)
iface.addDockWidget(Qt.RightDockWidgetArea, self.plan_manager.regulation_groups_dock)
self.plan_manager.regulation_groups_dock.setUserVisible(False)
self.plan_manager.regulation_groups_dock.visibilityChanged.connect(
self.regulation_groups_dock_visibility_changed
)

# Try initializing the plugin immediately in case the project is already open
self.plan_manager.initialize_from_project()

# (Re)initialize whenever a project is opened
iface.projectRead.connect(self.plan_manager.initialize_from_project)

# Actions
self.new_land_use_plan_action = self.add_action(
text="Luo kaava",
icon=QIcon(resources_path("icons", "toolbar", "luo_kaava2.svg")),
Expand Down Expand Up @@ -183,8 +176,7 @@ def initGui(self) -> None: # noqa N802
text="Luo kaavakohde",
# icon=QgsApplication.getThemeIcon("mIconFieldGeometry.svg"),
icon=QIcon(resources_path("icons", "toolbar", "luo_kaavakohde.svg")),
toggled_callback=self.toggle_new_feature_dock,
checkable=True,
triggered_callback=lambda _: self.toggle_dock_visibility(self.plan_manager.new_feature_dock),
add_to_menu=True,
add_to_toolbar=True,
)
Expand All @@ -201,8 +193,7 @@ def initGui(self) -> None: # noqa N802
self.regulation_groups_dock_action = self.add_action(
text="Hallitse kaavamääräysryhmiä",
icon=QgsApplication.getThemeIcon("mActionOpenTable.svg"),
toggled_callback=self.toggle_regulation_groups_dock,
checkable=True,
triggered_callback=lambda _: self.toggle_dock_visibility(self.plan_manager.regulation_groups_dock),
add_to_menu=True,
add_to_toolbar=True,
)
Expand All @@ -211,8 +202,7 @@ def initGui(self) -> None: # noqa N802
text="Validointi",
# icon=QgsApplication.getThemeIcon("mActionEditNodesItem.svg"),
icon=QIcon(resources_path("icons", "toolbar", "kaavan_validointi2.svg")),
toggled_callback=self.toggle_validation_dock,
checkable=True,
triggered_callback=lambda _: self.toggle_dock_visibility(self.validation_dock),
add_to_menu=True,
add_to_toolbar=True,
)
Expand Down Expand Up @@ -249,6 +239,13 @@ def initGui(self) -> None: # noqa N802
lambda: self.identify_plan_features_action.setChecked(False)
)

def toggle_dock_visibility(self, dock_widget: QgsDockWidget):
if dock_widget.isUserVisible():
dock_widget.hide()
else:
dock_widget.show()
dock_widget.raise_()

def add_new_plan(self):
self.plan_manager.add_new_plan()

Expand Down Expand Up @@ -295,21 +292,3 @@ def unload(self) -> None:

# Handle logger
teardown_logger(Plugin.name)

def new_feature_dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
self.new_feature_dock_action.setChecked(visible)

def toggle_new_feature_dock(self, show: bool) -> None: # noqa: FBT001
self.plan_manager.new_feature_dock.setUserVisible(show)

def regulation_groups_dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
self.regulation_groups_dock_action.setChecked(visible)

def toggle_regulation_groups_dock(self, show: bool) -> None: # noqa: FBT001
self.plan_manager.regulation_groups_dock.setUserVisible(show)

def validation_dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
self.validation_dock_action.setChecked(visible)

def toggle_validation_dock(self, show: bool) -> None: # noqa: FBT001
self.validation_dock.setUserVisible(show)
Loading