Skip to content

Commit

Permalink
Fixes for DomainTableModel (#159)
Browse files Browse the repository at this point in the history
* Fixing a couple of problems with the domain table selection

* Avoid np.int in color options display

---------

Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
pshriwise and paulromano authored Oct 23, 2024
1 parent b5a1fd9 commit a96872c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,12 @@ def __deepcopy__(self, memo):
obj.defaults = self.defaults
return obj

def get_defaults(self, key: int) -> DomainView:
return self.defaults[key]

def get_default_color(self, key: int):
return self.get_defaults(key).color

def set_name(self, key: int, name: Optional[str]):
domain = self[key]
self[key] = DomainView(domain.id, name, domain.color, domain.masked, domain.highlight)
Expand Down Expand Up @@ -1265,7 +1271,8 @@ def data(self, index, role=Qt.DisplayRole):
elif column == COLOR:
return '' if domain.color is not None else '+'
elif column == COLORLABEL:
return str(tuple(domain.color)) if domain.color is not None else '--'
return (str(tuple(int(x) for x in domain.color))
if domain.color is not None else '--')
elif column == MASK:
return None
elif column == HIGHLIGHT:
Expand Down Expand Up @@ -1343,10 +1350,11 @@ def setData(self, index, value, role=Qt.EditRole):

if column == NAME:
self.domains.set_name(key, value if value else None)
elif column == COLOR:
self.domains.set_color(key, value)
elif column == COLORLABEL:
self.domains.set_color(key, value)
elif column == COLOR or column == COLORLABEL:
# reset the color to the default value if the coloar value is None
if value is None:
value = self.domains.get_default_color(key)
self.domains.set_color(key, value)
elif column == MASK:
if role == Qt.CheckStateRole:
self.domains.set_masked(key, Qt.CheckState(value) == Qt.Checked)
Expand Down Expand Up @@ -1402,7 +1410,7 @@ def setEditorData(self, editor, index):
def editorEvent(self, event, model, option, index):

if index.column() in (COLOR, COLORLABEL):
if not int(index.flags() & Qt.ItemIsEditable) > 0:
if (index.flags() & Qt.ItemFlag.ItemIsEditable) == Qt.ItemFlag.NoItemFlags:
return False
if event.type() == QEvent.MouseButtonRelease \
and event.button() == Qt.RightButton:
Expand Down

0 comments on commit a96872c

Please sign in to comment.