Skip to content

Commit 985f43c

Browse files
committedOct 11, 2011
WFS: Move uri logic and GetCapabilities parsing to WFSConnection class.
1 parent c0dc60b commit 985f43c

File tree

4 files changed

+329
-223
lines changed

4 files changed

+329
-223
lines changed
 

‎src/providers/wfs/qgswfsconnection.cpp

Lines changed: 198 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,210 @@
11
#include "qgswfsconnection.h"
22

3+
#include "qgslogger.h"
4+
5+
#include <QDomDocument>
36
#include <QSettings>
47
#include <QStringList>
58

6-
QgsWFSConnection::QgsWFSConnection(QObject *parent) :
7-
QObject(parent)
9+
#include "qgsnetworkaccessmanager.h"
10+
#include <QNetworkRequest>
11+
#include <QNetworkReply>
12+
13+
static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";
14+
15+
QgsWFSConnection::QgsWFSConnection( QString connName, QObject *parent ) :
16+
QObject( parent ),
17+
mConnName( connName ),
18+
mCapabilitiesReply( 0 ),
19+
mErrorCode( QgsWFSConnection::NoError )
20+
{
21+
//find out the server URL
22+
QSettings settings;
23+
QString key = "/Qgis/connections-wfs/" + mConnName + "/url";
24+
mUri = settings.value( key ).toString();
25+
QgsDebugMsg( QString( "url is: %1" ).arg( mUri ) );
26+
27+
//make a GetCapabilities request
28+
//modify mUri to add '?' or '&' at the end if it is not already there
29+
if ( !( mUri.contains( "?" ) ) )
30+
{
31+
mUri.append( "?" );
32+
}
33+
else if (( mUri.right( 1 ) != "?" ) && ( mUri.right( 1 ) != "&" ) )
34+
{
35+
mUri.append( "&" );
36+
}
37+
}
38+
39+
QString QgsWFSConnection::uriGetCapabilities()
40+
{
41+
return mUri + "SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0";
42+
}
43+
44+
QString QgsWFSConnection::uriGetFeature( QString typeName, QString crsString, QString filter, QgsRectangle bBox )
845
{
46+
//get CRS
47+
if ( !crsString.isEmpty() )
48+
{
49+
crsString.prepend( "&SRSNAME=" );
50+
}
51+
52+
QString filterString;
53+
if ( !filter.isEmpty() )
54+
{
55+
filterString = "&FILTER=" + filter;
56+
}
57+
58+
QString bBoxString;
59+
if ( !bBox.isEmpty() )
60+
{
61+
bBoxString = QString( "&BBOX=%1,%2,%3,%4" )
62+
.arg( bBox.xMinimum(), 0, 'f' )
63+
.arg( bBox.yMinimum(), 0, 'f' )
64+
.arg( bBox.xMaximum(), 0, 'f' )
65+
.arg( bBox.yMaximum(), 0, 'f' );
66+
}
67+
68+
QString uri = mUri;
69+
if ( !( uri.contains( "?" ) ) )
70+
{
71+
uri.append( "?" );
72+
}
73+
74+
//add a wfs layer to the map
75+
uri += "SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=" + typeName + crsString + bBoxString + filterString;
76+
QgsDebugMsg( uri );
77+
return uri;
978
}
1079

1180

