Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI/UX] Highlight edited service entries #25

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions pg_service_parser/core/item_models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from qgis.PyQt.QtCore import QAbstractTableModel, Qt
from qgis.PyQt.QtGui import QFont
from qgis.PyQt.QtCore import QAbstractTableModel, Qt, pyqtSignal
from qgis.PyQt.QtGui import QColorConstants, 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
self.__model_data = service_config
self.__original_data = service_config.copy()
self.__dirty = False

def rowCount(self, parent):
Expand All @@ -30,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 @@ -44,7 +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

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 @@ -69,4 +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)
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