Skip to content

Commit

Permalink
Merge pull request #2410 from gluesolutions/fix-layer-checkbox
Browse files Browse the repository at this point in the history
Fix Qt6 bug that prevented layers from being re-enabled
  • Loading branch information
astrofrog authored Jun 1, 2023
2 parents 802eeba + 28ba18e commit c9da44e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
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

0 comments on commit c9da44e

Please sign in to comment.