81+
void QgsWFSConnection::requestCapabilities()
82+
{
83+
mErrorCode = QgsWFSConnection::NoError;
84+
mErrorMessage.clear();
85+
86+
QNetworkRequest request( uriGetCapabilities() );
87+
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
88+
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
89+
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
90+
}
91+
92+
void QgsWFSConnection::capabilitiesReplyFinished()
93+
{
94+
// handle network errors
95+
if ( mCapabilitiesReply->error() != QNetworkReply::NoError )
96+
{
97+
mErrorCode = QgsWFSConnection::NetworkError;
98+
mErrorMessage = mCapabilitiesReply->errorString();
99+
emit gotCapabilities();
100+
return;
101+
}
102+
103+
// handle HTTP redirects
104+
QVariant redirect = mCapabilitiesReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
105+
if ( !redirect.isNull() )
106+
{
107+
QgsDebugMsg( "redirecting to " + redirect.toUrl().toString() );
108+
QNetworkRequest request( redirect.toUrl() );
109+
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
110+
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
111+
112+
mCapabilitiesReply->deleteLater();
113+
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
114+
115+
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
116+
return;
117+
}
118+
119+
QByteArray buffer = mCapabilitiesReply->readAll();
120+
121+
QgsDebugMsg( "parsing capabilities: " + buffer );
122+
123+
// parse XML
124+
QString capabilitiesDocError;
125+
QDomDocument capabilitiesDocument;
126+
if ( !capabilitiesDocument.setContent( buffer, true, &capabilitiesDocError ) )
127+
{
128+
mErrorCode = QgsWFSConnection::XmlError;
129+
mErrorMessage = capabilitiesDocError;
130+
emit gotCapabilities();
131+
return;
132+
}
133+
134+
QDomElement doc = capabilitiesDocument.documentElement();
135+
136+
// hangle exceptions
137+
if ( doc.tagName() == "ExceptionReport" )
138+
{
139+
QDomNode ex = doc.firstChild();
140+
QString exc = ex.toElement().attribute( "exceptionCode", "Exception" );
141+
QDomElement ext = ex.firstChild().toElement();
142+
mErrorCode = QgsWFSConnection::ServerExceptionError;
143+
mErrorMessage = exc + ": " + ext.firstChild().nodeValue();
144+
emit gotCapabilities();
145+
return;
146+
}
147+
148+
mCaps.clear();
149+
150+
// get the <FeatureType> elements
151+
QDomNodeList featureTypeList = capabilitiesDocument.elementsByTagNameNS( WFS_NAMESPACE, "FeatureType" );
152+
for ( unsigned int i = 0; i < featureTypeList.length(); ++i )
153+
{
154+
FeatureType featureType;
155+
QDomElement featureTypeElem = featureTypeList.at( i ).toElement();
156+
157+
//Name
158+
QDomNodeList nameList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Name" );
159+
if ( nameList.length() > 0 )
160+
{
161+
featureType.name = nameList.at( 0 ).toElement().text();
162+
}
163+
//Title
164+
QDomNodeList titleList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Title" );
165+
if ( titleList.length() > 0 )
166+
{
167+
featureType.title = titleList.at( 0 ).toElement().text();
168+
}
169+
//Abstract
170+
QDomNodeList abstractList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Abstract" );
171+
if ( abstractList.length() > 0 )
172+
{
173+
featureType.abstract = abstractList.at( 0 ).toElement().text();
174+
}
175+
176+
//DefaultSRS is always the first entry in the feature srs list
177+
QDomNodeList defaultCRSList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "DefaultSRS" );
178+
if ( defaultCRSList.length() > 0 )
179+
{
180+
featureType.crslist.append( defaultCRSList.at( 0 ).toElement().text() );
181+
}
182+
183+
//OtherSRS
184+
QDomNodeList otherCRSList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "OtherSRS" );
185+
for ( unsigned int i = 0; i < otherCRSList.length(); ++i )
186+
{
187+
featureType.crslist.append( otherCRSList.at( i ).toElement().text() );
188+
}
189+
190+
//Support <SRS> for compatibility with older versions
191+
QDomNodeList srsList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "SRS" );
192+
for ( unsigned int i = 0; i < srsList.length(); ++i )
193+
{
194+
featureType.crslist.append( srsList.at( i ).toElement().text() );
195+
}
196+
197+
mCaps.featureTypes.append( featureType );
198+
}
199+
200+
mCapabilitiesReply->deleteLater();
201+
mCapabilitiesReply = 0;
202+
emit gotCapabilities();
203+
}
204+
205+
206+
207+
12208
QStringList QgsWFSConnection::connectionList()
13209
{
14210
QSettings settings;
@@ -33,8 +229,3 @@ void QgsWFSConnection::deleteConnection( QString name )
33229
QSettings settings;
34230
settings.remove( "/Qgis/connections-wfs/" + name );
35231
}
36-
37-
38-
// TODO:
39-
// - get URI
40-
// - get capabilities

‎src/providers/wfs/qgswfsconnection.h

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,74 @@
33

44
#include <QObject>
55

