Menü und Symbolleiste überarbeitet.
This commit is contained in:
@@ -3,6 +3,7 @@ from qgis.PyQt.QtWidgets import QDockWidget, QTabWidget
|
|||||||
class BaseDockWidget(QDockWidget):
|
class BaseDockWidget(QDockWidget):
|
||||||
base_title = "LNO Sachsen"
|
base_title = "LNO Sachsen"
|
||||||
tabs = []
|
tabs = []
|
||||||
|
action = None # Referenz auf die Toolbar-Action
|
||||||
|
|
||||||
def __init__(self, parent=None, subtitle=""):
|
def __init__(self, parent=None, subtitle=""):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -11,11 +12,17 @@ class BaseDockWidget(QDockWidget):
|
|||||||
title = self.base_title if not subtitle else f"{self.base_title} | {subtitle}"
|
title = self.base_title if not subtitle else f"{self.base_title} | {subtitle}"
|
||||||
self.setWindowTitle(title)
|
self.setWindowTitle(title)
|
||||||
|
|
||||||
# Dock fixieren (Nur schließen erlaubt)
|
# Dock fixieren (nur schließen erlaubt)
|
||||||
self.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetClosable)
|
self.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetClosable)
|
||||||
|
|
||||||
|
# Tabs hinzufügen
|
||||||
tab_widget = QTabWidget()
|
tab_widget = QTabWidget()
|
||||||
for tab_class in self.tabs:
|
for tab_class in self.tabs:
|
||||||
tab_widget.addTab(tab_class(), getattr(tab_class, "tab_title", tab_class.__name__))
|
tab_widget.addTab(tab_class(), getattr(tab_class, "tab_title", tab_class.__name__))
|
||||||
self.setWidget(tab_widget)
|
self.setWidget(tab_widget)
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
"""Wird aufgerufen, wenn das Dock geschlossen wird."""
|
||||||
|
if self.action:
|
||||||
|
self.action.setChecked(False) # Toolbar-Button zurücksetzen
|
||||||
|
super().closeEvent(event)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QToolBar
|
from qgis.PyQt.QtWidgets import QAction, QMenu, QToolBar, QActionGroup
|
||||||
|
|
||||||
class Navigation:
|
class Navigation:
|
||||||
def __init__(self, iface):
|
def __init__(self, iface):
|
||||||
self.iface = iface
|
self.iface = iface
|
||||||
self.actions = []
|
self.actions = []
|
||||||
|
|
||||||
# Menü und Toolbar einmalig anlegen
|
# Menü und Toolbar einmalig anlegen
|
||||||
self.menu = QMenu("LNO Sachsen", iface.mainWindow())
|
self.menu = QMenu("LNO Sachsen", iface.mainWindow())
|
||||||
iface.mainWindow().menuBar().addMenu(self.menu)
|
iface.mainWindow().menuBar().addMenu(self.menu)
|
||||||
@@ -12,23 +12,39 @@ class Navigation:
|
|||||||
self.toolbar = QToolBar("LNO Sachsen")
|
self.toolbar = QToolBar("LNO Sachsen")
|
||||||
iface.addToolBar(self.toolbar)
|
iface.addToolBar(self.toolbar)
|
||||||
|
|
||||||
def add_action(self, text, callback, tooltip="", priority=100, icon=None):
|
# Gruppe für exklusive Auswahl (nur ein Plugin aktiv)
|
||||||
|
self.plugin_group = QActionGroup(iface.mainWindow())
|
||||||
|
self.plugin_group.setExclusive(True)
|
||||||
|
|
||||||
|
def add_action(self, text, callback, tooltip="", priority=100):
|
||||||
action = QAction(text, self.iface.mainWindow())
|
action = QAction(text, self.iface.mainWindow())
|
||||||
if icon:
|
action.setToolTip(tooltip)
|
||||||
action.setIcon(icon)
|
action.setCheckable(True) # Button kann aktiv sein
|
||||||
if tooltip:
|
|
||||||
action.setToolTip(tooltip)
|
|
||||||
action.triggered.connect(callback)
|
action.triggered.connect(callback)
|
||||||
|
|
||||||
|
# Action in Gruppe aufnehmen
|
||||||
|
self.plugin_group.addAction(action)
|
||||||
|
|
||||||
|
# Action mit Priority speichern
|
||||||
self.actions.append((priority, action))
|
self.actions.append((priority, action))
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def finalize_menu_and_toolbar(self):
|
def finalize_menu_and_toolbar(self):
|
||||||
# Menü und Toolbar leeren
|
# Sortieren nach Priority
|
||||||
self.menu.clear()
|
self.actions.sort(key=lambda x: x[0])
|
||||||
self.toolbar.clear()
|
|
||||||
|
|
||||||
# Sortiert nach Priority einfügen
|
# Menüeinträge
|
||||||
for _, action in sorted(self.actions, key=lambda x: x[0]):
|
self.menu.clear()
|
||||||
|
for _, action in self.actions:
|
||||||
self.menu.addAction(action)
|
self.menu.addAction(action)
|
||||||
|
|
||||||
|
# Toolbar-Einträge
|
||||||
|
self.toolbar.clear()
|
||||||
|
for _, action in self.actions:
|
||||||
self.toolbar.addAction(action)
|
self.toolbar.addAction(action)
|
||||||
|
|
||||||
|
def set_active_plugin(self, active_action):
|
||||||
|
# Alle zurücksetzen, dann aktives Plugin markieren
|
||||||
|
for _, action in self.actions:
|
||||||
|
action.setChecked(False)
|
||||||
|
active_action.setChecked(True)
|
||||||
|
|||||||
Reference in New Issue
Block a user