@@ -455,8 +455,8 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
455
455
const QgsFields& fields = layer->pendingFields ();
456
456
for ( int idx = 0 ; idx < fields.count (); ++idx )
457
457
{
458
-
459
- QString attributeName = fields. at ( idx ) .name ();
458
+ const QgsField field = fields. at ( idx );
459
+ QString attributeName = field .name ();
460
460
// skip attribute if excluded from WFS publication
461
461
if ( layerExcludedAttributes.contains ( attributeName ) )
462
462
{
@@ -466,27 +466,57 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
466
466
// xsd:element
467
467
QDomElement attElem = doc.createElement ( " element" /* xsd:element*/ );
468
468
attElem.setAttribute ( " name" , attributeName.replace ( " " , " _" ).replace ( mCleanTagNameRegExp , " " ) );
469
- QVariant::Type attributeType = fields[idx] .type ();
469
+ QVariant::Type attributeType = field .type ();
470
470
if ( attributeType == QVariant::Int )
471
- attElem.setAttribute ( " type" , " integer" );
471
+ {
472
+ attElem.setAttribute ( " type" , " int" );
473
+ }
474
+ else if ( attributeType == QVariant::UInt )
475
+ {
476
+ attElem.setAttribute ( " type" , " unsignedInt" );
477
+ }
472
478
else if ( attributeType == QVariant::LongLong )
479
+ {
473
480
attElem.setAttribute ( " type" , " long" );
481
+ }
482
+ else if ( attributeType == QVariant::ULongLong )
483
+ {
484
+ attElem.setAttribute ( " type" , " unsignedLong" );
485
+ }
474
486
else if ( attributeType == QVariant::Double )
475
- attElem.setAttribute ( " type" , " double" );
487
+ {
488
+ // if the size is well known, it may be an integer
489
+ // else a decimal
490
+ // in sqlite the length is unknown but int type can be used
491
+ if ( field.length () != 0 && field.precision () == 0 )
492
+ attElem.setAttribute ( " type" , " integer" );
493
+ else
494
+ attElem.setAttribute ( " type" , " decimal" );
495
+ }
476
496
else if ( attributeType == QVariant::Bool )
497
+ {
477
498
attElem.setAttribute ( " type" , " boolean" );
499
+ }
478
500
else if ( attributeType == QVariant::Date )
501
+ {
479
502
attElem.setAttribute ( " type" , " date" );
503
+ }
480
504
else if ( attributeType == QVariant::Time )
505
+ {
481
506
attElem.setAttribute ( " type" , " time" );
507
+ }
482
508
else if ( attributeType == QVariant::DateTime )
509
+ {
483
510
attElem.setAttribute ( " type" , " dateTime" );
511
+ }
484
512
else
513
+ {
485
514
attElem.setAttribute ( " type" , " string" );
515
+ }
486
516
487
517
sequenceElem.appendChild ( attElem );
488
518
489
- QString alias = fields. at ( idx ) .alias ();
519
+ QString alias = field .alias ();
490
520
if ( !alias.isEmpty () )
491
521
{
492
522
attElem.setAttribute ( " alias" , alias );
0 commit comments