API changes for version 20
Version 6 (Pirmin Kalberer, 12/13/2011 04:32 am) → Version 7/35 (Pirmin Kalberer, 12/13/2011 04:34 am)
h1. 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
h2. Print composer
h3. 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
h2. 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 e.g.: clause:
<pre>
try:
from qgis.core import newFunctionName as newFunctionName
except:
from qgis.core import oldFunctionName as newFunctionName
</pre>
Following To follow the "duck typing":http://en.wikipedia.org/wiki/Duck_typing#In_Python scheme of dynamic langagues, this could also be done before calling the function:
<pre>
if hasattr(composerView, "addComposerShape"):
composerView.addComposerShape(item)
else
composition.addComposerShape(item)
</pre>