Skip to content

Commit

Permalink
Merge pull request #7170 from rouault/wfs_pagesize
Browse files Browse the repository at this point in the history
[WFS provider] [FEATURE] Allow user to enable/disable paging and specify page size (fixes #18935)
  • Loading branch information
rouault committed Jun 22, 2018
2 parents cbde32f + e998fcf commit 14a913e
Show file tree
Hide file tree
Showing 19 changed files with 640 additions and 55 deletions.
5 changes: 5 additions & 0 deletions python/gui/auto_generated/qgsnewhttpconnection.sip.in
Expand Up @@ -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.
Expand Down
91 changes: 75 additions & 16 deletions src/gui/qgsnewhttpconnection.cpp
Expand Up @@ -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() )
{
Expand All @@ -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 ) )
{
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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() );
Expand Down Expand Up @@ -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() );
Expand Down
32 changes: 32 additions & 0 deletions src/gui/qgsnewhttpconnection.h
Expand Up @@ -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:

Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wfs/CMakeLists.txt
Expand Up @@ -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 ()

Expand Down
14 changes: 14 additions & 0 deletions src/providers/wfs/qgswfsconnection.cpp
Expand Up @@ -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() ) ) );
}

Expand Down
4 changes: 4 additions & 0 deletions src/providers/wfs/qgswfsconstants.cpp
Expand Up @@ -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" ) );
Expand Down
4 changes: 4 additions & 0 deletions src/providers/wfs/qgswfsconstants.h
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/providers/wfs/qgswfsdatasourceuri.cpp
Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/providers/wfs/qgswfsdatasourceuri.h
Expand Up @@ -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;

Expand Down

0 comments on commit 14a913e

Please sign in to comment.