|
22 | 22 | #include "qgswfsutils.h"
|
23 | 23 | #include "qgsserverprojectutils.h"
|
24 | 24 | #include "qgsfields.h"
|
| 25 | +#include "qgsfieldformatterregistry.h" |
| 26 | +#include "qgsfieldformatter.h" |
| 27 | +#include "qgsdatetimefieldformatter.h" |
25 | 28 | #include "qgsexpression.h"
|
26 | 29 | #include "qgsgeometry.h"
|
27 | 30 | #include "qgsmaplayer.h"
|
@@ -62,7 +65,7 @@ namespace QgsWfs
|
62 | 65 |
|
63 | 66 | QString createFeatureGeoJSON( QgsFeature *feat, const createFeatureParams ¶ms );
|
64 | 67 |
|
65 |
| - QString encodeValueToText( const QVariant &value ); |
| 68 | + QString encodeValueToText( const QVariant &value, const QgsEditorWidgetSetup &setup ); |
66 | 69 |
|
67 | 70 | QDomElement createFeatureGML2( QgsFeature *feat, QDomDocument &doc, const createFeatureParams ¶ms, const QgsProject *project );
|
68 | 71 |
|
@@ -1337,10 +1340,12 @@ namespace QgsWfs
|
1337 | 1340 | {
|
1338 | 1341 | continue;
|
1339 | 1342 | }
|
1340 |
| - QString attributeName = fields.at( idx ).name(); |
| 1343 | + const QgsField field = fields.at( idx ); |
| 1344 | + const QgsEditorWidgetSetup setup = field.editorWidgetSetup(); |
| 1345 | + QString attributeName = field.name(); |
1341 | 1346 |
|
1342 | 1347 | QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ).replace( cleanTagNameRegExp, QString() ) );
|
1343 |
| - QDomText fieldText = doc.createTextNode( encodeValueToText( featureAttributes[idx] ) ); |
| 1348 | + QDomText fieldText = doc.createTextNode( encodeValueToText( featureAttributes[idx], setup ) ); |
1344 | 1349 | fieldElem.appendChild( fieldText );
|
1345 | 1350 | typeNameElement.appendChild( fieldElem );
|
1346 | 1351 | }
|
@@ -1432,22 +1437,37 @@ namespace QgsWfs
|
1432 | 1437 | {
|
1433 | 1438 | continue;
|
1434 | 1439 | }
|
1435 |
| - QString attributeName = fields.at( idx ).name(); |
| 1440 | + const QgsField field = fields.at( idx ); |
| 1441 | + const QgsEditorWidgetSetup setup = field.editorWidgetSetup(); |
| 1442 | + QString attributeName = field.name(); |
1436 | 1443 |
|
1437 | 1444 | QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ).replace( cleanTagNameRegExp, QString() ) );
|
1438 |
| - QDomText fieldText = doc.createTextNode( encodeValueToText( featureAttributes[idx] ) ); |
| 1445 | + QDomText fieldText = doc.createTextNode( encodeValueToText( featureAttributes[idx], setup ) ); |
1439 | 1446 | fieldElem.appendChild( fieldText );
|
1440 | 1447 | typeNameElement.appendChild( fieldElem );
|
1441 | 1448 | }
|
1442 | 1449 |
|
1443 | 1450 | return featureElement;
|
1444 | 1451 | }
|
1445 | 1452 |
|
1446 |
| - QString encodeValueToText( const QVariant &value ) |
| 1453 | + QString encodeValueToText( const QVariant &value, const QgsEditorWidgetSetup &setup ) |
1447 | 1454 | {
|
1448 | 1455 | if ( value.isNull() )
|
1449 | 1456 | return QStringLiteral( "null" );
|
1450 | 1457 |
|
| 1458 | + if ( setup.type() == QStringLiteral( "DateTime" ) ) |
| 1459 | + { |
| 1460 | + QgsDateTimeFieldFormatter fieldFormatter; |
| 1461 | + const QVariantMap config = setup.config(); |
| 1462 | + const QString fieldFormat = config.value( QStringLiteral( "field_format" ), fieldFormatter.defaultFormat( value.type() ) ).toString(); |
| 1463 | + QDateTime date = value.toDateTime(); |
| 1464 | + |
| 1465 | + if ( date.isValid() ) |
| 1466 | + { |
| 1467 | + return date.toString( fieldFormat ); |
| 1468 | + } |
| 1469 | + } |
| 1470 | + |
1451 | 1471 | switch ( value.type() )
|
1452 | 1472 | {
|
1453 | 1473 | case QVariant::Int:
|
|
0 commit comments