1313 * *
1414 ***************************************************************************/
1515
16+ #include " QtGlobal"
17+
1618#include " qgswfsconstants.h"
1719#include " qgswfsdatasourceuri.h"
1820#include " qgsmessagelog.h"
@@ -25,11 +27,26 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
2527 if ( !mURI .hasParam ( QgsWFSConstants::URI_PARAM_URL ) )
2628 {
2729 QUrl url ( uri );
28- QString srsname = url.queryItemValue ( " SRSNAME" );
29- QString bbox = url.queryItemValue ( " BBOX" );
30- QString typeName = url.queryItemValue ( " TYPENAME" );
31- QString filter = url.queryItemValue ( " FILTER" );
30+ // Transform all param keys to lowercase
31+ typedef QPair<QString, QString> queryItem;
32+ QList<queryItem> items ( url.queryItems () );
33+ foreach ( queryItem item, items )
34+ {
35+ url.removeQueryItem ( item.first );
36+ url.addQueryItem ( item.first .toLower (), item.second );
37+ }
38+
39+ QString srsname = url.queryItemValue ( QgsWFSConstants::URI_PARAM_SRSNAME );
40+ QString bbox = url.queryItemValue ( QgsWFSConstants::URI_PARAM_BBOX );
41+ QString typeName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_TYPENAME );
42+ QString version = url.queryItemValue ( QgsWFSConstants::URI_PARAM_VERSION );
43+ QString filter = url.queryItemValue ( QgsWFSConstants::URI_PARAM_FILTER );
3244 mAuth .mUserName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_USERNAME );
45+ // In QgsDataSourceURI, the "username" param is named "user", check it
46+ if ( mAuth .mUserName .isEmpty () )
47+ {
48+ mAuth .mUserName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_USER );
49+ }
3350 mAuth .mPassword = url.queryItemValue ( QgsWFSConstants::URI_PARAM_PASSWORD );
3451 mAuth .mAuthCfg = url.queryItemValue ( QgsWFSConstants::URI_PARAM_AUTHCFG );
3552
@@ -49,6 +66,7 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
4966 mURI .setParam ( QgsWFSConstants::URI_PARAM_URL , url.toEncoded () );
5067 setTypeName ( typeName );
5168 setSRSName ( srsname );
69+ setVersion ( version );
5270
5371 // if the xml comes from the dialog, it needs to be a string to pass the validity test
5472 if ( filter.startsWith ( ' \' ' ) && filter.endsWith ( ' \' ' ) && filter.size () > 1 )
@@ -63,17 +81,32 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
6381 }
6482 else
6583 {
66- mAuth .mUserName = mURI .param ( QgsWFSConstants:: URI_PARAM_USERNAME );
67- mAuth .mPassword = mURI .param ( QgsWFSConstants:: URI_PARAM_PASSWORD );
68- mAuth .mAuthCfg = mURI .param ( QgsWFSConstants:: URI_PARAM_AUTHCFG );
84+ mAuth .mUserName = mURI .username ( );
85+ mAuth .mPassword = mURI .password ( );
86+ mAuth .mAuthCfg = mURI .authConfigId ( );
6987 }
7088}
7189
72- QString QgsWFSDataSourceURI::uri ()
90+ const QString QgsWFSDataSourceURI::uri ( bool expandAuthConfig ) const
7391{
74- return mURI .uri ();
92+ QgsDataSourceURI theURI ( mURI );
93+ // Add auth params back into the uri
94+ if ( ! mAuth .mAuthCfg .isEmpty () )
95+ {
96+ theURI.setAuthConfigId ( mAuth .mAuthCfg );
97+ }
98+ if ( ! mAuth .mUserName .isEmpty () )
99+ {
100+ theURI.setUsername ( mAuth .mUserName );
101+ }
102+ if ( ! mAuth .mPassword .isEmpty () )
103+ {
104+ theURI.setPassword ( mAuth .mPassword );
105+ }
106+ return theURI.uri ( expandAuthConfig );
75107}
76108
109+
77110QUrl QgsWFSDataSourceURI::baseURL ( bool bIncludeServiceWFS ) const
78111{
79112 QUrl url ( mURI .param ( QgsWFSConstants::URI_PARAM_URL ) );
@@ -122,6 +155,13 @@ void QgsWFSDataSourceURI::setSRSName( const QString& crsString )
122155 mURI .setParam ( QgsWFSConstants::URI_PARAM_SRSNAME , crsString );
123156}
124157
158+ void QgsWFSDataSourceURI::setVersion ( const QString& versionString )
159+ {
160+ mURI .removeParam ( QgsWFSConstants::URI_PARAM_VERSION );
161+ if ( !versionString.isEmpty () )
162+ mURI .setParam ( QgsWFSConstants::URI_PARAM_VERSION , versionString );
163+ }
164+
125165QString QgsWFSDataSourceURI::SRSName () const
126166{
127167 return mURI .param ( QgsWFSConstants::URI_PARAM_SRSNAME );
0 commit comments