Skip to content

Commit

Permalink
Updates from review (debug msg level 2, qBound, wider lines for test)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 28, 2020
1 parent 804ac87 commit 81a7af7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 51 deletions.
32 changes: 10 additions & 22 deletions src/core/qgstiles.cpp
Expand Up @@ -15,7 +15,7 @@

#include "qgstiles.h"

#include <QtDebug>
#include "qgslogger.h"

QgsTileMatrix QgsTileMatrix::fromWebMercator( int zoomLevel )
{
Expand Down Expand Up @@ -51,24 +51,12 @@ QgsPointXY QgsTileMatrix::tileCenter( QgsTileXYZ id ) const
return QgsPointXY( x, y );
}

inline double clampDouble( double lo, double v, double hi )
{
return ( v < lo ) ? lo : ( hi < v ) ? hi : v;
}

static int clampTile( int tile, int nTiles )
{
if ( tile < 0 ) return 0;
if ( tile >= nTiles ) return nTiles - 1;
return tile;
}

QgsTileRange QgsTileMatrix::tileRangeFromExtent( const QgsRectangle &r )
{
double x0 = clampDouble( mExtent.xMinimum(), r.xMinimum(), mExtent.xMaximum() );
double y0 = clampDouble( mExtent.yMinimum(), r.yMinimum(), mExtent.yMaximum() );
double x1 = clampDouble( mExtent.xMinimum(), r.xMaximum(), mExtent.xMaximum() );
double y1 = clampDouble( mExtent.yMinimum(), r.yMaximum(), mExtent.yMaximum() );
double x0 = qBound( mExtent.xMinimum(), r.xMinimum(), mExtent.xMaximum() );
double y0 = qBound( mExtent.yMinimum(), r.yMinimum(), mExtent.yMaximum() );
double x1 = qBound( mExtent.xMinimum(), r.xMaximum(), mExtent.xMaximum() );
double y1 = qBound( mExtent.yMinimum(), r.yMaximum(), mExtent.yMaximum() );
if ( x0 >= x1 || y0 >= y1 )
return QgsTileRange(); // nothing to display

Expand All @@ -77,13 +65,13 @@ QgsTileRange QgsTileMatrix::tileRangeFromExtent( const QgsRectangle &r )
double tileY1 = ( mExtent.yMaximum() - y1 ) / mTileYSpan;
double tileY2 = ( mExtent.yMaximum() - y0 ) / mTileYSpan;

qDebug() << "tile range of edges" << tileX1 << tileY1 << tileX2 << tileY2;
QgsDebugMsgLevel( QStringLiteral( "Tile range of edges [%1,%2] - [%3,%4]" ).arg( tileX1 ).arg( tileY1 ).arg( tileX2 ).arg( tileY2 ), 2 );

// figure out tile range from zoom
int startColumn = clampTile( static_cast<int>( floor( tileX1 ) ), mMatrixWidth );
int endColumn = clampTile( static_cast<int>( floor( tileX2 ) ), mMatrixWidth );
int startRow = clampTile( static_cast<int>( floor( tileY1 ) ), mMatrixHeight );
int endRow = clampTile( static_cast<int>( floor( tileY2 ) ), mMatrixHeight );
int startColumn = qBound( 0, static_cast<int>( floor( tileX1 ) ), mMatrixWidth - 1 );
int endColumn = qBound( 0, static_cast<int>( floor( tileX2 ) ), mMatrixWidth - 1 );
int startRow = qBound( 0, static_cast<int>( floor( tileY1 ) ), mMatrixHeight - 1 );
int endRow = qBound( 0, static_cast<int>( floor( tileY2 ) ), mMatrixHeight - 1 );
return QgsTileRange( startColumn, endColumn, startRow, endRow );
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -55,15 +55,15 @@ QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseN
return;
}

