Skip to content

Commit 0f74e07

Browse files
committed
Read available provider fields for expression dialog from wfs DescribeFeatureInfo
1 parent c12b9ba commit 0f74e07

File tree

7 files changed

+73
-26
lines changed

7 files changed

+73
-26
lines changed

src/providers/wfs/qgswfsconnection.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ QgsWFSConnection::QgsWFSConnection( QString connName, QObject *parent ) :
3636
}
3737
}
3838

39-
QString QgsWFSConnection::uriGetCapabilities()
39+
QString QgsWFSConnection::uriGetCapabilities() const
4040
{
4141
return mUri + "SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0";
4242
}
4343

44-
QString QgsWFSConnection::uriGetFeature( QString typeName, QString crsString, QString filter, QgsRectangle bBox )
44+
QString QgsWFSConnection::uriDescribeFeatureType( const QString& typeName ) const
45+
{
46+
return mUri + "SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=" + typeName;
47+
}
48+
49+
QString QgsWFSConnection::uriGetFeature( QString typeName, QString crsString, QString filter, QgsRectangle bBox ) const
4550
{
4651
//get CRS
4752
if ( !crsString.isEmpty() )

src/providers/wfs/qgswfsconnection.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ class QgsWFSConnection : public QObject
2121
static void setSelectedConnection( QString name );
2222

2323
//! base service URI
24-
QString uri() { return mUri; }
24+
QString uri() const { return mUri; }
2525
//! URI to get capabilities
26-
QString uriGetCapabilities();
26+
QString uriGetCapabilities() const;
27+
//! URI to get schema of wfs layer
28+
QString uriDescribeFeatureType( const QString& typeName ) const;
2729
//! URI to get features
2830
QString uriGetFeature( QString typeName,
2931
QString crs = QString(),
3032
QString filter = QString(),
31-
QgsRectangle bBox = QgsRectangle() );
33+
QgsRectangle bBox = QgsRectangle() ) const;
3234

3335
//! start network connection to get capabilities
3436
void requestCapabilities();

