[Qgis-developer] loading/saving subclasses of layers
b.rowlingson at lancaster.ac.uk
Thu Jan 29 06:02:10 EST 2009
I've created a subclass of QgsVectorLayer, called 'surveyLayer', in
python in order to override some of the default methods of
QgsVectorLayer. My plugin adds a menu item to read data into one of
these specialised vector layer classes.
However I can't see how to make sure that when the project is saved
and loaded that it creates a surveyLayer instead of a plain
QgsVectorLayer. Currently "Save" just saves it as a normal vector
layer but without any <symbology> section (because symbology for these
layers is a bit special and outside the realm of included Qgis
symbolisers). When loaded, qgis errors on creating the layer because
of the lack of symbology and says it can't find the shapefile.
Loading a project seems to unavoidably go via _getMapLayers(...) in
qgsproject.cpp, which creates a QgsVectorLayer. There doesn't seem to
be a way to include something in the project XML to hand off layer
creation to a specific constructor.
I'm probably just pushing things too far here and expecting too much,
so I'll probably think of a workaround... Meanwhile, any thoughts
would be useful. The real solution might be some kind of layer type
registry, but that's way off...
More information about the Qgis-developer