Skip to content

Commit

Permalink
Rename QgsJSONExporter/Utils to QgsJsonExporter/Utils
Browse files Browse the repository at this point in the history
Follows proper QGIS/Qt capitalization convention
  • Loading branch information
nyalldawson committed May 24, 2017
1 parent 4b33e2f commit 5b0bc93
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .ci/travis/linux/blacklist.txt
@@ -1,5 +1,5 @@
# black list
PyQgsJSONUtils
PyQgsJsonUtils
PyQgsLocalServer
PyQgsPalLabelingServer
qgis_composermapgridtest
Expand Down
2 changes: 2 additions & 0 deletions doc/api_break.dox
Expand Up @@ -104,6 +104,8 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsGraduatedSymbolRendererV2Model<td>QgsGraduatedSymbolRendererModel
<tr><td>QgsGraduatedSymbolRendererV2ViewStyle<td>QgsGraduatedSymbolRendererViewStyle
<tr><td>QgsGraduatedSymbolRendererV2Widget<td>QgsGraduatedSymbolRendererWidget
<tr><td>QgsJSONExporter<td>QgsJsonExporter
<tr><td>QgsJSONUtils<td>QgsJsonUtils
<tr><td>QgsLabelingEngineV2<td>QgsLabelingEngine
<tr><td>QgsLegendModelV2<td>QgsLegendModel
<tr><td>QgsLegendSymbolItemV2<td>QgsLegendSymbolItem
Expand Down
8 changes: 4 additions & 4 deletions python/core/qgsjsonutils.sip
Expand Up @@ -10,7 +10,7 @@



class QgsJSONExporter
class QgsJsonExporter
{
%Docstring
Handles exporting QgsFeature features to GeoJSON features.
Expand All @@ -25,9 +25,9 @@ class QgsJSONExporter
%End
public:

QgsJSONExporter( QgsVectorLayer *vectorLayer = 0, int precision = 6 );
QgsJsonExporter( QgsVectorLayer *vectorLayer = 0, int precision = 6 );
%Docstring
Constructor for QgsJSONExporter.
Constructor for QgsJsonExporter.
\param vectorLayer associated vector layer (required for related attribute export)
\param precision maximum number of decimal places to use for geometry coordinates,
the RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
Expand Down Expand Up @@ -199,7 +199,7 @@ class QgsJSONExporter
};


class QgsJSONUtils
class QgsJsonUtils
{
%Docstring
Helper utilities for working with JSON and GeoJSON conversions.
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsclipboard.cpp
Expand Up @@ -142,7 +142,7 @@ QString QgsClipboard::generateClipboardText() const
}
case GeoJSON:
{
QgsJSONExporter exporter;
QgsJsonExporter exporter;
exporter.setSourceCrs( mCRS );
return exporter.exportFeatures( mFeatureClipboard );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerhtml.cpp
Expand Up @@ -551,7 +551,7 @@ void QgsComposerHtml::setExpressionContext( const QgsFeature &feature, QgsVector
}

// create JSON representation of feature
QgsJSONExporter exporter( layer );
QgsJsonExporter exporter( layer );
exporter.setIncludeRelated( true );
mAtlasFeatureJSON = exporter.exportFeature( feature );
}
Expand Down
34 changes: 17 additions & 17 deletions src/core/qgsjsonutils.cpp
Expand Up @@ -29,7 +29,7 @@
#include <QJsonDocument>
#include <QJsonArray>

QgsJSONExporter::QgsJSONExporter( QgsVectorLayer *vectorLayer, int precision )
QgsJsonExporter::QgsJsonExporter( QgsVectorLayer *vectorLayer, int precision )
: mPrecision( precision )
, mIncludeGeometry( true )
, mIncludeAttributes( true )
Expand All @@ -44,7 +44,7 @@ QgsJSONExporter::QgsJSONExporter( QgsVectorLayer *vectorLayer, int precision )
mTransform.setDestinationCrs( QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ) );
}

void QgsJSONExporter::setVectorLayer( QgsVectorLayer *vectorLayer )
void QgsJsonExporter::setVectorLayer( QgsVectorLayer *vectorLayer )
{
mLayer = vectorLayer;
if ( vectorLayer )
Expand All @@ -54,29 +54,29 @@ void QgsJSONExporter::setVectorLayer( QgsVectorLayer *vectorLayer )
}
}

