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