-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Plugin migration to QGIS 3
QGIS 3 has entered feature freeze. It's, therefore, time to port your plugin. But be aware that the API is not freezed yet.
While you are porting/rewriting your plugin, think about using QGIS native widgets. For instance, if you need a combobox providing a list of layers, use a QgsMapLayerComboBox
instead of a QComboBox
. There is also QgsFieldComboBox
if you need to pick a field in a vector layer. The full list of widgets is here http://python.qgis.org/api/gui/index.html It's less code to write for you, and users will have the same user experience across plugins and QGIS Desktop.
Also think about using the Processing framework. Your plugin can become its own Processing provider so your algorithms can be included in models and have the same UI as native algorithms. It's also less code to write, the UI is managed by QGIS. In QGIS 3, Processing has been refactored and is much more powerful than in QGIS 2.
In QGIS 3, GeoPackage is much more present. Avoid creating shapefile in your plugin if possible and use the OGC standard GeoPackage format which can store both raster and vector in a single file: http://www.geopackage.org
pip install future
-
git checkout the source tree and run QGIS/scripts/2to3 (https://github.com/qgis/QGIS/blob/master/scripts/2to3) on your plugin
path/to/QGIS/scripts/2to3 /path/to/your/plugin
- This command will print the diff. If you want to write these changes to files, use
-w
- The script will automatically update from Py2 to Py3, from Qt4 to the correct PyQt version. For instance
from PyQt4.QtGui import QMainWindow
will becomefrom qgis.PyQt.QtWidgets import QMainWindow
. - The script will update some QGIS API changes.
- have a good look at: https://qgis.org/api/api_break.html
- make sure you do python3 and Qt5 !
- tweak and fix until it works :-)
It was more work then I hoped, but after setting
qgisMinimumVersion=3.0
in metadata you should see your plugin in QGIS 2.99 and up (note: if it does not appear, make sure your build is newer than 4.01.2018, as there was an important change 3.01.2018 17:09 UTC: https://github.com/qgis/QGIS/pull/5904)
You can find Python API documentation at http://python.qgis.org/api/ (work in progress). Please note: QGIS3 compatibility module (so 3.x plugins will also work on 2.18) has been deprecated.
QGIS 3 MetaSearch user migration: problems with Python plugins? Clear out your *.pyc files (so QGIS Python can compile via Python 3).
You can use IDEs (PyCharm or Eclipse) to step through your code. Alternatively, you can install First Aid plugin and use it within QGIS. More info can be found here: https://www.lutraconsulting.co.uk/blog/2016/06/12/introducing-first-aid-plugin/