QgsDebugMsg( QStringLiteral( "name: " ) + reader.metadataValue( QStringLiteral( "name" ) ) );
QgsDebugMsgLevel( QStringLiteral( "name: " ) + reader.metadataValue( QStringLiteral( "name" ) ), 2 );
bool minZoomOk, maxZoomOk;
int minZoom = reader.metadataValue( QStringLiteral( "minzoom" ) ).toInt( &minZoomOk );
int maxZoom = reader.metadataValue( QStringLiteral( "maxzoom" ) ).toInt( &maxZoomOk );
if ( minZoomOk )
mSourceMinZoom = minZoom;
if ( maxZoomOk )
mSourceMaxZoom = maxZoom;
QgsDebugMsg( QStringLiteral( "zoom range: %1 - %2" ).arg( mSourceMinZoom ).arg( mSourceMaxZoom ) );
QgsDebugMsgLevel( QStringLiteral( "zoom range: %1 - %2" ).arg( mSourceMinZoom ).arg( mSourceMaxZoom ), 2 );

QgsRectangle r = reader.extent();
// TODO: reproject to EPSG:3857
Expand Down
28 changes: 14 additions & 14 deletions src/core/vectortile/qgsvectortilelayerrenderer.cpp
Expand Up @@ -49,25 +49,25 @@ bool QgsVectorTileLayerRenderer::render()
QElapsedTimer tTotal;
tTotal.start();

QgsDebugMsg( QStringLiteral( "Vector tiles rendering extent: " ) + ctx.extent().toString( -1 ) );
QgsDebugMsg( QStringLiteral( "Vector tiles map scale 1 : %1" ).arg( ctx.rendererScale() ) );
QgsDebugMsgLevel( QStringLiteral( "Vector tiles rendering extent: " ) + ctx.extent().toString( -1 ), 2 );
QgsDebugMsgLevel( QStringLiteral( "Vector tiles map scale 1 : %1" ).arg( ctx.rendererScale() ), 2 );

mTileZoom = QgsVectorTileUtils::scaleToZoomLevel( ctx.rendererScale(), mSourceMinZoom, mSourceMaxZoom );
QgsDebugMsg( QStringLiteral( "Vector tiles zoom level: %1" ).arg( mTileZoom ) );
QgsDebugMsgLevel( QStringLiteral( "Vector tiles zoom level: %1" ).arg( mTileZoom ), 2 );

mTileMatrix = QgsTileMatrix::fromWebMercator( mTileZoom );

mTileRange = mTileMatrix.tileRangeFromExtent( ctx.extent() );
QgsDebugMsg( QStringLiteral( "Vector tiles range X: %1 - %2 Y: %3 - %4" )
.arg( mTileRange.startColumn() ).arg( mTileRange.endColumn() )
.arg( mTileRange.startRow() ).arg( mTileRange.endRow() ) );
QgsDebugMsgLevel( QStringLiteral( "Vector tiles range X: %1 - %2 Y: %3 - %4" )
.arg( mTileRange.startColumn() ).arg( mTileRange.endColumn() )
.arg( mTileRange.startRow() ).arg( mTileRange.endRow() ), 2 );

// view center is used to sort the order of tiles for fetching and rendering
QPointF viewCenter = mTileMatrix.mapToTileCoordinates( ctx.extent().center() );

if ( !mTileRange.isValid() )
{
QgsDebugMsg( QStringLiteral( "Vector tiles - outside of range" ) );
QgsDebugMsgLevel( QStringLiteral( "Vector tiles - outside of range" ), 2 );
return true; // nothing to do
}

