From 5a72fe82a71031f0d1854cc441935011d411ecd1 Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Fri, 26 May 2023 14:37:17 -0400 Subject: [PATCH 1/3] Fix Qt6 bug that prevented layers from being re-enabled --- glue/core/qt/layer_artist_model.py | 7 +++-- glue/core/qt/tests/test_layer_artist_model.py | 27 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/glue/core/qt/layer_artist_model.py b/glue/core/qt/layer_artist_model.py index c58c0d9a0..e8a01729d 100644 --- a/glue/core/qt/layer_artist_model.py +++ b/glue/core/qt/layer_artist_model.py @@ -76,16 +76,19 @@ def flags(self, index): return result + def setData(self, index, value, role): if not index.isValid(): return False if role == Qt.EditRole: self.change_label(index.row(), str(value)) if role == Qt.CheckStateRole: - vis = value == Qt.Checked + if isinstance(value, int): + vis = value == Qt.Checked.value # https://bugreports.qt.io/browse/QTBUG-104688 + else: + vis = value == Qt.Checked self.artists[index.row()].visible = vis self.artists[index.row()].redraw() - self.dataChanged.emit(index, index) return True diff --git a/glue/core/qt/tests/test_layer_artist_model.py b/glue/core/qt/tests/test_layer_artist_model.py index 8863eb1c2..1bee8a90e 100644 --- a/glue/core/qt/tests/test_layer_artist_model.py +++ b/glue/core/qt/tests/test_layer_artist_model.py @@ -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) From 53f38f4c5fc74ab29e72ad429178fcf24a1551bc Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Tue, 30 May 2023 10:31:54 -0400 Subject: [PATCH 2/3] Codestyle fix --- glue/core/qt/layer_artist_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/glue/core/qt/layer_artist_model.py b/glue/core/qt/layer_artist_model.py index e8a01729d..71b973946 100644 --- a/glue/core/qt/layer_artist_model.py +++ b/glue/core/qt/layer_artist_model.py @@ -76,7 +76,6 @@ def flags(self, index): return result - def setData(self, index, value, role): if not index.isValid(): return False From 28ba18e562370590093f2e9b631f09a1d468249f Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Tue, 30 May 2023 12:07:59 -0400 Subject: [PATCH 3/3] More reliable fix for Qt5 --- glue/core/qt/layer_artist_model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glue/core/qt/layer_artist_model.py b/glue/core/qt/layer_artist_model.py index 71b973946..6c9994fb7 100644 --- a/glue/core/qt/layer_artist_model.py +++ b/glue/core/qt/layer_artist_model.py @@ -83,7 +83,10 @@ def setData(self, index, value, role): self.change_label(index.row(), str(value)) if role == Qt.CheckStateRole: if isinstance(value, int): - vis = value == Qt.Checked.value # https://bugreports.qt.io/browse/QTBUG-104688 + 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