Skip to content
Permalink
Browse files

Layout

  • Loading branch information
elpaso committed Apr 24, 2019
1 parent 6371151 commit 8378eae0e5692744d54f15aee8b7c9351debc178
@@ -376,7 +376,7 @@ QString QgsCircularString::asJson( int precision ) const
return json;
}

json QgsCircularString::asJsonObject(int precision) const
json QgsCircularString::asJsonObject( int precision ) const
{
// GeoJSON does not support curves
std::unique_ptr< QgsLineString > line( curveToLine() );
@@ -300,7 +300,7 @@ QString QgsCompoundCurve::asJson( int precision ) const
return json;
}

json QgsCompoundCurve::asJsonObject(int precision) const
json QgsCompoundCurve::asJsonObject( int precision ) const
{
// GeoJSON does not support curves
std::unique_ptr< QgsLineString > line( curveToLine() );
@@ -430,7 +430,7 @@ QString QgsCurvePolygon::asJson( int precision ) const
return json;
}

json QgsCurvePolygon::asJsonObject(int precision) const
json QgsCurvePolygon::asJsonObject( int precision ) const
{
json coordinates;
if ( exteriorRing() )
@@ -452,7 +452,7 @@ json QgsCurvePolygon::asJsonObject(int precision) const
return
{
{ "type", "Polygon" },
{ "coordinates" , coordinates }
{ "coordinates", coordinates }
};
}

@@ -1270,7 +1270,7 @@ QString QgsGeometry::asJson( int precision ) const
return d->geometry->asJson( precision );
}

json QgsGeometry::asJsonObject(int precision) const
json QgsGeometry::asJsonObject( int precision ) const
{
if ( !d->geometry )
{
@@ -432,7 +432,7 @@ QString QgsGeometryCollection::asJson( int precision ) const
return json;
}

json QgsGeometryCollection::asJsonObject(int precision) const
json QgsGeometryCollection::asJsonObject( int precision ) const
{
json coordinates;
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
@@ -441,8 +441,8 @@ json QgsGeometryCollection::asJsonObject(int precision) const
}
return
{
{ "type" , "GeometryCollection" },
{ "coordinates" , coordinates }
{ "type", "GeometryCollection" },
{ "coordinates", coordinates }
};
}

@@ -1214,7 +1214,7 @@ QJsonArray QgsGeometryUtils::pointsToJsonObject( const QgsPointSequence &points,
return coordinates;
}

json QgsGeometryUtils::pointsToJson(const QgsPointSequence& points, int precision)
json QgsGeometryUtils::pointsToJson( const QgsPointSequence &points, int precision )
{
json coordinates;
for ( const QgsPoint &p : points )
@@ -420,14 +420,14 @@ QString QgsLineString::asJson( int precision ) const
return "{\"type\": \"LineString\", \"coordinates\": " + QgsGeometryUtils::pointsToJSON( pts, precision ) + '}';
}

json QgsLineString::asJsonObject(int precision) const
json QgsLineString::asJsonObject( int precision ) const
{
QgsPointSequence pts;
points( pts );
return
{
{ "type", "LineString" },
{ "coordinates" , QgsGeometryUtils::pointsToJson( pts, precision ) }
{ "coordinates", QgsGeometryUtils::pointsToJson( pts, precision ) }
};
}

@@ -132,7 +132,7 @@ QString QgsMultiCurve::asJson( int precision ) const
return json;
}

json QgsMultiCurve::asJsonObject(int precision) const
json QgsMultiCurve::asJsonObject( int precision ) const
{
json coordinates;
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
@@ -147,7 +147,7 @@ json QgsMultiCurve::asJsonObject(int precision) const
}
return
{
{ "type" , "MultiLineString" },
{ "type", "MultiLineString" },
{ "coordinates", coordinates }
};
}
@@ -119,7 +119,7 @@ QString QgsMultiLineString::asJson( int precision ) const
return json;
}

json QgsMultiLineString::asJsonObject(int precision) const
json QgsMultiLineString::asJsonObject( int precision ) const
{
json coordinates;
for ( const QgsAbstractGeometry *geom : mGeometries )
@@ -135,7 +135,7 @@ json QgsMultiLineString::asJsonObject(int precision) const
return
{
{ "type", "MultiLineString" },
{ "coordinates" , coordinates }
{ "coordinates", coordinates }
};
}

