Skip to content
Permalink
Browse files

displayString on textoutput

but only works if json contains a map...

and codestyle in python
  • Loading branch information
signedav authored and nyalldawson committed Sep 14, 2018
1 parent e972e21 commit 8d4ffac671eaf9904e973c3a98c879ac9a6b915d
@@ -23,6 +23,8 @@
#include <QDataStream>
#include <QIcon>
#include <QLocale>
#include <QJsonDocument>
#include <QJsonObject>

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
@@ -253,10 +255,13 @@ QString QgsField::displayString( const QVariant &v ) const
if ( ok )
return QLocale().toString( converted );
}
else if ( d->typeName.compare( "json" ) == 0 )
else if ( d->typeName.compare( "json" ) == 0 || d->typeName.compare( "jsonb" ) == 0 )
{
//QJsonDocument jsonDocument = variable.toJsonDocument();
//return QString::fromUtf8( jsonDocument.toJson() );
//this works only if the json/jsonb field contains a map - this has to be improved.
//toJsonDocument works only if the usertype is QJsonDocument
QJsonValue value = QJsonValue::fromVariant( v );
QJsonDocument doc( value.toObject() );
return QString::fromUtf8( doc.toJson( QJsonDocument::Indented ).data() );
}
// Fallback if special rules do not apply
return v.toString();
@@ -44,5 +44,5 @@ QgsEditorConfigWidget *QgsListWidgetFactory::configWidget( QgsVectorLayer *vl, i
unsigned int QgsListWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
{
const QgsField field = vl->fields().field( fieldIdx );
return ( field.type() == QVariant::List || field.type() == QVariant::StringList ) && field.subType() != QVariant::Invalid ? 20 : 0;
return ( field.type() == QVariant::List || field.type() == QVariant::StringList || field.typeName().compare( QLatin1String( "json" ) ) == 0 || field.typeName().compare( QLatin1String( "jsonb" ) ) == 0 ) && field.subType() != QVariant::Invalid ? 20 : 0;
}
@@ -124,16 +124,16 @@ class TestQgsPostgresProvider: public QObject
qDebug() << "actual: " << decoded;
QCOMPARE( decoded.toMap(), expected );
}
/* now working yet
/*
void decodeJsonInt()
{
const QVariant decoded = QgsPostgresProvider::convertValue( QVariant::Map, QVariant::String, QStringLiteral( "'123'" ), QStringLiteral( "json" ) );
QCOMPARE( decoded.type(), QVariant::Int );
int expected;
expected=123;
expected="'123'";
qDebug() << "actual: " << decoded;
QCOMPARE( decoded.toInt(), expected );
QCOMPARE( decoded., expected );
}
void decodeJsonbInt()
{

0 comments on commit 8d4ffac

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