mirror of https://gitlab.com/pamhyr/pamhyr2
Pollutants: line becomes grey when we disable a pollutant + it's mentionned 'disabled' on the view only in the tab
parent
1f5ce72fb2
commit
5da607865c
|
|
@ -26,6 +26,7 @@ from PyQt5.QtCore import (
|
|||
QCoreApplication, QModelIndex, pyqtSlot,
|
||||
QRect,
|
||||
)
|
||||
from PyQt5.QtGui import QColor
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
|
|
@ -59,14 +60,23 @@ class TableModel(PamhyrTableModel):
|
|||
return len(self._lst)
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
if not index.isValid():
|
||||
return QVariant()
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if role == Qt.BackgroundRole and not self._lst[row].enabled:
|
||||
return QColor(190, 190, 190)
|
||||
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return self._lst[row].name
|
||||
name = self._lst[row].name
|
||||
if not self._lst[row].enabled:
|
||||
name += f" ({self._trad['disabled']})"
|
||||
return name
|
||||
|
||||
return QVariant()
|
||||
|
||||
|
|
@ -74,12 +84,19 @@ class TableModel(PamhyrTableModel):
|
|||
if not index.isValid() or role != Qt.EditRole:
|
||||
return False
|
||||
|
||||
if self.is_same_data(index, value):
|
||||
return False
|
||||
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
if self._headers[column] == "name":
|
||||
suffix = f" ({self._trad['disabled']})"
|
||||
if not self._lst[row].enabled and str(value).endswith(suffix):
|
||||
value = str(value)[:-len(suffix)]
|
||||
|
||||
if str(self._lst[row].name) == str(value):
|
||||
return False
|
||||
elif self.is_same_data(index, value):
|
||||
return False
|
||||
|
||||
try:
|
||||
if self._headers[column] == "name":
|
||||
self._undo.push(
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class PollutantsTranslate(MainTranslate):
|
|||
)
|
||||
|
||||
self._dict["x"] = _translate("Pollutants", "X (m)")
|
||||
self._dict["disabled"] = _translate("Pollutants", "disabled")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": self._dict["name"],
|
||||
|
|
|
|||
Loading…
Reference in New Issue