Skip to content

Commit

Permalink
Read available provider fields for expression dialog from wfs Describ…
Browse files Browse the repository at this point in the history
…eFeatureInfo
  • Loading branch information
mhugent committed Dec 7, 2011
1 parent c12b9ba commit 0f74e07
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 26 deletions.
9 changes: 7 additions & 2 deletions src/providers/wfs/qgswfsconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down
8 changes: 5 additions & 3 deletions src/providers/wfs/qgswfsconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
7 changes: 3 additions & 4 deletions src/providers/wfs/qgswfsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand Down
44 changes: 43 additions & 1 deletion src/providers/wfs/qgswfssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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() );
}
}
}
1 change: 1 addition & 0 deletions src/providers/wfs/qgswfssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() ); }
};
Expand Down
23 changes: 7 additions & 16 deletions src/ui/qgswfssourceselectbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<bool>true</bool>
</property>
<property name="columnCount">
<number>3</number>
<number>4</number>
</property>
<column>
<property name="text">
Expand All @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 0f74e07

Please sign in to comment.