Skip to content
Permalink
Browse files

[WFS provider] [FEATURE] Allow user to enable/disable paging and spec…

…ify page size (fixes #18935)

The 'maximum number of features' settings is now always the maximum number of
features requested, even in WFS 2.0 with paging.
For WFS 2.0, we add a checkbox to enable/disable paging and a text entry to
specify the page size (if let to empty, server default is used)
We also add a Detect button so that the WFS version is autodetected.
  • Loading branch information
rouault committed Jun 4, 2018
1 parent e5e966b commit e998fcf0b2a1c7e07e6433b656a652eae46c6c35
@@ -92,6 +92,11 @@ Returns the "test connection" button.
.. versionadded:: 3.0
%End






virtual QString wfsSettingsKey( const QString &base, const QString &connectionName ) const;
%Docstring
Returns the QSettings key for WFS related settings for the connection.
@@ -62,10 +62,16 @@ QgsNewHttpConnection::QgsNewHttpConnection( QWidget *parent, ConnectionTypes typ
cmbDpiMode->addItem( tr( "GeoServer" ) );

cmbVersion->clear();
cmbVersion->addItem( tr( "Auto-detect" ) );
cmbVersion->addItem( tr( "Maximum" ) );
cmbVersion->addItem( tr( "1.0" ) );
cmbVersion->addItem( tr( "1.1" ) );
cmbVersion->addItem( tr( "2.0" ) );
connect( cmbVersion,
static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );

connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );

if ( !connectionName.isEmpty() )
{
@@ -86,6 +92,7 @@ QgsNewHttpConnection::QgsNewHttpConnection( QWidget *parent, ConnectionTypes typ
mAuthSettings->setPassword( settings.value( credentialsKey + "/password" ).toString() );
mAuthSettings->setConfigId( settings.value( credentialsKey + "/authcfg" ).toString() );
}
mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );

if ( !( mTypes & ConnectionWms ) && !( mTypes & ConnectionWcs ) )
{
@@ -148,6 +155,20 @@ QgsNewHttpConnection::QgsNewHttpConnection( QWidget *parent, ConnectionTypes typ
nameChanged( connectionName );
}

void QgsNewHttpConnection::wfsVersionCurrentIndexChanged( int index )
{
cbxWfsFeaturePaging->setEnabled( index == 0 || index == 3 );
lblPageSize->setEnabled( index == 0 || index == 3 );
txtPageSize->setEnabled( index == 0 || index == 3 );
cbxWfsIgnoreAxisOrientation->setEnabled( index != 1 );
}

void QgsNewHttpConnection::wfsFeaturePagingStateChanged( int state )
{
lblPageSize->setEnabled( state == Qt::Checked );
txtPageSize->setEnabled( state == Qt::Checked );
}

QString QgsNewHttpConnection::name() const
{
return txtName->text();
@@ -168,6 +189,7 @@ void QgsNewHttpConnection::urlChanged( const QString &text )
{
Q_UNUSED( text );
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
}

void QgsNewHttpConnection::updateOkButtonState()
@@ -209,6 +231,26 @@ QPushButton *QgsNewHttpConnection::testConnectButton()
return mTestConnectionButton;
}

QPushButton *QgsNewHttpConnection::wfsVersionDetectButton()
{
return mWfsVersionDetectButton;
}

QComboBox *QgsNewHttpConnection::wfsVersionComboBox()
{
return cmbVersion;
}

QCheckBox *QgsNewHttpConnection::wfsPagingEnabledCheckBox()
{
return cbxWfsFeaturePaging;
}

QLineEdit *QgsNewHttpConnection::wfsPageSizeLineEdit()
{
return txtPageSize;
}

QString QgsNewHttpConnection::wfsSettingsKey( const QString &base, const QString &connectionName ) const
{
return base + connectionName;
@@ -266,24 +308,18 @@ void QgsNewHttpConnection::updateServiceSpecificSettings()

txtReferer->setText( settings.value( wmsKey + "/referer" ).toString() );
txtMaxNumFeatures->setText( settings.value( wfsKey + "/maxnumfeatures" ).toString() );
}

void QgsNewHttpConnection::accept()
{
QgsSettings settings;
QString key = mBaseKey + txtName->text();
QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + txtName->text();
bool pagingEnabled = settings.value( wfsKey + "/pagingenabled", true ).toBool();
txtPageSize->setText( settings.value( wfsKey + "/pagesize" ).toString() );
cbxWfsFeaturePaging->setChecked( pagingEnabled );

if ( !validate() )
return;
txtPageSize->setEnabled( pagingEnabled );
lblPageSize->setEnabled( pagingEnabled );
cbxWfsFeaturePaging->setEnabled( pagingEnabled );
}

// on rename delete original entry first
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
{
settings.remove( mBaseKey + mOriginalConnName );
settings.remove( "qgis/" + mCredentialsBaseKey + '/' + mOriginalConnName );
settings.sync();
}
QUrl QgsNewHttpConnection::urlTrimmed() const
{

QUrl url( txtUrl->text().trimmed() );
const QList< QPair<QByteArray, QByteArray> > &items = url.encodedQueryItems();
@@ -306,7 +342,27 @@ void QgsNewHttpConnection::accept()
{
url.setEncodedPath( "/" );
}
return url;
}

void QgsNewHttpConnection::accept()
{
QgsSettings settings;
QString key = mBaseKey + txtName->text();
QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + txtName->text();

if ( !validate() )
return;

// on rename delete original entry first
if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
{
settings.remove( mBaseKey + mOriginalConnName );
settings.remove( "qgis/" + mCredentialsBaseKey + '/' + mOriginalConnName );
settings.sync();
}

QUrl url( urlTrimmed() );
settings.setValue( key + "/url", url.toString() );

QString wfsKey = wfsSettingsKey( mBaseKey, txtName->text() );
@@ -374,6 +430,9 @@ void QgsNewHttpConnection::accept()
settings.setValue( wfsKey + "/version", version );

settings.setValue( wfsKey + "/maxnumfeatures", txtMaxNumFeatures->text() );

settings.setValue( wfsKey + "/pagesize", txtPageSize->text() );
settings.setValue( wfsKey + "/pagingenabled", cbxWfsFeaturePaging->isChecked() );
}

settings.setValue( credentialsKey + "/username", mAuthSettings->username() );
@@ -97,6 +97,8 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo
void nameChanged( const QString & );
void urlChanged( const QString & );
void updateOkButtonState();
void wfsVersionCurrentIndexChanged( int index );
void wfsFeaturePagingStateChanged( int state );

protected:

@@ -113,6 +115,36 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo
*/
QPushButton *testConnectButton();

/**
* Returns the "WFS version detect" button.
* \since QGIS 3.2
*/
QPushButton *wfsVersionDetectButton() SIP_SKIP;

/**
* Returns the "WFS version" combobox.
* \since QGIS 3.2
*/
QComboBox *wfsVersionComboBox() SIP_SKIP;

/**
* Returns the "WFS paging enabled" checkbox
* \since QGIS 3.2
*/
QCheckBox *wfsPagingEnabledCheckBox() SIP_SKIP;

/**
* Returns the "WFS page size" edit
* \since QGIS 3.2
*/
QLineEdit *wfsPageSizeLineEdit() SIP_SKIP;

/**
* Returns the url.
* \since QGIS 3.2
*/
QUrl urlTrimmed() const SIP_SKIP;

/**
* Returns the QSettings key for WFS related settings for the connection.
* \see wmsSettingsKey()
@@ -33,9 +33,11 @@ SET (WFS_MOC_HDRS
IF (WITH_GUI)
SET(WFS_SRCS ${WFS_SRCS}
qgswfssourceselect.cpp
qgswfsnewconnection.cpp
)
SET(WFS_MOC_HDRS ${WFS_MOC_HDRS}
qgswfssourceselect.h
qgswfsnewconnection.h
)
ENDIF ()

@@ -39,6 +39,20 @@ QgsWfsConnection::QgsWfsConnection( const QString &connName )
mUri.setParam( QgsWFSConstants::URI_PARAM_MAXNUMFEATURES, maxnumfeatures );
}

const QString &pagesize = settings.value( key + "/" + QgsWFSConstants::SETTINGS_PAGE_SIZE ).toString();
if ( !pagesize.isEmpty() )
{
mUri.removeParam( QgsWFSConstants::URI_PARAM_PAGE_SIZE ); // setParam allow for duplicates!
mUri.setParam( QgsWFSConstants::URI_PARAM_PAGE_SIZE, pagesize );
}

if ( settings.contains( key + "/" + QgsWFSConstants::SETTINGS_PAGING_ENABLED ) )
{
mUri.removeParam( QgsWFSConstants::URI_PARAM_PAGING_ENABLED ); // setParam allow for duplicates!
mUri.setParam( QgsWFSConstants::URI_PARAM_PAGING_ENABLED,
settings.value( key + "/" + QgsWFSConstants::SETTINGS_PAGING_ENABLED, true ).toBool() ? "true" : "false" );
}

QgsDebugMsg( QString( "WFS full uri: '%1'." ).arg( QString( mUri.uri() ) ) );
}

@@ -38,12 +38,16 @@ const QString QgsWFSConstants::URI_PARAM_IGNOREAXISORIENTATION( QStringLiteral(
const QString QgsWFSConstants::URI_PARAM_INVERTAXISORIENTATION( QStringLiteral( "InvertAxisOrientation" ) );
const QString QgsWFSConstants::URI_PARAM_VALIDATESQLFUNCTIONS( QStringLiteral( "validateSQLFunctions" ) );
const QString QgsWFSConstants::URI_PARAM_HIDEDOWNLOADPROGRESSDIALOG( QStringLiteral( "hideDownloadProgressDialog" ) );
const QString QgsWFSConstants::URI_PARAM_PAGING_ENABLED( "pagingEnabled" );
const QString QgsWFSConstants::URI_PARAM_PAGE_SIZE( "pageSize" );

const QString QgsWFSConstants::VERSION_AUTO( QStringLiteral( "auto" ) );

const QString QgsWFSConstants::CONNECTIONS_WFS( QStringLiteral( "qgis/connections-wfs/" ) );
const QString QgsWFSConstants::SETTINGS_VERSION( QStringLiteral( "version" ) );
const QString QgsWFSConstants::SETTINGS_MAXNUMFEATURES( QStringLiteral( "maxnumfeatures" ) );
const QString QgsWFSConstants::SETTINGS_PAGING_ENABLED( QStringLiteral( "pagingenabled" ) );
const QString QgsWFSConstants::SETTINGS_PAGE_SIZE( QStringLiteral( "pagesize" ) );

const QString QgsWFSConstants::FIELD_GEN_COUNTER( QStringLiteral( "__qgis_gen_counter" ) );
const QString QgsWFSConstants::FIELD_GMLID( QStringLiteral( "__qgis_gmlid" ) );
@@ -46,6 +46,8 @@ struct QgsWFSConstants
static const QString URI_PARAM_INVERTAXISORIENTATION;
static const QString URI_PARAM_VALIDATESQLFUNCTIONS;
static const QString URI_PARAM_HIDEDOWNLOADPROGRESSDIALOG;
static const QString URI_PARAM_PAGING_ENABLED;
static const QString URI_PARAM_PAGE_SIZE;

//
static const QString VERSION_AUTO;
@@ -54,6 +56,8 @@ struct QgsWFSConstants
static const QString CONNECTIONS_WFS;
static const QString SETTINGS_VERSION;
static const QString SETTINGS_MAXNUMFEATURES;
static const QString SETTINGS_PAGING_ENABLED;
static const QString SETTINGS_PAGE_SIZE;

// Special fields of the cache
static const QString FIELD_GEN_COUNTER;
@@ -207,6 +207,20 @@ void QgsWFSDataSourceURI::setMaxNumFeatures( int maxNumFeatures )
mURI.setParam( QgsWFSConstants::URI_PARAM_MAXNUMFEATURES, QString( maxNumFeatures ) );
}

int QgsWFSDataSourceURI::pageSize() const
{
if ( !mURI.hasParam( QgsWFSConstants::URI_PARAM_PAGE_SIZE ) )
return 0;
return mURI.param( QgsWFSConstants::URI_PARAM_PAGE_SIZE ).toInt();
}

bool QgsWFSDataSourceURI::pagingEnabled() const
{
if ( !mURI.hasParam( QgsWFSConstants::URI_PARAM_PAGING_ENABLED ) )
return true;
return mURI.param( QgsWFSConstants::URI_PARAM_PAGING_ENABLED ) == QStringLiteral( "true" );
}

void QgsWFSDataSourceURI::setTypeName( const QString &typeName )
{
mURI.removeParam( QgsWFSConstants::URI_PARAM_TYPENAME );
@@ -102,6 +102,12 @@ class QgsWFSDataSourceURI
//! Sets user defined limit of features to download
void setMaxNumFeatures( int maxNumFeatures );

//! Returns user defined limit page size. 0=server udefault
int pageSize() const;

//! Returns whether paging is enabled.
bool pagingEnabled() const;

//! Gets typename (with prefix)
QString typeName() const;

0 comments on commit e998fcf

Please sign in to comment.
You can’t perform that action at this time.