QgsVectorLayer *QgsJSONExporter::vectorLayer() const
QgsVectorLayer *QgsJsonExporter::vectorLayer() const
{
return mLayer.data();
}

void QgsJSONExporter::setSourceCrs( const QgsCoordinateReferenceSystem &crs )
void QgsJsonExporter::setSourceCrs( const QgsCoordinateReferenceSystem &crs )
{
mCrs = crs;
mTransform.setSourceCrs( mCrs );
}

QgsCoordinateReferenceSystem QgsJSONExporter::sourceCrs() const
QgsCoordinateReferenceSystem QgsJsonExporter::sourceCrs() const
{
return mCrs;
}

QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVariantMap &extraProperties,
QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVariantMap &extraProperties,
const QVariant &id ) const
{
QString s = QStringLiteral( "{\n \"type\":\"Feature\",\n" );

// ID
s += QStringLiteral( " \"id\":%1,\n" ).arg( !id.isValid() ? QString::number( feature.id() ) : QgsJSONUtils::encodeValue( id ) );
s += QStringLiteral( " \"id\":%1,\n" ).arg( !id.isValid() ? QString::number( feature.id() ) : QgsJsonUtils::encodeValue( id ) );

QgsGeometry geom = feature.geometry();
if ( !geom.isNull() && mIncludeGeometry )
Expand Down Expand Up @@ -140,7 +140,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
val = fieldFormatter->representValue( mLayer.data(), i, setup.config(), QVariant(), val );
}

properties += QStringLiteral( " \"%1\":%2" ).arg( fields.at( i ).name(), QgsJSONUtils::encodeValue( val ) );
properties += QStringLiteral( " \"%1\":%2" ).arg( fields.at( i ).name(), QgsJsonUtils::encodeValue( val ) );

++attributeCounter;
}
Expand All @@ -154,7 +154,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
if ( attributeCounter > 0 )
properties += QLatin1String( ",\n" );

properties += QStringLiteral( " \"%1\":%2" ).arg( it.key(), QgsJSONUtils::encodeValue( it.value() ) );
properties += QStringLiteral( " \"%1\":%2" ).arg( it.key(), QgsJsonUtils::encodeValue( it.value() ) );

++attributeCounter;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
if ( relationFeatures > 0 )
relatedFeatureAttributes += QLatin1String( ",\n" );

relatedFeatureAttributes += QgsJSONUtils::exportAttributes( relatedFet, childLayer, attributeWidgetCaches );
relatedFeatureAttributes += QgsJsonUtils::exportAttributes( relatedFet, childLayer, attributeWidgetCaches );
relationFeatures++;
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature &feature, const QVarian
return s;
}

QString QgsJSONExporter::exportFeatures( const QgsFeatureList &features ) const
QString QgsJsonExporter::exportFeatures( const QgsFeatureList &features ) const
{
QStringList featureJSON;
Q_FOREACH ( const QgsFeature &feature, features )
Expand All @@ -237,20 +237,20 @@ QString QgsJSONExporter::exportFeatures( const QgsFeatureList &features ) const


//
// QgsJSONUtils
// QgsJsonUtils
//

QgsFeatureList QgsJSONUtils::stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding )
QgsFeatureList QgsJsonUtils::stringToFeatureList( const QString &string, const QgsFields &fields, QTextCodec *encoding )
{
return QgsOgrUtils::stringToFeatureList( string, fields, encoding );
}

QgsFields QgsJSONUtils::stringToFields( const QString &string, QTextCodec *encoding )
QgsFields QgsJsonUtils::stringToFields( const QString &string, QTextCodec *encoding )
{
return QgsOgrUtils::stringToFields( string, encoding );
}

QString QgsJSONUtils::encodeValue( const QVariant &value )
QString QgsJsonUtils::encodeValue( const QVariant &value )
{
if ( value.isNull() )
return QStringLiteral( "null" );
Expand Down Expand Up @@ -287,7 +287,7 @@ QString QgsJSONUtils::encodeValue( const QVariant &value )
}
}

