Skip to content

Commit 9a33979

Browse files
committed
change toolbar dock icon behaviour
1 parent c0519dc commit 9a33979

File tree

4 files changed

+25
-46
lines changed

4 files changed

+25
-46
lines changed

arho_feature_template/core/plan_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ def __init__(self):
9595
self.regulation_group_libraries = []
9696

9797
# Initialize new feature dock
98-
self.new_feature_dock = NewFeatureDock()
98+
self.new_feature_dock = NewFeatureDock(iface.mainWindow())
9999
self.new_feature_dock.tool_activated.connect(self.add_new_plan_feature)
100100
self.new_feature_dock.hide()
101101

102102
# Initialize regulation groups dock
103-
self.regulation_groups_dock = RegulationGroupsDock()
103+
self.regulation_groups_dock = RegulationGroupsDock(iface.mainWindow())
104104
self.regulation_groups_dock.new_regulation_group_requested.connect(self.create_new_regulation_group)
105105
self.regulation_groups_dock.edit_regulation_group_requested.connect(self.edit_regulation_group)
106106
self.regulation_groups_dock.delete_regulation_group_requested.connect(self.delete_regulation_group)

arho_feature_template/gui/docks/new_feature_dock.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class NewFeatureDock(QgsDockWidget, DockClass): # type: ignore
2929

3030
tool_activated = pyqtSignal()
3131

32-
def __init__(self) -> None:
33-
super().__init__()
32+
def __init__(self, parent=None) -> None:
33+
super().__init__(parent)
3434
self.setupUi(self)
3535

3636
# INIT

arho_feature_template/gui/docks/regulation_groups_dock.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class RegulationGroupsDock(QgsDockWidget, DockClass): # type: ignore
3434
edit_regulation_group_requested = pyqtSignal(RegulationGroup)
3535
delete_regulation_group_requested = pyqtSignal(RegulationGroup)
3636

37-
def __init__(self):
38-
super().__init__()
37+
def __init__(self, parent=None):
38+
super().__init__(parent)
3939
self.setupUi(self)
4040

4141
self.new_btn.setIcon(QgsApplication.getThemeIcon("mActionAdd.svg"))

arho_feature_template/plugin.py

+19-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Callable
3+
from typing import TYPE_CHECKING, Callable
44

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

18+
if TYPE_CHECKING:
19+
from qgis.gui import QgsDockWidget
20+
1821

1922
class Plugin:
2023
"""QGIS Plugin Implementation."""
@@ -120,33 +123,23 @@ def add_action(
120123
return action
121124

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

125-
iface.addDockWidget(Qt.RightDockWidgetArea, self.plan_manager.new_feature_dock)
126-
self.plan_manager.new_feature_dock.setUserVisible(False)
127-
128-
self.plan_manager.new_feature_dock.visibilityChanged.connect(self.new_feature_dock_visibility_changed)
129-
130+
# Docks
130131
self.validation_dock = ValidationDock()
131132
iface.addDockWidget(Qt.RightDockWidgetArea, self.validation_dock)
132-
self.validation_dock.setUserVisible(False)
133-
self.validation_dock.visibilityChanged.connect(self.validation_dock_visibility_changed)
134-
135-
iface.mapCanvas().mapToolSet.connect(self.plan_manager.plan_digitize_map_tool.deactivate)
136-
137-
# Regulation groups dock
133+
iface.addDockWidget(Qt.RightDockWidgetArea, self.plan_manager.new_feature_dock)
138134
iface.addDockWidget(Qt.RightDockWidgetArea, self.plan_manager.regulation_groups_dock)
139-
self.plan_manager.regulation_groups_dock.setUserVisible(False)
140-
self.plan_manager.regulation_groups_dock.visibilityChanged.connect(
141-
self.regulation_groups_dock_visibility_changed
142-
)
143135

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

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

142+
# Actions
150143
self.new_land_use_plan_action = self.add_action(
151144
text="Luo kaava",
152145
icon=QIcon(resources_path("icons", "toolbar", "luo_kaava2.svg")),
@@ -183,8 +176,7 @@ def initGui(self) -> None: # noqa N802
183176
text="Luo kaavakohde",
184177
# icon=QgsApplication.getThemeIcon("mIconFieldGeometry.svg"),
185178
icon=QIcon(resources_path("icons", "toolbar", "luo_kaavakohde.svg")),
186-
toggled_callback=self.toggle_new_feature_dock,
187-
checkable=True,
179+
triggered_callback=lambda _: self.toggle_dock_visibility(self.plan_manager.new_feature_dock),
188180
add_to_menu=True,
189181
add_to_toolbar=True,
190182
)
@@ -201,8 +193,7 @@ def initGui(self) -> None: # noqa N802
201193
self.regulation_groups_dock_action = self.add_action(
202194
text="Hallitse kaavamääräysryhmiä",
203195
icon=QgsApplication.getThemeIcon("mActionOpenTable.svg"),
204-
toggled_callback=self.toggle_regulation_groups_dock,
205-
checkable=True,
196+
triggered_callback=lambda _: self.toggle_dock_visibility(self.plan_manager.regulation_groups_dock),
206197
add_to_menu=True,
207198
add_to_toolbar=True,
208199
)
@@ -211,8 +202,7 @@ def initGui(self) -> None: # noqa N802
211202
text="Validointi",
212203
# icon=QgsApplication.getThemeIcon("mActionEditNodesItem.svg"),
213204
icon=QIcon(resources_path("icons", "toolbar", "kaavan_validointi2.svg")),
214-
toggled_callback=self.toggle_validation_dock,
215-
checkable=True,
205+
triggered_callback=lambda _: self.toggle_dock_visibility(self.validation_dock),
216206
add_to_menu=True,
217207
add_to_toolbar=True,
218208
)
@@ -249,6 +239,13 @@ def initGui(self) -> None: # noqa N802
249239
lambda: self.identify_plan_features_action.setChecked(False)
250240
)
251241

242+
def toggle_dock_visibility(self, dock_widget: QgsDockWidget):
243+
if dock_widget.isUserVisible():
244+
dock_widget.hide()
245+
else:
246+
dock_widget.show()
247+
dock_widget.raise_()
248+
252249
def add_new_plan(self):
253250
self.plan_manager.add_new_plan()
254251

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

296293
# Handle logger
297294
teardown_logger(Plugin.name)
298-
299-
def new_feature_dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
300-
self.new_feature_dock_action.setChecked(visible)
301-
302-
def toggle_new_feature_dock(self, show: bool) -> None: # noqa: FBT001
303-
self.plan_manager.new_feature_dock.setUserVisible(show)
304-
305-
def regulation_groups_dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
306-
self.regulation_groups_dock_action.setChecked(visible)
307-
308-
def toggle_regulation_groups_dock(self, show: bool) -> None: # noqa: FBT001
309-
self.plan_manager.regulation_groups_dock.setUserVisible(show)
310-
311-
def validation_dock_visibility_changed(self, visible: bool) -> None: # noqa: FBT001
312-
self.validation_dock_action.setChecked(visible)
313-
314-
def toggle_validation_dock(self, show: bool) -> None: # noqa: FBT001
315-
self.validation_dock.setUserVisible(show)

0 commit comments

Comments
 (0)