Skip to content

Commit

Permalink
Address comments from Nyall's review
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 15, 2020
1 parent 59c1ac3 commit ba7b785
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsvectortileutils.cpp
Expand Up @@ -53,7 +53,7 @@ QgsFields QgsVectorTileUtils::makeQgisFields( QSet<QString> flds )
QgsFields fields;
QStringList fieldsSorted = flds.toList();
std::sort( fieldsSorted.begin(), fieldsSorted.end() );
for ( QString fieldName : qgis::as_const( fieldsSorted ) )
for ( const QString &fieldName : qgis::as_const( fieldsSorted ) )
{
fields.append( QgsField( fieldName, QVariant::String ) );
}
Expand Down
11 changes: 6 additions & 5 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -329,11 +329,11 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList<QgsMapToolIdentify::Iden

if ( !layer->isInScaleRange( mCanvas->mapSettings().scale() ) )
{
QgsDebugMsg( QStringLiteral( "Out of scale limits" ) );
QgsDebugMsgLevel( QStringLiteral( "Out of scale limits" ), 2 );
return false;
}

QApplication::setOverrideCursor( Qt::WaitCursor );
QgsTemporaryCursorOverride waitCursor( Qt::WaitCursor );

QMap< QString, QString > commonDerivedAttributes;

Expand Down Expand Up @@ -403,14 +403,16 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList<QgsMapToolIdentify::Iden
continue; // failed to decode

QMap<QString, QgsFields> perLayerFields;
for ( QString layerName : decoder.layers() )
const QStringList layerNames = decoder.layers();
for ( const QString &layerName : layerNames )
{
QSet<QString> fieldNames = QSet<QString>::fromList( decoder.layerFieldNames( layerName ) );
perLayerFields[layerName] = QgsVectorTileUtils::makeQgisFields( fieldNames );
}

const QgsVectorTileFeatures features = decoder.layerFeatures( perLayerFields, QgsCoordinateTransform() );
for ( QString layerName : features.keys() )
const QStringList featuresLayerNames = features.keys();
for ( const QString &layerName : featuresLayerNames )
{
const QgsFields fFields = perLayerFields[layerName];
const QVector<QgsFeature> &layerFeatures = features[layerName];
Expand Down Expand Up @@ -438,7 +440,6 @@ bool QgsMapToolIdentify::identifyVectorTileLayer( QList<QgsMapToolIdentify::Iden
QgsDebugMsg( QStringLiteral( "Caught CRS exception %1" ).arg( cse.what() ) );
}

QApplication::restoreOverrideCursor();
return featureCount > 0;
}

Expand Down
1 change: 1 addition & 0 deletions tests/src/app/CMakeLists.txt
Expand Up @@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/effects
${CMAKE_SOURCE_DIR}/src/core/validity
${CMAKE_SOURCE_DIR}/src/core/vectortile
${CMAKE_SOURCE_DIR}/src/ui
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
Expand Down
40 changes: 40 additions & 0 deletions tests/src/app/testqgsmaptoolidentifyaction.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsfeature.h"
#include "qgsgeometry.h"
#include "qgsvectordataprovider.h"
#include "qgsvectortilelayer.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
#include "qgsmeshlayer.h"
Expand Down Expand Up @@ -56,6 +57,7 @@ class TestQgsMapToolIdentifyAction : public QObject
void identifyRasterFloat32(); // test pixel identification and decimal precision
void identifyRasterFloat64(); // test pixel identification and decimal precision
void identifyMesh(); // test identification for mesh layer
void identifyVectorTile(); // test identification for vector tile layer
void identifyInvalidPolygons(); // test selecting invalid polygons
void clickxy(); // test if clicked_x and clicked_y variables are propagated
void closestPoint();
Expand All @@ -70,6 +72,7 @@ class TestQgsMapToolIdentifyAction : public QObject
QString testIdentifyRaster( QgsRasterLayer *layer, double xGeoref, double yGeoref );
QList<QgsMapToolIdentify::IdentifyResult> testIdentifyVector( QgsVectorLayer *layer, double xGeoref, double yGeoref );
QList<QgsMapToolIdentify::IdentifyResult> testIdentifyMesh( QgsMeshLayer *layer, double xGeoref, double yGeoref );
QList<QgsMapToolIdentify::IdentifyResult> testIdentifyVectorTile( QgsVectorTileLayer *layer, double xGeoref, double yGeoref );

// Release return with delete []
unsigned char *
Expand Down Expand Up @@ -540,6 +543,16 @@ TestQgsMapToolIdentifyAction::testIdentifyVector( QgsVectorLayer *layer, double
return result;
}

// private
QList<QgsMapToolIdentify::IdentifyResult>
TestQgsMapToolIdentifyAction::testIdentifyVectorTile( QgsVectorTileLayer *layer, double xGeoref, double yGeoref )
{
std::unique_ptr< QgsMapToolIdentifyAction > action( new QgsMapToolIdentifyAction( canvas ) );
QgsPointXY mapPoint = canvas->getCoordinateTransform()->transform( xGeoref, yGeoref );
QList<QgsMapToolIdentify::IdentifyResult> result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << layer );
return result;
}

void TestQgsMapToolIdentifyAction::identifyRasterFloat32()
{
//create a temporary layer
Expand Down Expand Up @@ -663,6 +676,33 @@ void TestQgsMapToolIdentifyAction::identifyMesh()
QCOMPARE( results[0].mAttributes[ QStringLiteral( "Vector y-component" )], QStringLiteral( "2.4" ) );
}

void TestQgsMapToolIdentifyAction::identifyVectorTile()
{
//create a temporary layer
QgsDataSourceUri dsUri;
dsUri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) );
dsUri.setParam( QStringLiteral( "url" ), QStringLiteral( "file://%1/vector_tile/{z}-{x}-{y}.pbf" ).arg( QStringLiteral( TEST_DATA_DIR ) ) );
QgsVectorTileLayer *tempLayer = new QgsVectorTileLayer( dsUri.encodedUri(), QStringLiteral( "testlayer" ) );
QVERIFY( tempLayer->isValid() );

QgsCoordinateReferenceSystem srs( QStringLiteral( "EPSG:3857" ) );
canvas->setDestinationCrs( srs );
canvas->setExtent( tempLayer->extent() );
canvas->setLayers( QList<QgsMapLayer *>() << tempLayer );
canvas->setCurrentLayer( tempLayer );

QList<QgsMapToolIdentify::IdentifyResult> results;
results = testIdentifyVectorTile( tempLayer, 15186127, -2974969 );
QCOMPARE( results.size(), 1 );
QCOMPARE( results[0].mLayer, tempLayer );
QCOMPARE( results[0].mLabel, QStringLiteral( "place" ) );
QCOMPARE( results[0].mFeature.geometry().wkbType(), QgsWkbTypes::Point );
QCOMPARE( results[0].mFeature.attribute( QStringLiteral( "class" ) ).toString(), QStringLiteral( "country" ) );
QCOMPARE( results[0].mFeature.attribute( QStringLiteral( "name" ) ).toString(), QStringLiteral( "Australia" ) );

delete tempLayer;
}

void TestQgsMapToolIdentifyAction::identifyInvalidPolygons()
{
//create a temporary layer
Expand Down

0 comments on commit ba7b785

Please sign in to comment.