Skip to content

Commit b4de0ac

Browse files
authored
Merge pull request #4512 from nyalldawson/locator
[FEATURE] Implement a QtCreator style locator bar in the QGIS status bar
2 parents 8231d75 + 7108d6b commit b4de0ac

40 files changed

+3239
-56
lines changed

.ci/travis/macos/blacklist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ PyQgsDBManagerGpkg
4848
PyQgsFileDownloader
4949
PyQgsSettings
5050
PyQgsConsole
51+
PyQgsLocator
5152
PyQgsAuthManagerPasswordOWSTest

doc/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ IF(WITH_APIDOC)
7878
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
7979
${CMAKE_SOURCE_DIR}/src/gui/effects
8080
${CMAKE_SOURCE_DIR}/src/gui/layertree
81+
${CMAKE_SOURCE_DIR}/src/gui/locator
8182
${CMAKE_SOURCE_DIR}/src/gui/raster
8283
${CMAKE_SOURCE_DIR}/src/gui/symbology-ng
8384
${CMAKE_SOURCE_DIR}/src/analysis

python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ INCLUDE_DIRECTORIES(
122122
../src/gui/editorwidgets/core
123123
../src/gui/effects
124124
../src/gui/layertree
125+
../src/gui/locator
125126

126127
../src/plugins
127128

python/core/qgsmaplayermodel.sip

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ returns if the items can be checked or not
134134
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
135135

136136

137+
static QIcon iconForLayer( QgsMapLayer *layer );
138+
%Docstring
139+
Returns the icon corresponding to a specified map ``layer``.
140+
.. versionadded:: 3.0
141+
:rtype: QIcon
142+
%End
143+
137144
protected slots:
138145
void removeLayers( const QStringList &layerIds );
139146
void addLayers( const QList<QgsMapLayer *> &layers );

python/gui/gui.sip

+5
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@
211211
%Include layertree/qgslayertreeview.sip
212212
%Include layertree/qgslayertreeviewdefaultactions.sip
213213

214+
%Include locator/qgslocator.sip
215+
%Include locator/qgslocatorcontext.sip
216+
%Include locator/qgslocatorfilter.sip
217+
%Include locator/qgslocatorwidget.sip
218+
214219
%Include raster/qgsmultibandcolorrendererwidget.sip
215220
%Include raster/qgspalettedrendererwidget.sip
216221
%Include raster/qgsrasterbandcombobox.sip

python/gui/locator/qgslocator.sip

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/locator/qgslocator.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLocator : QObject
13+
{
14+
%Docstring
15+
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
16+
17+
QgsLocator acts as both a registry for QgsLocatorFilter objects and a means of firing up
18+
asynchronous queries against these filter objects.
19+
20+
Filters are first registered to the locator by calling registerFilter(). Registering filters
21+
transfers their ownership to the locator object. Plugins which register filters to the locator
22+
must take care to correctly call deregisterFilter() and deregister their filter upon plugin
23+
unload to avoid crashes.
24+
25+
In order to trigger a search across registered filters, the fetchResults() method is called.
26+
This triggers threaded calls to QgsLocatorFilter.fetchResults() for all registered filters.
27+
As individual filters find matching results, the foundResult() signal will be triggered
28+
for each result. Callers should connect this signal to an appropriate slot designed
29+
to collect and handle these results. Since foundResult() is triggered whenever a filter
30+
encounters an individual result, it will usually be triggered many times for a single
31+
call to fetchResults().
32+
33+
.. versionadded:: 3.0
34+
%End
35+
36+
%TypeHeaderCode
37+
#include "qgslocator.h"
38+
%End
39+
public:
40+
41+
QgsLocator( QObject *parent /TransferThis/ = 0 );
42+
%Docstring
43+
Constructor for QgsLocator.
44+
%End
45+
46+
~QgsLocator();
47+
%Docstring
48+
Destructor for QgsLocator. Destruction will block while any currently running query is terminated.
49+
%End
50+
51+
void registerFilter( QgsLocatorFilter *filter /Transfer/ );
52+
%Docstring
53+
Registers a ``filter`` within the locator. Ownership of the filter is transferred to the
54+
locator.
55+
\warning Plugins which register filters to the locator must take care to correctly call
56+
deregisterFilter() and deregister their filters upon plugin unload to avoid crashes.
57+
.. seealso:: deregisterFilter()
58+
%End
59+
60+
void deregisterFilter( QgsLocatorFilter *filter );
61+
%Docstring
62+
Deregisters a ``filter`` from the locator and deletes it. Calling this will block whilst
63+
any currently running query is terminated.
64+
65+
Plugins which register filters to the locator must take care to correctly call
66+
deregisterFilter() to deregister their filters upon plugin unload to avoid crashes.
67+
68+
.. seealso:: registerFilter()
69+
%End
70+
71+
QList< QgsLocatorFilter *> filters();
72+
%Docstring
73+
Returns the list of filters registered in the locator.
74+
.. seealso:: prefixedFilters()
75+
:rtype: list of QgsLocatorFilter
76+
%End
77+
78+
QMap< QString, QgsLocatorFilter *> prefixedFilters() const;
79+
%Docstring
80+
Returns a map of prefix to filter, for all registered filters
81+
with valid prefixes.
82+
.. seealso:: filters()
83+
:rtype: QMap< str, QgsLocatorFilter *>
84+
%End
85+
86+
void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback = 0 );
87+
%Docstring
88+
Triggers the background fetching of filter results for a specified search ``string``.
89+
The ``context`` argument encapsulates the context relating to the search (such as a map
90+
extent to prioritize).
91+
92+
If specified, the ``feedback`` object must exist for the lifetime of this query.
93+
94+
The foundResult() signal will be emitted for each individual result encountered
95+
by the registered filters.
96+
%End
97+
98+
void cancel();
99+
%Docstring
100+
Cancels any current running query, and blocks until query is completely canceled by
101+
all filters.
102+
.. seealso:: cancelWithoutBlocking()
103+
%End
104+
105+
void cancelWithoutBlocking();
106+
%Docstring
107+
Triggers cancelation of any current running query without blocking. The query may
108+
take some time to cancel after calling this.
109+
.. seealso:: cancel()
110+
%End
111+
112+
bool isRunning() const;
113+
%Docstring
114+
Returns true if a query is currently being executed by the locator.
115+
:rtype: bool
116+
%End
117+
118+
signals:
119+
120+
void foundResult( const QgsLocatorResult &result );
121+
%Docstring
122+
Emitted whenever a filter encounters a matching ``result`` after the fetchResults() method
123+
is called.
124+
%End
125+
126+
void finished();
127+
%Docstring
128+
Emitted when locator has finished a query, either as a result
129+
of successful completion or early cancelation.
130+
%End
131+
132+
};
133+
134+
135+
136+
/************************************************************************
137+
* This file has been generated automatically from *
138+
* *
139+
* src/gui/locator/qgslocator.h *
140+
* *
141+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
142+
************************************************************************/
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/locator/qgslocatorcontext.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLocatorContext
13+
{
14+
%Docstring
15+
Encapsulates the properties relating to the context of a locator search.
16+
.. versionadded:: 3.0
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgslocatorcontext.h"
21+
%End
22+
public:
23+
24+
QgsLocatorContext();
25+
%Docstring
26+
Constructor for QgsLocatorContext.
27+
%End
28+
29+
QgsRectangle targetExtent;
30+
%Docstring
31+
Map extent to target in results. This can be used to prioritize searching
32+
for results close to the current map extent. The CRS for the extent
33+
is specified by targetExtentCrs.
34+
.. seealso:: targetExtentCrs
35+
%End
36+
37+
QgsCoordinateReferenceSystem targetExtentCrs;
38+
%Docstring
39+
Coordinate reference system for the map extent variable.
40+
.. seealso:: targetExtent
41+
%End
42+
43+
};
44+
45+
46+
47+
/************************************************************************
48+
* This file has been generated automatically from *
49+
* *
50+
* src/gui/locator/qgslocatorcontext.h *
51+
* *
52+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
53+
************************************************************************/

0 commit comments

Comments
 (0)