Commit dbcf0d63 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

BC: Fix combobox delegate.

Showing with 19 additions and 13 deletions
+19 -13
......@@ -11,7 +11,6 @@ class NotDefined(BoundaryCondition):
self._type = "ND"
self._header = ["", ""]
self._types = [str, str]
class PonctualContribution(BoundaryCondition):
def __init__(self, name:str = ""):
......@@ -22,21 +21,21 @@ class PonctualContribution(BoundaryCondition):
class TimeOverZ(BoundaryCondition):
def __init__(self, name:str = ""):
super(PonctualContribution, self).__init__(name=name)
super(TimeOverZ, self).__init__(name=name)
self._type = "TZ"
self._header = ["time", "z"]
class TimeOverDebit(BoundaryCondition):
def __init__(self, name:str = ""):
super(PonctualContribution, self).__init__(name=name)
super(TimeOverDebit, self).__init__(name=name)
self._type = "TD"
self._header = ["time", "debit"]
class ZOverDebit(BoundaryCondition):
def __init__(self, name:str = ""):
super(PonctualContribution, self).__init__(name=name)
super(ZOverDebit, self).__init__(name=name)
self._type = "ZD"
self._header = ["z", "debit"]
......
......@@ -51,12 +51,17 @@ class Graph(object):
)
def node(self, node_name:str):
return list(
node = list(
filter(
lambda n: n.name == node_name,
self._nodes
)
)[0]
)
if len(node) == 0:
return None
return node[0]
def _add_node(self, node):
self._nodes.append(node)
......
......@@ -31,7 +31,7 @@ class SetNodeCommand(QUndoCommand):
self._lst = lst
self._index = index
self._old = self.lst[index].node
self._old = self._lst[index].node
self._new = node
def undo(self):
......@@ -47,8 +47,8 @@ class SetTypeCommand(QUndoCommand):
self._lst = lst
self._index = index
self._type = _type
self._old = self.lst[index]
self._new = self.lst[index].convert(self._type)
self._old = self._lst[index]
self._new = self._lst[index].convert(self._type)
def undo(self):
self._lst[self._index] = self._old
......
......@@ -12,6 +12,7 @@ from PyQt5.QtGui import (
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QRect,
)
from PyQt5.QtWidgets import (
......@@ -68,10 +69,10 @@ class ComboBoxDelegate(QItemDelegate):
self.editor = QComboBox(parent)
if self._mode == "type":
self.editor.addItems(BC_types.keys())
self.editor.addItems([long_types[k] for k in BC_types.keys()])
else:
self.editor.addItems(
["Not associate"] +
[_translate("BoundaryCondition", "Not associate")] +
self._data.nodes_names()
)
......@@ -134,7 +135,7 @@ class TableModel(QAbstractTableModel):
elif self._headers[column] == "node":
n = self._lst[row].node
if n is None:
return "-"
return _translate("BoundaryCondition", "Not associate")
return n.name
return QVariant()
......@@ -159,9 +160,10 @@ class TableModel(QAbstractTableModel):
)
)
elif self._headers[column] == "type":
key = next(k for k, v in long_types.items() if v == value)
self._undo.push(
SetTypeCommand(
self._lst, row, BC_types[value]
self._lst, row, BC_types[key]
)
)
elif self._headers[column] == "node":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment