mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
switch to QgsJsonUtils + QStringLiterals + typo
This commit is contained in:
parent
6f746b557e
commit
ccaf379ef8
@ -35,7 +35,7 @@ class QgsRectangle;
|
||||
class CORE_EXPORT QgsMBTilesReader
|
||||
{
|
||||
public:
|
||||
//! Contructs MBTiles reader (but it does not open the file yet)
|
||||
//! Constructs MBTiles reader (but it does not open the file yet)
|
||||
explicit QgsMBTilesReader( const QString &filename );
|
||||
|
||||
//! Tries to open the file, returns true on success
|
||||
|
@ -17,17 +17,18 @@
|
||||
|
||||
#include "qgsdatasourceuri.h"
|
||||
#include "qgsfeedback.h"
|
||||
#include "qgsjsonutils.h"
|
||||
#include "qgsmbtilesreader.h"
|
||||
#include "qgstiles.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectortilemvtencoder.h"
|
||||
#include "qgsvectortileutils.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QUrl>
|
||||
|
||||
|
||||
@ -196,38 +197,36 @@ bool QgsVectorTileWriter::writeTileFileXYZ( const QString &sourcePath, QgsTileXY
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString QgsVectorTileWriter::mbtilesJsonSchema()
|
||||
{
|
||||
QJsonArray arrayLayers;
|
||||
QVariantList arrayLayers;
|
||||
for ( const Layer &layer : qgis::as_const( mLayers ) )
|
||||
{
|
||||
QgsVectorLayer *vl = layer.layer();
|
||||
const QgsFields fields = vl->fields();
|
||||
|
||||
QJsonObject fieldsObj;
|
||||
QVariantMap fieldsObj;
|
||||
for ( const QgsField &field : fields )
|
||||
{
|
||||
QString fieldTypeStr;
|
||||
if ( field.type() == QVariant::Bool )
|
||||
fieldTypeStr = "Boolean";
|
||||
fieldTypeStr = QStringLiteral( "Boolean" );
|
||||
else if ( field.type() == QVariant::Int || field.type() == QVariant::Double )
|
||||
fieldTypeStr = "Number";
|
||||
fieldTypeStr = QStringLiteral( "Number" );
|
||||
else
|
||||
fieldTypeStr = "String";
|
||||
fieldTypeStr = QStringLiteral( "String" );
|
||||
|
||||
fieldsObj["field"] = fieldTypeStr;
|
||||
fieldsObj[field.name()] = fieldTypeStr;
|
||||
}
|
||||
|
||||
QJsonObject layerObj;
|
||||
QVariantMap layerObj;
|
||||
layerObj["id"] = vl->name();
|
||||
layerObj["fields"] = fieldsObj;
|
||||
arrayLayers.append( layerObj );
|
||||
}
|
||||
|
||||
QJsonObject rootObj;
|
||||
QVariantMap rootObj;
|
||||
rootObj["vector_layers"] = arrayLayers;
|
||||
|
||||
QJsonDocument doc;
|
||||
doc.setObject( rootObj );
|
||||
return doc.toJson();
|
||||
return QString::fromStdString( QgsJsonUtils::jsonFromVariant( rootObj ).dump() );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user