Skip to content

Commit

Permalink
Peter's review
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 20, 2021
1 parent b76a2a2 commit 0cf985f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 33 deletions.
4 changes: 0 additions & 4 deletions python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -789,10 +789,6 @@ Returns the application's classification methods registry, used in graduated ren
%Docstring
Returns the application's bookmark manager, used for storing installation-wide bookmarks.

.. note::

not available in Python bindings

.. versionadded:: 3.10
%End

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsapplication.h
Expand Up @@ -734,13 +734,13 @@ class CORE_EXPORT QgsApplication : public QApplication

/**
* Returns the application's bookmark manager, used for storing installation-wide bookmarks.
* \note not available in Python bindings
* \since QGIS 3.10
*/
static QgsBookmarkManager *bookmarkManager();

/**
* Returns the application's tile download manager, used for download of map tiles when rendering.
* \note not available in Python bindings
* \since QGIS 3.18
*/
static QgsTileDownloadManager *tileDownloadManager() SIP_SKIP;
Expand Down
38 changes: 13 additions & 25 deletions src/core/vectortile/qgsvectortileloader.cpp
Expand Up @@ -57,7 +57,7 @@ QgsVectorTileLoader::~QgsVectorTileLoader()
{
QgsDebugMsgLevel( QStringLiteral( "Terminating network loader" ), 2 );

if ( !mRepliesV2.isEmpty() )
if ( !mReplies.isEmpty() )
{
// this can happen when the loader is terminated without getting requests finalized
// (e.g. downloadBlocking() was not called)
Expand All @@ -73,13 +73,13 @@ void QgsVectorTileLoader::downloadBlocking()
return; // nothing to do
}

QgsDebugMsgLevel( QStringLiteral( "Starting event loop with %1 requests" ).arg( mRepliesV2.count() ), 2 );
QgsDebugMsgLevel( QStringLiteral( "Starting event loop with %1 requests" ).arg( mReplies.count() ), 2 );

mEventLoop->exec( QEventLoop::ExcludeUserInputEvents );

QgsDebugMsgLevel( QStringLiteral( "downloadBlocking finished" ), 2 );

Q_ASSERT( mRepliesV2.isEmpty() );
Q_ASSERT( mReplies.isEmpty() );
}

void QgsVectorTileLoader::loadFromNetworkAsync( const QgsTileXYZ &id, const QgsTileMatrix &tileMatrix, const QString &requestUrl )
Expand All @@ -104,18 +104,13 @@ void QgsVectorTileLoader::loadFromNetworkAsync( const QgsTileXYZ &id, const QgsT
QgsMessageLog::logMessage( tr( "network request update failed for authentication config" ), tr( "Network" ) );
}

QgsTileDownloadManagerReply *replyV2 = QgsApplication::tileDownloadManager()->get( request );
connect( replyV2, &QgsTileDownloadManagerReply::finished, this, &QgsVectorTileLoader::tileReplyFinished );
mRepliesV2 << replyV2;

//QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request );
//connect( reply, &QNetworkReply::finished, this, &QgsVectorTileLoader::tileReplyFinished );
//mReplies << reply;
QgsTileDownloadManagerReply *reply = QgsApplication::tileDownloadManager()->get( request );
connect( reply, &QgsTileDownloadManagerReply::finished, this, &QgsVectorTileLoader::tileReplyFinished );
mReplies << reply;
}

void QgsVectorTileLoader::tileReplyFinished()
{
//QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() );
QgsTileDownloadManagerReply *reply = qobject_cast<QgsTileDownloadManagerReply *>( sender() );

int reqX = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ) ).toInt();
Expand All @@ -128,24 +123,22 @@ void QgsVectorTileLoader::tileReplyFinished()
// TODO: handle redirections?

QgsDebugMsgLevel( QStringLiteral( "Tile download successful: " ) + tileID.toString(), 2 );
QByteArray rawData = reply->data(); //reply->readAll();
mRepliesV2.removeOne( reply );
//mReplies.removeOne( reply );
QByteArray rawData = reply->data();
mReplies.removeOne( reply );
reply->deleteLater();

emit tileRequestFinished( QgsVectorTileRawData( tileID, rawData ) );
}
else
{
QgsDebugMsg( QStringLiteral( "Tile download failed! " ) + reply->errorString() );
mRepliesV2.removeOne( reply );
//mReplies.removeOne( reply );
mReplies.removeOne( reply );
reply->deleteLater();

emit tileRequestFinished( QgsVectorTileRawData( tileID, QByteArray() ) );
}

if ( mRepliesV2.isEmpty() )
if ( mReplies.isEmpty() )
{
// exist the event loop
QMetaObject::invokeMethod( mEventLoop.get(), "quit", Qt::QueuedConnection );
Expand All @@ -154,18 +147,13 @@ void QgsVectorTileLoader::tileReplyFinished()

void QgsVectorTileLoader::canceled()
{
QgsDebugMsgLevel( QStringLiteral( "Canceling %1 pending requests" ).arg( mRepliesV2.count() ), 2 );
qDeleteAll( mRepliesV2 );
mRepliesV2.clear();
QgsDebugMsgLevel( QStringLiteral( "Canceling %1 pending requests" ).arg( mReplies.count() ), 2 );
qDeleteAll( mReplies );
mReplies.clear();

// stop blocking download
mEventLoop->quit();

// const QList<QNetworkReply *> replies = mReplies;
// for ( QNetworkReply *reply : replies )
// {
// reply->abort();
// }
}

//////
Expand Down
4 changes: 1 addition & 3 deletions src/core/vectortile/qgsvectortileloader.h
Expand Up @@ -111,9 +111,7 @@ class QgsVectorTileLoader : public QObject
QString mReferer;

//! Running tile requests
//QList<QNetworkReply *> mReplies;

QList<QgsTileDownloadManagerReply *> mRepliesV2;
QList<QgsTileDownloadManagerReply *> mReplies;

};

Expand Down

0 comments on commit 0cf985f

Please sign in to comment.