Skip to content

Commit

Permalink
[Server][WFS] Set correctly attribute type for number fields in XSD
Browse files Browse the repository at this point in the history
Replace `double` by `decimal`

Use `int`, `unsignedInt`, `long` and `unsignedLong` for `QVariant::Int`, `QVariant::UInt`, `QVariant::LongLong` and `QVariant::ULongLong`

Define double with 0 precision to `integer`
  • Loading branch information
rldhont committed Sep 26, 2018
1 parent 5047571 commit 6de6c08
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/server/services/wfs/qgswfsdescribefeaturetype.cpp
Expand Up @@ -251,8 +251,8 @@ namespace QgsWfs
const QSet<QString> &layerExcludedAttributes = layer->excludeAttributesWfs();
for ( int idx = 0; idx < fields.count(); ++idx )
{

QString attributeName = fields.at( idx ).name();
const QgsField field = fields.at( idx );
QString attributeName = field.name();
//skip attribute if excluded from WFS publication
if ( layerExcludedAttributes.contains( attributeName ) )
{
Expand All @@ -262,27 +262,54 @@ namespace QgsWfs
//xsd:element
QDomElement attElem = doc.createElement( QStringLiteral( "element" )/*xsd:element*/ );
attElem.setAttribute( QStringLiteral( "name" ), attributeName.replace( ' ', '_' ).replace( cleanTagNameRegExp, QString() ) );
QVariant::Type attributeType = fields.at( idx ).type();
QVariant::Type attributeType = field.type();
if ( attributeType == QVariant::Int )
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "integer" ) );
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "int" ) );
}
else if ( attributeType == QVariant::UInt )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "unsignedInt" ) );
}
else if ( attributeType == QVariant::LongLong )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "long" ) );
}
else if ( attributeType == QVariant::ULongLong )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "unsignedLong" ) );
}
else if ( attributeType == QVariant::Double )
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "double" ) );
{
if ( field.length() != 0 && field.precision() == 0 )
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "integer" ) );
else
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "decimal" ) );
}
else if ( attributeType == QVariant::Bool )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "boolean" ) );
}
else if ( attributeType == QVariant::Date )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "date" ) );
}
else if ( attributeType == QVariant::Time )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "time" ) );
}
else if ( attributeType == QVariant::DateTime )
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "dateTime" ) );
}
else
{
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "string" ) );
}

sequenceElem.appendChild( attElem );

QString alias = fields.at( idx ).alias();
QString alias = field.alias();
if ( !alias.isEmpty() )
{
attElem.setAttribute( QStringLiteral( "alias" ), alias );
Expand Down

0 comments on commit 6de6c08

Please sign in to comment.