src/providers/wfs/qgswfsprovider.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,19 @@ static const QString GML_NAMESPACE = "http://www.opengis.net/gml";
4747
QgsWFSProvider::QgsWFSProvider( const QString& uri )
4848
: QgsVectorDataProvider( uri ),
4949
mNetworkRequestFinished( true ),
50+
mEncoding( QgsWFSProvider::GET ),
5051
mUseIntersect( false ),
5152
mSourceCRS( 0 ),
5253
mFeatureCount( 0 ),
5354
mValid( true )
5455
{
5556
mSpatialIndex = 0;
57+
if ( uri.isEmpty() )
58+
{
59+
mValid = false;
60+
return;
61+
}
62+
5663
reloadData();
5764
if ( mValid )
5865
{

src/providers/wfs/qgswfsprovider.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class QgsWFSProvider: public QgsVectorDataProvider
140140
synchronize with changes in the data source*/
141141
virtual void reloadData();
142142

143+
/**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*/
144+
int describeFeatureType( const QString& uri, QString& geometryAttribute, QgsFieldMap& fields );
145+
143146
signals:
144147
void dataReadProgressMessage( QString message );
145148

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

192-
193-
/**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*/
194-
int describeFeatureType( const QString& uri, QString& geometryAttribute, QgsFieldMap& fields );
195-
196195
//encoding specific methods of getFeature
197196
int getFeatureGET( const QString& uri, const QString& geometryAttribute );
198197
int getFeaturePOST( const QString& uri, const QString& geometryAttribute );

src/providers/wfs/qgswfssourceselect.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include "qgisinterface.h"
1919
#include "qgswfssourceselect.h"
2020
#include "qgswfsconnection.h"
21+
#include "qgswfsprovider.h"
2122
#include "qgsnewhttpconnection.h"
2223
#include "qgsgenericprojectionselector.h"
24+
#include "qgsexpressionbuilderdialog.h"
2325
#include "qgscontexthelp.h"
2426
#include "qgsproject.h"
2527
#include "qgscoordinatereferencesystem.h"
@@ -279,7 +281,7 @@ void QgsWFSSourceSelect::addLayer()
279281
{
280282
QString typeName = ( *sIt )->text( 1 );
281283
QString crs = labelCoordRefSys->text();
282-
QString filter = mFilterLineEdit->text();
284+
QString filter = ( *sIt )->text( 3 );
283285

284286
//add a wfs layer to the map
285287
QgsWFSConnection conn( cmbConnections->currentText() );
@@ -364,3 +366,43 @@ void QgsWFSSourceSelect::on_btnLoad_clicked()
364366
populateConnectionList();
365367
emit connectionsChanged();
366368
}
369+
370+
void QgsWFSSourceSelect::on_treeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
371+
{
372+
if ( item && column == 3 )
373+
{
374+
//get available fields for wfs layer
375+
QgsWFSProvider p( "" );
376+
QgsWFSConnection conn( cmbConnections->currentText() );
377+
QString uri = conn.uriDescribeFeatureType( item->text( 1 ) );
378+
379+
QgsFieldMap fields;
380+
QString geometryAttribute;
381+
if ( p.describeFeatureType( uri, geometryAttribute, fields ) != 0 )
382+
{
383+
return;
384+
}
385+
386+
387+
//show expression builder
388+
QgsExpressionBuilderDialog d( 0, item->text( 3 ) );
389+
390+
//add available attributes to expression builder
391+
QgsExpressionBuilderWidget* w = d.expressionBuilder();
392+
if ( !w )
393+
{
394+
return;
395+
}
396+
397+
QgsFieldMap::const_iterator fieldIt = fields.constBegin();
398+
for ( ; fieldIt != fields.constEnd(); ++fieldIt )
399+
{
400+
w->registerItem( tr( "Fields" ), fieldIt->name(), " " + fieldIt->name() + " ", "", QgsExpressionItem::Field );
401+
}
402+
403+
if ( d.exec() == QDialog::Accepted )
404+
{
405+
item->setText( 3, w->getExpressionString() );
406+
}
407+
}
408+
}

src/providers/wfs/qgswfssourceselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
6868
void capabilitiesReplyFinished();
6969
void on_btnSave_clicked();
7070
void on_btnLoad_clicked();
71+
void on_treeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column );
7172

7273
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
7374
};

src/ui/qgswfssourceselectbase.ui

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<bool>true</bool>
113113
</property>
114114
<property name="columnCount">
115-
<number>3</number>
115+
<number>4</number>
116116
</property>
117117
<column>
118118
<property name="text">
@@ -129,6 +129,11 @@
129129
<string>Abstract</string>
130130
</property>
131131
</column>
132+
<column>
133+
<property name="text">
134+
<string>Filter</string>
135+
</property>
136+
</column>
132137
</widget>
133138
</item>
134139
<item row="2" column="0">
@@ -180,27 +185,13 @@
180185
</widget>
181186
</item>
182187
<item row="3" column="0">
183-
<layout class="QHBoxLayout" name="horizontalLayout_2">
184-
<item>
185-
<widget class="QLabel" name="mFilterStringLabel">
186-
<property name="text">
187-
<string>Filter</string>
188-
</property>
189-
</widget>
190-
</item>
191-
<item>
192-
<widget class="QLineEdit" name="mFilterLineEdit"/>
193-
</item>
194-
</layout>
195-
</item>
196-
<item row="4" column="0">
197188
<widget class="QCheckBox" name="mBboxCheckBox">
198189
<property name="text">
199190
<string>Only request features overlapping the current view extent</string>
200191
</property>
201192
</widget>
202193
</item>
203-
<item row="5" column="0">
194+
<item row="4" column="0">
204195
<widget class="QDialogButtonBox" name="buttonBox">
205196
<property name="orientation">
206197
<enum>Qt::Horizontal</enum>

0 commit comments

Comments
 (0)