[Qgis-developer] Suppress emitting of signal: Bad practice?

Tim Sutton lists at linfiniti.com
Fri Apr 19 08:58:48 PDT 2013


Hi

On Fri, Apr 19, 2013 at 9:07 PM, Matthias Kuhn <matthias.kuhn at gmx.ch> wrote:
> The QgsMapLayerRegistry::removeMapLayers allows to specify a parameter,
> which will suppress emitting signals (altough it seems that this is not
> even properly working [1]).
>
> This parameter can lead to strange behavior, where some parts of the
> software might not realize, that a layer has been removed and keep
> references to no longer available objects.
>
> The same fact applied to selected features in a vector layer. The
> problem there was most probably, that only a method was available to
> change the selection of a single feature and while iterating over
> features, the signal was suppressed to not update the map canvas in
> every iteration.
>
> In my opinion, this is bad practice and we should remove these
> parameters and add methods which allow batch jobs (removeMapLayers is
> already in place) and then emit a single signal for a batch and call
> this method wherever an iteration takes place.
>
> So my questions are:
> * Does somebody know why removeMapLayer(s) accepts this parameter?
> * Do you see any negative effect of removing these or any upside in
> keeping these?


It was added to allow batch removal of layers. If you have a plugin
and you listen for layers removed and say 5 are removed at once and
you have some long running code that updates when the layer set is
changed, it is called 5 times. I think it is important to have a way
to remove layers in batch and let clients only receive a single event.

When I wrote that code I delegated the actual layer removal work to
the layer removal function. No problem from me if you update this but
I think the ability to remove multiple layers while triggering only a
single remove event should remain in place.

Regards

Tim

>
> API freeze is approaching fast and I think we should get rid of these
> parameters now.
>
> Any opinions on this?
>
> Matthias
>
> [1] http://hub.qgis.org/issues/7633 <http://hub.qgis.org/issues/7633>
> _______________________________________________
> 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)
==============================================
Please do not email me off-list with technical
support questions. Using the lists will gain
more exposure for your issues and the knowledge
surrounding your issue will be shared with all.

Visit http://linfiniti.com to find out about:
 * QGIS programming and support 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