Skip to content
Permalink
Browse files
Read available provider fields for expression dialog from wfs Describ…
…eFeatureInfo
  • Loading branch information
mhugent committed Dec 7, 2011
1 parent c12b9ba commit 0f74e0782b2078959a5ca4dbf30ea1d65fc6a820
@@ -36,12 +36,17 @@ QgsWFSConnection::QgsWFSConnection( QString connName, QObject *parent ) :
}
}

QString QgsWFSConnection::uriGetCapabilities()
QString QgsWFSConnection::uriGetCapabilities() const
{
return mUri + "SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0";
}

QString QgsWFSConnection::uriGetFeature( QString typeName, QString crsString, QString filter, QgsRectangle bBox )
QString QgsWFSConnection::uriDescribeFeatureType( const QString& typeName ) const
{
return mUri + "SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=" + typeName;
}

QString QgsWFSConnection::uriGetFeature( QString typeName, QString crsString, QString filter, QgsRectangle bBox ) const
{
//get CRS
if ( !crsString.isEmpty() )
@@ -21,14 +21,16 @@ class QgsWFSConnection : public QObject
static void setSelectedConnection( QString name );

//! base service URI
QString uri() { return mUri; }
QString uri() const { return mUri; }
//! URI to get capabilities
QString uriGetCapabilities();
QString uriGetCapabilities() const;
//! URI to get schema of wfs layer
QString uriDescribeFeatureType( const QString& typeName ) const;
//! URI to get features
QString uriGetFeature( QString typeName,
QString crs = QString(),
QString filter = QString(),
QgsRectangle bBox = QgsRectangle() );
QgsRectangle bBox = QgsRectangle() ) const;

//! start network connection to get capabilities
void requestCapabilities();
@@ -47,12 +47,19 @@ static const QString GML_NAMESPACE = "http://www.opengis.net/gml";
QgsWFSProvider::QgsWFSProvider( const QString& uri )
: QgsVectorDataProvider( uri ),
mNetworkRequestFinished( true ),
mEncoding( QgsWFSProvider::GET ),
mUseIntersect( false ),
mSourceCRS( 0 ),
mFeatureCount( 0 ),
mValid( true )
{
mSpatialIndex = 0;
if ( uri.isEmpty() )
{
mValid = false;
return;
}

reloadData();
if ( mValid )
{
@@ -140,6 +140,9 @@ class QgsWFSProvider: public QgsVectorDataProvider
synchronize with changes in the data source*/
virtual void reloadData();

/**Collects information about the field types. Is called internally from QgsWFSProvider::getFeature. The method delegates the work to request specific ones and gives back the name of the geometry attribute and the thematic attributes with their types*/
int describeFeatureType( const QString& uri, QString& geometryAttribute, QgsFieldMap& fields );

signals:
void dataReadProgressMessage( QString message );

@@ -189,10 +192,6 @@ class QgsWFSProvider: public QgsVectorDataProvider
/**Server capabilities for this layer (generated from capabilities document)*/
int mCapabilities;


/**Collects information about the field types. Is called internally from QgsWFSProvider::getFeature. The method delegates the work to request specific ones and gives back the name of the geometry attribute and the thematic attributes with their types*/
int describeFeatureType( const QString& uri, QString& geometryAttribute, QgsFieldMap& fields );

//encoding specific methods of getFeature
int getFeatureGET( const QString& uri, const QString& geometryAttribute );
int getFeaturePOST( const QString& uri, const QString& geometryAttribute );
@@ -18,8 +18,10 @@
#include "qgisinterface.h"
#include "qgswfssourceselect.h"
#include "qgswfsconnection.h"
#include "qgswfsprovider.h"
#include "qgsnewhttpconnection.h"
#include "qgsgenericprojectionselector.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgscontexthelp.h"
#include "qgsproject.h"
#include "qgscoordinatereferencesystem.h"
@@ -279,7 +281,7 @@ void QgsWFSSourceSelect::addLayer()
{
QString typeName = ( *sIt )->text( 1 );
QString crs = labelCoordRefSys->text();
QString filter = mFilterLineEdit->text();
QString filter = ( *sIt )->text( 3 );

//add a wfs layer to the map
QgsWFSConnection conn( cmbConnections->currentText() );
@@ -364,3 +366,43 @@ void QgsWFSSourceSelect::on_btnLoad_clicked()
populateConnectionList();
emit connectionsChanged();
}

void QgsWFSSourceSelect::on_treeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
{
if ( item && column == 3 )
{
//get available fields for wfs layer
QgsWFSProvider p( "" );
QgsWFSConnection conn( cmbConnections->currentText() );
QString uri = conn.uriDescribeFeatureType( item->text( 1 ) );

QgsFieldMap fields;
QString geometryAttribute;
if ( p.describeFeatureType( uri, geometryAttribute, fields ) != 0 )
{
return;
}


//show expression builder
QgsExpressionBuilderDialog d( 0, item->text( 3 ) );

//add available attributes to expression builder
QgsExpressionBuilderWidget* w = d.expressionBuilder();
if ( !w )
{
return;
}

QgsFieldMap::const_iterator fieldIt = fields.constBegin();
for ( ; fieldIt != fields.constEnd(); ++fieldIt )
{
w->registerItem( tr( "Fields" ), fieldIt->name(), " " + fieldIt->name() + " ", "", QgsExpressionItem::Field );
}

if ( d.exec() == QDialog::Accepted )
{
item->setText( 3, w->getExpressionString() );
}
}
}
@@ -68,6 +68,7 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
void capabilitiesReplyFinished();
void on_btnSave_clicked();
void on_btnLoad_clicked();
void on_treeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column );

void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
};
@@ -112,7 +112,7 @@
<bool>true</bool>
</property>
<property name="columnCount">
<number>3</number>
<number>4</number>
</property>
<column>
<property name="text">
@@ -129,6 +129,11 @@
<string>Abstract</string>
</property>
</column>
<column>
<property name="text">
<string>Filter</string>
</property>
</column>
</widget>
</item>
<item row="2" column="0">
@@ -180,27 +185,13 @@
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mFilterStringLabel">
<property name="text">
<string>Filter</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mFilterLineEdit"/>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="mBboxCheckBox">
<property name="text">
<string>Only request features overlapping the current view extent</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>

0 comments on commit 0f74e07

Please sign in to comment.