6+
#include "qgsrectangle.h"
7+
8+
class QNetworkReply;
9+
610
class QgsWFSConnection : public QObject
711
{
812
Q_OBJECT
9-
public:
10-
explicit QgsWFSConnection(QObject *parent = 0);
13+
public:
14+
explicit QgsWFSConnection( QString connName, QObject *parent = 0 );
15+
16+
static QStringList connectionList();
17+
18+
static void deleteConnection( QString name );
19+
20+
static QString selectedConnection();
21+
static void setSelectedConnection( QString name );
22+
23+
//! base service URI
24+
QString uri() { return mUri; }
25+
//! URI to get capabilities
26+
QString uriGetCapabilities();
27+
//! URI to get features
28+
QString uriGetFeature( QString typeName,
29+
QString crs = QString(),
30+
QString filter = QString(),
31+
QgsRectangle bBox = QgsRectangle() );
32+
33+
//! start network connection to get capabilities
34+
void requestCapabilities();
35+
36+
//! description of a vector layer
37+
struct FeatureType
38+
{
39+
QString name;
40+
QString title;
41+
QString abstract;
42+
QList<QString> crslist; // first is default
43+
};
44+
45+
//! parsed get capabilities document
46+
struct GetCapabilities
47+
{
48+
void clear() { featureTypes.clear(); }
49+
50+
QList<FeatureType> featureTypes;
51+
};
1152

12-
static QStringList connectionList();
53+
enum ErrorCode { NoError, NetworkError, XmlError, ServerExceptionError };
54+
ErrorCode errorCode() { return mErrorCode; }
55+
QString errorMessage() { return mErrorMessage; }
1356

14-
static void deleteConnection( QString name );
57+
//! return parsed capabilities - requestCapabilities() must be called before
58+
GetCapabilities capabilities() { return mCaps; }
1559

16-
static QString selectedConnection();
17-
static void setSelectedConnection( QString name );
60+
signals:
61+
void gotCapabilities();
1862

19-
signals:
63+
public slots:
64+
void capabilitiesReplyFinished();
2065

21-
public slots:
66+
protected:
67+
QString mConnName;
68+
QString mUri;
2269

70+
QNetworkReply *mCapabilitiesReply;
71+
GetCapabilities mCaps;
72+
ErrorCode mErrorCode;
73+
QString mErrorMessage;
2374
};
2475

2576
#endif // QGSWFSCONNECTION_H

‎src/providers/wfs/qgswfssourceselect.cpp

Lines changed: 70 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,18 @@
2525
#include "qgscoordinatereferencesystem.h"
2626
#include "qgslogger.h"
2727
#include "qgsmapcanvas.h" //for current view extent
28-
#include "qgsnetworkaccessmanager.h"
2928
#include "qgsmanageconnectionsdialog.h"
3029

3130
#include <QDomDocument>
3231
#include <QListWidgetItem>
3332
#include <QMessageBox>
3433
#include <QSettings>
35-
#include <QNetworkRequest>
36-
#include <QNetworkReply>
3734
#include <QFileDialog>
3835

39-
static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";
4036

4137
QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, Qt::WFlags fl )
4238
: QDialog( parent, fl )
43-
, mCapabilitiesReply( 0 )
39+
, mConn( NULL )
4440
{
4541
setupUi( this );
4642
btnAdd = buttonBox->button( QDialogButtonBox::Ok );
@@ -62,6 +58,8 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, Qt::WFlags fl )
6258
QgsWFSSourceSelect::~QgsWFSSourceSelect()
6359
{
6460
delete mProjectionSelector;
61+
62+
delete mConn;
6563
}
6664

6765
void QgsWFSSourceSelect::populateConnectionList()
@@ -99,6 +97,10 @@ void QgsWFSSourceSelect::populateConnectionList()
9997
{
10098
cmbConnections->setCurrentIndex( index );
10199
}
100+
101+
delete mConn;
102+
mConn = new QgsWFSConnection( cmbConnections->currentText() );
103+
connect( mConn, SIGNAL( gotCapabilities() ), this, SLOT( capabilitiesReplyFinished() ) );
102104
}
103105

104106
QString QgsWFSSourceSelect::getPreferredCrs( const QSet<QString>& crsSet ) const
@@ -135,163 +137,60 @@ QString QgsWFSSourceSelect::getPreferredCrs( const QSet<QString>& crsSet ) const
135137

