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
Full diff¶
See this full diff between the Python API 1.8 compared to the master branch
How to update (relative to your build directory):
sort ../python/qsci_apis/PyQGIS-1.8.api >/tmp/previous.api sort python/qsci_apis/PyQGIS.api >/tmp/current.api diff /tmp/previous.api /tmp/current.api
Core library¶
Removed classes:- QgsSearchString, QgsSearchTreeNode: old code should be migrated to use QgsExpression
QgsRasterBandStats¶
Removed histogram related members (moved to QgsRasterHistogram)
QgsRasterDataProvider¶
Removed methods:- QgsRasterBandStats bandStatistics( int theBandNo )
replaced by QgsRasterBandStats bandStatistics( int theBandNo, const QgsRectangle & theExtent = QgsRectangle(), int theSampleSize = 0 )
- void populateHistogram( int theBandNoInt, QgsRasterBandStats & theBandStats, int theBinCountInt = RASTER_HISTOGRAM_BINS, bool theIgnoreOutOfRangeFlag = true, bool theThoroughBandScanFlag = false )
replaced by virtual QgsRasterHistogram histogram( int theBandNo, int theBinCount = 0, double theMinimum = std::numeric_limits<double>::quiet_NaN(), double theMaximum = std::numeric_limits<double>::quiet_NaN(), const QgsRectangle & theExtent = QgsRectangle(), int theSampleSize = 0, bool theIncludeOutOfRange = false );
- bool identify( const QgsPoint & point, QMap<QString, QString>& results )
- QMap<int, void *> identify( const QgsPoint & point )
- QString identifyAsText( const QgsPoint& point )
- QString identifyAsHtml( const QgsPoint& point )
- virtual void addLayers( const QStringList & layers, const QStringList & styles = QStringList() ) = 0;
- virtual QStringList supportedImageEncodings() = 0;
- virtual QString imageEncoding() const = 0;
- virtual void setImageEncoding( const QString & mimeType ) = 0;
- virtual void setImageCrs( const QString & crs ) = 0;
WMS provider relic.
New methods:
- QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 )
Muslim wedding organizer bekasi
Islamic wedding organizer bekasi
QgsSvgMarkerSymbolLayerV2¶
Look at dffae7962f.
The following methods was moved from QgsSvgMarkerSymbolLayerV2 to QgsSymbolLayerV2Utils:- QStringList listSvgFiles()
- QStringList listSvgFilesAt( QString directory )
- QString symbolNameToPath( QString name )
- QString symbolPathToName( QString path )
Thus to port 1.x plugins, use the corresponding methods of QgsSymbolLayerV2Utils
Main application¶
QgisApp¶
Removed methods:- addRasterLayer( QString const &rasterLayerPath, QString const &baseName, QString const &providerKey, QStringList const & layers, QStringList const & styles, QString const &format, QString const &crs )
This method was a hack for WMS used before true raster providers. Use QgsDataSourceURI to create encoded URI and addRasterLayer( QString const & uri, QString const & baseName, QString const & providerKey );
- QgsContrastEnhancement* rasterContrastEnhancement( QgsRasterLayer* rlayer, int band, bool visibleAreaOnly = false ) const
- void histogramStretch( bool visibleAreaOnly = false )
Changed to void histogramStretch( bool visibleAreaOnly = false, QgsRasterLayer::ContrastEnhancementLimits theLimits = QgsRasterLayer::ContrastEnhancementMinMax )
QgisAppInterface¶
Removed methods:- addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey, const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs )
Replaced by addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey)
QgsRasterLayer¶
Removed methods:- QgsRasterLayer( int dummy, const QString & baseName = QString(), const QString & path = QString(), const QString & providerLib = QString(), const QStringList & layers = QStringList(), const QStringList & styles = QStringList(), const QString & format = QString(), const QString & crs = QString() );
Replaced by QgsRasterLayer( const QString & uri, const QString & baseName, const QString & providerKey, bool loadDefaultStyleFlag = true );
- setDataProvider( QString const & provider, QStringList const & layers, QStringList const & styles, QString const & format, QString const & theCrs, bool loadDefaultStyleFlag )
Replaced by setDataProvider( QString const & provider)
- setDataProvider( QString const & provider, QStringList const & layers, QStringList const & styles, QString const & format, QString const & theCrs )
Replaced by setDataProvider( QString const & provider)
- bool hasCachedHistogram( int theBandNoInt, int theBinCountInt = RASTER_HISTOGRAM_BINS )
Use provider hasHistogram()
- void populateHistogram( int theBandNoInt, int theBinCountInt = RASTER_HISTOGRAM_BINS, bool theIgnoreOutOfRangeFlag = true, bool theThoroughBandScanFlag = false )
Use provider histogram()
- bool hasStatistics( int theBandNoInt )
Use provider hasStatistics()
- const QgsRasterBandStats bandStatistics( int )
Use provider bandsStatistics()
- const QgsRasterBandStats bandStatistics( const QString & )
Use provider bandsStatistics()
- QList<QgsColorRampShader::ColorRampItem>* QgsRasterLayer::colorTable( int theBandNo )
Changed to QList<QgsColorRampShader::ColorRampItem> QgsRasterLayer::colorTable( int theBandNo )
- QString grayBandName() const
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- QString greenBandName() const
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- bool invertHistogram() const
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- QgsRasterTransparency* rasterTransparency()
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- QgsRasterShader* rasterShader()
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- QString redBandName() const
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- QString transparentBandName() const
Use QgsRasterRenderer and subclasses to get/set how the raster is displayed ( QgsRasterLayer::renderer() )
- bool isGrayMinimumMaximumEstimated() const
Functions related to statistics are now in QgsRasterDataProvider
- void setGrayMinimumMaximumEstimated( bool theBool )
Functions related to statistics are now in QgsRasterDataProvider
- bool isRGBMinimumMaximumEstimated() const
Functions related to statistics are now in QgsRasterDataProvider
- void setRGBMinimumMaximumEstimated( bool theBool )
Functions related to statistics are now in QgsRasterDataProvider
- bool identify( const QgsPoint & point, QMap<QString, QString>& results )
identify method available in QgsRasterDataProvider
- bool identify( const QgsPoint & point, QMap<int, QString>& results )
identify method available in QgsRasterDataProvider
- QString identifyAsText( const QgsPoint & point )
identify method available in QgsRasterDataProvider
- QString identifyAsHtml( const QgsPoint & point )
identify method available in QgsRasterDataProvider
- static void buildSupportedRasterFileFilter( QString & fileFilters )
Use QgsProviderRegistry::instance()->fileRasterFilters()
Layer Init Function¶
Init function is now passed a reference to the QgsFeature and QgsVectorLayer rather then a feature and layer id.
Example:
def myFunction(dialog, layer, feature):
id = layer.id()
name = layer.name
geom = feature.geometry()
# etc
Print composer¶
QgsComposerView¶
Removed methods:- addComposerLabel
- addComposerMap
- addComposerScaleBar
- addComposerLegend
- addComposerPicture
- addComposerShape
- addComposerTable
- pushAddRemoveCommand
- sendItemAddedSignal
- composerLabelAdded
- composerMapAdded
- composerScaleBarAdded
- composerLegendAdded
- composerPictureAdded
To port 1.x plugins, use the corresponding methods and signals of QgsComposition
QgsComposerMap¶
Removed Methods:- setGridAnnotationPosition( GridAnnotationPosition p )
Replaced by setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border ) - gridAnnotationPosition()
Replaced by gridAnnotationPosition( QgsComposerMap::Border border ) - setGridAnnotationDirection( GridAnnotationDirection d )
Replaced by setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border ) - gridAnnotationDirection()
Replaced by gridAnnotationDirection( QgsComposerMap::Border border )
PostrgeSQL data provider¶
Look at ce4fc1daa5
Deprecated methods¶
See also 5e45a22d06
QgsProjectionSelector¶
- selectedEpsg()
Removed, there are other authorities - use selectedAuthId() - setSelectedEpsg( long epsg )
Removed, there are other authorities - so not always defined. Use setSelectedAuthId( QString authId )
QgsMapCanvasMap¶
- pixmap()
Removed, use paintDevice()
QgsMapCanvas¶
- canvasPixmap
Removed, use canvasPaintDevice()
QgsGenericProjectionSelector¶
- selectedProj4String
- setSelectedEpsg
Removed, use other authorities: setSelectedCrsName( QString theName ), setSelectedCrsId( long theID ), setSelectedAuthId( QString authId ) - selectedEpsg
There are other authorities - selectedCrsId() and selectedAuthId()
QgisAppInterface¶
Removed:- actionCapturePoint
- actionCaptureLine
- actionCapturePolygon
- actionAddVertex
- actionDeleteVertex
- actionMoveVertex
- actionFileSeparator1
- actionFileSeparator2
- actionFileSeparator3
- actionFileSeparator4
- actionEditSeparator1
- actionEditSeparator2
- actionViewSeparator1
- actionViewSeparator2
- actionViewSeparator3
- actionLayerSeparator1
- actionLayerSeparator2
- actionLayerSeparator3
- actionPluginSeparator1
- actionPluginSeparator2
- actionPluginPythonSeparator
- actionSettingsSeparator1
- actionHelpSeparator1
- actionHelpSeparator2
- actionAddIsland
Removed, use actionAddPart() - refreshLegend( QgsMapLayer *l )
Removed, use QgsLegendInterface::refreshLayerSymbology
QgsVectorDataProvider¶
- updateFeatureCount
Does nothing useful, removed - addAttributes( const QMap<QString, QString> &attributes )
Replaced by addAttributes( const QList<QgsField> &attributes ) - supportedNativeTypes()
Replaced by nativeTypes()
QgsGeometry¶
- addIsland( const QList<QgsPoint> &points )
Replaced by addPart( const QList<QgsPoint> &points )
QgsMaplayer¶
- getLayerID()
Replaced by id() - srs()
Replaced by crs()
QgsRectangle¶
- expand( double scaleFactor, const QgsPoint *c = 0 )
Replaced by scale( double scaleFactor, const QgsPoint *c = 0 )
QgsComposerMultiFrame¶
- nFrames
Use frameCount() instead
QgsComposerItem¶
- frame()
Replaced with hasFrame() - setFrame( bool drawFrame )
Replaced with setFrameEnabled( bool drawFrame )
QgsComposerMap¶
draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi )
Replaced by draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double forceWidthScale = 0 )
QgsOverlayObject¶
- getGeosGeometry()
Use geometry() and QgsGeometry::asGeos instead - releaseGeosGeometry( GEOSGeometry *the_geom )
This method actually does nothing, removed
QgsCoordinateReferenceSystem¶
*createFromEpsg( const long theEpsg )Use createFromOgcWmsCrs()
- equals( QString theProj4String )
Removed because the same proj.4 string not necessarily means the same CRS - epsg()
There are other authorities, use authid() instead
QgsDistanceArea¶
- setProjectionsEnabled( bool flag )
Replaced by setEllipsoidalMode( bool flag ) - hasCrsTransformEnabled()
Replaced by ellipsoidalEnabled() - setSourceEpsgCrsId( long epsgId )
There are other authorities, use setSourceAuthid()
QgsMapRenderer¶
- distanceArea()
Removed - setDestinationSrs( const QgsCoordinateReferenceSystem& srs )
Replaced by setDestinationCrs( const QgsCoordinateReferenceSystem& srs ) - destinationSrs()
Replaced by destinationCrs()
QgsApplication¶
- developerPath()
Removed, images are not provided anymore - svgPath()
Use svgPaths() instead
Qgis¶
- GEOWkt
Replaced by GEOWKT
QgsVectorFileWriter¶
- writeAsShapefile( QgsVectorLayer* layer, const QString& shapefileName, const QString& fileEncoding, const QgsCoordinateReferenceSystem destCRS, bool onlySelected = false, QString *errorMessage = 0, const QStringList &datasourceOptions = QStringList(), const QStringList &layerOptions = QStringList())
Removed, use writeAsVectorFormat( QgsVectorLayer layer, const QString& fileName, const QString& fileEncoding, const QgsCoordinateReferenceSystem *destCRS, const QString& driverName = "ESRI Shapefile", bool onlySelected = false, QString *errorMessage = 0, const QStringList &datasourceOptions = QStringList(), const QStringList &layerOptions = QStringList(), bool skipAttributeCreation = false, QString *newFilename = 0))
QgsRasterLayer¶
- providerKey()
Replaced with providerType() - thumbnailAsPixmap()
Use previewAsPixmap()
- usesProvider()
- legendAsPixmap()
- legendAsPixmap( bool )
- legendAsPixmap( int theLabelCount )
- setBlueBandName( const QString & theBandName )
- setColorShadingAlgorithm( QgsRasterLayer::ColorShadingAlgorithm theShaderAlgorithm )
- setColorShadingAlgorithm( QString theShaderAlgorithm )
- setGrayBandName( const QString & theBandName )
- setGreenBandName( const QString & theBandName )
- setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true )
- setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true )
- setMinimumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true )
- setRasterShaderFunction( QgsRasterShaderFunction* theFunction )
- setRedBandName( const QString & theBandName )
- setTransparentBandName( const QString & theBandName )
QgsMapLayerRegistry¶
- addMapLayer( QgsMapLayer * theMapLayer, bool theEmitSignal = true )
Use addMapLayers( QList<QgsMapLayer *> theMapLayers, bool theEmitSignal = true ) - removeMapLayer( QString theLayerId, bool theEmitSignal = true )
Use removeMapLayers( QStringList theLayerIds, bool theEmitSignal = true )
QgsLabel¶
- renderLabel(QPainter* painter, const QgsRectangle& viewExtent, QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel *transform, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0, double sizeScale = 1.0, double rasterScaleFactor = 1.0)
Removed - layerAttributes()
Use attributes() rather
QgsVectorLayer¶
- updateFeatureCount()
Does nothing, removed - addIsland( const QList<QgsPoint>& ring )
Replaced by addPart( const QList<QgsPoint>& ring ) - addAttribute( QString name, QString type )
Replaced by addAttribute( const QgsField &field )
QgsFeature¶
see http://lists.osgeo.org/pipermail/qgis-developer/2013-February/024278.html
QgsAttributeAction
- doActiondoAction( int index, const QgsAttributeMap &attributes, int defaultValueIndex = 0, void ( *executePython )( const QString & ) = 0 )
Removed
Removed
QgsProject¶
- readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool * ok = 0 ) const;
Default argument added before ok.
Best practises for Plugin developers¶
During a transition time, a plugin should work with both the old and new API.
This can be achieved with exception handling in an import clause e.g.:
try:
from qgis.core import newFunctionName as newFunctionName
except:
from qgis.core import oldFunctionName as newFunctionName
Following 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)
Another approach is to test qgis version and use appropriate API functions:
if QGis.QGIS_VERSION_INT < 10900:
composerView.addComposerShape(item)
else:
composition.addComposerShape(item)
Also see this page Python_plugin_API_changes_from_18_to_20