@@ -38,7 +38,7 @@ class CORE_EXPORT QgsMultiLineString: public QgsMultiCurve
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17) const override SIP_SKIP;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;
bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override;
bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override;

@@ -130,19 +130,20 @@ QString QgsMultiPoint::asJson( int precision ) const
return json;
}

json QgsMultiPoint::asJsonObject(int precision) const
json QgsMultiPoint::asJsonObject( int precision ) const
{
json j {
{ "type", "MultiPoint" },
{ "coordinates", json::array() },
};
json j
{
{ "type", "MultiPoint" },
{ "coordinates", json::array() },
};
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
{
const QgsPoint *point = static_cast<const QgsPoint *>( geom );
if ( point->is3D() )
j[ "coordinates" ].push_back( { qgsRound( point->x(), precision ), qgsRound( point->y(), precision ), qgsRound( point->z(), precision ) } );
else
j[ "coordinates" ].push_back( { qgsRound( point->x(), precision ), qgsRound( point->y(), precision ) } );
j[ "coordinates" ].push_back( { qgsRound( point->x(), precision ), qgsRound( point->y(), precision ) } );
}
return j;
}
@@ -140,7 +140,7 @@ QString QgsMultiPolygon::asJson( int precision ) const
}


json QgsMultiPolygon::asJsonObject(int precision) const
json QgsMultiPolygon::asJsonObject( int precision ) const
{
json polygons;
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
@@ -150,7 +150,7 @@ QString QgsMultiSurface::asJson( int precision ) const
return json;
}

json QgsMultiSurface::asJsonObject(int precision) const
json QgsMultiSurface::asJsonObject( int precision ) const
{
json coordinates;
for ( const QgsAbstractGeometry *geom : qgis::as_const( mGeometries ) )
@@ -175,7 +175,7 @@ json QgsMultiSurface::asJsonObject(int precision) const
}
return
{
{ "type" , "MultiPolygon" },
{ "type", "MultiPolygon" },
{ "coordinates", coordinates }
};
}
@@ -38,7 +38,7 @@ class CORE_EXPORT QgsMultiSurface: public QgsGeometryCollection
QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
QString asJson( int precision = 17 ) const override;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;
json asJsonObject( int precision = 17 ) const override SIP_SKIP;
bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override;
bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override;
QgsAbstractGeometry *boundary() const override SIP_FACTORY;
@@ -287,15 +287,16 @@ QString QgsPoint::asJson( int precision ) const
{
return "{\"type\": \"Point\", \"coordinates\": ["
+ qgsDoubleToString( mX, precision ) + QLatin1String( ", " ) + qgsDoubleToString( mY, precision )
+ QLatin1String( "]}" );
+ QLatin1String( "]}" );
}

json QgsPoint::asJsonObject(int precision) const
json QgsPoint::asJsonObject( int precision ) const
{
json j {
{ "type", "Point" },
{ "coordinates", { qgsRound( mX, precision ), qgsRound( mY, precision ) } },
};
json j
{
{ "type", "Point" },
{ "coordinates", { qgsRound( mX, precision ), qgsRound( mY, precision ) } },
};
if ( is3D() )
{
j["coordinates"].push_back( qgsRound( mZ, precision ) );
@@ -236,9 +236,10 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian
return s;
}

json QgsJsonExporter::exportFeatureToJsonObject( const QgsFeature& feature, const QVariantMap& extraProperties, const QVariant& id) const
json QgsJsonExporter::exportFeatureToJsonObject( const QgsFeature &feature, const QVariantMap &extraProperties, const QVariant &id ) const
{
json featureJson {
json featureJson
{
{ "type", "Feature" },
};
if ( id.isValid() )
@@ -270,10 +271,13 @@ json QgsJsonExporter::exportFeatureToJsonObject( const QgsFeature& feature, cons

if ( QgsWkbTypes::flatType( geom.wkbType() ) != QgsWkbTypes::Point )
{
featureJson[ "bbox" ] = { { box.xMinimum(),
featureJson[ "bbox" ] = { {
box.xMinimum(),
box.yMinimum(),
box.xMaximum(),
box.yMaximum() } };
box.yMaximum()
}
};
}
featureJson[ "geometry" ] = geom.asJsonObject( mPrecision );
}
@@ -484,10 +488,10 @@ QVariantList QgsJsonUtils::parseArray( const QString &json, QVariant::Type type
return result;
}

json QgsJsonUtils::jsonFromVariant(const QVariant& val)
json QgsJsonUtils::jsonFromVariant( const QVariant &val )
{

switch (val.userType())
switch ( val.userType() )
{
case QMetaType::Int:
case QMetaType::UInt:
@@ -502,7 +506,7 @@ json QgsJsonUtils::jsonFromVariant(const QVariant& val)
}
}

json QgsJsonUtils::exportAttributesToJsonObject(const QgsFeature& feature, QgsVectorLayer* layer, const QVector<QVariant>& attributeWidgetCaches)
json QgsJsonUtils::exportAttributesToJsonObject( const QgsFeature &feature, QgsVectorLayer *layer, const QVector<QVariant> &attributeWidgetCaches )
{
QgsFields fields = feature.fields();
json attrs;
@@ -516,8 +520,8 @@ json QgsJsonUtils::exportAttributesToJsonObject(const QgsFeature& feature, QgsVe
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
if ( fieldFormatter != QgsApplication::fieldFormatterRegistry()->fallbackFieldFormatter() )
val = fieldFormatter->representValue( layer, i, setup.config(), attributeWidgetCaches.count() >= i ? attributeWidgetCaches.at( i ) : QVariant(), val );
}
attrs[fields.at( i ).name().toStdString()] = jsonFromVariant(val);
}
attrs[fields.at( i ).name().toStdString()] = jsonFromVariant( val );
}
return attrs;
}
@@ -216,8 +216,8 @@ class CORE_EXPORT QgsJsonExporter
* \see exportFeatures()
*/
json exportFeatureToJsonObject( const QgsFeature &feature,
const QVariantMap &extraProperties = QVariantMap(),
const QVariant &id = QVariant() ) const SIP_SKIP;
const QVariantMap &extraProperties = QVariantMap(),
const QVariant &id = QVariant() ) const SIP_SKIP;


