« Previous - Version 6/36 (diff) - Next » - Current version
Pirmin Kalberer, 12/13/2011 04:32 am
Best practises for Plugin developers


API changes for version 2.0

This is a list of changes for 2.0 which are breaking the API compatibility. It also serves as a basic guide on how to port plugins from 1.x to 2.0

QgsComposerView

Removed methods:
  • addComposerLabel
  • addComposerMap
  • addComposerScaleBar
  • addComposerLegend
  • addComposerPicture
  • addComposerShape
  • addComposerTable
  • pushAddRemoveCommand
  • sendItemAddedSignal
Removed signals:
  • composerLabelAdded
  • composerMapAdded
  • composerScaleBarAdded
  • composerLegendAdded
  • composerPictureAdded

To port 1.x plugins, use the corresponding methods and signals of QgsComposition

Best practises for Plugin developers

During a transition time, a plugin sould work with both the old and new API.
This can be achieved e.g. with exception handling in an import clause:

try:
    from qgis.core import newFunctionName as newFunctionName
except:
    from qgis.core import oldFunctionName as newFunctionName

To follow the duck typing scheme of dynamic langagues, this could also be done before calling the function:

if hasattr(composerView, "addComposerShape"):
    composerView.addComposerShape(item)
else
    composition.addComposerShape(item)