Skip to content

Commit 4dc4552

Browse files
committed
WFS: add support (#4164)
1 parent 985f43c commit 4dc4552

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

src/providers/wfs/qgswfsdataitems.cpp

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "qgswfsdataitems.h"
2+
3+
#include "qgswfsprovider.h"
4+
#include "qgswfsconnection.h"
5+
#include "qgswfssourceselect.h"
6+
7+
#include <QSettings>
8+
#include <QCoreApplication>
9+
10+
11+
QgsWFSLayerItem::QgsWFSLayerItem( QgsDataItem* parent, QString connName, QString name, QString title )
12+
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Vector, "WFS" )
13+
{
14+
mUri = QgsWFSConnection( connName ).uriGetFeature( name );
15+
mPopulated = true;
16+
}
17+
18+
QgsWFSLayerItem::~QgsWFSLayerItem()
19+
{
20+
}
21+
22+
////
23+
24+
QgsWFSConnectionItem::QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path )
25+
: QgsDataCollectionItem( parent, name, path ), mName( name ), mConn( NULL )
26+
{
27+
}
28+
29+
QgsWFSConnectionItem::~QgsWFSConnectionItem()
30+
{
31+
}
32+
33+
QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
34+
{
35+
mGotCapabilities = false;
36+
mConn = new QgsWFSConnection( mName, this );
37+
connect( mConn, SIGNAL( gotCapabilities() ), this, SLOT( gotCapabilities() ) );
38+
39+
mConn->requestCapabilities();
40+
41+
while ( !mGotCapabilities )
42+
{
43+
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
44+
}
45+
46+
QVector<QgsDataItem*> layers;
47+
if ( mConn->errorCode() == QgsWFSConnection::NoError )
48+
{
49+
QgsWFSConnection::GetCapabilities caps = mConn->capabilities();
50+
foreach( const QgsWFSConnection::FeatureType& featureType, caps.featureTypes )
51+
{
52+
QgsWFSLayerItem* layer = new QgsWFSLayerItem( this, mName, featureType.name, featureType.title );
53+
layers.append( layer );
54+
}
55+
}
56+
else
57+
{
58+
// TODO: return an "error" item
59+
}
60+
61+
mConn->deleteLater();
62+
mConn = NULL;
63+
64+
return layers;
65+
}
66+
67+
void QgsWFSConnectionItem::gotCapabilities()
68+
{
69+
mGotCapabilities = true;
70+
}
71+
72+
//////
73+
74+
75+
QgsWFSRootItem::QgsWFSRootItem( QgsDataItem* parent, QString name, QString path )
76+
: QgsDataCollectionItem( parent, name, path )
77+
{
78+
mIcon = QIcon( getThemePixmap( "mIconWms.png" ) );
79+
80+
populate();
81+
}
82+
83+
QgsWFSRootItem::~QgsWFSRootItem()
84+
{
85+
}
86+
87+
QVector<QgsDataItem*> QgsWFSRootItem::createChildren()
88+
{
89+
QVector<QgsDataItem*> connections;
90+
QSettings settings;
91+
92+
settings.beginGroup( "/Qgis/connections-wfs" );
93+
foreach( QString connName, settings.childGroups() )
94+
{
95+
QgsDataItem * conn = new QgsWFSConnectionItem( this, connName, mPath + "/" + connName );
96+
connections.append( conn );
97+
}
98+
return connections;
99+
}
100+
101+
QWidget * QgsWFSRootItem::paramWidget()
102+
{
103+
QgsWFSSourceSelect *select = new QgsWFSSourceSelect( 0, 0 );
104+
connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
105+
return select;
106+
}
107+
108+
void QgsWFSRootItem::connectionsChanged()
109+
{
110+
refresh();
111+
}
112+
113+
114+
QGISEXTERN int dataCapabilities()
115+
{
116+
return QgsDataProvider::Net;
117+
}
118+
119+
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
120+
{
121+
Q_UNUSED( thePath );
122+
123+
return new QgsWFSRootItem( parentItem, "WFS", "wfs:" );
124+
}
125+

src/providers/wfs/qgswfsdataitems.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef QGSWFSDATAITEMS_H
2+
#define QGSWFSDATAITEMS_H
3+
4+
#include "qgsdataitem.h"
5+
6+
class QgsWFSRootItem : public QgsDataCollectionItem
7+
{
8+
Q_OBJECT
9+
public:
10+
QgsWFSRootItem( QgsDataItem* parent, QString name, QString path );
11+
~QgsWFSRootItem();
12+
13+
QVector<QgsDataItem*> createChildren();
14+
15+
virtual QWidget * paramWidget();
16+
17+
public slots:
18+
void connectionsChanged();
19+
};
20+
21+
class QgsWFSConnection;
22+
23+
class QgsWFSConnectionItem : public QgsDataCollectionItem
24+
{
25+
Q_OBJECT
26+
public:
27+
QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path );
28+
~QgsWFSConnectionItem();
29+
30+
QVector<QgsDataItem*> createChildren();
31+
//virtual bool equal( const QgsDataItem *other );
32+
33+
private slots:
34+
void gotCapabilities();
35+
36+
private:
37+
QString mName;
38+
39+
QgsWFSConnection* mConn;
40+
bool mGotCapabilities;
41+
};
42+
43+
44+
class QgsWFSLayerItem : public QgsLayerItem
45+
{
46+
public:
47+
QgsWFSLayerItem( QgsDataItem* parent, QString connName, QString name, QString title );
48+
~QgsWFSLayerItem();
49+
50+
};
51+
52+
53+
#endif // QGSWFSDATAITEMS_H

src/providers/wfs/qgswfssourceselect.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ void QgsWFSSourceSelect::addEntryToServerList()
201201
if ( nc.exec() )
202202
{
203203
populateConnectionList();
204+
emit connectionsChanged();
204205
}
205206
}
206207

@@ -212,6 +213,7 @@ void QgsWFSSourceSelect::modifyEntryOfServerList()
212213
if ( nc.exec() )
213214
{
214215
populateConnectionList();
216+
emit connectionsChanged();
215217
}
216218
}
217219

@@ -224,6 +226,7 @@ void QgsWFSSourceSelect::deleteEntryOfServerList()
224226
{
225227
QgsWFSConnection::deleteConnection( cmbConnections->currentText() );
226228
cmbConnections->removeItem( cmbConnections->currentIndex() );
229+
emit connectionsChanged();
227230
}
228231
}
229232

@@ -346,4 +349,5 @@ void QgsWFSSourceSelect::on_btnLoad_clicked()
346349
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::WFS, fileName );
347350
dlg.exec();
348351
populateConnectionList();
352+
emit connectionsChanged();
349353
}

src/providers/wfs/qgswfssourceselect.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
3535

3636
signals:
3737
void addWfsLayer( QString uri, QString typeName );
38+
void connectionsChanged();
3839

3940
private:
4041
QgsWFSSourceSelect(); //default constructor is forbidden

0 commit comments

Comments
 (0)