/**
@@ -332,7 +332,7 @@ class CORE_EXPORT QgsJsonUtils
*/
static QVariantList parseArray( const QString &json, QVariant::Type type );

static json jsonFromVariant( const QVariant &v) SIP_SKIP;
static json jsonFromVariant( const QVariant &v ) SIP_SKIP;


};
@@ -22,13 +22,14 @@
class TestQgsJsonUtils : public QObject
{

public:
public:

enum JsonAlgs {
Json,
String
};
Q_ENUM(JsonAlgs)
enum JsonAlgs
{
Json,
String
};
Q_ENUM( JsonAlgs )

Q_OBJECT
private slots:
@@ -105,7 +106,7 @@ class TestQgsJsonUtils : public QObject
QBENCHMARK
{
json j { QgsJsonUtils::exportAttributesToJsonObject( feature, &vl ) };
QCOMPARE( QString::fromStdString( j.dump() ), QStringLiteral(R"raw({"flddbl":2.0,"fldint":1,"fldtxt":"a value"})raw" ) );
QCOMPARE( QString::fromStdString( j.dump() ), QStringLiteral( R"raw({"flddbl":2.0,"fldint":1,"fldtxt":"a value"})raw" ) );
}
}
else // 0.0032
@@ -143,11 +144,11 @@ class TestQgsJsonUtils : public QObject
{
const auto j { exporter.exportFeatureToJsonObject( feature ) };
QCOMPARE( QString::fromStdString( j.dump() ), QStringLiteral( "{\"bbox\":[[1.12,1.12,5.45,5.33]],\"geometry\":{\"coordinates\":"
"[[[1.12,1.34],[5.45,1.12],[5.34,5.33],[1.56,5.2],[1.12,1.34]],"
"[[2.0,2.0],[3.0,2.0],[3.0,3.0],[2.0,3.0],[2.0,2.0]]],\"type\":\"Polygon\"}"
",\"id\":0,\"properties\":{\"flddbl\":2.0,\"fldint\":1,\"fldtxt\":\"a value\"}"
",\"type\":\"Feature\"}"
) );
"[[[1.12,1.34],[5.45,1.12],[5.34,5.33],[1.56,5.2],[1.12,1.34]],"
"[[2.0,2.0],[3.0,2.0],[3.0,3.0],[2.0,3.0],[2.0,2.0]]],\"type\":\"Polygon\"}"
",\"id\":0,\"properties\":{\"flddbl\":2.0,\"fldint\":1,\"fldtxt\":\"a value\"}"
",\"type\":\"Feature\"}"
) );
}
}
else

0 comments on commit 8378eae

Please sign in to comment.
You can’t perform that action at this time.