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

Fix Qt6 bug that prevented layers from being re-enabled #2410

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions glue/core/qt/layer_artist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ def setData(self, index, value, role):
if role == Qt.EditRole:
self.change_label(index.row(), str(value))
if role == Qt.CheckStateRole:
vis = value == Qt.Checked
if isinstance(value, int):
try: # Qt6
vis = value == Qt.Checked.value # https://bugreports.qt.io/browse/QTBUG-104688
except AttributeError: # Qt5
vis = value == Qt.Checked
else:
vis = value == Qt.Checked
self.artists[index.row()].visible = vis
self.artists[index.row()].redraw()

self.dataChanged.emit(index, index)
return True

Expand Down
27 changes: 24 additions & 3 deletions glue/core/qt/tests/test_layer_artist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,36 @@ def test_check_syncs_to_visible():

m0.visible = True
assert m0.visible
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.Checked
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Checked
m0.visible = False
assert not m0.visible
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.Unchecked
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Unchecked

model.setData(model.index(0), Qt.Checked, Qt.CheckStateRole)
model.setData(model.index(0), Qt.CheckState.Checked, Qt.CheckStateRole)
assert m0.visible


def test_artist_check_uncheck_works():
"""
Because of https://bugreports.qt.io/browse/QTBUG-104688, under Qt6
the checkbox in the UI actually sends a bare integer (0 for unchecked,
2 for checked) so we have to check this against Qt.CheckState.Checked.value
in setData. This is a regression test for this behavior.
"""
mgrs = [LayerArtist(Data(label='A'))]
mgrs[0].artists = [MagicMock()]

model = LayerArtistModel(mgrs)
mgrs[0].visible = True
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Checked

model.setData(model.index(0), 0, Qt.CheckStateRole)
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Unchecked

model.setData(model.index(0), 2, Qt.CheckStateRole)
assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Checked


def test_data():

model, mgrs = setup_model(3)
Expand Down