Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplacemanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
8
9#include <QtCore/QDebug>
10#include <QtCore/QLocale>
11
12
13#include <QtLocation/QPlace>
14#include <QtLocation/QPlaceCategory>
15#include <QtLocation/QPlaceContentReply>
16#include <QtLocation/QPlaceContentRequest>
17#include <QtLocation/QPlaceDetailsReply>
18#include <QtLocation/QPlaceIcon>
19#include <QtLocation/QPlaceIdReply>
20#include <QtLocation/QPlaceMatchReply>
21#include <QtLocation/QPlaceMatchRequest>
22#include <QtLocation/QPlaceReply>
23#include <QtLocation/QPlaceSearchSuggestionReply>
24#include <QtLocation/QPlaceSearchRequest>
25#include <QtLocation/QPlaceSearchResult>
26
28
29/*!
30 \class QPlaceManager
31 \inmodule QtLocation
32 \ingroup QtLocation-places
33 \ingroup QtLocation-places-manager
34 \since 5.6
35
36 \brief The QPlaceManager class provides the interface which allows clients to access
37 places stored in a particular backend.
38
39 The following table gives an overview of the functionality provided by the QPlaceManager
40 \table
41 \header
42 \li Functionality
43 \li Description
44 \row
45 \li Searching for places
46 \li Using set of parameters such as a search term and search area, relevant places
47 can be returned to the user.
48 \row
49 \li Categories
50 \li Places can be classified as belonging to different categories. The
51 manager supports access to these categories.
52 \row
53 \li Search term suggestions
54 \li Given a partially complete search term, a list of potential
55 search terms can be given.
56 \row
57 \li Recommendations
58 \li Given an existing place, a set of similar recommended places can
59 be suggested to the user.
60 \row
61 \li Rich Content
62 \li Rich content such as images, reviews etc can be retrieved in a paged
63 fashion.
64 \row
65 \li Place or Category management
66 \li Places and categories may be saved and removed. It is possible
67 for notifications to be given when this happens.
68 \row
69 \li Localization
70 \li Different locales may be specified to return place
71 data in different languages.
72 \endtable
73
74 \section1 Obtaining a QPlaceManager Instance
75 Creation of a QPlaceManager is facilitated by the QGeoServiceProvider.
76 See \l {Initializing a manager} for an example on how to create a manager.
77
78
79 \section1 Asynchronous Interface
80 The QPlaceManager class provides an abstraction of the datastore which contains place information.
81 The functions provided by the QPlaceManager and primarily asynchronous and follow
82 a request-reply model. Typically a request is given to the manager, consisting
83 of a various set of parameters and a reply object is created. The reply object
84 has a signal to notify when the request is done, and once completed, the reply
85 contains the results of the request, along with any errors that occurred, if any.
86
87 An asynchronous request is generally handled as follows:
88 \snippet places/requesthandler.h Simple search
89 \dots
90 \dots
91 \snippet places/requesthandler.h Simple search handler
92
93 See \l {Common Operations} for a list of examples demonstrating how the QPlaceManger
94 is used.
95
96 \section1 Category Initialization
97 Sometime during startup of an application, the initializeCategories() function should
98 be called to setup the categories. Initializing the categories enables the usage of the
99 following functions:
100
101 \list
102 \li QPlaceManager::childCategories()
103 \li QPlaceManager::category()
104 \li QPlaceManager::parentCategoryId()
105 \li QPlaceManager::childCategoryIds();
106 \endlist
107
108 If the categories need to be refreshed or reloaded, the initializeCategories() function
109 may be called again.
110
111*/
112
113/*!
114 Constructs a new manager with the specified \a parent and with the
115 implementation provided by \a engine.
116
117 This constructor is used internally by QGeoServiceProviderFactory. Regular
118 users should acquire instances of QGeoRoutingManager with
119 QGeoServiceProvider::routingManager();
120*/
121QPlaceManager::QPlaceManager(QPlaceManagerEngine *engine, QObject *parent)
122 : QObject(parent), d(engine)
123{
124 if (d) {
125 d->setParent(this);
126 d->d_ptr->manager = this;
127
128 qRegisterMetaType<QPlaceCategory>();
129
130 connect(d, &QPlaceManagerEngine::finished,
131 this, &QPlaceManager::finished);
132 connect(d, &QPlaceManagerEngine::errorOccurred,
133 this, &QPlaceManager::errorOccurred);
134
135 connect(d, &QPlaceManagerEngine::placeAdded,
136 this, &QPlaceManager::placeAdded, Qt::QueuedConnection);
137 connect(d, &QPlaceManagerEngine::placeUpdated,
138 this, &QPlaceManager::placeUpdated, Qt::QueuedConnection);
139 connect(d, &QPlaceManagerEngine::placeRemoved,
140 this, &QPlaceManager::placeRemoved, Qt::QueuedConnection);
141
142 connect(d, &QPlaceManagerEngine::categoryAdded,
143 this, &QPlaceManager::categoryAdded);
144 connect(d, &QPlaceManagerEngine::categoryUpdated,
145 this, &QPlaceManager::categoryUpdated);
146 connect(d, &QPlaceManagerEngine::categoryRemoved,
147 this, &QPlaceManager::categoryRemoved);
148 connect(d, &QPlaceManagerEngine::dataChanged,
149 this, &QPlaceManager::dataChanged, Qt::QueuedConnection);
150 } else {
151 qFatal("The place manager engine that was set for this place manager was NULL.");
152 }
153}
154
155/*!
156 Destroys the manager. This destructor is used internally by QGeoServiceProvider
157 and should never need to be called in application code.
158*/
159QPlaceManager::~QPlaceManager()
160{
161 delete d;
162}
163
164/*!
165 Returns the name of the manager
166*/
167QString QPlaceManager::managerName() const
168{
169 return d->managerName();
170}
171
172/*!
173 Returns the manager version.
174*/
175int QPlaceManager::managerVersion() const
176{
177 return d->managerVersion();
178}
179
180/*!
181 Retrieves a details of place corresponding to the given \a placeId.
182
183 See \l {QML Places API#Fetching Place Details}{Fetching Place Details} for an example of usage.
184*/
185QPlaceDetailsReply *QPlaceManager::getPlaceDetails(const QString &placeId) const
186{
187 return d->getPlaceDetails(placeId);
188}
189
190/*!
191 Retrieves content for a place according to the parameters specified in \a request.
192
193 See \l {Fetching Rich Content} for an example of usage.
194*/
195QPlaceContentReply *QPlaceManager::getPlaceContent(const QPlaceContentRequest &request) const
196{
197 return d->getPlaceContent(request);
198}
199
200/*!
201 Searches for places according to the parameters specified in \a request.
202
203 See \l {Discovery/Search} for an example of usage.
204*/
205QPlaceSearchReply *QPlaceManager::search(const QPlaceSearchRequest &request) const
206{
207 return d->search(request);
208}
209
210/*!
211 Requests a set of search term suggestions according to the parameters specified in \a request.
212 The \a request can hold the incomplete search term, along with other data such
213 as a search area to narrow down relevant results.
214
215 See \l {Search Suggestions} for an example of usage.
216*/
217QPlaceSearchSuggestionReply *QPlaceManager::searchSuggestions(const QPlaceSearchRequest &request) const
218{
219 return d->searchSuggestions(request);
220}
221
222/*!
223 Saves a specified \a place.
224
225 See \l {Saving a place cpp} for an example of usage.
226*/
227QPlaceIdReply *QPlaceManager::savePlace(const QPlace &place)
228{
229 return d->savePlace(place);
230}
231
232/*!
233 Removes the place corresponding to \a placeId from the manager.
234
235 See \l {Removing a place cpp} for an example of usage.
236*/
237QPlaceIdReply *QPlaceManager::removePlace(const QString &placeId)
238{
239 return d->removePlace(placeId);
240}
241
242/*!
243 Saves a \a category that is a child of the category specified by \a parentId.
244 An empty \a parentId means \a category is saved as a top level category.
245
246 See \l {Saving a category} for an example of usage.
247*/
248QPlaceIdReply *QPlaceManager::saveCategory(const QPlaceCategory &category, const QString &parentId)
249{
250 return d->saveCategory(category, parentId);
251}
252
253/*!
254 Removes the category corresponding to \a categoryId from the manager.
255
256 See \l {Removing a category} for an example of usage.
257*/
258QPlaceIdReply *QPlaceManager::removeCategory(const QString &categoryId)
259{
260 return d->removeCategory(categoryId);
261}
262
263/*!
264 Initializes the categories of the manager.
265
266 See \l {Using Categories} for an example of usage.
267*/
268QPlaceReply *QPlaceManager::initializeCategories()
269{
270 return d->initializeCategories();
271}
272
273/*!
274 Returns the parent category identifier of the category corresponding to \a categoryId.
275*/
276QString QPlaceManager::parentCategoryId(const QString &categoryId) const
277{
278 return d->parentCategoryId(categoryId);
279}
280
281/*!
282 Returns the child category identifiers of the category corresponding to \a parentId.
283 If \a parentId is empty then all top level category identifiers are returned.
284*/
285QStringList QPlaceManager::childCategoryIds(const QString &parentId) const
286{
287 return d->childCategoryIds(parentId);
288}
289
290/*!
291 Returns the category corresponding to the given \a categoryId.
292*/
293QPlaceCategory QPlaceManager::category(const QString &categoryId) const
294{
295 return d->category(categoryId);
296}
297
298/*!
299 Returns a list of categories that are children of the category corresponding to \a parentId.
300 If \a parentId is empty, all the top level categories are returned.
301*/
302QList<QPlaceCategory> QPlaceManager::childCategories(const QString &parentId) const
303{
304 return d->childCategories(parentId);
305}
306
307/*!
308 Returns a list of preferred locales. The locales are used as a hint to the manager for what language
309 place and category details should be returned in.
310
311 If the first specified locale cannot be accommodated, the manager falls back to the next and so forth.
312 Some manager backends may not support a set of locales which are rigidly defined. An arbitrary
313 example is that some places in France could have French and English localizations, while
314 certain areas in America may only have the English localization available. In this example,
315 the set of supported locales is context dependent on the search location.
316
317 If the manager cannot accommodate any of the preferred locales, the manager falls
318 back to using a supported language that is backend specific.
319
320 Support for locales may vary from provider to provider. For those that do support it,
321 by default, the global default locale is set as the manager's only locale.
322
323 For managers that do not support locales, the locale list is always empty.
324*/
325QList<QLocale> QPlaceManager::locales() const
326{
327 return d->locales();
328}
329
330/*!
331 Convenience function which sets the manager's list of preferred locales
332 to a single \a locale.
333*/
334void QPlaceManager::setLocale(const QLocale &locale)
335{
336 QList<QLocale> locales;
337 locales << locale;
338 d->setLocales(locales);
339}
340
341/*!
342 Set the list of preferred \a locales.
343*/
344void QPlaceManager::setLocales(const QList<QLocale> &locales)
345{
346 d->setLocales(locales);
347}
348
349/*!
350 Returns a pruned or modified version of the \a original place
351 which is suitable to be saved into this manager.
352
353 Only place details that are supported by this manager is
354 present in the modified version. Manager specific data such
355 as the place id, is not copied over from the \a original.
356*/
357QPlace QPlaceManager::compatiblePlace(const QPlace &original) const
358{
359 return d->compatiblePlace(original);
360}
361
362/*!
363 Returns a reply which contains a list of places which correspond/match those
364 specified in the \a request. The places specified in the request come from a
365 different manager.
366*/
367QPlaceMatchReply *QPlaceManager::matchingPlaces(const QPlaceMatchRequest &request) const
368{
369 return d->matchingPlaces(request);
370}
371
372/*!
373 \fn void QPlaceManager::finished(QPlaceReply *reply)
374
375 This signal is emitted when \a reply has finished processing.
376
377 If reply->error() equals QPlaceReply::NoError then the processing
378 finished successfully.
379
380 This signal and QPlaceReply::finished() will be emitted at the same time.
381
382 \note Do not delete the \a reply object in the slot connected to this signal.
383 Use deleteLater() instead.
384*/
385
386/*!
387 \fn void QPlaceManager::errorOccurred(QPlaceReply *reply, QPlaceReply::Error error, const QString &errorString)
388
389 This signal is emitted when an error has been detected in the processing of
390 \a reply. The QPlaceManager::finished() signal will probably follow.
391
392 The error will be described by the error code \a error. If \a errorString is
393 not empty it will contain a textual description of the error meant for developers
394 and not end users.
395
396 This signal and QPlaceReply::errorOccurred() will be emitted at the same time.
397
398 \note Do not delete the \a reply object in the slot connected to this signal.
399 Use deleteLater() instead.
400*/
401
402/*!
403 \fn void QPlaceManager::placeAdded(const QString &placeId)
404
405 This signal is emitted if a place has been added to the manager engine's datastore.
406 The particular added place is specified by \a placeId.
407
408 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
409 \sa dataChanged()
410*/
411
412/*!
413 \fn void QPlaceManager::placeUpdated(const QString &placeId)
414
415 This signal is emitted if a place has been modified in the manager's datastore.
416 The particular modified place is specified by \a placeId.
417
418 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
419 \sa dataChanged()
420*/
421
422/*!
423 \fn void QPlaceManager::placeRemoved(const QString &placeId)
424
425 This signal is emitted if a place has been removed from the manager's datastore.
426 The particular place that has been removed is specified by \a placeId.
427
428 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
429 \sa dataChanged()
430*/
431
432/*!
433 \fn void QPlaceManager::categoryAdded(const QPlaceCategory &category, const QString &parentId)
434
435 This signal is emitted if a \a category has been added to the manager's datastore.
436 The parent of the \a category is specified by \a parentId.
437
438 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
439 \sa dataChanged()
440*/
441
442/*!
443 \fn void QPlaceManager::categoryUpdated(const QPlaceCategory &category, const QString &parentId)
444
445 This signal is emitted if a \a category has been modified in the manager's datastore.
446 The parent of the modified category is specified by \a parentId.
447
448 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
449 \sa dataChanged()
450*/
451
452/*!
453 \fn void QPlaceManager::categoryRemoved(const QString &categoryId, const QString &parentId)
454
455 This signal is emitted when the category corresponding to \a categoryId has
456 been removed from the manager's datastore. The parent of the removed category
457 is specified by \a parentId.
458
459 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
460 \sa dataChanged()
461*/
462
463/*!
464 \fn QPlaceManager::dataChanged()
465 This signal is emitted by the manager if there are large scale changes to its
466 underlying datastore and the manager considers these changes radical enough
467 to require clients to reload all data.
468
469 If the signal is emitted, no other signals will be emitted for the associated changes.
470
471 This signal is only emitted by managers that support the QPlaceManager::NotificationsFeature.
472*/
473
474QT_END_NAMESPACE