Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
places-backend.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page location-places-backend.html
6\title Places Backend
7
8\brief The Places backend is responsible for managing a places datastore whether
9 it is located remotely or locally
10
11\section1 Overview
12
13The QPlaceManager interface, provided to clients to allow access to place information,
14depends directly on an implementation of QPlaceManagerEngine. The engine provides
15the backend function implementations which are called by the manager.
16
17A places backend implementer needs to derive from QPlaceManagerEngine and provide implementations
18for the virtual functions relevant for their backend. Most of these functions are asynchronous and
19so implementers will also need to derive the appropriate \l {Places Reply Classes}{reply classes}.
20The reply objects are responsible for managing an asynchronous request; they are used to notify
21when a request is complete and hold the results of that request. QPlaceManagerEngine provides a
22default implementation for all virtual functions. The default implementations for the asynchronous
23functions return a reply that will emit the errorOccurred() and finished() signals at the next iteration
24through the event loop.
25
26\section1 Implementing/Inheriting Reply Objects
27A reply object would be inherited as follows:
28\snippet places/requesthandler.h Implement reply pt1
29\dots
30\snippet places/requesthandler.h Implement reply pt2
31
32The implementation of a QPlaceManagerEngine must ensure that any signals emitted by the reply
33objects are delayed until the request functions have returned and the application code has a chance
34to connect those signals to slots. The typical approach is to use \l {QMetaObject::invokeMethod()}
35with a \l {Qt::QueuedConnection} to emit the signals.
36
37\snippet places/requesthandler.h Trigger done
38
39Note that the \c finished signals should always be emitted when a reply is complete, even if
40an error has been encountered, that is, if there is an error, both the \c error and \c finished signals
41should be emitted while if there is no error, only the \c finished signals are emitted.
42
43The protected functions of QPlaceSearchReply::setResults() and QPlaceSearchReply::setRequest()
44are made publicly accessible so the plugin can assign results and requests. Because
45these functions are not publicly exported, accessibility is not so much of an issue.
46An alternative would have been to declare a friend class in SearchReply.
47
48Typically the engine instance would be made the \c parent of the reply. If the developer
49fails to discard the replies when finished, the engine can clean those upon destruction.
50Commonly, the reply also has a pointer reference back to the engine, which may be used
51to emit the QPlaceManagerEngine::finished() and QPlaceManagerEngine::error() signals. This is
52just one of many ways the reply could be implemented.
53
54\section1 Icon URLs
55Icon URLs are provided through the QPlaceManagerEngine::constructIconUrl() function.
56The expected behaviour is that the engine will use the QPlaceIcon::parameters()
57in order to construct an appropriate URL. When a QPlace object is returned
58from the manager either from a search or a query to get place details,
59it is expected the engine will correctly populate the parameters as necessary.
60
61The backend is free to choose what the parameter key and values are, however
62if a backend only ever has one URL per icon it is recommended that the QPlaceIcon::SingleUrl
63be used as the key.
64
65\section1 Categories
66The categories of a manager engine are relatively static entities; for engines accessing
67remote place datastores it may be desirable to cache the category structure rather than
68querying a server every time QPlaceManagerEngine::initializeCategories() is called.
69Depending on how dynamic the categories are, always downloading the freshest
70set of categories may be more appropriate.
71
72\section1 Saving Places to the Manager
73A place generally cannot be saved directly between managers as is because it contains manager specific data such as icons
74and categories. In order to facilitate saving to one's own manager, engine implementers should implement
75the QPlaceManagerEngine::compatiblePlace() function. This function returns a copy of the input place
76with properties pruned or modified as necessary such that the copy can be saved into manager.
77
78Construction of a compatible place may involve ignoring certain properties from the
79original place, for example if contact details are not supported, these are left out of the
80compatible place. Other times it may involve modifying certain properties, for example
81modifying the icon parameters to facilitate copying or downloading of the original
82place's icon to a location that the backend can access.
83
84\section1 Cross-Referencing Places Between Managers
85Sometimes a situation may arise where we wish to cross-reference and match places between managers.
86Such a situation may arise where one manager provides read-only access to places (origin manager), while another second r/w
87manager (destination manager) is used to save selected favorites from the first. During a search of the origin manager, we may want to
88know which ones have been 'favorited' into the destination manager and perhaps display the customized favorite name
89rather than the original name.
90
91\section2 Alternative Identifier Cross-Referencing
92In order to accomplish cross-referencing, there needs to be a link between the original place and the favorited place
93and this is typically handled via an alternative identifier attribute. The favorited place contains an alternative identifier attribute which has the identifier of the original place.
94
95\include place-crossref.qdocinc
96
97There are 3 prerequisites for implementing cross-referencing by alternative identifier. The first is that the origin manager must provide the x_provider attribute
98with the value being the name of the manager's QGeoServiceProvider. The attribute label should be kept empty, indicating the attribute should not
99be displayed to users. \note It is generally expected that all managers should set the \c x_provider attribute.
100
101The second is that QPlaceManager::compatiblePlace() of the destination manager use the \c x_provider attribute of the initial place
102and set an alternative identifier attribute of the place to be saved. The key of the alternative identifier attribute is \c x_id_<provider name> and
103the text value is the identifier of the initial place. The \c x_provider attribute should not be passed to the compatible place. When
104it is saved, the x_provider of the saved place is considered to be the destination manager.
105
106The third is that QPlaceManager::matchingPlaces() of the destination manager accept the QPlaceMatchRequest::AlternativeId as a parameter key
107and the alternative identifier attribute key as the value, in this case \c x_id_<provider name> would be the expected value.
108This indicates that the identifiers of places in the QPlaceMatchRequest should be matched against the \c x_id_<provider name> alternative identifier attributes.
109
110Note that if the destination manager is to facilitate saving and cross-referencing from any arbitrary manager, it internally must
111accommodate saving of arbitrary key value pairs since we cannot know the provider names before hand, nor can we know what structure the
112ids will be.
113
114\section3 Other Methods of Linking
115If an origin manager does not supply a place id, it may be necessary to provide some other means of cross-referencing/matching.
116One approach might be to do so via the place coordinates, if the coordinate of a place in the origin manager is identical or close
117to a place in the destination manager, there is a high likelihood that they are the same place.
118In this case, the manager might implement QPlaceManager::matchingPlaces() to accept a QPlaceMatchRequest with a parameter key of 'proximity'
119and a parameter value of the distance two places must be in order to detect a match. for example if an origin place and destination place are within 50m
120of each other, they can be considered the same place.
121
122Generally however it is recommended that cross referencing be implemented via alternative identifiers as mentioned above.
123
124\section3 User Readable vs Non-User Readable Extended Attributes
125If an attribute is not intended to be readable by end users, the label field should be kept
126empty as an indicator of this fact.
127*/