[QGIS-Developer] Generic use of QgsLocator and friends?

Nyall Dawson nyall.dawson at gmail.com
Mon Sep 25 21:43:21 PDT 2017


On 23 September 2017 at 01:13, Richard Duivenvoorde <rdmailings at duif.net> wrote:
>
> Hi Devs,
>
> I've been playing a little with the QgsLocatorWidget and friends (in
> Python).
>
> Hoping to be able to use this for a geocoder I have to reimplement.
> And also hoping it could be used as a generic geocoder interface, see an
> earlier QEP:
> https://github.com/qgis/QGIS-Enhancement-Proposals/issues/64
>
> I've not been able to get results yet, though I am able to create the
> widget in a toolbar, and see that name and displayname of my Filter are
> called....

How are you adding your filter to the widget? If you're using the
iface methods, then that's were your problem lies... read on...

> - is the QgsLocatorWidget re-usable, or is it a singleton

Reusable. Each QgsLocatorWidget has it's own internal QgsLocator,
which does all the heavy lifting and manages the filter providers.
Qgis app has a single locator widget (the one located in the status
bar), which is where filters get registered to when calling the
iface.registerLocatorFilter() method. So it's 'kind of' a singleton in
this aspect, but there's absolutely nothing stopping plugins from
having their own QgsLocatorWidgets with their own set of registered
filters.

> - is it a good idea to make it a reusable component for geocoder(s0?

*maybe*. Is there any reason NOT to use the existing, all powerful,
integrated with everything locator widget? The intention with the
creation of the locator was specifically to avoid the need for
multiple different search widgets reimplemented by each plugin and
cluttering up the interface.  I personally can't see any reason not to
include geolocator results here too.

> - is it possible to make the results go down instead of up (as I think
> these geocoders should be somewhere in the toolbars)

Not in the current API - it's hardcoded at
https://github.com/qgis/QGIS/blob/master/src/gui/locator/qgslocatorwidget.cpp#L64
. But this could be exposed to the public API for the widget if
there's a strong use case.

Nyall


More information about the QGIS-Developer mailing list