136138
void QgsWFSSourceSelect::capabilitiesReplyFinished()
137139
{
138-
if ( mCapabilitiesReply->error() == QNetworkReply::NoError )
140+
btnConnect->setEnabled( true );
141+
142+
if ( !mConn )
143+
return;
144+
QgsWFSConnection::ErrorCode err = mConn->errorCode();
145+
if ( err != QgsWFSConnection::NoError )
139146
{
140-
QVariant redirect = mCapabilitiesReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
141-
if ( !redirect.isNull() )
147+
QString title;
148+
switch ( err )
142149
{
143-
QgsDebugMsg( "redirecting to " + redirect.toUrl().toString() );
144-
QNetworkRequest request( redirect.toUrl() );
145-
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
146-
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
147-
148-
mCapabilitiesReply->deleteLater();
149-
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
150-
151-
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
152-
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
153-
return;
150+
case QgsWFSConnection::NetworkError: title = tr( "Network Error" ); break;
151+
case QgsWFSConnection::XmlError: title = tr( "Capabilities document is not valid" ); break;
152+
case QgsWFSConnection::ServerExceptionError: title = tr( "Server Exception" ); break;
153+
default: tr( "Error" ); break;
154154
}
155+
// handle errors
156+
QMessageBox::critical( 0, title, mConn->errorMessage() );
155157

156-
QByteArray buffer = mCapabilitiesReply->readAll();
157-
158-
QgsDebugMsg( "parsing capabilities: " + buffer );
159-
160-
QString capabilitiesDocError;
161-
QDomDocument capabilitiesDocument;
162-
if ( capabilitiesDocument.setContent( buffer, true, &capabilitiesDocError ) )
163-
{
164-
QDomElement doc = capabilitiesDocument.documentElement();
165-
if ( doc.tagName() != "ExceptionReport" )
166-
{
167-
std::list<QString> typenames;
168-
std::list< std::list<QString> > crs;
169-
std::list<QString> titles;
170-
std::list<QString> abstracts;
171-
172-
//get the <FeatureType> elements
173-
QDomNodeList featureTypeList = capabilitiesDocument.elementsByTagNameNS( WFS_NAMESPACE, "FeatureType" );
174-
for ( unsigned int i = 0; i < featureTypeList.length(); ++i )
175-
{
176-
QString tname, title, abstract;
177-
QDomElement featureTypeElem = featureTypeList.at( i ).toElement();
178-
std::list<QString> featureCRSList; //CRS list for this feature
179-
180-
//Name
181-
QDomNodeList nameList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Name" );
182-
if ( nameList.length() > 0 )
183-
{
184-
tname = nameList.at( 0 ).toElement().text();
185-
//strip away namespace prefixes
186-
/* if ( tname.contains( ":" ) )
187-
{
188-
tname = tname.section( ":", 1, 1 );
189-
}*/
190-
}
191-
//Title
192-
QDomNodeList titleList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Title" );
193-
if ( titleList.length() > 0 )
194-
{
195-
title = titleList.at( 0 ).toElement().text();
196-
}
197-
//Abstract
198-
QDomNodeList abstractList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Abstract" );
199-
if ( abstractList.length() > 0 )
200-
{
201-
abstract = abstractList.at( 0 ).toElement().text();
202-
}
203-
204-
//DefaultSRS is always the first entry in the feature srs list
205-
QDomNodeList defaultCRSList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "DefaultSRS" );
206-
if ( defaultCRSList.length() > 0 )
207-
{
208-
featureCRSList.push_back( defaultCRSList.at( 0 ).toElement().text() );
209-
}
210-
211-
//OtherSRS
212-
QDomNodeList otherCRSList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "OtherSRS" );
213-
for ( unsigned int i = 0; i < otherCRSList.length(); ++i )
214-
{
215-
featureCRSList.push_back( otherCRSList.at( i ).toElement().text() );
216-
}
217-
218-
//Support <SRS> for compatibility with older versions
219-
QDomNodeList srsList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "SRS" );
220-
for ( unsigned int i = 0; i < srsList.length(); ++i )
221-
{
222-
featureCRSList.push_back( srsList.at( i ).toElement().text() );
223-
}
224-
225-
crs.push_back( featureCRSList );
226-
typenames.push_back( tname );
227-
titles.push_back( title );
228-
abstracts.push_back( abstract );
229-
}
230-
231-
//insert the available CRS into mAvailableCRS
232-
mAvailableCRS.clear();
233-
std::list<QString>::const_iterator typeNameIter;
234-
std::list< std::list<QString> >::const_iterator crsIter;
235-
for ( typeNameIter = typenames.begin(), crsIter = crs.begin(); typeNameIter != typenames.end(); ++typeNameIter, ++crsIter )
236-
{
237-
std::list<QString> currentCRSList;
238-
for ( std::list<QString>::const_iterator it = crsIter->begin(); it != crsIter->end(); ++it )
239-
{
240-
currentCRSList.push_back( *it );
241-
}
242-
mAvailableCRS.insert( std::make_pair( *typeNameIter, currentCRSList ) );
243-
}
158+
btnAdd->setEnabled( false );
159+
return;
160+
}
244161

