Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for DomainTableModel #159

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 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 @@ -1343,10 +1349,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 +1409,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