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
qgeotiledmaposm.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Aaron McCarthy <mccarthy.aaron@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qgeotiledmaposm.h"
7
8#include <QtLocation/private/qgeotilespec_p.h>
9
11
13: Map(engine, parent), m_mapId(-1), m_engine(engine)
14{
15 // Needed because evaluateCopyrights() is only triggered if visible tiles change in the map.
16 // It fails the first time it gets called if providers aren't resolved, and subsequent calls
17 // to it will be skipped until visible tiles change.
18 // This connection makes sure the copyrights are evaluated when copyright data are ready regardless
19 // of what tiles are visible.
20 connect(qobject_cast<QGeoTileFetcherOsm *>(engine->tileFetcher()), &QGeoTileFetcherOsm::providerDataUpdated,
22}
23
27
28void QGeoTiledMapOsm::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
29{
30 if (visibleTiles.isEmpty())
31 return;
32
33 QGeoTileSpec tile = *visibleTiles.constBegin();
34 if (tile.mapId() == m_mapId)
35 return;
36
37 int providerId = tile.mapId() - 1;
38 if (providerId < 0 || providerId >= m_engine->providers().size())
39 return;
40
41 m_mapId = tile.mapId();
42 if (!m_engine->providers().at(providerId)->isValid())
43 return;
44
45 onProviderDataUpdated(m_engine->providers().at(providerId));
46}
47
49{
50 if (!provider->isResolved() || provider->mapType().mapId() != m_mapId)
51 return;
52 QString copyRights;
53 const QString mapCopy = provider->mapCopyRight();
54 const QString dataCopy = provider->dataCopyRight();
55 const QString styleCopy = provider->styleCopyRight();
56 if (!mapCopy.isEmpty()) {
57 copyRights += QStringLiteral("Map &copy; ");
58 copyRights += mapCopy;
59 }
60 if (!dataCopy.isEmpty()) {
61 if (!copyRights.isEmpty())
62 copyRights += QStringLiteral(" | ");
63 copyRights += QStringLiteral("Data &copy; ");
64 copyRights += dataCopy;
65 }
66 if (!styleCopy.isEmpty()) {
67 if (!copyRights.isEmpty())
68 copyRights += QStringLiteral(" | ");
69 copyRights += QStringLiteral("Style &copy; ");
70 copyRights += styleCopy;
71 }
72
73 if (copyRights.isEmpty() && provider->mapType().style() == QGeoMapType::CustomMap)
74 copyRights = m_engine->customCopyright();
75
76 // Update CameraCapabilities
78
79 emit copyrightsChanged(copyRights);
80}
81
QML_STRUCTURED_VALUEMapStyle style
int mapId() const
void copyrightsChanged(const QString &copyrightsHtml)
void setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities)
Definition qgeomap.cpp:62
void providerDataUpdated(const QGeoTileProviderOsm *provider)
QString dataCopyRight() const
const QGeoMapType & mapType() const
QGeoCameraCapabilities cameraCapabilities() const
QString styleCopyRight() const
void onProviderDataUpdated(const QGeoTileProviderOsm *provider)
void evaluateCopyrights(const QSet< QGeoTileSpec > &visibleTiles) override
QGeoTiledMapOsm(QGeoTiledMappingManagerEngineOsm *engine, QObject *parent=nullptr)
const QList< QGeoTileProviderOsm * > & providers()
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
#define QStringLiteral(str)
#define emit
QJSEngine engine
[0]