40 changes: 40 additions & 0 deletions src/providers/wfs/qgswfsconnection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "qgswfsconnection.h"

#include <QSettings>
#include <QStringList>

QgsWFSConnection::QgsWFSConnection(QObject *parent) :
QObject(parent)
{
}


QStringList QgsWFSConnection::connectionList()
{
QSettings settings;
settings.beginGroup( "/Qgis/connections-wfs" );
return settings.childGroups();
}

QString QgsWFSConnection::selectedConnection()
{
QSettings settings;
return settings.value( "/Qgis/connections-wfs/selected" ).toString();
}

void QgsWFSConnection::setSelectedConnection( QString name )
{
QSettings settings;
settings.setValue( "/Qgis/connections-wfs/selected", name );
}

void QgsWFSConnection::deleteConnection( QString name )
{
QSettings settings;
settings.remove( "/Qgis/connections-wfs/" + name );
}


// TODO:
// - get URI
// - get capabilities
25 changes: 25 additions & 0 deletions src/providers/wfs/qgswfsconnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef QGSWFSCONNECTION_H
#define QGSWFSCONNECTION_H

#include <QObject>

class QgsWFSConnection : public QObject
{
Q_OBJECT
public:
explicit QgsWFSConnection(QObject *parent = 0);

static QStringList connectionList();

static void deleteConnection( QString name );

static QString selectedConnection();
static void setSelectedConnection( QString name );

signals:

public slots:

};

#endif // QGSWFSCONNECTION_H
9 changes: 9 additions & 0 deletions src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2301,3 +2301,12 @@ QGISEXTERN bool isProvider()
{
return true;
}

// ---------------------------------------------------------------------------

#include "qgswfssourceselect.h"

