From 807b1a1b3bd14a2af888a3835162fde0d595cff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Thu, 2 May 2024 15:17:47 +0200 Subject: [PATCH 1/3] Disable 'Update service' button if nothing has changed --- pg_service_parser/core/item_models.py | 6 +++++- pg_service_parser/gui/dlg_pg_service.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pg_service_parser/core/item_models.py b/pg_service_parser/core/item_models.py index 1419205..161597d 100644 --- a/pg_service_parser/core/item_models.py +++ b/pg_service_parser/core/item_models.py @@ -1,4 +1,4 @@ -from qgis.PyQt.QtCore import QAbstractTableModel, Qt +from qgis.PyQt.QtCore import QAbstractTableModel, Qt, pyqtSignal from qgis.PyQt.QtGui import QFont @@ -6,6 +6,8 @@ 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 @@ -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 @@ -70,3 +73,4 @@ def service_name(self): def set_not_dirty(self): self.__dirty = False + self.is_dirty_changed.emit(False) diff --git a/pg_service_parser/gui/dlg_pg_service.py b/pg_service_parser/gui/dlg_pg_service.py index dacd738..d502922 100644 --- a/pg_service_parser/gui/dlg_pg_service.py +++ b/pg_service_parser/gui/dlg_pg_service.py @@ -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): From 2a8d2b70aeada9457fae3382ca720aaa000cb2d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Thu, 2 May 2024 16:39:04 +0200 Subject: [PATCH 2/3] Highlight edited service entries --- pg_service_parser/core/item_models.py | 35 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/pg_service_parser/core/item_models.py b/pg_service_parser/core/item_models.py index 161597d..47a8eac 100644 --- a/pg_service_parser/core/item_models.py +++ b/pg_service_parser/core/item_models.py @@ -1,5 +1,5 @@ from qgis.PyQt.QtCore import QAbstractTableModel, Qt, pyqtSignal -from qgis.PyQt.QtGui import QFont +from qgis.PyQt.QtGui import QColorConstants, QFont class ServiceConfigModel(QAbstractTableModel): @@ -12,6 +12,7 @@ def __init__(self, service_name, service_config): super().__init__() self.__service_name = service_name self.__model_data = service_config + self.__original_data = service_config.copy() self.__dirty = False def rowCount(self, parent): @@ -32,10 +33,21 @@ def data(self, index, role=Qt.DisplayRole): return self.__model_data[key] elif role == Qt.EditRole and index.column() == self.VALUE_COL: return self.__model_data[key] - elif role == Qt.FontRole and index.column() == self.KEY_COL: - font = QFont() - font.setBold(True) - return font + elif role == Qt.FontRole: + if index.column() == self.KEY_COL: + font = QFont() + font.setBold(True) + return font + elif ( + index.column() == self.VALUE_COL + and self.__model_data[key] != self.__original_data[key] + ): + font = QFont() + font.setItalic(True) + return font + elif role == Qt.ForegroundRole and index.column() == self.VALUE_COL: + if self.__model_data[key] != self.__original_data[key]: + return QColorConstants.Red return None @@ -46,8 +58,15 @@ def setData(self, index, value, role=Qt.EditRole) -> bool: key = list(self.__model_data.keys())[index.row()] if value != self.__model_data[key]: self.__model_data[key] = value - self.__dirty = True - self.is_dirty_changed.emit(True) + + if value != self.__original_data[key]: + self.__dirty = True + self.is_dirty_changed.emit(True) + else: + if self.__model_data == self.__original_data: + self.__dirty = False + self.is_dirty_changed.emit(False) + return True return False @@ -72,5 +91,7 @@ def service_name(self): return self.__service_name def set_not_dirty(self): + # Data saved in the provider + self.__original_data = self.__model_data.copy() self.__dirty = False self.is_dirty_changed.emit(False) From 6617cadaed7f5219c183049dd6f1cf26ff7ebd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Fri, 3 May 2024 14:15:58 +0200 Subject: [PATCH 3/3] Set to DarkGreen the highlighting color for edited service entries --- pg_service_parser/core/item_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pg_service_parser/core/item_models.py b/pg_service_parser/core/item_models.py index 47a8eac..4c72be8 100644 --- a/pg_service_parser/core/item_models.py +++ b/pg_service_parser/core/item_models.py @@ -47,7 +47,7 @@ def data(self, index, role=Qt.DisplayRole): return font elif role == Qt.ForegroundRole and index.column() == self.VALUE_COL: if self.__model_data[key] != self.__original_data[key]: - return QColorConstants.Red + return QColorConstants.DarkGreen return None