Skip to content

Commit

Permalink
Changed load model in QGVLayerTilesOnline
Browse files Browse the repository at this point in the history
  • Loading branch information
AmonRaNet committed Mar 26, 2024
1 parent 2cf5c91 commit e6234b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
4 changes: 1 addition & 3 deletions lib/include/QGeoView/QGVLayerTilesOnline.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ class QGV_LIB_DECL QGVLayerTilesOnline : public QGVLayerTiles
virtual QString tilePosToUrl(const QGV::GeoTilePos& tilePos) const = 0;

private:
void onProjection(QGVMap* geoMap) override;
void onClean() override;
void request(const QGV::GeoTilePos& tilePos) override;
void cancel(const QGV::GeoTilePos& tilePos) override;
void onReplyFinished(QNetworkReply* reply);
void onReplyFinished(QNetworkReply* reply, const QGV::GeoTilePos& tilePos);
void removeReply(const QGV::GeoTilePos& tilePos);

private:
Expand Down
34 changes: 8 additions & 26 deletions lib/src/QGVLayerTilesOnline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,29 @@ QGVLayerTilesOnline::~QGVLayerTilesOnline()
qDeleteAll(mRequest);
}

void QGVLayerTilesOnline::onProjection(QGVMap* geoMap)
void QGVLayerTilesOnline::request(const QGV::GeoTilePos& tilePos)
{
Q_ASSERT(QGV::getNetworkManager());
QGVLayerTiles::onProjection(geoMap);
connect(QGV::getNetworkManager(), &QNetworkAccessManager::finished, this, &QGVLayerTilesOnline::onReplyFinished);
}

void QGVLayerTilesOnline::onClean()
{
Q_ASSERT(QGV::getNetworkManager());
disconnect(QGV::getNetworkManager(), 0, this, 0);
}

void QGVLayerTilesOnline::request(const QGV::GeoTilePos& tilePos)
{
const QUrl url(tilePosToUrl(tilePos));

QNetworkRequest request(url);
QSslConfiguration conf = request.sslConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);

request.setSslConfiguration(conf);
request.setRawHeader("User-Agent",
"Mozilla/5.0 (Windows; U; MSIE "
"6.0; Windows NT 5.1; SV1; .NET "
"CLR 2.0.50727)");
request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);

QNetworkReply* reply = QGV::getNetworkManager()->get(request);
reply->setProperty("TILE_OWNER", QVariant::fromValue(this));
reply->setProperty("TILE_REQUEST", true);
reply->setProperty("TILE_POS", QVariant::fromValue(tilePos));

mRequest[tilePos] = reply;
connect(reply, &QNetworkReply::finished, reply, [this, reply, tilePos]() { onReplyFinished(reply, tilePos); });

qgvDebug() << "request" << url;
}

Expand All @@ -63,18 +55,8 @@ void QGVLayerTilesOnline::cancel(const QGV::GeoTilePos& tilePos)
removeReply(tilePos);
}

void QGVLayerTilesOnline::onReplyFinished(QNetworkReply* reply)
void QGVLayerTilesOnline::onReplyFinished(QNetworkReply* reply, const QGV::GeoTilePos& tilePos)
{
const auto tileRequest = reply->property("TILE_REQUEST").toBool();
if (!tileRequest) {
return;
}
const auto tileOwner = reply->property("TILE_OWNER").value<QGVLayerTilesOnline*>();
if (tileOwner != this) {
return;
}
const auto tilePos = reply->property("TILE_POS").value<QGV::GeoTilePos>();

if (reply->error() != QNetworkReply::NoError) {
if (reply->error() != QNetworkReply::OperationCanceledError) {
qgvCritical() << "ERROR" << reply->errorString();
Expand Down

0 comments on commit e6234b3

Please sign in to comment.