245-
//insert the typenames, titles and abstracts into the tree view
246-
std::list<QString>::const_iterator t_it = titles.begin();
247-
std::list<QString>::const_iterator n_it = typenames.begin();
248-
std::list<QString>::const_iterator a_it = abstracts.begin();
249-
for ( ; t_it != titles.end(); ++t_it, ++n_it, ++a_it )
250-
{
251-
QTreeWidgetItem* newItem = new QTreeWidgetItem();
252-
newItem->setText( 0, *t_it );
253-
newItem->setText( 1, *n_it );
254-
newItem->setText( 2, *a_it );
255-
treeWidget->addTopLevelItem( newItem );
256-
}
162+
QgsWFSConnection::GetCapabilities caps = mConn->capabilities();
257163

258-
if ( typenames.size() > 0 )
259-
{
260-
btnAdd->setEnabled( true );
261-
treeWidget->setCurrentItem( treeWidget->topLevelItem( 0 ) );
262-
btnChangeSpatialRefSys->setEnabled( true );
263-
}
264-
else
265-
{
266-
QMessageBox::information( 0, tr( "No Layers" ), tr( "capabilities document contained no layers." ) );
267-
btnAdd->setEnabled( false );
268-
}
269-
}
270-
else
271-
{
272-
QDomNode ex = doc.firstChild();
273-
QString exc = ex.toElement().attribute( "exceptionCode", "Exception" );
274-
QDomElement ext = ex.firstChild().toElement();
275-
QMessageBox::critical( 0, tr( "Error" ), exc + ": " + ext.firstChild().nodeValue() );
276-
}
277-
}
278-
else
164+
mAvailableCRS.clear();
165+
foreach( QgsWFSConnection::FeatureType featureType, caps.featureTypes )
166+
{
167+
// insert the typenames, titles and abstracts into the tree view
168+
QTreeWidgetItem* newItem = new QTreeWidgetItem();
169+
newItem->setText( 0, featureType.title );
170+
newItem->setText( 1, featureType.name );
171+
newItem->setText( 2, featureType.abstract );
172+
treeWidget->addTopLevelItem( newItem );
173+
174+
// insert the available CRS into mAvailableCRS
175+
std::list<QString> currentCRSList;
176+
foreach( QString crs, featureType.crslist )
279177
{
280-
QMessageBox::critical( 0, tr( "Capabilities document is not valid" ), capabilitiesDocError );
178+
currentCRSList.push_back( crs );
281179
}
180+
mAvailableCRS.insert( std::make_pair( featureType.name, currentCRSList ) );
181+
}
182+
183+
if ( caps.featureTypes.count() > 0 )
184+
{
185+
btnAdd->setEnabled( true );
186+
treeWidget->setCurrentItem( treeWidget->topLevelItem( 0 ) );
187+
btnChangeSpatialRefSys->setEnabled( true );
282188
}
283189
else
284190
{
285-
QMessageBox::critical( 0, tr( "GetCapabilities Error" ), mCapabilitiesReply->errorString() );
191+
QMessageBox::information( 0, tr( "No Layers" ), tr( "capabilities document contained no layers." ) );
192+
btnAdd->setEnabled( false );
286193
}
287-
288-
btnConnect->setEnabled( true );
289-
mCapabilitiesReply->deleteLater();
290-
mCapabilitiesReply = 0;
291-
}
292-
293-
void QgsWFSSourceSelect::capabilitiesReplyProgress( qint64, qint64 )
294-
{
295194
}
296195

297196
void QgsWFSSourceSelect::addEntryToServerList()
@@ -330,31 +229,13 @@ void QgsWFSSourceSelect::deleteEntryOfServerList()
330229

331230
void QgsWFSSourceSelect::connectToServer()
332231
{
333-
//find out the server URL
334-
QSettings settings;
335-
QString key = "/Qgis/connections-wfs/" + cmbConnections->currentText() + "/url";
336-
mUri = settings.value( key ).toString();
337-
QgsDebugMsg( QString( "url is: %1" ).arg( mUri ) );
338-
339-
//make a GetCapabilities request
340-
//modify mUri to add '?' or '&' at the end if it is not already there
341-
if ( !( mUri.contains( "?" ) ) )
342-
{
343-
mUri.append( "?" );
344-
}
345-
else if (( mUri.right( 1 ) != "?" ) && ( mUri.right( 1 ) != "&" ) )
346-
{
347-
mUri.append( "&" );
348-
}
349-
350232
btnConnect->setEnabled( false );
351233
treeWidget->clear();
352234

353-
QNetworkRequest request( mUri + "SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0" );
354-
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
355-
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
356-
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
357-
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
235+
if ( mConn )
236+
{
237+
mConn->requestCapabilities();
238+
}
358239
}
359240