Expand All @@ -80,15 +80,15 @@ bool QgsVectorTileLayerRenderer::render()
QElapsedTimer tFetch;
tFetch.start();
rawTiles = QgsVectorTileLoader::blockingFetchTileRawData( mSourceType, mSourcePath, mTileZoom, viewCenter, mTileRange );
QgsDebugMsg( QStringLiteral( "Tile fetching time: %1" ).arg( tFetch.elapsed() / 1000. ) );
QgsDebugMsg( QStringLiteral( "Fetched tiles: %1" ).arg( rawTiles.count() ) );
QgsDebugMsgLevel( QStringLiteral( "Tile fetching time: %1" ).arg( tFetch.elapsed() / 1000. ), 2 );
QgsDebugMsgLevel( QStringLiteral( "Fetched tiles: %1" ).arg( rawTiles.count() ), 2 );
}
else
{
asyncLoader.reset( new QgsVectorTileLoader( mSourcePath, mTileZoom, mTileRange, viewCenter, mFeedback.get() ) );
QObject::connect( asyncLoader.get(), &QgsVectorTileLoader::tileRequestFinished, [this]( const QgsVectorTileRawData & rawTile )
{
QgsDebugMsg( QStringLiteral( "Got tile asynchronously: " ) + rawTile.id.toString() );
QgsDebugMsgLevel( QStringLiteral( "Got tile asynchronously: " ) + rawTile.id.toString(), 2 );
if ( !rawTile.data.isEmpty() )
decodeAndDrawTile( rawTile );
} );
Expand Down Expand Up @@ -126,9 +126,9 @@ bool QgsVectorTileLayerRenderer::render()

ctx.painter()->setClipping( false );

QgsDebugMsg( QStringLiteral( "Total time for decoding: %1" ).arg( mTotalDecodeTime / 1000. ) );
QgsDebugMsg( QStringLiteral( "Drawing time: %1" ).arg( mTotalDrawTime / 1000. ) );
QgsDebugMsg( QStringLiteral( "Total time: %1" ).arg( tTotal.elapsed() / 1000. ) );
QgsDebugMsgLevel( QStringLiteral( "Total time for decoding: %1" ).arg( mTotalDecodeTime / 1000. ), 2 );
QgsDebugMsgLevel( QStringLiteral( "Drawing time: %1" ).arg( mTotalDrawTime / 1000. ), 2 );
QgsDebugMsgLevel( QStringLiteral( "Total time: %1" ).arg( tTotal.elapsed() / 1000. ), 2 );

return !ctx.renderingStopped();
}
Expand All @@ -146,7 +146,7 @@ void QgsVectorTileLayerRenderer::decodeAndDrawTile( const QgsVectorTileRawData &
QgsVectorTileMVTDecoder decoder;
if ( !decoder.decode( rawTile.id, rawTile.data ) )
{
QgsDebugMsg( QStringLiteral( "Failed to parse raw tile data! " ) + rawTile.id.toString() );
QgsDebugMsgLevel( QStringLiteral( "Failed to parse raw tile data! " ) + rawTile.id.toString(), 2 );
return;
}

Expand Down
25 changes: 15 additions & 10 deletions src/core/vectortile/qgsvectortileloader.cpp
Expand Up @@ -39,7 +39,7 @@ QgsVectorTileLoader::QgsVectorTileLoader( const QString &uri, int zoomLevel, con
return;
}

QgsDebugMsg( QStringLiteral( "Starting network loader" ) );
QgsDebugMsgLevel( QStringLiteral( "Starting network loader" ), 2 );
QVector<QgsTileXYZ> tiles = QgsVectorTileUtils::tilesInRange( range, zoomLevel );
QgsVectorTileUtils::sortTilesByDistanceFromCenter( tiles, viewCenter );
for ( QgsTileXYZ id : qgis::as_const( tiles ) )
Expand All @@ -50,7 +50,7 @@ QgsVectorTileLoader::QgsVectorTileLoader( const QString &uri, int zoomLevel, con

QgsVectorTileLoader::~QgsVectorTileLoader()
{
QgsDebugMsg( QStringLiteral( "Terminating network loader" ) );
QgsDebugMsgLevel( QStringLiteral( "Terminating network loader" ), 2 );

if ( !mReplies.isEmpty() )
{
Expand All @@ -64,15 +64,15 @@ void QgsVectorTileLoader::downloadBlocking()
{
if ( mFeedback && mFeedback->isCanceled() )
{
QgsDebugMsg( QStringLiteral( "downloadBlocking - not staring event loop - canceled" ) );
QgsDebugMsgLevel( QStringLiteral( "downloadBlocking - not staring event loop - canceled" ), 2 );
return; // nothing to do
}

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

mEventLoop->exec( QEventLoop::ExcludeUserInputEvents );

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

Q_ASSERT( mReplies.isEmpty() );
}
Expand Down Expand Up @@ -110,7 +110,7 @@ void QgsVectorTileLoader::tileReplyFinished()
{
// TODO: handle redirections?

QgsDebugMsg( QStringLiteral( "Tile download successful: " ) + tileID.toString() );
QgsDebugMsgLevel( QStringLiteral( "Tile download successful: " ) + tileID.toString(), 2 );
QByteArray rawData = reply->readAll();
mReplies.removeOne( reply );
reply->deleteLater();
Expand All @@ -135,7 +135,7 @@ void QgsVectorTileLoader::tileReplyFinished()

void QgsVectorTileLoader::canceled()
{
QgsDebugMsg( QStringLiteral( "Canceling %1 pending requests" ).arg( mReplies.count() ) );
QgsDebugMsgLevel( QStringLiteral( "Canceling %1 pending requests" ).arg( mReplies.count() ), 2 );
const QList<QNetworkReply *> replies = mReplies;
for ( QNetworkReply *reply : replies )
{
Expand Down Expand Up @@ -176,10 +176,15 @@ QByteArray QgsVectorTileLoader::loadFromNetwork( const QgsTileXYZ &id, const QSt
QNetworkRequest nr;
nr.setUrl( QUrl( url ) );
QgsBlockingNetworkRequest req;
QgsDebugMsg( QStringLiteral( "Blocking request: " ) + url );
QgsDebugMsgLevel( QStringLiteral( "Blocking request: " ) + url, 2 );
QgsBlockingNetworkRequest::ErrorCode errCode = req.get( nr );
if ( errCode != QgsBlockingNetworkRequest::NoError )
{
QgsDebugMsg( QStringLiteral( "Request failed: " ) + url );
return QByteArray();
}
QgsNetworkReplyContent reply = req.reply();
QgsDebugMsg( QStringLiteral( "Got error code %1, content size %2" ).arg( errCode ).arg( reply.content().size() ) );
QgsDebugMsgLevel( QStringLiteral( "Request successful, content size %1" ).arg( reply.content().size() ), 2 );
return reply.content();
}

Expand All @@ -204,7 +209,7 @@ QByteArray QgsVectorTileLoader::loadFromMBTiles( const QgsTileXYZ &id, QgsMBTile
return QByteArray();
}

QgsDebugMsg( QStringLiteral( "Tile blob size %1 -> uncompressed size %2" ).arg( gzippedTileData.size() ).arg( data.size() ) );
QgsDebugMsgLevel( QStringLiteral( "Tile blob size %1 -> uncompressed size %2" ).arg( gzippedTileData.size() ).arg( data.size() ), 2 );
return data;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortileutils.cpp
Expand Up @@ -109,7 +109,7 @@ QgsVectorLayer *QgsVectorTileUtils::makeVectorLayerForTile( QgsVectorTileLayer *
Q_ASSERT( res );
Q_ASSERT( featuresList.count() == vl->featureCount() );
vl->updateExtents();
QgsDebugMsg( QStringLiteral( "Layer %1 features %2" ).arg( layerName ).arg( vl->featureCount() ) );
QgsDebugMsgLevel( QStringLiteral( "Layer %1 features %2" ).arg( layerName ).arg( vl->featureCount() ), 2 );
return vl;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsvectortilelayer.cpp
Expand Up @@ -80,9 +80,9 @@ void TestQgsVectorTileLayer::initTestCase()
QColor polygonFillColor = Qt::blue;
QColor polygonStrokeColor = polygonFillColor;
polygonFillColor.setAlpha( 100 );
double polygonStrokeWidth = DEFAULT_LINE_WIDTH;
double polygonStrokeWidth = DEFAULT_LINE_WIDTH * 2;
QColor lineStrokeColor = Qt::blue;
double lineStrokeWidth = DEFAULT_LINE_WIDTH;
double lineStrokeWidth = DEFAULT_LINE_WIDTH * 2;
QColor pointFillColor = Qt::red;
QColor pointStrokeColor = pointFillColor;
pointFillColor.setAlpha( 100 );
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 81a7af7

Please sign in to comment.