Graphics Reference
In-Depth Information
Possibilities and limitations of plugins
As we have seen, it's quite possible to write a plugin that acts as a sophisticated mapping
tool integrated directly into the QGIS user interface, interacting with the map canvas and
responding in various ways to the user's actions. Some of the other things you can do with
a QGIS plugin include:
• Creating your own subclass of QgsMapCanvasItem , so your plugin can draw
items directly onto the QGIS map canvas.
• Creating a custom map layer by subclassing QgsPluginLayer . This allows
your plugin to act as a completely separate map layer.
• Using signal handlers to intercept standard QGIS actions, for example, redrawing
the canvas and executing your own code when a signal is sent.
• Creating map layers programmatically, setting up the data provider, and creating
custom symbols and renderers to control how the map data is displayed.
• Using the QGIS Map Composer tools to combine rendered map layers, labels, le-
gends, tables, and so on, mimicking the layout of a paper map. The resulting map
view can be displayed in a window, printed, or saved to disk as an image or a PDF
file.
There are, however, some limitations on what a QGIS plugin is able to do:
• By its very nature, a plugin sits inside the running QGIS application. Your plugin
runs alongside all the other plugins that the user has installed, and shares the same
user interface and menu structure. This means that you can't implement turnkey
mapping applications as QGIS plugins. The full complexity of QGIS is shown to
the user, which can be daunting for the user who might be looking for a custom ap-
plication that performs just one task. In this situation, it might be better to write
your code as an external application that uses the PyQGIS library, rather than at-
tempt to write it as a plugin.
• Since the plugin runs within QGIS itself, there are many points of contact between
the plugin code and the QGIS environment. As QGIS is constantly evolving, this
means that a plugin can stop working when a new version of QGIS is released.
This is far more likely to happen with a plugin than with code written as an extern-
al application using the PyQGIS library.
• Since the plugin uses the Python interpreter built into QGIS itself, you can't make
use of third-party Python libraries that aren't included in QGIS's Python interpreter.
While you can get around this for pure Python libraries (by including the Python
Search WWH ::




Custom Search