30
30
#include " qgsvectordataprovider.h"
31
31
#include " qgsmapserviceexception.h"
32
32
#include " qgscoordinatereferencesystem.h"
33
+ #include " qgsfieldformatterregistry.h"
34
+ #include " qgsfieldformatter.h"
35
+ #include " qgsdatetimefieldformatter.h"
33
36
34
37
#include < QStringList>
35
38
@@ -251,8 +254,8 @@ namespace QgsWfs
251
254
const QSet<QString> &layerExcludedAttributes = layer->excludeAttributesWfs ();
252
255
for ( int idx = 0 ; idx < fields.count (); ++idx )
253
256
{
254
-
255
- QString attributeName = fields. at ( idx ) .name ();
257
+ const QgsField field = fields. at ( idx );
258
+ QString attributeName = field .name ();
256
259
// skip attribute if excluded from WFS publication
257
260
if ( layerExcludedAttributes.contains ( attributeName ) )
258
261
{
@@ -262,27 +265,86 @@ namespace QgsWfs
262
265
// xsd:element
263
266
QDomElement attElem = doc.createElement ( QStringLiteral ( " element" )/* xsd:element*/ );
264
267
attElem.setAttribute ( QStringLiteral ( " name" ), attributeName.replace ( ' ' , ' _' ).replace ( cleanTagNameRegExp, QString () ) );
265
- QVariant::Type attributeType = fields. at ( idx ) .type ();
268
+ QVariant::Type attributeType = field .type ();
266
269
if ( attributeType == QVariant::Int )
267
- attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " integer" ) );
270
+ {
271
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " int" ) );
272
+ }
273
+ else if ( attributeType == QVariant::UInt )
274
+ {
275
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " unsignedInt" ) );
276
+ }
268
277
else if ( attributeType == QVariant::LongLong )
278
+ {
269
279
attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " long" ) );
280
+ }
281
+ else if ( attributeType == QVariant::ULongLong )
282
+ {
283
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " unsignedLong" ) );
284
+ }
270
285
else if ( attributeType == QVariant::Double )
271
- attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " double" ) );
286
+ {
287
+ if ( field.length () != 0 && field.precision () == 0 )
288
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " integer" ) );
289
+ else
290
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " decimal" ) );
291
+ }
272
292
else if ( attributeType == QVariant::Bool )
293
+ {
273
294
attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " boolean" ) );
295
+ }
274
296
else if ( attributeType == QVariant::Date )
297
+ {
275
298
attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " date" ) );
299
+ }
276
300
else if ( attributeType == QVariant::Time )
301
+ {
277
302
attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " time" ) );
303
+ }
278
304
else if ( attributeType == QVariant::DateTime )
305
+ {
279
306
attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " dateTime" ) );
307
+ }
280
308
else
309
+ {
281
310
attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " string" ) );
311
+ }
312
+
313
+ const QgsEditorWidgetSetup setup = field.editorWidgetSetup ();
314
+ if ( setup.type () == QStringLiteral ( " DateTime" ) )
315
+ {
316
+ QgsDateTimeFieldFormatter fieldFormatter;
317
+ const QVariantMap config = setup.config ();
318
+ const QString fieldFormat = config.value ( QStringLiteral ( " field_format" ), fieldFormatter.defaultFormat ( field.type () ) ).toString ();
319
+ if ( fieldFormat == QStringLiteral ( " yyyy-MM-dd" ) )
320
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " date" ) );
321
+ else if ( fieldFormat == QStringLiteral ( " HH:mm:ss" ) )
322
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " time" ) );
323
+ else
324
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " dateTime" ) );
325
+ }
326
+ else if ( setup.type () == QStringLiteral ( " Range" ) )
327
+ {
328
+ const QVariantMap config = setup.config ();
329
+ if ( config.contains ( QStringLiteral ( " Precision" ) ) )
330
+ {
331
+ // if precision in range config is not the same as the attributePrec
332
+ // we need to update type
333
+ bool ok;
334
+ int configPrec ( config[ QStringLiteral ( " Precision" ) ].toInt ( &ok ) );
335
+ if ( ok && configPrec != field.precision () )
336
+ {
337
+ if ( configPrec == 0 )
338
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " integer" ) );
339
+ else
340
+ attElem.setAttribute ( QStringLiteral ( " type" ), QStringLiteral ( " decimal" ) );
341
+ }
342
+ }
343
+ }
282
344
283
345
sequenceElem.appendChild ( attElem );
284
346
285
- QString alias = fields. at ( idx ) .alias ();
347
+ QString alias = field .alias ();
286
348
if ( !alias.isEmpty () )
287
349
{
288
350
attElem.setAttribute ( QStringLiteral ( " alias" ), alias );
0 commit comments