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

Lisää kuvakkeet toolbariin #88

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
34 changes: 19 additions & 15 deletions arho_feature_template/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING, Callable, cast

from qgis.core import QgsApplication
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTranslator
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QWidget
Expand Down Expand Up @@ -44,11 +45,12 @@ def __init__(self) -> None:
self.menu = Plugin.name

self.toolbar = iface.addToolBar("ARHO Toolbar")
self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

def add_action(
self,
icon_path: str,
text: str,
icon: QIcon | None = None,
triggered_callback: Callable | None = None,
*,
toggled_callback: Callable | None = None,
Expand All @@ -63,8 +65,7 @@ def add_action(
) -> QAction:
"""Add a toolbar icon to the toolbar.

:param icon_path: Path to the icon for this action. Can be a resource
path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
:param icon: Icon for this action.

:param text: Text that should be shown in menu items for this action.

Expand All @@ -91,8 +92,8 @@ def add_action(
added to self.actions list.
:rtype: QAction
"""

icon = QIcon(icon_path)
if not icon:
icon = QIcon("")
action = QAction(icon, text, parent)
# noinspection PyUnresolvedReferences
if triggered_callback:
Expand Down Expand Up @@ -136,19 +137,24 @@ def initGui(self) -> None: # noqa N802

iface.mapCanvas().mapToolSet.connect(self.templater.digitize_map_tool.deactivate)

# icons to consider:
# icon=QgsApplication.getThemeIcon("mActionStreamingDigitize.svg"),
# icon=QgsApplication.getThemeIcon("mIconGeometryCollectionLayer.svg"),
# icon=QgsApplication.getThemeIcon("mActionSharingExport.svg"),

# Add main plugin action to the toolbar
self.new_land_use_plan_action = self.add_action(
"",
"Luo uusi kaava",
self.add_new_plan,
text="Luo uusi kaava",
icon=QgsApplication.getThemeIcon("mActionNewMap.svg"),
triggered_callback=self.add_new_plan,
add_to_menu=True,
add_to_toolbar=True,
status_tip="Luo uusi kaava",
)

self.load_land_use_plan_action = self.add_action(
"",
text="Lataa/avaa kaavaa",
icon=QgsApplication.getThemeIcon("mActionFileOpen.svg"),
triggered_callback=self.load_existing_land_use_plan,
parent=iface.mainWindow(),
add_to_menu=True,
Expand All @@ -157,34 +163,32 @@ def initGui(self) -> None: # noqa N802
)

self.template_dock_action = self.add_action(
"",
"Kaavakohdetemplaatit",
None,
text="Kaavakohdetemplaatit",
icon=QgsApplication.getThemeIcon("mIconFieldGeometry.svg"),
toggled_callback=self.toggle_template_dock,
checkable=True,
add_to_menu=True,
add_to_toolbar=True,
)

self.new_plan_regulation_group = self.add_action(
"",
text="Luo kaavamääräysryhmä",
icon=QgsApplication.getThemeIcon("mActionAddManualTable.svg"),
triggered_callback=self.open_plan_regulation_group_form,
add_to_menu=True,
add_to_toolbar=True,
)

self.serialize_plan_action = self.add_action(
"",
text="Tallenna kaava JSON",
icon=QgsApplication.getThemeIcon("mActionFileSaveAs.svg"),
triggered_callback=self.serialize_plan,
add_to_menu=True,
add_to_toolbar=True,
status_tip="Tallenna aktiivinen kaava JSON muodossa",
)

self.plugin_settings_action = self.add_action(
"",
text="Asetukset",
triggered_callback=self.open_settings,
add_to_menu=True,
Expand Down
Loading