Skip to content

Commit d80cead

Browse files
committed
fix: update qgis4 compatibility
1 parent f0ce0b6 commit d80cead

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

loopstructural/gui/compatibility.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# compat.py
22
from qgis.PyQt.QtCore import QVariant
33

4-
try:
4+
if hasattr(QVariant, "Int"):
5+
# QGIS 3 / PyQt5: QVariant still exposes the legacy .Type enum members.
6+
# (QMetaType is importable under PyQt5 too, so we can't use that import
7+
# to detect QGIS 4 - checking for the attribute QGIS 4 actually removed
8+
# is the only reliable signal.)
9+
QVariantCompat = QVariant
10+
else:
11+
# QGIS 4 / PyQt6: QVariant.Type was removed; use QMetaType instead.
512
from qgis.PyQt.QtCore import QMetaType
613

714
# We create a proxy class to mimic the old QVariant.Type behavior
@@ -12,9 +19,6 @@ class QVariantProxy:
1219
Double = QMetaType.Type.Double
1320
String = QMetaType.Type.QString
1421
Bool = QMetaType.Type.Bool
22+
DateTime = QMetaType.Type.QDateTime
1523

16-
# In QGIS 4, we use our proxy
1724
QVariantCompat = QVariantProxy
18-
except (ImportError, AttributeError):
19-
# In QGIS 3, QVariant already has .Type
20-
QVariantCompat = QVariant

0 commit comments

Comments
 (0)