Skip to content

Commit a8e1d33

Browse files
committed
Move locator non-gui classes to core
Allows reuse in projects which don't build QGIS gui, e.g. QField
1 parent e30f704 commit a8e1d33

22 files changed

+977
-333
lines changed

doc/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ IF(WITH_APIDOC)
6464
${CMAKE_SOURCE_DIR}/src/core/gps
6565
${CMAKE_SOURCE_DIR}/src/core/layertree
6666
${CMAKE_SOURCE_DIR}/src/core/layout
67+
${CMAKE_SOURCE_DIR}/src/core/locator
6768
${CMAKE_SOURCE_DIR}/src/core/metadata
6869
${CMAKE_SOURCE_DIR}/src/core/pal
6970
${CMAKE_SOURCE_DIR}/src/core/processing

python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ INCLUDE_DIRECTORIES(
115115
${CMAKE_SOURCE_DIR}/src/core/gps
116116
${CMAKE_SOURCE_DIR}/src/core/layertree
117117
${CMAKE_SOURCE_DIR}/src/core/layout
118+
${CMAKE_SOURCE_DIR}/src/core/locator
118119
${CMAKE_SOURCE_DIR}/src/core/metadata
119120
${CMAKE_SOURCE_DIR}/src/core/processing
120121
${CMAKE_SOURCE_DIR}/src/core/processing/models

python/core/core_auto.sip

+4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
%Include symbology/qgsvectorfieldsymbollayer.sip
249249
%Include symbology/qgsgeometrygeneratorsymbollayer.sip
250250
%Include layertree/qgslayertreeutils.sip
251+
%Include locator/qgslocatorcontext.sip
251252
%Include geometry/qgsabstractgeometry.sip
252253
%Include geometry/qgsbox3d.sip
253254
%Include geometry/qgscircularstring.sip
@@ -369,6 +370,9 @@
369370
%Include composer/qgscomposition.sip
370371
%Include composer/qgsgroupungroupitemscommand.sip
371372
%Include composer/qgslayoutmanager.sip
373+
%Include locator/qgslocator.sip
374+
%Include locator/qgslocatorfilter.sip
375+
%Include locator/qgslocatormodel.sip
372376
%Include processing/qgsprocessingalgrunnertask.sip
373377
%Include processing/qgsprocessingfeedback.sip
374378
%Include processing/qgsprocessingprovider.sip

python/core/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/core/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/core/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/core/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/core/locator/qgslocatorcontext.h *
51+
* *
52+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
53+
************************************************************************/

0 commit comments

Comments
 (0)