Skip to content

Commit

Permalink
Merge pull request #4512 from nyalldawson/locator
Browse files Browse the repository at this point in the history
[FEATURE] Implement a QtCreator style locator bar in the QGIS status bar
  • Loading branch information
nyalldawson committed May 17, 2017
2 parents 8231d75 + 7108d6b commit b4de0ac
Show file tree
Hide file tree
Showing 40 changed files with 3,239 additions and 56 deletions.
1 change: 1 addition & 0 deletions .ci/travis/macos/blacklist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ PyQgsDBManagerGpkg
PyQgsFileDownloader
PyQgsSettings
PyQgsConsole
PyQgsLocator
PyQgsAuthManagerPasswordOWSTest
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/locator
${CMAKE_SOURCE_DIR}/src/gui/raster
${CMAKE_SOURCE_DIR}/src/gui/symbology-ng
${CMAKE_SOURCE_DIR}/src/analysis
Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ INCLUDE_DIRECTORIES(
../src/gui/editorwidgets/core
../src/gui/effects
../src/gui/layertree
../src/gui/locator

../src/plugins

Expand Down
7 changes: 7 additions & 0 deletions python/core/qgsmaplayermodel.sip
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ returns if the items can be checked or not
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;


static QIcon iconForLayer( QgsMapLayer *layer );
%Docstring
Returns the icon corresponding to a specified map ``layer``.
.. versionadded:: 3.0
:rtype: QIcon
%End

protected slots:
void removeLayers( const QStringList &layerIds );
void addLayers( const QList<QgsMapLayer *> &layers );
Expand Down
5 changes: 5 additions & 0 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@
%Include layertree/qgslayertreeview.sip
%Include layertree/qgslayertreeviewdefaultactions.sip

%Include locator/qgslocator.sip
%Include locator/qgslocatorcontext.sip
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatorwidget.sip

%Include raster/qgsmultibandcolorrendererwidget.sip
%Include raster/qgspalettedrendererwidget.sip
%Include raster/qgsrasterbandcombobox.sip
Expand Down
142 changes: 142 additions & 0 deletions python/gui/locator/qgslocator.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/locator/qgslocator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLocator : QObject
{
%Docstring
Handles the management of QgsLocatorFilter objects and async collection of search results from them.

QgsLocator acts as both a registry for QgsLocatorFilter objects and a means of firing up
asynchronous queries against these filter objects.

Filters are first registered to the locator by calling registerFilter(). Registering filters
transfers their ownership to the locator object. Plugins which register filters to the locator
must take care to correctly call deregisterFilter() and deregister their filter upon plugin
unload to avoid crashes.

In order to trigger a search across registered filters, the fetchResults() method is called.
This triggers threaded calls to QgsLocatorFilter.fetchResults() for all registered filters.
As individual filters find matching results, the foundResult() signal will be triggered
for each result. Callers should connect this signal to an appropriate slot designed
to collect and handle these results. Since foundResult() is triggered whenever a filter
encounters an individual result, it will usually be triggered many times for a single
call to fetchResults().

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslocator.h"
%End
public:

QgsLocator( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLocator.
%End

~QgsLocator();
%Docstring
Destructor for QgsLocator. Destruction will block while any currently running query is terminated.
%End

void registerFilter( QgsLocatorFilter *filter /Transfer/ );
%Docstring
Registers a ``filter`` within the locator. Ownership of the filter is transferred to the
locator.
\warning Plugins which register filters to the locator must take care to correctly call
deregisterFilter() and deregister their filters upon plugin unload to avoid crashes.
.. seealso:: deregisterFilter()
%End

void deregisterFilter( QgsLocatorFilter *filter );
%Docstring
Deregisters a ``filter`` from the locator and deletes it. Calling this will block whilst
any currently running query is terminated.

Plugins which register filters to the locator must take care to correctly call
deregisterFilter() to deregister their filters upon plugin unload to avoid crashes.

.. seealso:: registerFilter()
%End

QList< QgsLocatorFilter *> filters();
%Docstring
Returns the list of filters registered in the locator.
.. seealso:: prefixedFilters()
:rtype: list of QgsLocatorFilter
%End

QMap< QString, QgsLocatorFilter *> prefixedFilters() const;
%Docstring
Returns a map of prefix to filter, for all registered filters
with valid prefixes.
.. seealso:: filters()
:rtype: QMap< str, QgsLocatorFilter *>
%End

void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback = 0 );
%Docstring
Triggers the background fetching of filter results for a specified search ``string``.
The ``context`` argument encapsulates the context relating to the search (such as a map
extent to prioritize).

If specified, the ``feedback`` object must exist for the lifetime of this query.

The foundResult() signal will be emitted for each individual result encountered
by the registered filters.
%End

void cancel();
%Docstring
Cancels any current running query, and blocks until query is completely canceled by
all filters.
.. seealso:: cancelWithoutBlocking()
%End

void cancelWithoutBlocking();
%Docstring
Triggers cancelation of any current running query without blocking. The query may
take some time to cancel after calling this.
.. seealso:: cancel()
%End

bool isRunning() const;
%Docstring
Returns true if a query is currently being executed by the locator.
:rtype: bool
%End

signals:

void foundResult( const QgsLocatorResult &result );
%Docstring
Emitted whenever a filter encounters a matching ``result`` after the fetchResults() method
is called.
%End

void finished();
%Docstring
Emitted when locator has finished a query, either as a result
of successful completion or early cancelation.
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/locator/qgslocator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
53 changes: 53 additions & 0 deletions python/gui/locator/qgslocatorcontext.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/locator/qgslocatorcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLocatorContext
{
%Docstring
Encapsulates the properties relating to the context of a locator search.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslocatorcontext.h"
%End
public:

QgsLocatorContext();
%Docstring
Constructor for QgsLocatorContext.
%End

QgsRectangle targetExtent;
%Docstring
Map extent to target in results. This can be used to prioritize searching
for results close to the current map extent. The CRS for the extent
is specified by targetExtentCrs.
.. seealso:: targetExtentCrs
%End

QgsCoordinateReferenceSystem targetExtentCrs;
%Docstring
Coordinate reference system for the map extent variable.
.. seealso:: targetExtent
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/locator/qgslocatorcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit b4de0ac

Please sign in to comment.