64
64
#include < QEventLoop>
65
65
#include < QTextCodec>
66
66
#include < QThread>
67
- #include < QScriptEngine>
68
- #include < QScriptValue>
69
- #include < QScriptValueIterator>
70
67
#include < QNetworkDiskCache>
71
68
#include < QTimer>
72
69
@@ -2972,39 +2969,33 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPointXY &point, QgsRa
2972
2969
else if ( jsonPart != -1 )
2973
2970
{
2974
2971
QString json = QString::fromUtf8 ( mIdentifyResultBodies .value ( jsonPart ) );
2975
- json.prepend ( ' (' ).append ( ' )' );
2976
-
2977
- QScriptEngine engine;
2978
- engine.evaluate ( QStringLiteral ( " function json_stringify(obj) { return JSON.stringify(obj); }" ) );
2979
- QScriptValue json_stringify = engine.globalObject ().property ( QStringLiteral ( " json_stringify" ) );
2980
- Q_ASSERT ( json_stringify.isFunction () );
2981
-
2982
- QScriptValue result = engine.evaluate ( json );
2983
2972
2984
2973
QgsFeatureStoreList featureStoreList;
2985
2974
QgsCoordinateTransform coordinateTransform;
2986
2975
2987
2976
try
2988
2977
{
2989
- QgsDebugMsg ( QString ( " result:%1" ).arg ( result.toString () ) );
2990
-
2991
- if ( !result.isObject () )
2992
- throw QStringLiteral ( " object expected" );
2978
+ QJsonDocument doc = QJsonDocument::fromJson ( json.toUtf8 () );
2979
+ if ( doc.isNull () )
2980
+ throw QStringLiteral ( " Doc expected" );
2981
+ if ( !doc.isObject () )
2982
+ throw QStringLiteral ( " Object expected" );
2993
2983
2994
- if ( result.property ( QStringLiteral ( " type" ) ).toString () != QLatin1String ( " FeatureCollection" ) )
2995
- throw QStringLiteral ( " type FeatureCollection expected: %1" ).arg ( result.property ( QStringLiteral ( " type" ) ).toString () );
2984
+ QJsonObject result = doc.object ();
2985
+ if ( result.value ( QLatin1String ( " type" ) ).toString () != QLatin1String ( " FeatureCollection" ) )
2986
+ throw QStringLiteral ( " Type FeatureCollection expected: %1" ).arg ( result.value ( QLatin1String ( " type" ) ).toString () );
2996
2987
2997
- if ( result.property ( QStringLiteral ( " crs" ) ).isValid () )
2988
+ if ( result.value ( QLatin1String ( " crs" ) ).isObject () )
2998
2989
{
2999
- QString crsType = result.property ( QStringLiteral ( " crs" ) ).property ( QStringLiteral ( " type" ) ).toString ();
2990
+ QString crsType = result.value ( QLatin1String ( " crs" ) ).toObject (). value ( QLatin1String ( " type" ) ).toString ();
3000
2991
QString crsText;
3001
2992
if ( crsType == QLatin1String ( " name" ) )
3002
- crsText = result.property ( QStringLiteral ( " crs" ) ).property ( QStringLiteral ( " properties" ) ).property ( QStringLiteral ( " name" ) ).toString ();
2993
+ crsText = result.value ( QStringLiteral ( " crs" ) ).toObject (). value ( QLatin1String ( " properties" ) ).toObject (). value ( QLatin1String ( " name" ) ).toString ();
3003
2994
else if ( crsType == QLatin1String ( " EPSG" ) )
3004
- crsText = QStringLiteral ( " %1:%2" ).arg ( crsType, result.property ( QStringLiteral ( " crs" ) ).property ( QStringLiteral ( " properties" ) ).property ( QStringLiteral ( " code" ) ).toString () );
2995
+ crsText = QStringLiteral ( " %1:%2" ).arg ( crsType, result.value ( QLatin1String ( " crs" ) ).toObject (). value ( QLatin1String ( " properties" ) ).toObject (). value ( QStringLiteral ( " code" ) ).toString () );
3005
2996
else
3006
2997
{
3007
- QgsDebugMsg ( QString ( " crs not supported:%1" ).arg ( result.property ( " crs" ).toString () ) );
2998
+ QgsDebugMsg ( QStringLiteral ( " crs not supported:%1" ).arg ( result.value ( QLatin1String ( " crs" ) ).toString () ) );
3008
2999
}
3009
3000
3010
3001
QgsCoordinateReferenceSystem featuresCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs ( crsText );
@@ -3018,69 +3009,71 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPointXY &point, QgsRa
3018
3009
}
3019
3010
}
3020
3011
3021
- QScriptValue fc = result.property ( QStringLiteral ( " features" ) );
3012
+ const QJsonValue fc = result.value ( QLatin1String ( " features" ) );
3022
3013
if ( !fc.isArray () )
3023
3014
throw QStringLiteral ( " FeatureCollection array expected" );
3024
3015
3025
- QScriptValue f;
3026
- for ( int i = 0 ; f = fc.property ( i ), f.isValid (); i++ )
3027
- {
3028
- QgsDebugMsg ( QString ( " feature %1" ).arg ( i ) );
3016
+ const QJsonArray features = fc.toArray ();
3029
3017
3030
- QScriptValue props = f.property ( QStringLiteral ( " properties" ) );
3018
+ int i = -1 ;
3019
+ for ( const QJsonValue &fv : features )
3020
+ {
3021
+ ++i;
3022
+ const QJsonObject f = fv.toObject ();
3023
+ const QJsonValue props = f.value ( QLatin1String ( " properties" ) );
3031
3024
if ( !props.isObject () )
3032
3025
{
3033
3026
QgsDebugMsg ( " no properties found" );
3034
3027
continue ;
3035
3028
}
3036
3029
3037
3030
QgsFields fields;
3038
- QScriptValueIterator it ( props );
3039
- while ( it.hasNext () )
3031
+
3032
+ const QJsonObject properties = props.toObject ();
3033
+ auto fieldIterator = properties.constBegin ();
3034
+
3035
+ for ( ; fieldIterator != properties.constEnd (); ++fieldIterator )
3040
3036
{
3041
- it.next ();
3042
- fields.append ( QgsField ( it.name (), QVariant::String ) );
3037
+ fields.append ( QgsField ( fieldIterator.key (), QVariant::String ) );
3043
3038
}
3044
3039
3045
3040
QgsFeature feature ( fields );
3046
3041
3047
- if ( f.property ( QStringLiteral ( " geometry" ) ).isValid () )
3042
+ if ( f.value ( QLatin1String ( " geometry" ) ).isObject () )
3048
3043
{
3049
- QScriptValue geom = json_stringify.call ( QScriptValue (), QScriptValueList () << f.property ( QStringLiteral ( " geometry" ) ) );
3050
- if ( geom.isString () )
3044
+ QJsonDocument serializer ( f.value ( QLatin1String ( " geometry" ) ).toObject () );
3045
+ QString geom = serializer.toJson ( QJsonDocument::JsonFormat::Compact );
3046
+
3047
+ gdal::ogr_geometry_unique_ptr ogrGeom ( OGR_G_CreateGeometryFromJson ( geom.toUtf8 () ) );
3048
+ if ( ogrGeom )
3051
3049
{
3052
- gdal::ogr_geometry_unique_ptr ogrGeom ( OGR_G_CreateGeometryFromJson ( geom.toString ().toUtf8 () ) );
3053
- if ( ogrGeom )
3050
+ int wkbSize = OGR_G_WkbSize ( ogrGeom.get () );
3051
+ unsigned char *wkb = new unsigned char [ wkbSize ];
3052
+ OGR_G_ExportToWkb ( ogrGeom.get (), ( OGRwkbByteOrder ) QgsApplication::endian (), wkb );
3053
+
3054
+ QgsGeometry g;
3055
+ g.fromWkb ( wkb, wkbSize );
3056
+ feature.setGeometry ( g );
3057
+
3058
+ if ( coordinateTransform.isValid () && feature.hasGeometry () )
3054
3059
{
3055
- int wkbSize = OGR_G_WkbSize ( ogrGeom.get () );
3056
- unsigned char *wkb = new unsigned char [ wkbSize ];
3057
- OGR_G_ExportToWkb ( ogrGeom.get (), ( OGRwkbByteOrder ) QgsApplication::endian (), wkb );
3058
-
3059
- QgsGeometry g;
3060
- g.fromWkb ( wkb, wkbSize );
3061
- feature.setGeometry ( g );
3062
-
3063
- if ( coordinateTransform.isValid () && feature.hasGeometry () )
3064
- {
3065
- QgsGeometry transformed = feature.geometry ();
3066
- transformed.transform ( coordinateTransform );
3067
- feature.setGeometry ( transformed );
3068
- }
3060
+ QgsGeometry transformed = feature.geometry ();
3061
+ transformed.transform ( coordinateTransform );
3062
+ feature.setGeometry ( transformed );
3069
3063
}
3070
3064
}
3071
3065
}
3072
3066
3073
3067
int j = 0 ;
3074
- it. toFront ();
3075
- while ( it. hasNext () )
3068
+ fieldIterator = properties. constBegin ();
3069
+ for ( ; fieldIterator != properties. constEnd (); ++fieldIterator )
3076
3070
{
3077
- it.next ();
3078
- feature.setAttribute ( j++, it.value ().toString () );
3071
+ feature.setAttribute ( j++, fieldIterator.value ().toString () );
3079
3072
}
3080
3073
3081
3074
QgsFeatureStore featureStore ( fields, crs () );
3082
3075
3083
- QMap<QString, QVariant> params;
3076
+ QVariantMap params;
3084
3077
params.insert ( QStringLiteral ( " sublayer" ), layerList[count] );
3085
3078
params.insert ( QStringLiteral ( " featureType" ), QStringLiteral ( " %1_%2" ).arg ( count ).arg ( i ) );
3086
3079
params.insert ( QStringLiteral ( " getFeatureInfoUrl" ), requestUrl.toString () );
0 commit comments