Skip to content
Permalink
Browse files

[Server][WFS] Set correctly attribute type for number fields in XSD

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 14, 2018
1 parent ff5bd09 commit 00d81e087012caa5489dff3c262b3e4b44700797
Showing with 36 additions and 6 deletions.
  1. +36 −6 src/server/qgswfsprojectparser.cpp
@@ -455,8 +455,8 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
const QgsFields& fields = layer->pendingFields();
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 ) )
{
@@ -466,27 +466,57 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
//xsd:element
QDomElement attElem = doc.createElement( "element"/*xsd:element*/ );
attElem.setAttribute( "name", attributeName.replace( " ", "_" ).replace( mCleanTagNameRegExp, "" ) );
QVariant::Type attributeType = fields[idx].type();
QVariant::Type attributeType = field.type();
if ( attributeType == QVariant::Int )
attElem.setAttribute( "type", "integer" );
{
attElem.setAttribute( "type", "int" );
}
else if ( attributeType == QVariant::UInt )
{
attElem.setAttribute( "type", "unsignedInt" );
}
else if ( attributeType == QVariant::LongLong )
{
attElem.setAttribute( "type", "long" );
}
else if ( attributeType == QVariant::ULongLong )
{
attElem.setAttribute( "type", "unsignedLong" );
}
else if ( attributeType == QVariant::Double )
attElem.setAttribute( "type", "double" );
{
// if the size is well known, it may be an integer
// else a decimal
// in sqlite the length is unknown but int type can be used
if ( field.length() != 0 && field.precision() == 0 )
attElem.setAttribute( "type", "integer" );
else
attElem.setAttribute( "type", "decimal" );
}
else if ( attributeType == QVariant::Bool )
{
attElem.setAttribute( "type", "boolean" );
}
else if ( attributeType == QVariant::Date )
{
attElem.setAttribute( "type", "date" );
}
else if ( attributeType == QVariant::Time )
{
attElem.setAttribute( "type", "time" );
}
else if ( attributeType == QVariant::DateTime )
{
attElem.setAttribute( "type", "dateTime" );
}
else
{
attElem.setAttribute( "type", "string" );
}

sequenceElem.appendChild( attElem );

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

0 comments on commit 00d81e0

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