From ec1b4f822a6e4b694f20d3557f1ecc3f1a915ede Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 15 Feb 2024 09:51:46 +1000 Subject: [PATCH] QVariant.Type, Qt.ItemFlag and Qt.CheckState need to be int compatible For reasons(?) these aren't IntEnums/IntFlags on PyQt6, but we need them to be int compatible for compatibility with PyQt5 code --- .ci/test_blocklist_qt6.txt | 2 -- python/PyQt/PyQt/QtCore.py.in | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.ci/test_blocklist_qt6.txt b/.ci/test_blocklist_qt6.txt index a81734d8aee2..ea2cf64851c2 100644 --- a/.ci/test_blocklist_qt6.txt +++ b/.ci/test_blocklist_qt6.txt @@ -41,13 +41,11 @@ PyQgsPythonProvider PyQgsAnnotation PyQgsAuthenticationSystem PyQgsBlockingProcess -PyQgsBookmarkModel PyQgsCodeEditor PyQgsDelimitedTextProvider PyQgsEditWidgets PyQgsElevationProfileCanvas PyQgsProject -PyQgsFieldModel PyQgsFloatingWidget PyQgsJsonUtils PyQgsLayoutHtml diff --git a/python/PyQt/PyQt/QtCore.py.in b/python/PyQt/PyQt/QtCore.py.in index 064f56b6e58a..531e3266dced 100644 --- a/python/PyQt/PyQt/QtCore.py.in +++ b/python/PyQt/PyQt/QtCore.py.in @@ -132,6 +132,20 @@ if (QT_VERSION >= 0x060000): QVariant.SizePolicy = QMetaType.Type.QSizePolicy QVariant.UserType = QMetaType.Type.User + from enum import Enum + + + def _force_int(v): return int(v.value) if isinstance(v, Enum) else v + + QMetaType.Type.__int__ = _force_int + QMetaType.Type.__eq__ = lambda t1, t2: _force_int(t1) == _force_int(t2) + + # These types aren't IntEnums or IntFlags, so patch that back in + Qt.ItemFlag.__int__ = _force_int + Qt.ItemFlag.__eq__ = lambda t1, t2: _force_int(t1) == _force_int(t2) + Qt.CheckState.__int__ = _force_int + Qt.CheckState.__eq__ = lambda t1, t2: _force_int(t1) == _force_int(t2) + # patch back in Qt flags removed in PyQt QAbstractItemModel.CheckIndexOptions = lambda flags=0: QAbstractItemModel.CheckIndexOption(flags)