[Qgis-developer] Handling errors when reading layers from project

Chris Crook ccrook at linz.govt.nz
Mon Mar 1 14:40:34 EST 2010


Hi

I'm wanting to provide a clearer message to users when layers don't load properly.

The particular case I'm interested in is where a symoblogy V2 plugin renderer is not installed.  I'd like this to generate a message saying something like, "Renderer named ... could not be loaded for layer ..... Perhaps you need to install a plugin?"... or something like that!  Even better would be to generate the message, but render the layer with a default renderer.

At the moment failing to load gives a generic error message "Unable to load one or more ... "  leaving it unclear as to why the layer isn't loading.

I'm happy to code and submit a patch to do this, but I'm looking for some input on architecture.

The main issue I see with implementing it is that the error is only detectable deep in the loading code - in the QgsFeatureRendererV2::load function.  This is where the error (or warning) is generated.  The old symbology equivalent generated an error message in QgsVectorLayer::readSymbology, which is passed back to the QgsVectorLayer::readXml, but then ignored.  To be useful it would need to get passed up from there through QgsMapLayer::readXML to QgsProject::read(layerNode), to QgsProject::_getmapLayers, and finally QgsProject::read where the mBadLayerHandler->handleBadLayers is called to report the problem.

So I think what I need to do, with this architecture, is:

1) Replace the QList<QDomNode> in the _getMapLayers result set with a QList(QgsBadLayerError) structure which includes a QString error message (if we want to bury QString that deeply into the code), a layer name, and possibly a status (warning/failure).

2) Pass a by-reference string into each call from _getMapLayers down to retrieve the error message.  In fact this may need to be a more complex structure than a string, as the resulting error message will be a parameterised string (eg "Could not load renderer [name] ..."), and in order to be translatable to other languages presumably I'd need to keep the template text and the parameters separated until it gets to the GUI.  I'm not sure of a good way of doing this.

3) Update the QgsProjectBadLayerGuiHandler and default handler to use this information to provide more helpful messages

Does this seem like a good approach?  Can you suggest a better one?  Would it be supported as a patch?

Thanks for any input/suggestions
Chris

______________________________________________________________________________________________________

This message contains information, which is confidential and may be subject to legal privilege. 
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.

Thank you.
______________________________________________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20100302/aa4fac8f/attachment.html


More information about the Qgis-developer mailing list