Home › Adopt a plugin › QGIS 4 port guides › Coordinate Capture
Coordinate Capture QGIS 4 port guide
Coordinate Capture in the directory · 226,269 downloads · Latest release 0.2 (2020-08-14)
Not QGIS 4 ready · Automatic port estimate for 0.2: Easy
These notes come from reading the linked source. Runtime behavior still needs testing.
Source notes for version 0.2
- The dock opens on the left. Replace
Qt.LeftDockWidgetAreawithQt.DockWidgetArea.LeftDockWidgetArea. coordinate_capture.py:243 - The marker reset uses
QgsWkbTypesgeometry constants. PassQgis.GeometryType.PolygonorQgis.GeometryType.Lineto the QGIS 4 rubber band API. Update the constructor argument too. coordinate_capture_map_tool.py:56-68 - The capture tool uses
Qt.redfor its marker and tests unscoped mouse buttons. UseQt.GlobalColor.red,Qt.MouseButton.LeftButtonandQt.MouseButton.RightButton. coordinate_capture_map_tool.py:37-68
Test in QGIS 4
Open the dock, select a second coordinate reference system and click a known point. Check both coordinate readouts and the marker, then right-click to leave capture mode.
Qt 6 and QGIS 4 checklist
- Scope enum values. An unscoped name can raise
AttributeErrorwhen the widget opens. UseQt.AlignmentFlag.AlignLeftforQt.AlignLeftandQMessageBox.StandardButton.YesforQMessageBox.Yes. Check both the arguments and comparisons with the return value. QGIS enum migration examples - Check imports at startup. Replace direct
PyQt5imports withqgis.PyQtwhere available. In PyQt6,QActionandQShortcutmoved fromQtWidgetstoQtGui. For a QGIS 4 port, import them fromqgis.PyQt.QtGui. Dual-version plugins can keepqgis.PyQt.QtWidgetsfor these two classes because QGIS 4 re-exports them there. QGIS 4 compatibility imports - Update renamed and removed calls. Use
dialog.exec()fordialog.exec_(). ReplaceQRegExpwithQRegularExpressionand update matching code, for examplerx.match(text).hasMatch()for a substring search. Review QGIS API calls separately. QGIS migration script · QGIS API break notes - Test the package. Enable the plugin in a clean QGIS 4 profile, open its tools, then unload and enable it again. Repeat on the oldest supported QGIS 3 release if keeping dual support. The QGIS migration checker can flag other source changes before testing.
- Declare the tested range. In the
[general]section ofmetadata.txt, a plugin supporting QGIS 3 and 4 needs an explicit upper bound such asqgisMaximumVersion=4.99to include the 4.x series. For a 4-only release, setqgisMinimumVersion=4.0or the first supported version. The maximum is optional. QGIS 4 ignoressupportsQt6. Remove the old flag. QGIS repository migration guide · PyQGIS cookbook metadata reference