mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
2 Commits
0346080e16
...
e6d3564d9b
| Author | SHA1 | Date |
|---|---|---|
|
|
e6d3564d9b | |
|
|
d62e703439 |
|
|
@ -60,6 +60,9 @@ class Scenarios(PamhyrModelDict):
|
||||||
self.set(new._id, new)
|
self.set(new._id, new)
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.lst)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def lst(self):
|
def lst(self):
|
||||||
return list(
|
return list(
|
||||||
|
|
@ -70,8 +73,8 @@ class Scenarios(PamhyrModelDict):
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, key):
|
def delete(self, key):
|
||||||
el = self._dict.get(key)
|
if key not in self._dict:
|
||||||
if el is None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
el.set_as_deleted()
|
self._dict[key].set_as_deleted()
|
||||||
|
self._status.modified()
|
||||||
|
|
|
||||||
|
|
@ -84,13 +84,21 @@ class StudyScenarioTestCase(unittest.TestCase):
|
||||||
self.assertNotEqual(old, new)
|
self.assertNotEqual(old, new)
|
||||||
|
|
||||||
def test_open_study(self):
|
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.assertNotEqual(study, None)
|
||||||
self.assertEqual(study.name, "Enlargement")
|
self.assertEqual(study.name, "Enlargement")
|
||||||
self.assertEqual(study.status.scenario_id, 0)
|
self.assertEqual(study.status.scenario_id, 0)
|
||||||
|
|
||||||
def test_open_study_2(self):
|
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.assertNotEqual(study, None)
|
||||||
self.assertEqual(study.name, "TestMultibiefs")
|
self.assertEqual(study.name, "TestMultibiefs")
|
||||||
self.assertEqual(study.status.scenario_id, 0)
|
self.assertEqual(study.status.scenario_id, 0)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
Qt, QRect, QVariant, QAbstractTableModel, pyqtSlot, pyqtSignal,
|
Qt, QRect, QVariant, QAbstractTableModel, pyqtSlot, pyqtSignal,
|
||||||
QEvent,
|
QEvent, QModelIndex,
|
||||||
)
|
)
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
|
|
@ -41,20 +41,32 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
class ScenariosTableModel(PamhyrTableModel):
|
class ScenariosTableModel(PamhyrTableModel):
|
||||||
def _setup_lst(self):
|
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):
|
def data(self, index, role):
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
value = self._lst[index.row()]
|
||||||
|
|
||||||
if self._headers[index.column()] == "parent":
|
if self._headers[index.column()] == "parent":
|
||||||
parent = self._lst[index.row()][self._headers[index.column()]]
|
parent = value["parent"]
|
||||||
if parent is None:
|
if parent is None:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
return parent.name
|
return parent.name
|
||||||
|
|
||||||
return self._lst[index.row()][self._headers[index.column()]]
|
return value[self._headers[index.column()]]
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def setData(self, index, value, role=Qt.EditRole):
|
def setData(self, index, value, role=Qt.EditRole):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue