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 "qgeotilespec_p.h"
38#include "qgeotilespec_p_p.h"
39
40#include <QtCore/QDebug>
41
42QT_BEGIN_NAMESPACE
43
44QGeoTileSpec::QGeoTileSpec()
45 : d(QSharedDataPointer<QGeoTileSpecPrivate>(new QGeoTileSpecPrivate())) {}
46
47QGeoTileSpec::QGeoTileSpec(const QString &plugin, int mapId, int zoom, int x, int y, int version)
48 : d(QSharedDataPointer<QGeoTileSpecPrivate>(new QGeoTileSpecPrivate(plugin, mapId, zoom, x, y, version))) {}
49
50QGeoTileSpec::QGeoTileSpec(const QGeoTileSpec &other)
51 : d(other.d) {}
52
53QGeoTileSpec::~QGeoTileSpec() {
54}
55
56QGeoTileSpec &QGeoTileSpec::operator = (const QGeoTileSpec &other)
57{
58 if (this == &other)
59 return *this;
60
61 d = other.d;
62 return *this;
63}
64
65QString QGeoTileSpec::plugin() const
66{
67 return d->plugin_;
68}
69
70void QGeoTileSpec::setZoom(int zoom)
71{
72 d->zoom_ = zoom;
73}
74
75int QGeoTileSpec::zoom() const
76{
77 return d->zoom_;
78}
79
80void QGeoTileSpec::setX(int x)
81{
82 d->x_ = x;
83}
84
85int QGeoTileSpec::x() const
86{
87 return d->x_;
88}
89
90void QGeoTileSpec::setY(int y)
91{
92 d->y_ = y;
93}
94
95int QGeoTileSpec::y() const
96{
97 return d->y_;
98}
99
100void QGeoTileSpec::setMapId(int mapId)
101{
102 d->mapId_ = mapId;
103}
104
105int QGeoTileSpec::mapId() const
106{
107 return d->mapId_;
108}
109
110void QGeoTileSpec::setVersion(int version)
111{
112 d->version_ = version;
113}
114
115int QGeoTileSpec::version() const
116{
117 return d->version_;
118}
119
120bool QGeoTileSpec::operator == (const QGeoTileSpec &rhs) const
121{
122 return (*(d.constData()) == *(rhs.d.constData()));
123}
124
125bool QGeoTileSpec::operator < (const QGeoTileSpec &rhs) const
126{
127 return (*(d.constData()) < *(rhs.d.constData()));
128}
129
130unsigned int qHash(const QGeoTileSpec &spec)
131{
132 unsigned int result = (qHash(key: spec.plugin()) * 13) % 31;
133 result += ((spec.mapId() * 17) % 31) << 5;
134 result += ((spec.zoom() * 19) % 31) << 10;
135 result += ((spec.x() * 23) % 31) << 15;
136 result += ((spec.y() * 29) % 31) << 20;
137 result += (spec.version() % 3) << 25;
138 return result;
139}
140
141QDebug operator<< (QDebug dbg, const QGeoTileSpec &spec)
142{
143 dbg << spec.plugin() << spec.mapId() << spec.zoom() << spec.x() << spec.y() << spec.version();
144 return dbg;
145}
146
147QGeoTileSpecPrivate::QGeoTileSpecPrivate()
148 : mapId_(0),
149 zoom_(-1),
150 x_(-1),
151 y_(-1),
152 version_(-1) {}
153
154QGeoTileSpecPrivate::QGeoTileSpecPrivate(const QGeoTileSpecPrivate &other)
155 : QSharedData(other),
156 plugin_(other.plugin_),
157 mapId_(other.mapId_),
158 zoom_(other.zoom_),
159 x_(other.x_),
160 y_(other.y_),
161 version_(other.version_) {}
162
163QGeoTileSpecPrivate::QGeoTileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y, int version)
164 : plugin_(plugin),
165 mapId_(mapId),
166 zoom_(zoom),
167 x_(x),
168 y_(y),
169 version_(version) {}
170
171QGeoTileSpecPrivate::~QGeoTileSpecPrivate() {}
172
173QGeoTileSpecPrivate &QGeoTileSpecPrivate::operator = (const QGeoTileSpecPrivate &other)
174{
175 if (this == &other)
176 return *this;
177
178 plugin_ = other.plugin_;
179 mapId_ = other.mapId_;
180 zoom_ = other.zoom_;
181 x_ = other.x_;
182 y_ = other.y_;
183 version_ = other.version_;
184
185 return *this;
186}
187
188bool QGeoTileSpecPrivate::operator == (const QGeoTileSpecPrivate &rhs) const
189{
190 if (plugin_ != rhs.plugin_)
191 return false;
192
193 if (mapId_ != rhs.mapId_)
194 return false;
195
196 if (zoom_ != rhs.zoom_)
197 return false;
198
199 if (x_ != rhs.x_)
200 return false;
201
202 if (y_ != rhs.y_)
203 return false;
204
205 if (version_ != rhs.version_)
206 return false;
207
208 return true;
209}
210
211bool QGeoTileSpecPrivate::operator < (const QGeoTileSpecPrivate &rhs) const
212{
213 if (plugin_ < rhs.plugin_)
214 return true;
215 if (plugin_ > rhs.plugin_)
216 return false;
217
218 if (mapId_ < rhs.mapId_)
219 return true;
220 if (mapId_ > rhs.mapId_)
221 return false;
222
223 if (zoom_ < rhs.zoom_)
224 return true;
225 if (zoom_ > rhs.zoom_)
226 return false;
227
228 if (x_ < rhs.x_)
229 return true;
230 if (x_ > rhs.x_)
231 return false;
232
233 if (y_ < rhs.y_)
234 return true;
235 if (y_ > rhs.y_)
236 return false;
237
238 return (version_ < rhs.version_);
239}
240
241QT_END_NAMESPACE
242

source code of qtlocation/src/location/maps/qgeotilespec.cpp