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

Martin Dobias wonder.sk at gmail.com
Wed Mar 3 16:53:24 EST 2010


On Mon, Mar 1, 2010 at 8:40 PM, Chris Crook <ccrook at linz.govt.nz> wrote:
> I'm wanting to provide a clearer message to users when layers don't load
> properly.
>
> [...]
>
> 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?

Your suggestion makes sense, so please proceed with the patch. Few
things to consider: QgsBadLayerError could define an enum with
possible load errors, together with an additional QVariant or QString
with error details it could give a better clue to the bad layer
handler. The handler would easily know whether the data source was not
found (and will allow user to correct the path) or the renderer was
not found (and will issue a warning + use a default renderer) etc. Not
having such enumeration would result in somewhat complicated
resolution of individual errors - some of them are fatal, others are
not.

Thinking about the bad layer gui handler, I have a vision that a
list/table pops up with layers and their load errors, giving user
various options how to solve the situation.

When doing changes please make sure to keep the core/gui library API
compatible with older versions so the existing code will keep working.

Cheers
Martin


More information about the Qgis-developer mailing list