Skip to content

Commit

Permalink
[ux] Disable used items in 'Add setting' dialog instead of removing t…
Browse files Browse the repository at this point in the history
…hem; update main button depending on existing selection
  • Loading branch information
gacarrillor authored and 3nids committed Jul 9, 2024
1 parent ad1363b commit b4444c1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pg_service_parser/gui/dlg_service_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from qgis.PyQt.QtCore import pyqtSlot
from qgis.PyQt.QtWidgets import QDialog
from qgis.PyQt.QtCore import Qt, pyqtSlot
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem

from pg_service_parser.conf.service_settings import SERVICE_SETTINGS
from pg_service_parser.utils import get_ui_class
Expand All @@ -9,16 +9,31 @@

class ServiceSettingsDialog(QDialog, DIALOG_UI):

def __init__(self, parent, settings_to_hide: list[str]):
def __init__(self, parent, used_settings: list[str]):
QDialog.__init__(self, parent)
self.setupUi(self)

self.lstSettings.itemSelectionChanged.connect(self.__selection_changed)
self.buttonBox.accepted.connect(self.__accepted)

settings = set(SERVICE_SETTINGS.keys()) - set(settings_to_hide)
self.lstSettings.addItems(settings)
self.__selection_changed() # Initialize button status

# Load data
for setting in SERVICE_SETTINGS.keys():
item = QListWidgetItem(setting)
if setting in used_settings:
item.setFlags(item.flags() & ~Qt.ItemIsSelectable & ~Qt.ItemIsEnabled)

self.lstSettings.addItem(item)

self.settings_to_add = []

@pyqtSlot()
def __selection_changed(self):
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
bool(self.lstSettings.selectedItems())
)

@pyqtSlot()
def __accepted(self):
self.settings_to_add = [item.text() for item in self.lstSettings.selectedItems()]

0 comments on commit b4444c1

Please sign in to comment.