Compare commits

...

2 Commits

3 changed files with 32 additions and 9 deletions

View File

@ -60,6 +60,9 @@ class Scenarios(PamhyrModelDict):
self.set(new._id, new)
return new
def __len__(self):
return len(self.lst)
@property
def lst(self):
return list(
@ -70,8 +73,8 @@ class Scenarios(PamhyrModelDict):
)
def delete(self, key):
el = self._dict.get(key)
if el is None:
if key not in self._dict:
return
el.set_as_deleted()
self._dict[key].set_as_deleted()
self._status.modified()

View File

@ -84,13 +84,21 @@ class StudyScenarioTestCase(unittest.TestCase):
self.assertNotEqual(old, new)
def test_open_study(self):
study = Study.open("../tests_cases/Enlargement/Enlargement.pamhyr")
study = Study.open(
os.path.join(
"..", "tests_cases", "Enlargement", "Enlargement.pamhyr"
)
)
self.assertNotEqual(study, None)
self.assertEqual(study.name, "Enlargement")
self.assertEqual(study.status.scenario_id, 0)
def test_open_study_2(self):
study = Study.open("../tests_cases/MassZero/TestMultibiefs.pamhyr")
study = Study.open(
os.path.join(
"..", "tests_cases", "MassZero", "TestMultibiefs.pamhyr"
)
)
self.assertNotEqual(study, None)
self.assertEqual(study.name, "TestMultibiefs")
self.assertEqual(study.status.scenario_id, 0)

View File

@ -27,7 +27,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
from PyQt5.QtCore import (
Qt, QRect, QVariant, QAbstractTableModel, pyqtSlot, pyqtSignal,
QEvent,
QEvent, QModelIndex,
)
from PyQt5.QtWidgets import (
@ -41,20 +41,32 @@ logger = logging.getLogger()
class ScenariosTableModel(PamhyrTableModel):
def _setup_lst(self):
self._lst = self._data.scenarios.lst
self._lst = list(
filter(
lambda x: not x.is_deleted(),
self._data.scenarios.lst
)
)
def rowCount(self, parent=QModelIndex()):
self._setup_lst()
return len(self._lst)
def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
value = self._lst[index.row()]
if self._headers[index.column()] == "parent":
parent = self._lst[index.row()][self._headers[index.column()]]
parent = value["parent"]
if parent is None:
return ""
return parent.name
return self._lst[index.row()][self._headers[index.column()]]
return value[self._headers[index.column()]]
@pyqtSlot()
def setData(self, index, value, role=Qt.EditRole):