22
22
QgsWFSDataSourceURI::QgsWFSDataSourceURI ( const QString &uri )
23
23
: mURI( uri )
24
24
{
25
+ typedef QPair<QString, QString> queryItem;
26
+
25
27
// Compatibility with QGIS < 2.16 layer URI of the format
26
28
// http://example.com/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=x&SRSNAME=y&username=foo&password=
27
29
if ( !mURI .hasParam ( QgsWFSConstants::URI_PARAM_URL ) )
28
30
{
29
31
QUrl url ( uri );
30
32
// Transform all param keys to lowercase
31
- typedef QPair<QString, QString> queryItem;
32
33
QList<queryItem> items ( url.queryItems () );
33
34
Q_FOREACH ( const queryItem &item, items )
34
35
{
@@ -41,6 +42,7 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString &uri )
41
42
QString typeName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_TYPENAME );
42
43
QString version = url.queryItemValue ( QgsWFSConstants::URI_PARAM_VERSION );
43
44
QString filter = url.queryItemValue ( QgsWFSConstants::URI_PARAM_FILTER );
45
+ QString outputFormat = url.queryItemValue ( QgsWFSConstants::URI_PARAM_OUTPUTFORMAT );
44
46
mAuth .mAuthCfg = url.queryItemValue ( QgsWFSConstants::URI_PARAM_AUTHCFG );
45
47
// NOTE: A defined authcfg overrides any older username/password auth
46
48
// Only check for older auth if it is undefined
@@ -56,13 +58,14 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString &uri )
56
58
}
57
59
58
60
// Now remove all stuff that is not the core URL
59
- url.removeQueryItem ( QStringLiteral ( " SERVICE" ) );
60
- url.removeQueryItem ( QStringLiteral ( " VERSION" ) );
61
- url.removeQueryItem ( QStringLiteral ( " TYPENAME" ) );
62
- url.removeQueryItem ( QStringLiteral ( " REQUEST" ) );
63
- url.removeQueryItem ( QStringLiteral ( " BBOX" ) );
64
- url.removeQueryItem ( QStringLiteral ( " SRSNAME" ) );
65
- url.removeQueryItem ( QStringLiteral ( " FILTER" ) );
61
+ url.removeQueryItem ( QStringLiteral ( " service" ) );
62
+ url.removeQueryItem ( QgsWFSConstants::URI_PARAM_VERSION );
63
+ url.removeQueryItem ( QgsWFSConstants::URI_PARAM_TYPENAME );
64
+ url.removeQueryItem ( QStringLiteral ( " request" ) );
65
+ url.removeQueryItem ( QgsWFSConstants::URI_PARAM_BBOX );
66
+ url.removeQueryItem ( QgsWFSConstants::URI_PARAM_SRSNAME );
67
+ url.removeQueryItem ( QgsWFSConstants::URI_PARAM_FILTER );
68
+ url.removeQueryItem ( QgsWFSConstants::URI_PARAM_OUTPUTFORMAT );
66
69
url.removeQueryItem ( QgsWFSConstants::URI_PARAM_USERNAME );
67
70
url.removeQueryItem ( QgsWFSConstants::URI_PARAM_PASSWORD );
68
71
url.removeQueryItem ( QgsWFSConstants::URI_PARAM_AUTHCFG );
@@ -72,6 +75,7 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString &uri )
72
75
setTypeName ( typeName );
73
76
setSRSName ( srsname );
74
77
setVersion ( version );
78
+ setOutputFormat ( outputFormat );
75
79
76
80
// if the xml comes from the dialog, it needs to be a string to pass the validity test
77
81
if ( filter.startsWith ( ' \' ' ) && filter.endsWith ( ' \' ' ) && filter.size () > 1 )
@@ -86,6 +90,40 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString &uri )
86
90
}
87
91
else
88
92
{
93
+ QUrl url ( mURI .param ( QgsWFSConstants::URI_PARAM_URL ) );
94
+ bool URLModified = false ;
95
+ bool somethingChanged = false ;
96
+ do
97
+ {
98
+ somethingChanged = false ;
99
+ QList<queryItem> items ( url.queryItems () );
100
+ Q_FOREACH ( const queryItem &item, items )
101
+ {
102
+ const QString lowerName ( item.first .toLower () );
103
+ if ( lowerName == QgsWFSConstants::URI_PARAM_OUTPUTFORMAT )
104
+ {
105
+ setOutputFormat ( item.second );
106
+ url.removeQueryItem ( item.first );
107
+ somethingChanged = true ;
108
+ URLModified = true ;
109
+ break ;
110
+ }
111
+ else if ( lowerName == QLatin1String ( " service" ) ||
112
+ lowerName == QLatin1String ( " request" ) )
113
+ {
114
+ url.removeQueryItem ( item.first );
115
+ somethingChanged = true ;
116
+ URLModified = true ;
117
+ break ;
118
+ }
119
+ }
120
+ }
121
+ while ( somethingChanged );
122
+ if ( URLModified )
123
+ {
124
+ mURI .setParam ( QgsWFSConstants::URI_PARAM_URL, url.toEncoded () );
125
+ }
126
+
89
127
mAuth .mUserName = mURI .username ();
90
128
mAuth .mPassword = mURI .password ();
91
129
mAuth .mAuthCfg = mURI .authConfigId ();
@@ -201,6 +239,18 @@ void QgsWFSDataSourceURI::setSql( const QString &sql )
201
239
mURI .setSql ( sql );
202
240
}
203
241
242
+ QString QgsWFSDataSourceURI::outputFormat () const
243
+ {
244
+ return mURI .param ( QgsWFSConstants::URI_PARAM_OUTPUTFORMAT );
245
+ }
246
+
247
+ void QgsWFSDataSourceURI::setOutputFormat ( const QString &outputFormat )
248
+ {
249
+ mURI .removeParam ( QgsWFSConstants::URI_PARAM_OUTPUTFORMAT );
250
+ if ( !outputFormat.isEmpty () )
251
+ mURI .setParam ( QgsWFSConstants::URI_PARAM_OUTPUTFORMAT, outputFormat );
252
+ }
253
+
204
254
bool QgsWFSDataSourceURI::isRestrictedToRequestBBOX () const
205
255
{
206
256
if ( mURI .hasParam ( QgsWFSConstants::URI_PARAM_RESTRICT_TO_REQUEST_BBOX ) &&
0 commit comments