[Qgis-developer] acecss to qgisapp / qgisappinterface from tests (c++ or python?)

Etienne Tourigny etourigny.dev at gmail.com
Tue Nov 20 09:16:40 PST 2012


I understand that QgisAppInterface should only be available wen running the app.

I am working with sublayer handling, which is not handled my
QgsRasterLayer / QgsVectorLayer .  Have a closer look at the various
addRasterLayers and it's not as simple as you write (in part my fault
- I hacked around existing code to add zip support and also raster

- vectors datasets can have multiple layers
- rasters can have sublayers (subdatasets in GDAL)
- zip files can have multiple layers/subdatasets

Unfortunately the code that handles sublayer loading is in QgisApp,
and I would like to add some tests for this in case it gets broken in
the future. It broke a few months ago for rasters, and there ia a case
where it doesn't work for vectors.

Would you have a suggestion as to how we can improve this - i.e.
manage sublayers outside of QgisApp?


On Tue, Nov 20, 2012 at 3:08 PM, Martin Dobias <wonder.sk at gmail.com> wrote:
> On Tue, Nov 20, 2012 at 5:52 PM, Etienne Tourigny <etourigny.dev at gmail.com>
> wrote:
>> Hi,
>> I am trying to add some tests for the addRasterLayer() and
>> addVectorLayer() members in QgisApp, and it seems I cannot have access
>> to them from the test environment.
>> [...]
>> How to get the "real" QgsAppInterface like when using a plugin?
> Hi Etienne
> that's right, it's not possible to access QgisAppInterface outside of
> running QGIS instance. This has a reason: the interface provides various
> methods that make sense only when QGIS is running (e.g. access to map
> canvas, main window, toolbars). For testing purposes you could create a fake
> implmentation of QgisInterface, but that's most likely not what you want.
> IIRC addVectorLayer() and addRasterLayer() are just relatively simple
> wrappers around this code:
> layer = new Qgs[Vector / Raster]Layer( ... );
> if (layer->isValid())
>   QgsMapLayerRegistry::instance()->addMapLayer(layer);
> I'm wondering what exactly are you trying to test... is it the "core" layer
> (and provider) loading or the connection with other QGIS components?
> Regards
> Martin

More information about the Qgis-developer mailing list