1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtLocation module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL3$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or later as published by the Free
28 ** Software Foundation and appearing in the file LICENSE.GPL included in
29 ** the packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 2.0 requirements will be
31 ** met: http://www.gnu.org/licenses/gpl-2.0.html.
32 **
33 ** $QT_END_LICENSE$
34 **
35 ****************************************************************************/
36 
37 #include "qgeomappingmanagerengine_p.h"
38 #include "qgeomappingmanagerengine_p_p.h"
39 #include "qgeotiledmapreply_p.h"
40 #include "qgeotilespec_p.h"
41 
42 #include <QThread>
43 
44 QT_BEGIN_NAMESPACE
45 
46 /*!
47     \class QGeoMappingManagerEngine
48     \inmodule QtLocation
49     \ingroup QtLocation-impl
50     \since 5.6
51     \internal
52 
53     \brief Provides support functionality for map display with QGeoServiceProvider.
54 
55     The QGeoMappingManagerEngine class provides an interface and convenience
56     methods to implementors of QGeoServiceProvider plugins who want to
57     provide support for displaying and interacting with maps.
58 */
59 
60 /*!
61     Constructs a new engine with the specified \a parent.
62 */
QGeoMappingManagerEngine(QObject * parent)63 QGeoMappingManagerEngine::QGeoMappingManagerEngine(QObject *parent)
64     : QObject(parent),
65       d_ptr(new QGeoMappingManagerEnginePrivate()) {}
66 
67 /*!
68     Destroys this engine.
69 */
~QGeoMappingManagerEngine()70 QGeoMappingManagerEngine::~QGeoMappingManagerEngine()
71 {
72     Q_D(QGeoMappingManagerEngine);
73     delete d;
74 }
75 
76 /*!
77     Marks the engine as initialized. Subclasses of QGeoMappingManagerEngine are to
78     call this method after performing implementation-specific initializatioin within
79     the constructor.
80 */
engineInitialized()81 void QGeoMappingManagerEngine::engineInitialized()
82 {
83     Q_D(QGeoMappingManagerEngine);
84     d->initialized = true;
85     emit initialized();
86 }
87 
88 /*!
89     Sets the name which this engine implementation uses to distinguish itself
90     from the implementations provided by other plugins to \a managerName.
91 
92     The combination of managerName() and managerVersion() should be unique
93     amongst plugin implementations.
94 */
setManagerName(const QString & managerName)95 void QGeoMappingManagerEngine::setManagerName(const QString &managerName)
96 {
97     d_ptr->managerName = managerName;
98 }
99 
100 /*!
101     Returns the name which this engine implementation uses to distinguish
102     itself from the implementations provided by other plugins.
103 
104     The combination of managerName() and managerVersion() should be unique
105     amongst plugin implementations.
106 */
managerName() const107 QString QGeoMappingManagerEngine::managerName() const
108 {
109     return d_ptr->managerName;
110 }
111 
112 /*!
113     Sets the version of this engine implementation to \a managerVersion.
114 
115     The combination of managerName() and managerVersion() should be unique
116     amongst plugin implementations.
117 */
setManagerVersion(int managerVersion)118 void QGeoMappingManagerEngine::setManagerVersion(int managerVersion)
119 {
120     d_ptr->managerVersion = managerVersion;
121 }
122 
123 /*!
124     Returns the version of this engine implementation.
125 
126     The combination of managerName() and managerVersion() should be unique
127     amongst plugin implementations.
128 */
managerVersion() const129 int QGeoMappingManagerEngine::managerVersion() const
130 {
131     return d_ptr->managerVersion;
132 }
133 
supportedMapTypes() const134 QList<QGeoMapType> QGeoMappingManagerEngine::supportedMapTypes() const
135 {
136     Q_D(const QGeoMappingManagerEngine);
137     return d->supportedMapTypes;
138 }
139 
140 /*!
141     Sets the list of map types supported by this engine to \a mapTypes.
142 
143     Subclasses of QGeoMappingManagerEngine should use this function to ensure
144     that supportedMapTypes() provides accurate information.
145 */
setSupportedMapTypes(const QList<QGeoMapType> & supportedMapTypes)146 void QGeoMappingManagerEngine::setSupportedMapTypes(const QList<QGeoMapType> &supportedMapTypes)
147 {
148     Q_D(QGeoMappingManagerEngine);
149     d->supportedMapTypes = supportedMapTypes;
150     emit supportedMapTypesChanged();
151 }
152 
cameraCapabilities(int mapId) const153 QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities(int mapId) const
154 {
155     Q_UNUSED(mapId);
156     Q_D(const QGeoMappingManagerEngine);
157 
158     if (mapId == 0)
159         return d->capabilities_;
160     int idx = mapId - 1;
161     if (idx >= supportedMapTypes().size())
162         return d->capabilities_;
163     return supportedMapTypes().at(idx).cameraCapabilities();
164 }
165 
setCameraCapabilities(const QGeoCameraCapabilities & capabilities)166 void QGeoMappingManagerEngine::setCameraCapabilities(const QGeoCameraCapabilities &capabilities)
167 {
168     Q_D(QGeoMappingManagerEngine);
169     d->capabilities_ = capabilities;
170 }
171 
172 /*!
173     Return whether the engine has been initialized and is ready to be used.
174 */
175 
isInitialized() const176 bool QGeoMappingManagerEngine::isInitialized() const
177 {
178     Q_D(const QGeoMappingManagerEngine);
179     return d->initialized;
180 }
181 
182 /*!
183     Sets the locale to be used by the this manager to \a locale.
184 
185     If this mapping manager supports returning map labels
186     in different languages, they will be returned in the language of \a locale.
187 
188     The locale used defaults to the system locale if this is not set.
189 */
setLocale(const QLocale & locale)190 void QGeoMappingManagerEngine::setLocale(const QLocale &locale)
191 {
192     d_ptr->locale = locale;
193 }
194 
195 /*!
196     Returns the locale used to hint to this mapping manager about what
197     language to use for map labels.
198 */
locale() const199 QLocale QGeoMappingManagerEngine::locale() const
200 {
201     return d_ptr->locale;
202 }
203 
204 /*******************************************************************************
205 *******************************************************************************/
206 
QGeoMappingManagerEnginePrivate()207 QGeoMappingManagerEnginePrivate::QGeoMappingManagerEnginePrivate()
208     : managerVersion(-1),
209       initialized(false) {}
210 
~QGeoMappingManagerEnginePrivate()211 QGeoMappingManagerEnginePrivate::~QGeoMappingManagerEnginePrivate() {}
212 
213 QT_END_NAMESPACE
214