[Qgis-developer] QgsMapLayerRegistry (and QgsMapCanvas) problem

Tim Sutton tim at linfiniti.com
Fri Oct 17 17:31:06 EDT 2008


Hi

2008/10/17 Carson Farmer <carson.farmer at gmail.com>:
> Hello gang,
>
> According to the API, QgsMapLayerRegistry.instance().mapLayers() should
> return (in the case of python) a dict with the following format:
> { layer0 : QgsMapLayer, layer1: QgsMapLayer }
> However, what I appear to be getting is slightly different. Instead of
> QgsMapLayers, I get QgsVectorLayers and QgsRasterLayers. This also occurs
> when trying to get a QgsMapLayer from the map canvas. Is this intended, and
> if so then this creates a problem:
>
> QgsMapLayer.type() returns (as of 9490-ish) either VectorLayer (0) or
> RasterLayer (1) [ QgsMapLayer.LayerType ]
> QgsVectorLayer,type() returns either Point (0), Line (1), Polygon (2), or
> UnknownGeometry (3) [ QGis.geometryType ]
> QgsRasterLayer.type() returns (as far as I can tell) the same as
> QgsMapLayer.type(), so: RasterLayer (1)
>
> So the problem is this:
> If we are trying to check what type of layers we have in our
> QgsMapLayerRegistry, if it's a raster, we will be told that it's a raster by
> returning QgsMapLayer.RasterLayer (or 1), however, if it's a vector, then we
> will get QgsVectorLayer.type() instead of QgsMapLayer.type().
>
> I see three solutions to this problem:
> a) I'm doing this all wrong, and hopefully someone will tell me this,
> b) My favoured solution: Since QgsVectorLayer inherits QgsMapLayer,
> QgsVectorLayer.type() should be changed to QgsVectorLayer.vectorType()
> c) All of these enumerators should return something other than numbers?

Regarding b) yeah type() is probably being overloaded by
QgsVectorLayer causing confusion. I removed the vector from vectorType
because I thought it was redundant. If we need to change it back I'd
probably prefer to call it geometryType().

Regarding c) they should all be returning enumerated types but I guess
the side effect is that the QgsMapLayer::type() enumerators and those
of teh first two entries in QgsVectorLayer::type() return  matchin
numbers. I could force them to be higher no's to remove such
inadvertant collisions. I'll take a look at this later tomorrow -
thanks for the feedback on this.

Any other comments on API changes as I do them are welcome...

Regards

Tim

>
> Clear as mud?
>
> Thanks,
>
> Carson
>
> --
> Carson J.Q. Farmer
> PhD Fellow
> National Centre for Geocomputation (NCG),
> John Hume Building,
> National University of Ireland, Maynooth,
> Co. Kildare,
> Ireland.
> http://www.carsonfarmer.com
> http://www.ftools.ca
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>



-- 
Tim Sutton - QGIS Project Steering Committee Member (Release  Manager)
==============================================
Visit http://linfiniti.com to find out about:
 * QGIS programming services
 * Mapserver and PostGIS based hosting plans
 * FOSS Consulting Services
Skype: timlinux Irc: timlinux on #qgis at freenode.net
==============================================


More information about the Qgis-developer mailing list