QGISEXTERN QgsWFSSourceSelect * selectWidget( QWidget * parent, Qt::WFlags fl )
{
return new QgsWFSSourceSelect( parent, fl );
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "qgisinterface.h"
#include "qgswfssourceselect.h"
#include "qgswfsconnection.h"
#include "qgsnewhttpconnection.h"
#include "qgsgenericprojectionselector.h"
#include "qgscontexthelp.h"
Expand All @@ -37,9 +38,8 @@

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

QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, QgisInterface* iface )
: QDialog( parent )
, mIface( iface )
QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mCapabilitiesReply( 0 )
{
setupUi( this );
Expand All @@ -66,17 +66,15 @@ QgsWFSSourceSelect::~QgsWFSSourceSelect()

void QgsWFSSourceSelect::populateConnectionList()
{
QSettings settings;
settings.beginGroup( "/Qgis/connections-wfs" );
QStringList keys = settings.childGroups();
QStringList keys = QgsWFSConnection::connectionList();

QStringList::Iterator it = keys.begin();
cmbConnections->clear();
while ( it != keys.end() )
{
cmbConnections->addItem( *it );
++it;
}
settings.endGroup();

if ( keys.begin() != keys.end() )
{
Expand All @@ -95,8 +93,7 @@ void QgsWFSSourceSelect::populateConnectionList()
}

//set last used connection
QSettings s;
QString selectedConnection = s.value( "/Qgis/connections-wfs/selected" ).toString();
QString selectedConnection = QgsWFSConnection::selectedConnection();
int index = cmbConnections->findText( selectedConnection );
if ( index != -1 )
{
Expand Down Expand Up @@ -321,14 +318,12 @@ void QgsWFSSourceSelect::modifyEntryOfServerList()

void QgsWFSSourceSelect::deleteEntryOfServerList()
{
QSettings settings;
QString key = "/Qgis/connections-wfs/" + cmbConnections->currentText();
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
.arg( cmbConnections->currentText() );
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
if ( result == QMessageBox::Ok )
{
settings.remove( key );
QgsWFSConnection::deleteConnection( cmbConnections->currentText() );
cmbConnections->removeItem( cmbConnections->currentIndex() );
}
}
Expand Down Expand Up @@ -393,12 +388,11 @@ void QgsWFSSourceSelect::addLayer()
filterString = ( "&FILTER=" + mFilterLineEdit->text() );
}

//add a wfs layer to the map
if ( mIface )
{
QString bBoxString;
#if 0
// TODO: resolve [MD]
//get current extent
QgsMapCanvas* canvas = mIface->mapCanvas();
QString bBoxString;
if ( canvas && mBboxCheckBox->isChecked() )
{
QgsRectangle currentExtent = canvas->extent();
Expand All @@ -408,8 +402,12 @@ void QgsWFSSourceSelect::addLayer()
.arg( currentExtent.xMaximum(), 0, 'f' )
.arg( currentExtent.yMaximum(), 0, 'f' );
}
mIface->addVectorLayer( uri + "SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=" + typeName + crsString + bBoxString + filterString, typeName, "WFS" );
}
#endif

//add a wfs layer to the map
uri += "SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=" + typeName + crsString + bBoxString + filterString;
emit addWfsLayer( uri, typeName );

accept();
}

Expand Down Expand Up @@ -462,8 +460,7 @@ void QgsWFSSourceSelect::changeCRSFilter()
void QgsWFSSourceSelect::on_cmbConnections_activated( int index )
{
Q_UNUSED( index );
QSettings s;
s.setValue( "/Qgis/connections-wfs/selected", cmbConnections->currentText() );
QgsWFSConnection::setSelectedConnection( cmbConnections->currentText() );
}

void QgsWFSSourceSelect::on_btnSave_clicked()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "ui_qgswfssourceselectbase.h"
#include "qgscontexthelp.h"

class QgisInterface;
class QgsGenericProjectionSelector;
class QNetworkReply;

Expand All @@ -31,12 +30,14 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase

public:

QgsWFSSourceSelect( QWidget* parent, QgisInterface* iface );
QgsWFSSourceSelect( QWidget* parent, Qt::WFlags fl );
~QgsWFSSourceSelect();

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

private:
QgsWFSSourceSelect(); //default constructor is forbidden
QgisInterface* mIface; //pointer to the QGIS interface object (needed to add WFS layers)
QString mUri; //uri of the currently connected server
QgsGenericProjectionSelector* mProjectionSelector;
/**Stores the available CRS for a server connections.
Expand Down
20 changes: 17 additions & 3 deletions src/ui/qgisapp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1054</width>
<height>491</height>
<width>1052</width>
<height>489</height>
</rect>
</property>
<widget class="QWidget" name="centralwidget"/>
Expand All @@ -16,7 +16,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1054</width>
<width>1052</width>
<height>23</height>
</rect>
</property>
Expand Down Expand Up @@ -147,6 +147,7 @@
<addaction name="mActionAddSpatiaLiteLayer"/>
<addaction name="mActionAddWmsLayer"/>
<addaction name="mActionAddLayerSeparator"/>
<addaction name="mActionAddWfsLayer"/>
<addaction name="separator"/>
<addaction name="mActionOpenTable"/>
<addaction name="mActionSaveEdits"/>
Expand Down Expand Up @@ -248,6 +249,7 @@
<addaction name="mActionAddPgLayer"/>
<addaction name="mActionAddSpatiaLiteLayer"/>
<addaction name="mActionAddWmsLayer"/>
<addaction name="mActionAddWfsLayer"/>
<addaction name="mActionNewVectorLayer"/>
<addaction name="mActionRemoveLayer"/>
</widget>
Expand Down Expand Up @@ -1528,6 +1530,18 @@
<string>Creates a scale bar that is displayed on the map canvas</string>
</property>
</action>
<action name="mActionAddWfsLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionAddWfsLayer.png</normaloff>:/images/themes/default/mActionAddWfsLayer.png</iconset>
</property>
<property name="text">
<string>Add WFS Layer...</string>
</property>
<property name="toolTip">
<string>Add WFS Layer</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down
File renamed without changes.