QPlaceManager Class
The QPlaceManager class provides the interface which allows clients to access places stored in a particular backend. More...
| Header: | #include <QPlaceManager> |
| qmake: | QT += location |
| Since: | Qt 5.6 |
| Inherits: | QObject |
This class was introduced in Qt 5.6.
Detailed Description
The following table gives an overview of the functionality provided by the QPlaceManager
| Functionality | Description |
|---|---|
| Searching for places | Using set of parameters such as a search term and search area, relevant places can be returned to the user. |
| Categories | Places can be classified as belonging to different categories. The manager supports access to these categories. |
| Search term suggestions | Given a partially complete search term, a list of potential search terms can be given. |
| Recommendations | Given an existing place, a set of similar recommended places can be suggested to the user. |
| Rich Content | Rich content such as images, reviews etc can be retrieved in a paged fashion. |
| Place or Category management | Places and categories may be saved and removed. It is possible for notifications to be given when this happens. |
| Localization | Different locales may be specified to return place data in different languages. |
Obtaining a QPlaceManager Instance
Creation of a QPlaceManager is facilitated by the QGeoServiceProvider. See Initializing a manager for an example on how to create a manager.
Asynchronous Interface
The QPlaceManager class provides an abstraction of the datastore which contains place information. The functions provided by the QPlaceManager and primarily asynchronous and follow a request-reply model. Typically a request is given to the manager, consisting of a various set of parameters and a reply object is created. The reply object has a signal to notify when the request is done, and once completed, the reply contains the results of the request, along with any errors that occurred, if any.
An asynchronous request is generally handled as follows:
//1) Make an appropriate request QPlaceSearchRequest searchRequest; searchRequest.setSearchTerm("ice cream"); searchRequest.setSearchArea(QGeoCircle(QGeoCoordinate(12.34, 56.78))); //2) Use the manager to initiate a request and retrieve a reply object QPlaceSearchReply * searchReply = manager->search(searchRequest); //3) Connect the reply object to a slot which is invoked upon operation completion connect(searchReply, SIGNAL(finished()), this, SLOT(processSearchReply())); ... ... //4) Have the slot appropriately process the results of the operation void processSearchReply() { if (searchReply->error() == QPlaceReply::NoError) { foreach (const QPlaceSearchResult &result, searchReply->results()) { if (result.type() == QPlaceSearchResult::PlaceResult) qDebug() << "Title:" << result.title(); } } //5) Discard the rely object when done. searchReply->deleteLater(); searchReply = 0; }
See Common Operations for a list of examples demonstrating how the QPlaceManger is used.
Category Initialization
Sometime during startup of an application, the initializeCategories() function should be called to setup the categories. Initializing the categories enables the usage of the following functions:
- QPlaceManager::childCategories()
- QPlaceManager::category()
- QPlaceManager::parentCategoryId()
- QPlaceManager::childCategoryIds();
If the categories need to be refreshed or reloaded, the initializeCategories() function may be called again.