Skip to content

Commit

Permalink
Merge branch 'main' into sslmode
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored Jul 16, 2024
2 parents ecebef0 + 22f1e3a commit 8bdbdf2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pg_service_parser/gui/dlg_pg_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qgis.core import QgsApplication
from qgis.gui import QgsMessageBar
from qgis.PyQt.QtCore import Qt, pyqtSlot
from qgis.PyQt.QtCore import QItemSelection, Qt, pyqtSlot
from qgis.PyQt.QtWidgets import QDialog, QMessageBox, QSizePolicy

from pg_service_parser.conf.service_settings import SERVICE_SETTINGS, SETTINGS_TEMPLATE
Expand Down Expand Up @@ -63,6 +63,7 @@ def __initialize_dialog(self):
self.txtConfFile.setVisible(True)
self.tabWidget.setEnabled(True)
self.btnCreateServiceFile.setVisible(False)
self.btnRemoveSetting.setEnabled(False)

self.radOverwrite.toggled.connect(self.__update_target_controls)
self.btnCopyService.clicked.connect(self.__copy_service)
Expand All @@ -76,6 +77,7 @@ def __initialize_dialog(self):
self.__initialize_edit_services()
self.__initialize_copy_services()
self.__update_target_controls(True)
self.__update_add_settings_button()

self.bar = QgsMessageBar()
self.bar.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed)
Expand All @@ -98,6 +100,11 @@ def __update_target_controls(self, checked):
self.cboTargetService.setEnabled(self.radOverwrite.isChecked())
self.txtNewService.setEnabled(not self.radOverwrite.isChecked())

def __update_add_settings_button(self):
# Make sure to call this method whenever the settings are added/removed
enable = self.__edit_model and self.__edit_model.rowCount() < len(SERVICE_SETTINGS)
self.btnAddSettings.setEnabled(enable)

@pyqtSlot(int)
def __source_service_changed(self, index):
# Remember latest currentText only if current item in source
Expand Down Expand Up @@ -198,7 +205,9 @@ def __edit_service_changed(self, index):
target_service, service_config(target_service, self.__conf_file_path)
)
self.tblServiceConfig.setModel(self.__edit_model)
self.tblServiceConfig.setItemDelegate(ServiceConfigDelegate(self))
self.tblServiceConfig.selectionModel().selectionChanged.connect(
self.__update_settings_buttons
)
self.__edit_model.is_dirty_changed.connect(self.btnUpdateService.setEnabled)
self.btnUpdateService.setDisabled(True)

Expand All @@ -207,6 +216,13 @@ def __edit_service_changed(self, index):
self.__edit_model.add_settings(SETTINGS_TEMPLATE)
self.__new_empty_file = False

self.__update_add_settings_button() # Model just created
self.__update_settings_buttons(QItemSelection(), QItemSelection())

@pyqtSlot(QItemSelection, QItemSelection)
def __update_settings_buttons(self, selected, deselected):
self.btnRemoveSetting.setEnabled(bool(selected.indexes()))

@pyqtSlot()
def __add_settings_clicked(self):
dlg = ServiceSettingsDialog(self, self.__edit_model.current_setting_keys())
Expand All @@ -217,6 +233,7 @@ def __add_settings_clicked(self):
k: v["default"] for k, v in SERVICE_SETTINGS.items() if k in dlg.settings_to_add
}
self.__edit_model.add_settings(settings)
self.__update_add_settings_button() # Settings added

@pyqtSlot()
def __remove_setting_clicked(self):
Expand All @@ -234,6 +251,7 @@ def __remove_setting_clicked(self):
== QMessageBox.StandardButton.Yes
):
self.__edit_model.remove_setting(selected_indexes[0])
self.__update_add_settings_button() # Settings removed

@pyqtSlot()
def __update_service_clicked(self):
Expand Down

0 comments on commit 8bdbdf2

Please sign in to comment.