83 changes: 70 additions & 13 deletions 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 @@ -49,10 +51,6 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, Qt::WFlags fl, bool emb
buttonBox->button( QDialogButtonBox::Cancel )->hide();
}

// keep the "use current view extent" checkbox hidden until
// the functionality is reintroduced [MD]
mBboxCheckBox->hide();

connect( buttonBox, SIGNAL( accepted() ), this, SLOT( addLayer() ) );
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
connect( btnNew, SIGNAL( clicked() ), this, SLOT( addEntryToServerList() ) );
Expand Down Expand Up @@ -263,27 +261,24 @@ void QgsWFSSourceSelect::addLayer()
}

QgsRectangle bBox;
#if 0
// TODO: resolve [MD]
//get current extent
QgsMapCanvas* canvas = mIface->mapCanvas();
if ( canvas && mBboxCheckBox->isChecked() )
QgsRectangle currentRectangle;
if ( mBboxCheckBox->isChecked() )
{
QgsRectangle currentExtent = canvas->extent();
currentRectangle = mExtent;
}
#endif


QList<QTreeWidgetItem*> selectedItems = treeWidget->selectedItems();
QList<QTreeWidgetItem*>::const_iterator sIt = selectedItems.constBegin();
for ( ; sIt != selectedItems.constEnd(); ++sIt )
{
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() );
QString uri = conn.uriGetFeature( typeName, crs, filter, bBox );
QString uri = conn.uriGetFeature( typeName, crs, filter, currentRectangle );
emit addWfsLayer( uri, typeName );
}
}
Expand Down Expand Up @@ -364,3 +359,65 @@ 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() );
}
}
}

void QgsWFSSourceSelect::showEvent( QShowEvent* event )
{
Q_UNUSED( event );
QVariant extentVariant = property( "MapExtent" );
if ( extentVariant.isValid() )
{
QString extentString = extentVariant.toString();
QStringList minMaxSplit = extentString.split( ":" );
if ( minMaxSplit.size() > 1 )
{
QStringList xyMinSplit = minMaxSplit[0].split( "," );
QStringList xyMaxSplit = minMaxSplit[1].split( "," );
if ( xyMinSplit.size() > 1 && xyMaxSplit.size() > 1 )
{
mExtent.set( xyMinSplit[0].toDouble(), xyMinSplit[1].toDouble(), xyMaxSplit[0].toDouble(), xyMaxSplit[1].toDouble() );
return;
}
}
}
mBboxCheckBox->hide();
}
6 changes: 6 additions & 0 deletions src/providers/wfs/qgswfssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "ui_qgswfssourceselectbase.h"
#include "qgscontexthelp.h"
#include "qgsrectangle.h"

class QgsGenericProjectionSelector;
class QgsWFSConnection;
Expand All @@ -46,6 +47,7 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
std::map<QString, std::list<QString> > mAvailableCRS;
QAbstractButton* btnAdd;
QgsWFSConnection* mConn;
QgsRectangle mExtent;

void populateConnectionList();

Expand All @@ -68,8 +70,12 @@ 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() ); }

protected:
void showEvent( QShowEvent* event );
};

#endif
25 changes: 8 additions & 17 deletions src/ui/qgswfssourceselectbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@
<item row="1" column="0">
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<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