Skip to content

Commit

Permalink
Disable 'Update service' button if nothing has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed May 2, 2024
1 parent cd0d4ae commit 807b1a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pg_service_parser/core/item_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from qgis.PyQt.QtCore import QAbstractTableModel, Qt
from qgis.PyQt.QtCore import QAbstractTableModel, Qt, pyqtSignal
from qgis.PyQt.QtGui import QFont


class ServiceConfigModel(QAbstractTableModel):
KEY_COL = 0
VALUE_COL = 1

is_dirty_changed = pyqtSignal(bool) # Whether the model gets dirty or not

def __init__(self, service_name, service_config):
super().__init__()
self.__service_name = service_name
Expand Down Expand Up @@ -45,6 +47,7 @@ def setData(self, index, value, role=Qt.EditRole) -> bool:
if value != self.__model_data[key]:
self.__model_data[key] = value
self.__dirty = True
self.is_dirty_changed.emit(True)
return True

return False
Expand All @@ -70,3 +73,4 @@ def service_name(self):

def set_not_dirty(self):
self.__dirty = False
self.is_dirty_changed.emit(False)
2 changes: 2 additions & 0 deletions pg_service_parser/gui/dlg_pg_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def __edit_service_changed(self, index):

self.__edit_model = ServiceConfigModel(target_service, service_config(target_service))
self.tblServiceConfig.setModel(self.__edit_model)
self.__edit_model.is_dirty_changed.connect(self.btnUpdateService.setEnabled)
self.btnUpdateService.setDisabled(True)

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

0 comments on commit 807b1a1

Please sign in to comment.