QString QgsJSONUtils::exportAttributes( const QgsFeature &feature, QgsVectorLayer *layer, QVector<QVariant> attributeWidgetCaches )
QString QgsJsonUtils::exportAttributes( const QgsFeature &feature, QgsVectorLayer *layer, QVector<QVariant> attributeWidgetCaches )
{
QgsFields fields = feature.fields();
QString attrs;
Expand All @@ -311,7 +311,7 @@ QString QgsJSONUtils::exportAttributes( const QgsFeature &feature, QgsVectorLaye
return attrs.prepend( '{' ).append( '}' );
}

QVariantList QgsJSONUtils::parseArray( const QString &json, QVariant::Type type )
QVariantList QgsJsonUtils::parseArray( const QString &json, QVariant::Type type )
{
QJsonParseError error;
const QJsonDocument jsonDoc = QJsonDocument::fromJson( json.toUtf8(), &error );
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsjsonutils.h
Expand Up @@ -26,24 +26,24 @@
class QTextCodec;

/** \ingroup core
* \class QgsJSONExporter
* \class QgsJsonExporter
* \brief Handles exporting QgsFeature features to GeoJSON features.
*
* Note that geometries will be automatically reprojected to WGS84 to match GeoJSON spec
* if either the source vector layer or source CRS is set.
* \since QGIS 2.16
*/

class CORE_EXPORT QgsJSONExporter
class CORE_EXPORT QgsJsonExporter
{
public:

/** Constructor for QgsJSONExporter.
/** Constructor for QgsJsonExporter.
* \param vectorLayer associated vector layer (required for related attribute export)
* \param precision maximum number of decimal places to use for geometry coordinates,
* the RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
*/
QgsJSONExporter( QgsVectorLayer *vectorLayer = nullptr, int precision = 6 );
QgsJsonExporter( QgsVectorLayer *vectorLayer = nullptr, int precision = 6 );

/** Sets the maximum number of decimal places to use in geometry coordinates.
* The RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
Expand Down Expand Up @@ -203,12 +203,12 @@ class CORE_EXPORT QgsJSONExporter
};

/** \ingroup core
* \class QgsJSONUtils
* \class QgsJsonUtils
* \brief Helper utilities for working with JSON and GeoJSON conversions.
* \since QGIS 2.16
*/

class CORE_EXPORT QgsJSONUtils
class CORE_EXPORT QgsJsonUtils
{
public:

Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Expand Up @@ -543,7 +543,7 @@ QVariant QgsSpatiaLiteFeatureIterator::getFeatureAttribute( sqlite3_stmt *stmt,
if ( type == QVariant::List || type == QVariant::StringList )
{
// assume arrays are stored as JSON
QVariant result = QVariant( QgsJSONUtils::parseArray( txt, subType ) );
QVariant result = QVariant( QgsJsonUtils::parseArray( txt, subType ) );
result.convert( type );
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -3956,7 +3956,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList &flist )
}
else if ( type == QVariant::StringList || type == QVariant::List )
{
const QByteArray ba = QgsJSONUtils::encodeValue( v ).toUtf8();
const QByteArray ba = QgsJsonUtils::encodeValue( v ).toUtf8();
sqlite3_bind_text( stmt, ++ia, ba.constData(), ba.size(), SQLITE_TRANSIENT );
}
else
Expand Down Expand Up @@ -4264,7 +4264,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
else if ( type == QVariant::StringList || type == QVariant::List )
{
// binding an array value
sql += QStringLiteral( "%1=%2" ).arg( quotedIdentifier( fld.name() ), quotedValue( QgsJSONUtils::encodeValue( val ) ) );
sql += QStringLiteral( "%1=%2" ).arg( quotedIdentifier( fld.name() ), quotedValue( QgsJsonUtils::encodeValue( val ) ) );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wfs/qgswfsgetfeature.cpp
Expand Up @@ -993,9 +993,9 @@ namespace QgsWfs
{
QString id = QStringLiteral( "%1.%2" ).arg( typeName, FID_TO_STRING( feat->id() ) );

QgsJSONExporter exporter;
QgsJsonExporter exporter;
exporter.setSourceCrs( crs );
//QgsJSONExporter force transform geometry to ESPG:4326
//QgsJsonExporter force transform geometry to ESPG:4326
//and the RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
Q_UNUSED( prec );
//exporter.setPrecision( prec );
Expand Down
22 changes: 11 additions & 11 deletions tests/src/core/testqgsjsonutils.cpp
Expand Up @@ -16,7 +16,7 @@
#include "qgstest.h"
#include <qgsjsonutils.h>

class TestQgsJSONUtils : public QObject
class TestQgsJsonUtils : public QObject
{
Q_OBJECT
private slots:
Expand All @@ -25,17 +25,17 @@ class TestQgsJSONUtils : public QObject
QStringList list;

{
const QString json = QgsJSONUtils::encodeValue( list );
const QString json = QgsJsonUtils::encodeValue( list );
QCOMPARE( json, QString( "[]" ) );
const QVariant back = QgsJSONUtils::parseArray( json, QVariant::String );
const QVariant back = QgsJsonUtils::parseArray( json, QVariant::String );
QCOMPARE( back.toStringList(), list );
}

{
list << QStringLiteral( "one" ) << QStringLiteral( "<',\"\\>" ) << QStringLiteral( "two" );
const QString json = QgsJSONUtils::encodeValue( list );
const QString json = QgsJsonUtils::encodeValue( list );
QCOMPARE( json, QString( "[\"one\",\"<',\\\"\\\\>\",\"two\"]" ) );
const QVariant back = QgsJSONUtils::parseArray( json, QVariant::String );
const QVariant back = QgsJsonUtils::parseArray( json, QVariant::String );
QCOMPARE( back.toStringList(), list );
}
}
Expand All @@ -46,16 +46,16 @@ class TestQgsJSONUtils : public QObject

{
list << 1 << -2;
const QString json = QgsJSONUtils::encodeValue( list );
const QString json = QgsJsonUtils::encodeValue( list );
QCOMPARE( json, QString( "[1,-2]" ) );
const QVariantList back = QgsJSONUtils::parseArray( json, QVariant::Int );
const QVariantList back = QgsJsonUtils::parseArray( json, QVariant::Int );
QCOMPARE( back, list );
QCOMPARE( back.at( 0 ).type(), QVariant::Int );
}

{
// check invalid entries are ignored
const QVariantList back = QgsJSONUtils::parseArray( QStringLiteral( "[1,\"a\",-2]" ), QVariant::Int );
const QVariantList back = QgsJsonUtils::parseArray( QStringLiteral( "[1,\"a\",-2]" ), QVariant::Int );
QCOMPARE( back, list );
}
}
Expand All @@ -65,13 +65,13 @@ class TestQgsJSONUtils : public QObject
QVariantList list;

list << 1.0 << -2.2456;
const QString json = QgsJSONUtils::encodeValue( list );
const QString json = QgsJsonUtils::encodeValue( list );
QCOMPARE( json, QString( "[1,-2.2456]" ) );
const QVariantList back = QgsJSONUtils::parseArray( json, QVariant::Double );
const QVariantList back = QgsJsonUtils::parseArray( json, QVariant::Double );
QCOMPARE( back, list );
QCOMPARE( back.at( 0 ).type(), QVariant::Double );
}
};

QGSTEST_MAIN( TestQgsJSONUtils )
QGSTEST_MAIN( TestQgsJsonUtils )
#include "testqgsjsonutils.moc"
2 changes: 1 addition & 1 deletion tests/src/python/CMakeLists.txt
Expand Up @@ -66,7 +66,7 @@ ADD_PYTHON_TEST(PyQgsGeometryTest test_qgsgeometry.py)
ADD_PYTHON_TEST(PyQgsGeometryValidator test_qgsgeometryvalidator.py)
ADD_PYTHON_TEST(PyQgsGraduatedSymbolRenderer test_qgsgraduatedsymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsInterval test_qgsinterval.py)
ADD_PYTHON_TEST(PyQgsJSONUtils test_qgsjsonutils.py)
ADD_PYTHON_TEST(PyQgsJsonUtils test_qgsjsonutils.py)
ADD_PYTHON_TEST(PyQgsLayerTreeMapCanvasBridge test_qgslayertreemapcanvasbridge.py)
ADD_PYTHON_TEST(PyQgsLayerTree test_qgslayertree.py)
ADD_PYTHON_TEST(PyQgsLayoutManager test_qgslayoutmanager.py)
Expand Down

0 comments on commit 5b0bc93

Please sign in to comment.