Skip to content
Permalink
Browse files
WFS: add support (#4164)
  • Loading branch information
wonder-sk committed Oct 11, 2011
1 parent 985f43c commit 4dc4552729909d8bebaa81393523683df8d48a4b
@@ -0,0 +1,125 @@
#include "qgswfsdataitems.h"

#include "qgswfsprovider.h"
#include "qgswfsconnection.h"
#include "qgswfssourceselect.h"

#include <QSettings>
#include <QCoreApplication>


QgsWFSLayerItem::QgsWFSLayerItem( QgsDataItem* parent, QString connName, QString name, QString title )
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Vector, "WFS" )
{
mUri = QgsWFSConnection( connName ).uriGetFeature( name );
mPopulated = true;
}

QgsWFSLayerItem::~QgsWFSLayerItem()
{
}

////

QgsWFSConnectionItem::QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path ), mName( name ), mConn( NULL )
{
}

QgsWFSConnectionItem::~QgsWFSConnectionItem()
{
}

QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
{
mGotCapabilities = false;
mConn = new QgsWFSConnection( mName, this );
connect( mConn, SIGNAL( gotCapabilities() ), this, SLOT( gotCapabilities() ) );

mConn->requestCapabilities();

while ( !mGotCapabilities )
{
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
}

QVector<QgsDataItem*> layers;
if ( mConn->errorCode() == QgsWFSConnection::NoError )
{
QgsWFSConnection::GetCapabilities caps = mConn->capabilities();
foreach( const QgsWFSConnection::FeatureType& featureType, caps.featureTypes )
{
QgsWFSLayerItem* layer = new QgsWFSLayerItem( this, mName, featureType.name, featureType.title );
layers.append( layer );
}
}
else
{
// TODO: return an "error" item
}

mConn->deleteLater();
mConn = NULL;

return layers;
}

void QgsWFSConnectionItem::gotCapabilities()
{
mGotCapabilities = true;
}

//////


QgsWFSRootItem::QgsWFSRootItem( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
{
mIcon = QIcon( getThemePixmap( "mIconWms.png" ) );

populate();
}

QgsWFSRootItem::~QgsWFSRootItem()
{
}

QVector<QgsDataItem*> QgsWFSRootItem::createChildren()
{
QVector<QgsDataItem*> connections;
QSettings settings;

settings.beginGroup( "/Qgis/connections-wfs" );
foreach( QString connName, settings.childGroups() )
{
QgsDataItem * conn = new QgsWFSConnectionItem( this, connName, mPath + "/" + connName );
connections.append( conn );
}
return connections;
}

QWidget * QgsWFSRootItem::paramWidget()
{
QgsWFSSourceSelect *select = new QgsWFSSourceSelect( 0, 0 );
connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
return select;
}

void QgsWFSRootItem::connectionsChanged()
{
refresh();
}


QGISEXTERN int dataCapabilities()
{
return QgsDataProvider::Net;
}

QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
{
Q_UNUSED( thePath );

return new QgsWFSRootItem( parentItem, "WFS", "wfs:" );
}

@@ -0,0 +1,53 @@
#ifndef QGSWFSDATAITEMS_H
#define QGSWFSDATAITEMS_H

#include "qgsdataitem.h"

class QgsWFSRootItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsWFSRootItem( QgsDataItem* parent, QString name, QString path );
~QgsWFSRootItem();

QVector<QgsDataItem*> createChildren();

virtual QWidget * paramWidget();

public slots:
void connectionsChanged();
};

class QgsWFSConnection;

class QgsWFSConnectionItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path );
~QgsWFSConnectionItem();

QVector<QgsDataItem*> createChildren();
//virtual bool equal( const QgsDataItem *other );

private slots:
void gotCapabilities();

private:
QString mName;

QgsWFSConnection* mConn;
bool mGotCapabilities;
};


class QgsWFSLayerItem : public QgsLayerItem
{
public:
QgsWFSLayerItem( QgsDataItem* parent, QString connName, QString name, QString title );
~QgsWFSLayerItem();

};


#endif // QGSWFSDATAITEMS_H
@@ -201,6 +201,7 @@ void QgsWFSSourceSelect::addEntryToServerList()
if ( nc.exec() )
{
populateConnectionList();
emit connectionsChanged();
}
}

@@ -212,6 +213,7 @@ void QgsWFSSourceSelect::modifyEntryOfServerList()
if ( nc.exec() )
{
populateConnectionList();
emit connectionsChanged();
}
}

@@ -224,6 +226,7 @@ void QgsWFSSourceSelect::deleteEntryOfServerList()
{
QgsWFSConnection::deleteConnection( cmbConnections->currentText() );
cmbConnections->removeItem( cmbConnections->currentIndex() );
emit connectionsChanged();
}
}

@@ -346,4 +349,5 @@ void QgsWFSSourceSelect::on_btnLoad_clicked()
QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::WFS, fileName );
dlg.exec();
populateConnectionList();
emit connectionsChanged();
}
@@ -35,6 +35,7 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase

signals:
void addWfsLayer( QString uri, QString typeName );
void connectionsChanged();

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

0 comments on commit 4dc4552

Please sign in to comment.