360241

@@ -366,46 +247,26 @@ void QgsWFSSourceSelect::addLayer()
366247
{
367248
return;
368249
}
369-
QString typeName = tItem->text( 1 );
370-
371-
QString uri = mUri;
372-
if ( !( uri.contains( "?" ) ) )
373-
{
374-
uri.append( "?" );
375-
}
376-
QgsDebugMsg( QString( "%1SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=%2" ).arg( uri ).arg( typeName ) );
377250

378-
//get CRS
379-
QString crsString = labelCoordRefSys->text();
380-
if ( !crsString.isEmpty() )
381-
{
382-
crsString.prepend( "&SRSNAME=" );
383-
}
251+
QString typeName = tItem->text( 1 );
252+
QString crs = labelCoordRefSys->text();
253+
QString filter = mFilterLineEdit->text();
254+
QgsRectangle bBox;
384255

385-
QString filterString;
386-
if ( !mFilterLineEdit->text().isEmpty() )
256+
#if 0
257+
// TODO: resolve [MD]
258+
//get current extent
259+
QgsMapCanvas* canvas = mIface->mapCanvas();
260+
if ( canvas && mBboxCheckBox->isChecked() )
387261
{
388-
filterString = ( "&FILTER=" + mFilterLineEdit->text() );
262+
QgsRectangle currentExtent = canvas->extent();
389263
}
390-
391-
QString bBoxString;
392-
#if 0
393-
// TODO: resolve [MD]
394-
//get current extent
395-
QgsMapCanvas* canvas = mIface->mapCanvas();
396-
if ( canvas && mBboxCheckBox->isChecked() )
397-
{
398-
QgsRectangle currentExtent = canvas->extent();
399-
bBoxString = QString( "&BBOX=%1,%2,%3,%4" )
400-
.arg( currentExtent.xMinimum(), 0, 'f' )
401-
.arg( currentExtent.yMinimum(), 0, 'f' )
402-
.arg( currentExtent.xMaximum(), 0, 'f' )
403-
.arg( currentExtent.yMaximum(), 0, 'f' );
404-
}
405264
#endif
406265

407266
//add a wfs layer to the map
408-
uri += "SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=" + typeName + crsString + bBoxString + filterString;
267+
QgsWFSConnection conn( cmbConnections->currentText() );
268+
QString uri = conn.uriGetFeature( typeName, crs, filter, bBox );
269+
409270
emit addWfsLayer( uri, typeName );
410271

411272
accept();
@@ -461,6 +322,10 @@ void QgsWFSSourceSelect::on_cmbConnections_activated( int index )
461322
{
462323
Q_UNUSED( index );
463324
QgsWFSConnection::setSelectedConnection( cmbConnections->currentText() );
325+
326+
delete mConn;
327+
mConn = new QgsWFSConnection( cmbConnections->currentText() );
328+
connect( mConn, SIGNAL( gotCapabilities() ), this, SLOT( capabilitiesReplyFinished() ) );
464329
}
465330

466331
void QgsWFSSourceSelect::on_btnSave_clicked()

‎src/providers/wfs/qgswfssourceselect.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "qgscontexthelp.h"
2323

2424
class QgsGenericProjectionSelector;
25-
class QNetworkReply;
25+
class QgsWFSConnection;
2626

2727
class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
2828
{
@@ -38,14 +38,13 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
3838

3939
private:
4040
QgsWFSSourceSelect(); //default constructor is forbidden
41-
QString mUri; //uri of the currently connected server
4241
QgsGenericProjectionSelector* mProjectionSelector;
4342
/**Stores the available CRS for a server connections.
4443
The first string is the typename, the corresponding list
4544
stores the CRS for the typename in the form 'EPSG:XXXX'*/
4645
std::map<QString, std::list<QString> > mAvailableCRS;
4746
QAbstractButton* btnAdd;
48-
QNetworkReply *mCapabilitiesReply;
47+
QgsWFSConnection* mConn;
4948

5049
void populateConnectionList();
5150

0 commit comments

Comments
 (0)
Please sign in to comment.