Skip to content

Commit 659d3fa

Browse files
committed
QtLocationPlugin: Qt Integration Improvements & Fixes
1 parent 1dee7b6 commit 659d3fa

17 files changed

+1119
-326
lines changed

src/QmlControls/OfflineMapEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ FlightMap {
334334
text: qsTr("Delete")
335335
width: ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
336336
onClicked: deleteConfirmationDialogComponent.createObject(mainWindow).open()
337-
enabled: tileSet ? (tileSet.savedTileSize > 0) : false
337+
enabled: tileSet ? (!tileSet.deleting && (_defaultSet ? tileSet.savedTileSize > 0 : true)) : false
338338
}
339339
QGCButton {
340340
text: qsTr("Ok")

src/QtLocationPlugin/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ qt_add_plugin(QGCLocation
5151
QGeoTileFetcherQGC.h
5252
)
5353

54-
# ----------------------------------------------------------------------------
55-
# Platform-Specific Configuration
56-
# ----------------------------------------------------------------------------
57-
# Google Maps not available on iOS
58-
if(IOS)
59-
target_compile_definitions(QGCLocation PRIVATE QGC_NO_GOOGLE_MAPS)
60-
endif()
61-
6254
# ----------------------------------------------------------------------------
6355
# Dependencies
6456
# ----------------------------------------------------------------------------

src/QtLocationPlugin/QGCCachedTileSet.cpp

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ void QGCCachedTileSet::_doneWithDownload()
126126
setTotalTileSize(_savedTileSize);
127127

128128
quint32 avg = 0;
129-
if (_savedTileSize != 0) {
129+
if (_savedTileCount != 0) {
130130
avg = _savedTileSize / _savedTileCount;
131131
} else {
132-
qCWarning(QGCCachedTileSetLog) << "_savedTileSize=0";
132+
qCWarning(QGCCachedTileSetLog) << "_savedTileCount=0";
133133
}
134134

135135
setUniqueTileSize(_uniqueTileCount * avg);
@@ -151,11 +151,22 @@ void QGCCachedTileSet::_prepareDownload()
151151
return;
152152
}
153153

154-
for (qsizetype i = _replies.count(); i < QGeoTileFetcherQGC::concurrentDownloads(_type); i++) {
154+
const qsizetype maxConcurrent = QGeoTileFetcherQGC::concurrentDownloads(_type);
155+
156+
for (qsizetype i = 0; i < maxConcurrent; i++) {
155157
if (_tilesToDownload.isEmpty()) {
156158
break;
157159
}
158160

161+
// Check if we've reached the concurrent limit
162+
{
163+
QMutexLocker lock(&_repliesMutex);
164+
if (_replies.count() >= maxConcurrent) {
165+
break;
166+
}
167+
}
168+
169+
// Dequeue and prepare tile request without holding the mutex
159170
QGCTile* const tile = _tilesToDownload.dequeue();
160171
const int mapId = UrlFactory::getQtMapIdFromProviderType(tile->type);
161172
QNetworkRequest request = QGeoTileFetcherQGC::getNetworkRequest(mapId, tile->x, tile->y, tile->z);
@@ -167,10 +178,15 @@ void QGCCachedTileSet::_prepareDownload()
167178
QGCFileDownload::setIgnoreSSLErrorsIfNeeded(*reply);
168179
(void) connect(reply, &QNetworkReply::finished, this, &QGCCachedTileSet::_networkReplyFinished);
169180
(void) connect(reply, &QNetworkReply::errorOccurred, this, &QGCCachedTileSet::_networkReplyError);
170-
(void) _replies.insert(tile->hash, reply);
181+
182+
// Insert into replies map
183+
{
184+
QMutexLocker lock(&_repliesMutex);
185+
(void) _replies.insert(tile->hash, reply);
186+
}
171187

172188
delete tile;
173-
if (!_batchRequested && !_noMoreTiles && (_tilesToDownload.count() < (QGeoTileFetcherQGC::concurrentDownloads(_type) * 10))) {
189+
if (!_batchRequested && !_noMoreTiles && (_tilesToDownload.count() < (maxConcurrent * 10))) {
174190
createDownloadTask();
175191
}
176192
}
@@ -200,10 +216,13 @@ void QGCCachedTileSet::_networkReplyFinished()
200216
return;
201217
}
202218

203-
if (_replies.contains(hash)) {
204-
(void) _replies.remove(hash);
205-
} else {
206-
qCWarning(QGCCachedTileSetLog) << "Reply not in list: " << hash;
219+
{
220+
QMutexLocker lock(&_repliesMutex);
221+
if (_replies.contains(hash)) {
222+
(void) _replies.remove(hash);
223+
} else {
224+
qCWarning(QGCCachedTileSetLog) << "Reply not in list: " << hash;
225+
}
207226
}
208227
qCDebug(QGCCachedTileSetLog) << "Tile fetched:" << hash;
209228

@@ -215,7 +234,10 @@ void QGCCachedTileSet::_networkReplyFinished()
215234

216235
const QString type = UrlFactory::tileHashToType(hash);
217236
const SharedMapProvider mapProvider = UrlFactory::getMapProviderFromProviderType(type);
218-
Q_CHECK_PTR(mapProvider);
237+
if (!mapProvider) {
238+
qCWarning(QGCCachedTileSetLog) << "Invalid map provider for type:" << type;
239+
return;
240+
}
219241

220242
if (mapProvider->isElevationProvider()) {
221243
const SharedElevationProvider elevationProvider = std::dynamic_pointer_cast<const ElevationProvider>(mapProvider);
@@ -242,7 +264,7 @@ void QGCCachedTileSet::_networkReplyFinished()
242264
setSavedTileSize(_savedTileSize + image.size());
243265
setSavedTileCount(_savedTileCount + 1);
244266

245-
if (_savedTileCount % 10 == 0) {
267+
if (_savedTileCount % kSizeEstimateInterval == 0) {
246268
const quint32 avg = _savedTileSize / _savedTileCount;
247269
setTotalTileSize(avg * _totalTileCount);
248270
setUniqueTileSize(avg * _uniqueTileCount);
@@ -267,10 +289,13 @@ void QGCCachedTileSet::_networkReplyError(QNetworkReply::NetworkError error)
267289
return;
268290
}
269291

270-
if (_replies.contains(hash)) {
271-
(void) _replies.remove(hash);
272-
} else {
273-
qCWarning(QGCCachedTileSetLog) << "Reply not in list:" << hash;
292+
{
293+
QMutexLocker lock(&_repliesMutex);
294+
if (_replies.contains(hash)) {
295+
(void) _replies.remove(hash);
296+
} else {
297+
qCWarning(QGCCachedTileSetLog) << "Reply not in list:" << hash;
298+
}
274299
}
275300

276301
if (error != QNetworkReply::OperationCanceledError) {

src/QtLocationPlugin/QGCCachedTileSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <QtCore/QDateTime>
1313
#include <QtCore/QHash>
1414
#include <QtCore/QLoggingCategory>
15+
#include <QtCore/QMutex>
1516
#include <QtCore/QObject>
1617
#include <QtCore/QQueue>
1718
#include <QtCore/QString>
@@ -182,6 +183,8 @@ private slots:
182183
QQueue<QGCTile*> _tilesToDownload;
183184
QGCMapEngineManager *_manager = nullptr;
184185
QNetworkAccessManager *_networkManager = nullptr;
186+
QMutex _repliesMutex;
185187

186188
static constexpr uint32_t kTileBatchSize = 256;
189+
static constexpr uint32_t kSizeEstimateInterval = 10;
187190
};

src/QtLocationPlugin/QGCMapEngineManager.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ bool QGCMapEngineManager::exportSets(const QString &path)
401401

402402
for (qsizetype i = 0; i < _tileSets->count(); i++) {
403403
QGCCachedTileSet* const set = qobject_cast<QGCCachedTileSet*>(_tileSets->get(i));
404-
if (set->selected()) {
404+
if (set && set->selected()) {
405405
sets.append(set);
406406
}
407407
}
@@ -443,8 +443,6 @@ QString QGCMapEngineManager::getUniqueName() const
443443
return name;
444444
}
445445
}
446-
447-
return QString("");
448446
}
449447

450448
QStringList QGCMapEngineManager::mapList()

src/QtLocationPlugin/QGCMapUrlEngine.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
QGC_LOGGING_CATEGORY(QGCMapUrlEngineLog, "QtLocationPlugin.QGCMapUrlEngine")
2424

2525
const QList<SharedMapProvider> UrlFactory::_providers = {
26-
#ifndef QGC_NO_GOOGLE_MAPS
2726
std::make_shared<GoogleStreetMapProvider>(),
2827
std::make_shared<GoogleSatelliteMapProvider>(),
2928
std::make_shared<GoogleTerrainMapProvider>(),
3029
std::make_shared<GoogleHybridMapProvider>(),
3130
std::make_shared<GoogleLabelsMapProvider>(),
32-
#endif
31+
3332
std::make_shared<BingRoadMapProvider>(),
3433
std::make_shared<BingSatelliteMapProvider>(),
3534
std::make_shared<BingHybridMapProvider>(),
@@ -173,9 +172,8 @@ QGCTileSet UrlFactory::getTileCount(int zoom, double topleftLon, double topleftL
173172

174173
QString UrlFactory::getProviderTypeFromQtMapId(int qtMapId)
175174
{
176-
// Default Set
177-
if (qtMapId == -1) {
178-
return nullptr;
175+
if (qtMapId == defaultSetMapId()) {
176+
return QString();
179177
}
180178

181179
for (const SharedMapProvider &provider : _providers) {
@@ -190,8 +188,7 @@ QString UrlFactory::getProviderTypeFromQtMapId(int qtMapId)
190188

191189
SharedMapProvider UrlFactory::getMapProviderFromQtMapId(int qtMapId)
192190
{
193-
// Default Set
194-
if (qtMapId == -1) {
191+
if (qtMapId == defaultSetMapId()) {
195192
return nullptr;
196193
}
197194

src/QtLocationPlugin/QGCMapUrlEngine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class UrlFactory
5151
static QString tileHashToType(QStringView tileHash);
5252
static QString getTileHash(QStringView type, int x, int y, int z);
5353

54+
static constexpr int defaultSetMapId() { return -1; }
55+
static constexpr quint64 defaultTileSetId() { return 1; }
56+
5457
private:
5558
static const QList<std::shared_ptr<const MapProvider>> _providers;
5659
};

0 commit comments

Comments
 (0)