forked from AG_QGIS/Plugin_SN_Basis
Refactoring Aufgrund Fehler beim Beenden.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
from .tab_projekt import TabProjektWidget
|
||||
from .dockmanager import DockManager
|
||||
from .navigation import Navigation
|
||||
@@ -1,67 +1,21 @@
|
||||
from qgis.PyQt.QtCore import Qt
|
||||
from qgis.PyQt.QtWidgets import QDockWidget
|
||||
from qgis.utils import iface
|
||||
import inspect
|
||||
|
||||
class DockManager:
|
||||
"""
|
||||
Zeigt ein Dockwidget an und schließt alle anderen mit dem Namensschema 'sn_dock_'.
|
||||
Der Dockname wird automatisch aus dem Pluginmodul abgeleitet.
|
||||
"""
|
||||
|
||||
# Standard-Dockbereich: Rechts (wie die Verarbeitungswerkzeuge)
|
||||
# default_area = Qt.RightDockWidgetArea #Qt6
|
||||
default_area = Qt.DockWidgetArea.RightDockWidgetArea
|
||||
|
||||
@classmethod
|
||||
def show(cls, dock_widget, area=None):
|
||||
# Falls kein Bereich übergeben wurde, verwende den Standardwert
|
||||
if area is None:
|
||||
area = cls.default_area
|
||||
|
||||
# Pluginname automatisch aus dem Modulpfad ableiten (z. B. 'sn_plugin1' → 'plugin1')
|
||||
caller_module = inspect.getmodule(inspect.stack()[1][0])
|
||||
full_module_name = caller_module.__name__ # z. B. 'sn_plugin1.main'
|
||||
plugin_name = full_module_name.split('.')[0] # → 'sn_plugin1'
|
||||
dock_name = f"sn_dock_{plugin_name.replace('sn_', '')}" # → 'sn_dock_plugin1'
|
||||
|
||||
# Objektname für das Dock setzen, damit es eindeutig identifizierbar ist
|
||||
dock_widget.setObjectName(dock_name)
|
||||
|
||||
# Nur rechts andocken erlauben, wie bei der Toolbox
|
||||
# dock_widget.setAllowedAreas(Qt.RightDockWidgetArea) #Qt6
|
||||
dock_widget.setAllowedAreas(Qt.DockWidgetArea.RightDockWidgetArea)
|
||||
|
||||
# Dock-Features setzen: schließbar und verschiebbar
|
||||
#dock_widget.setFeatures(QDockWidget.DockWidgetClosable | QDockWidget.DockWidgetMovable) #Qt6
|
||||
dock_widget.setFeatures(
|
||||
QDockWidget.DockWidgetFeature.DockWidgetClosable |
|
||||
QDockWidget.DockWidgetFeature.DockWidgetMovable
|
||||
)
|
||||
|
||||
|
||||
# Alle vorhandenen Dockwidgets im Hauptfenster durchsuchen
|
||||
# und solche mit dem Namensschema 'sn_dock_' schließen – außer dem aktuellen
|
||||
all_docks = iface.mainWindow().findChildren(QDockWidget)
|
||||
for widget in all_docks:
|
||||
if widget.objectName().startswith("sn_dock_") and widget != dock_widget:
|
||||
try:
|
||||
iface.removeDockWidget(widget)
|
||||
widget.close()
|
||||
except Exception:
|
||||
pass # Fehler beim Schließen ignorieren (z. B. falls bereits entfernt)
|
||||
# Alle vorhandenen Plugin-Docks schließen
|
||||
for widget in iface.mainWindow().findChildren(QDockWidget):
|
||||
if widget != dock_widget and widget.objectName().startswith("sn_dock_"):
|
||||
iface.removeDockWidget(widget)
|
||||
widget.deleteLater()
|
||||
|
||||
# Neues Dock anzeigen
|
||||
iface.addDockWidget(area, dock_widget)
|
||||
|
||||
# Tabifizierung verhindern – andere Docks im selben Bereich entfernen
|
||||
for widget in iface.mainWindow().findChildren(QDockWidget):
|
||||
if widget != dock_widget and iface.mainWindow().dockWidgetArea(widget) == area:
|
||||
iface.mainWindow().removeDockWidget(widget)
|
||||
|
||||
# Breite setzen wie bei der Toolbox (optional, anpassbar)
|
||||
dock_widget.setMinimumWidth(300)
|
||||
dock_widget.setMaximumWidth(400)
|
||||
|
||||
# Höhe nicht erzwingen – Qt passt sie automatisch an
|
||||
dock_widget.show()
|
||||
|
||||
@@ -1,75 +1,37 @@
|
||||
from qgis.PyQt.QtWidgets import QMenu, QToolBar, QAction
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.utils import iface
|
||||
|
||||
_shared_toolbar = None # globale Toolbar-Instanz
|
||||
_shared_menu = None # globale Menü-Instanz
|
||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QToolBar
|
||||
|
||||
class Navigation:
|
||||
TITLE = "LNO Sachsen"
|
||||
def __init__(self, iface):
|
||||
self.iface = iface
|
||||
self.actions = []
|
||||
|
||||
def __init__(self):
|
||||
self.menu = self._get_or_create_menu()
|
||||
self.toolbar = self._get_or_create_toolbar()
|
||||
# Menü und Toolbar einmalig anlegen
|
||||
self.menu = QMenu("LNO Sachsen", iface.mainWindow())
|
||||
iface.mainWindow().menuBar().addMenu(self.menu)
|
||||
|
||||
def _get_or_create_menu(self):
|
||||
global _shared_menu
|
||||
if _shared_menu:
|
||||
return _shared_menu
|
||||
self.toolbar = QToolBar("LNO Sachsen")
|
||||
iface.addToolBar(self.toolbar)
|
||||
|
||||
menubar = iface.mainWindow().menuBar()
|
||||
for action in menubar.actions():
|
||||
if action.menu() and action.text() == self.TITLE:
|
||||
_shared_menu = action.menu()
|
||||
return _shared_menu
|
||||
def add_action(self, text, callback, tooltip="", priority=100, icon=None):
|
||||
action = QAction(icon, text, self.iface.mainWindow()) if icon else QAction(text, self.iface.mainWindow())
|
||||
if tooltip:
|
||||
action.setToolTip(tooltip)
|
||||
action.triggered.connect(callback)
|
||||
|
||||
menu = QMenu(self.TITLE, iface.mainWindow())
|
||||
menu.setObjectName(self.TITLE)
|
||||
menubar.addMenu(menu)
|
||||
_shared_menu = menu
|
||||
return menu
|
||||
# Action mit Priority speichern
|
||||
self.actions.append((priority, action))
|
||||
return action
|
||||
|
||||
def finalize_menu_and_toolbar(self):
|
||||
# Sortieren nach Priority
|
||||
self.actions.sort(key=lambda x: x[0])
|
||||
|
||||
def _get_or_create_toolbar(self):
|
||||
global _shared_toolbar
|
||||
if _shared_toolbar:
|
||||
return _shared_toolbar
|
||||
|
||||
main_window = iface.mainWindow()
|
||||
toolbar = main_window.findChild(QToolBar, self.TITLE)
|
||||
if not toolbar:
|
||||
toolbar = QToolBar(self.TITLE, main_window)
|
||||
toolbar.setObjectName(self.TITLE)
|
||||
main_window.addToolBar(toolbar)
|
||||
|
||||
_shared_toolbar = toolbar
|
||||
return toolbar
|
||||
|
||||
def add_action(self, text, callback, icon=None, tooltip=None):
|
||||
# Menüeintrag
|
||||
if not any(a.text() == text for a in self.menu.actions()):
|
||||
action = QAction(icon, text, iface.mainWindow()) if icon else QAction(text, iface.mainWindow())
|
||||
if tooltip:
|
||||
action.setToolTip(tooltip)
|
||||
action.triggered.connect(callback)
|
||||
# Menüeinträge
|
||||
self.menu.clear()
|
||||
for _, action in self.actions:
|
||||
self.menu.addAction(action)
|
||||
|
||||
# Symbolleistenaktion
|
||||
if not any(a.text() == text for a in self.toolbar.actions()):
|
||||
action = QAction(icon, text, iface.mainWindow()) if icon else QAction(text, iface.mainWindow())
|
||||
if tooltip:
|
||||
action.setToolTip(tooltip)
|
||||
action.triggered.connect(callback)
|
||||
# Toolbar-Einträge
|
||||
self.toolbar.clear()
|
||||
for _, action in self.actions:
|
||||
self.toolbar.addAction(action)
|
||||
|
||||
def remove_action(self, text):
|
||||
# Menüeintrag entfernen
|
||||
for act in self.menu.actions():
|
||||
if act.text() == text:
|
||||
self.menu.removeAction(act)
|
||||
break
|
||||
|
||||
# Symbolleistenaktion entfernen
|
||||
for act in self.toolbar.actions():
|
||||
if act.text() == text:
|
||||
self.toolbar.removeAction(act)
|
||||
break
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# tab_info.py
|
||||
from qgis.PyQt import uic
|
||||
from qgis.PyQt.QtWidgets import QWidget
|
||||
import os
|
||||
|
||||
FORM_CLASS, _ = uic.loadUiType(os.path.join(
|
||||
os.path.dirname(__file__), 'tab_projekt.ui'))
|
||||
|
||||
class TabProjektWidget(QWidget, FORM_CLASS):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
|
||||
# Zugriff auf den Button
|
||||
self.btn_save.setText("Sichern") # Text ändern
|
||||
self.btn_save.setEnabled(True) # Aktivieren
|
||||
self.btn_save.clicked.connect(self.speichern) # Klick-Event verbinden
|
||||
|
||||
def speichern(self):
|
||||
print("Speichern wurde geklickt!")
|
||||
@@ -1,264 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>604</width>
|
||||
<height>939</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Benutzerspezifische Festlegungen___</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Amt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_5"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Behörde</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_4"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Landkreis</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Sachgebiet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Projektspezifische Festlegungen</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Bezeichnung</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_8"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Verfahrensnummer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_7"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Gemeinde(n)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_3"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Landkreis(e)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_6"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_save">
|
||||
<property name="text">
|
||||
<string>Speichern</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
0
ui/tabs/__init__.py
Normal file
0
ui/tabs/__init__.py
Normal file
84
ui/tabs/settings_tab.py
Normal file
84
ui/tabs/settings_tab.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from qgis.PyQt.QtWidgets import (
|
||||
QWidget, QGridLayout, QLabel, QLineEdit,
|
||||
QGroupBox, QVBoxLayout, QPushButton
|
||||
)
|
||||
from sn_basis.logic.settings_logic import SettingsLogic
|
||||
|
||||
|
||||
class SettingsTab(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.logic = SettingsLogic()
|
||||
|
||||
main_layout = QVBoxLayout()
|
||||
|
||||
# 🟦 Benutzerspezifische Festlegungen
|
||||
user_group = QGroupBox("Benutzerspezifische Festlegungen")
|
||||
user_layout = QGridLayout()
|
||||
self.amt = QLineEdit()
|
||||
self.behoerde = QLineEdit()
|
||||
self.landkreis_user = QLineEdit()
|
||||
self.sachgebiet = QLineEdit()
|
||||
user_layout.addWidget(QLabel("Amt:"), 0, 0)
|
||||
user_layout.addWidget(self.amt, 0, 1)
|
||||
user_layout.addWidget(QLabel("Behörde:"), 1, 0)
|
||||
user_layout.addWidget(self.behoerde, 1, 1)
|
||||
user_layout.addWidget(QLabel("Landkreis:"), 2, 0)
|
||||
user_layout.addWidget(self.landkreis_user, 2, 1)
|
||||
user_layout.addWidget(QLabel("Sachgebiet:"), 3, 0)
|
||||
user_layout.addWidget(self.sachgebiet, 3, 1)
|
||||
user_group.setLayout(user_layout)
|
||||
|
||||
# 🟨 Projektspezifische Festlegungen
|
||||
project_group = QGroupBox("Projektspezifische Festlegungen")
|
||||
project_layout = QGridLayout()
|
||||
self.bezeichnung = QLineEdit()
|
||||
self.verfahrensnummer = QLineEdit()
|
||||
self.gemeinden = QLineEdit()
|
||||
self.landkreise_proj = QLineEdit()
|
||||
project_layout.addWidget(QLabel("Bezeichnung:"), 0, 0)
|
||||
project_layout.addWidget(self.bezeichnung, 0, 1)
|
||||
project_layout.addWidget(QLabel("Verfahrensnummer:"), 1, 0)
|
||||
project_layout.addWidget(self.verfahrensnummer, 1, 1)
|
||||
project_layout.addWidget(QLabel("Gemeinde(n):"), 2, 0)
|
||||
project_layout.addWidget(self.gemeinden, 2, 1)
|
||||
project_layout.addWidget(QLabel("Landkreis(e):"), 3, 0)
|
||||
project_layout.addWidget(self.landkreise_proj, 3, 1)
|
||||
project_group.setLayout(project_layout)
|
||||
|
||||
# 🟩 Speichern-Button
|
||||
save_button = QPushButton("Speichern")
|
||||
save_button.clicked.connect(self.save_data)
|
||||
|
||||
# Layout zusammenfügen
|
||||
main_layout.addWidget(user_group)
|
||||
main_layout.addWidget(project_group)
|
||||
main_layout.addStretch()
|
||||
main_layout.addWidget(save_button)
|
||||
|
||||
self.setLayout(main_layout)
|
||||
self.load_data()
|
||||
|
||||
def save_data(self):
|
||||
fields = {
|
||||
"amt": self.amt.text(),
|
||||
"behoerde": self.behoerde.text(),
|
||||
"landkreis_user": self.landkreis_user.text(),
|
||||
"sachgebiet": self.sachgebiet.text(),
|
||||
"bezeichnung": self.bezeichnung.text(),
|
||||
"verfahrensnummer": self.verfahrensnummer.text(),
|
||||
"gemeinden": self.gemeinden.text(),
|
||||
"landkreise_proj": self.landkreise_proj.text()
|
||||
}
|
||||
self.logic.save(fields)
|
||||
|
||||
def load_data(self):
|
||||
data = self.logic.load()
|
||||
self.amt.setText(data["amt"])
|
||||
self.behoerde.setText(data["behoerde"])
|
||||
self.landkreis_user.setText(data["landkreis_user"])
|
||||
self.sachgebiet.setText(data["sachgebiet"])
|
||||
self.bezeichnung.setText(data["bezeichnung"])
|
||||
self.verfahrensnummer.setText(data["verfahrensnummer"])
|
||||
self.gemeinden.setText(data["gemeinden"])
|
||||
self.landkreise_proj.setText(data["landkreise_proj"])
|
||||
Reference in New Issue
Block a user