Skip to content

Add QGIS 4.0, Qt6, and Python 3.14 compatibility enhancements while keeping backwards compatibility#4

Open
celray wants to merge 4 commits intoswat-model:masterfrom
celray:master
Open

Add QGIS 4.0, Qt6, and Python 3.14 compatibility enhancements while keeping backwards compatibility#4
celray wants to merge 4 commits intoswat-model:masterfrom
celray:master

Conversation

@celray
Copy link
Copy Markdown
Member

@celray celray commented Mar 29, 2026

This pull request introduces several improvements to how the code handles data type conversions and imports, particularly for compatibility with different Python environments and to ensure robust handling of Cython-compiled modules. The most significant changes include the introduction of a new utility function fv for safe value conversion, refactoring of import logic for Cython modules, and replacement of direct Qt enum and constant references with imports from a compatibility layer.

Compatibility and Import Handling Improvements:

  • Added robust import logic for Cython-compiled modules (such as dataInC) in both DBUtils.py and QSWATTopology.py, including dynamic compilation if necessary, to improve cross-environment compatibility.

Data Conversion and Type Safety:

  • Introduced and consistently used the fv utility function for extracting and converting feature attribute values, replacing direct usage of raw values to prevent type errors and improve code robustness. This change affects multiple locations in both DBUtils.py and QSWATTopology.py, especially where numeric computations are performed on feature attributes.
    UI and User Interaction Updates:

  • Replaced direct usage of Qt cursor and dialog result enums in QSWATPlusMain.py with imports from qt_compat, improving abstraction and compatibility for both QGIS 3.XX and QGIS 4.XX.

Sorting and List Handling:

  • Updated sorting of list widgets to use the imported AscendingOrder constant instead of Qt.AscendingOrder.

celray and others added 4 commits March 27, 2026 19:34
- Add qt_compat.py shim for Qt5/Qt6 enum differences
- Replace all exec_() calls with exec() (35 instances)
- Replace direct PyQt5 imports with qgis.PyQt wrapper
- Patch Qt5 short-name enums for auto-generated ui_*.py files
- Add fv() helper for NULL feature attributes (None in Qt6 vs
  QPyNullVariant in Qt5)
- Fix QMetaType enum values in parameters.py
- Separate dataInC Cython imports to prevent cascade failures
- Add metadata.txt and fix __init__.py import path
- Update make_uis.py to try PyQt6 first
- Fix missing logFile parameter in getLayerByFilenameOrLegend
Add compile_pyx() helper to qt_compat.py that invokes Cython/setuptools
to build a .pyx file for the running Python version. All dataInC,
polygonizeInC2, and jenks imports now fall back to auto-compilation
when the pre-built .so does not match the current Python.

Requires Cython, setuptools, numpy, and a C compiler at runtime.
QGIS 4.0 on Windows does not ship rtree, and it is not used
anywhere in the codebase — only imported but never referenced.
@celray celray requested a review from ChrisWGeorge March 29, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant