Skip to content

Commit

Permalink
Highlight edited service entries
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed May 2, 2024
1 parent 807b1a1 commit 2a8d2b7
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions pg_service_parser/core/item_models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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):
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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)

0 comments on commit 2a8d2b7

Please sign in to comment.