1/****************************************************************************
2**
3** Copyright (C) 2016 Aaron McCarthy <mccarthy.aaron@gmail.com>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtLocation module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qgeotiledmaposm.h"
41#include "qgeotiledmappingmanagerengineosm.h"
42#include "qgeotilefetcherosm.h"
43
44#include <QtLocation/private/qgeotilespec_p.h>
45
46QT_BEGIN_NAMESPACE
47
48QGeoTiledMapOsm::QGeoTiledMapOsm(QGeoTiledMappingManagerEngineOsm *engine, QObject *parent)
49: Map(engine, parent), m_mapId(-1), m_engine(engine)
50{
51 // Needed because evaluateCopyrights() is only triggered if visible tiles change in the map.
52 // It fails the first time it gets called if providers aren't resolved, and subsequent calls
53 // to it will be skipped until visible tiles change.
54 // This connection makes sure the copyrights are evaluated when copyright data are ready regardless
55 // of what tiles are visible.
56 connect(sender: qobject_cast<QGeoTileFetcherOsm *>(object: engine->tileFetcher()), signal: &QGeoTileFetcherOsm::providerDataUpdated,
57 receiver: this, slot: &QGeoTiledMapOsm::onProviderDataUpdated);
58}
59
60QGeoTiledMapOsm::~QGeoTiledMapOsm()
61{
62}
63
64void QGeoTiledMapOsm::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
65{
66 if (visibleTiles.isEmpty())
67 return;
68
69 QGeoTileSpec tile = *visibleTiles.constBegin();
70 if (tile.mapId() == m_mapId)
71 return;
72
73 int providerId = tile.mapId() - 1;
74 if (providerId < 0 || providerId >= m_engine->providers().size())
75 return;
76
77 m_mapId = tile.mapId();
78 if (!m_engine->providers().at(i: providerId)->isValid())
79 return;
80
81 onProviderDataUpdated(provider: m_engine->providers().at(i: providerId));
82}
83
84void QGeoTiledMapOsm::onProviderDataUpdated(const QGeoTileProviderOsm *provider)
85{
86 if (!provider->isResolved() || provider->mapType().mapId() != m_mapId)
87 return;
88 QString copyRights;
89 const QString mapCopy = provider->mapCopyRight();
90 const QString dataCopy = provider->dataCopyRight();
91 const QString styleCopy = provider->styleCopyRight();
92 if (!mapCopy.isEmpty()) {
93 copyRights += QStringLiteral("Map &copy; ");
94 copyRights += mapCopy;
95 }
96 if (!dataCopy.isEmpty()) {
97 if (!copyRights.isEmpty())
98 copyRights += QStringLiteral(" | ");
99 copyRights += QStringLiteral("Data &copy; ");
100 copyRights += dataCopy;
101 }
102 if (!styleCopy.isEmpty()) {
103 if (!copyRights.isEmpty())
104 copyRights += QStringLiteral(" | ");
105 copyRights += QStringLiteral("Style &copy; ");
106 copyRights += styleCopy;
107 }
108
109 if (copyRights.isEmpty() && provider->mapType().style() == QGeoMapType::CustomMap)
110 copyRights = m_engine->customCopyright();
111
112 // Update CameraCapabilities
113 setCameraCapabilities(provider->cameraCapabilities());
114
115 emit copyrightsChanged(copyrightsHtml: copyRights);
116}
117
118QT_END_NAMESPACE
119

source code of qtlocation/src/plugins/geoservices/osm/qgeotiledmaposm.cpp