Skip to content

Commit

Permalink
Use explicit flags to set behavior of QgsNewHttpConnection instead of…
Browse files Browse the repository at this point in the history
… key parsing
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 88b8741 commit 6134950
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 34 deletions.
25 changes: 23 additions & 2 deletions python/gui/qgsnewhttpconnection.sip
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,27 @@ class QgsNewHttpConnection : QDialog
#include "qgsnewhttpconnection.h"
%End
public:
QgsNewHttpConnection( QWidget *parent /TransferThis/ = 0, const QString &baseKey = "qgis/connections-wms/", const QString &connName = QString(), Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

enum ConnectionType
{
ConnectionWfs,
ConnectionWms,
ConnectionWcs,
ConnectionOther,
};
typedef QFlags<QgsNewHttpConnection::ConnectionType> ConnectionTypes;


QgsNewHttpConnection( QWidget *parent /TransferThis/ = 0,
QgsNewHttpConnection::ConnectionTypes types = ConnectionWms,
const QString &baseKey = "qgis/connections-wms/",
const QString &connectionName = QString(),
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
%Docstring
Constructor
Constructor for QgsNewHttpConnection.

The ``types`` argument dictates which connection type settings should be
shown in the dialog.
%End

public slots:
Expand All @@ -34,6 +52,9 @@ Constructor

};

QFlags<QgsNewHttpConnection::ConnectionType> operator|(QgsNewHttpConnection::ConnectionType f1, QFlags<QgsNewHttpConnection::ConnectionType> f2);


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
27 changes: 13 additions & 14 deletions src/gui/qgsnewhttpconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
#include <QRegExp>
#include <QRegExpValidator>

QgsNewHttpConnection::QgsNewHttpConnection(
QWidget *parent, const QString &baseKey, const QString &connName, Qt::WindowFlags fl )
QgsNewHttpConnection::QgsNewHttpConnection( QWidget *parent, ConnectionTypes types, const QString &baseKey, const QString &connectionName, Qt::WindowFlags fl )
: QDialog( parent, fl )
, mTypes( types )
, mBaseKey( baseKey )
, mOriginalConnName( connName )

{
setupUi( this );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsNewHttpConnection::showHelp );
Expand Down Expand Up @@ -64,16 +63,16 @@ QgsNewHttpConnection::QgsNewHttpConnection(
mAuthConfigSelect = new QgsAuthConfigSelect( this );
tabAuth->insertTab( 1, mAuthConfigSelect, tr( "Configurations" ) );

if ( !connName.isEmpty() )
if ( !connectionName.isEmpty() )
{
// populate the dialog with the information stored for the connection
// populate the fields with the stored setting parameters

QgsSettings settings;

QString key = mBaseKey + connName;
QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + connName;
txtName->setText( connName );
QString key = mBaseKey + connectionName;
QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + connectionName;
txtName->setText( connectionName );
txtUrl->setText( settings.value( key + "/url" ).toString() );

cbxIgnoreGetMapURI->setChecked( settings.value( key + "/ignoreGetMapURI", false ).toBool() );
Expand Down Expand Up @@ -127,23 +126,23 @@ QgsNewHttpConnection::QgsNewHttpConnection(
}
}

if ( mBaseKey != QLatin1String( "qgis/connections-wms/" ) )
if ( !( mTypes & ConnectionWms ) )
{
if ( mBaseKey != QLatin1String( "qgis/connections-wcs/" ) &&
mBaseKey != QLatin1String( "qgis/connections-wfs/" ) )
if ( !( mTypes & ConnectionWcs ) &&
!( mTypes & ConnectionWfs ) )
{
cbxIgnoreAxisOrientation->setVisible( false );
cbxInvertAxisOrientation->setVisible( false );
mGroupBox->layout()->removeWidget( cbxIgnoreAxisOrientation );
mGroupBox->layout()->removeWidget( cbxInvertAxisOrientation );
}

if ( mBaseKey == QLatin1String( "qgis/connections-wfs/" ) )
if ( mTypes & ConnectionWfs )
{
cbxIgnoreAxisOrientation->setText( tr( "Ignore axis orientation (WFS 1.1/WFS 2.0)" ) );
}

if ( mBaseKey == QLatin1String( "qgis/connections-wcs/" ) )
if ( mTypes & ConnectionWcs )
{
cbxIgnoreGetMapURI->setText( tr( "Ignore GetCoverage URI reported in capabilities" ) );
cbxIgnoreAxisOrientation->setText( tr( "Ignore axis orientation" ) );
Expand All @@ -170,7 +169,7 @@ QgsNewHttpConnection::QgsNewHttpConnection(
mGroupBox->layout()->removeWidget( lblReferer );
}

if ( mBaseKey != QLatin1String( "qgis/connections-wfs/" ) )
if ( !( mTypes & ConnectionWfs ) )
{
lblVersion->setVisible( false );
cmbVersion->setVisible( false );
Expand All @@ -186,7 +185,7 @@ QgsNewHttpConnection::QgsNewHttpConnection(
adjustSize();
resize( w, height() );

on_txtName_textChanged( connName );
on_txtName_textChanged( connectionName );
}

void QgsNewHttpConnection::on_txtName_textChanged( const QString &text )
Expand Down
33 changes: 31 additions & 2 deletions src/gui/qgsnewhttpconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,32 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo
Q_OBJECT

public:
//! Constructor
QgsNewHttpConnection( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &baseKey = "qgis/connections-wms/", const QString &connName = QString(), Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

/**
* Available connection types for configuring in the dialog.
* \since QGIS 3.0
*/
enum ConnectionType
{
ConnectionWfs = 1 << 1, //!< WFS connection
ConnectionWms = 1 << 2, //!< WMS connection
ConnectionWcs = 1 << 3, //!< WCS connection
ConnectionOther = 1 << 4, //!< Other connection type
};
Q_DECLARE_FLAGS( ConnectionTypes, ConnectionType )

/**
* Constructor for QgsNewHttpConnection.
*
* The \a types argument dictates which connection type settings should be
* shown in the dialog.
*
*/
QgsNewHttpConnection( QWidget *parent SIP_TRANSFERTHIS = nullptr,
QgsNewHttpConnection::ConnectionTypes types = ConnectionWms,
const QString &baseKey = "qgis/connections-wms/",
const QString &connectionName = QString(),
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );

public slots:
// Saves the connection to ~/.qt/qgisrc
Expand All @@ -44,6 +68,9 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo
void on_txtUrl_textChanged( const QString & );

private:

ConnectionTypes mTypes = ConnectionWms;

QString mBaseKey;
QString mCredentialsBaseKey;
QString mOriginalConnName; //store initial name to delete entry in case of rename
Expand All @@ -52,4 +79,6 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsNewHttpConnection::ConnectionTypes )

#endif // QGSNEWHTTPCONNECTION_H
19 changes: 17 additions & 2 deletions src/gui/qgsowssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,23 @@ void QgsOWSSourceSelect::populateConnectionList()

setConnectionListPosition();
}

QgsNewHttpConnection::ConnectionType connectionTypeFromServiceString( const QString &string )
{
if ( string.compare( QStringLiteral( "wms" ), Qt::CaseInsensitive ) == 0 )
return QgsNewHttpConnection::ConnectionWms;
else if ( string.compare( QStringLiteral( "wfs" ), Qt::CaseInsensitive ) == 0 )
return QgsNewHttpConnection::ConnectionWfs;
else if ( string.compare( QStringLiteral( "wcs" ), Qt::CaseInsensitive ) == 0 )
return QgsNewHttpConnection::ConnectionWcs;
else
return QgsNewHttpConnection::ConnectionWms;
}

void QgsOWSSourceSelect::on_mNewButton_clicked()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/qgis/connections-" + mService.toLower() + '/' );
QgsNewHttpConnection::ConnectionType type = connectionTypeFromServiceString( mService );
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, "/qgis/connections-" + mService.toLower() + '/' );

if ( nc->exec() )
{
Expand All @@ -244,7 +258,8 @@ void QgsOWSSourceSelect::on_mNewButton_clicked()

void QgsOWSSourceSelect::on_mEditButton_clicked()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );
QgsNewHttpConnection::ConnectionType type = connectionTypeFromServiceString( mService );
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, "/qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );

if ( nc->exec() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsafsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void QgsAfsRootItem::connectionsChanged()

void QgsAfsRootItem::newConnection()
{
QgsNewHttpConnection nc( 0, QStringLiteral( "qgis/connections-arcgisfeatureserver/" ) );
QgsNewHttpConnection nc( 0, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgisfeatureserver/" ) );
nc.setWindowTitle( tr( "Create a New ArcGisFeatureServer Connection" ) );

if ( nc.exec() )
Expand Down Expand Up @@ -137,7 +137,7 @@ QList<QAction *> QgsAfsConnectionItem::actions()

void QgsAfsConnectionItem::editConnection()
{
QgsNewHttpConnection nc( 0, QStringLiteral( "qgis/connections-arcgisfeatureserver/" ), mName );
QgsNewHttpConnection nc( 0, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgisfeatureserver/" ), mName );
nc.setWindowTitle( tr( "Modify ArcGisFeatureServer Connection" ) );

if ( nc.exec() )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsamsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void QgsAmsRootItem::connectionsChanged()

void QgsAmsRootItem::newConnection()
{
QgsNewHttpConnection nc( 0, QStringLiteral( "qgis/connections-arcgismapserver/" ) );
QgsNewHttpConnection nc( 0, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgismapserver/" ) );
nc.setWindowTitle( tr( "Create a New ArcGisMapServer Connection" ) );

if ( nc.exec() )
Expand Down Expand Up @@ -153,7 +153,7 @@ QList<QAction *> QgsAmsConnectionItem::actions()

void QgsAmsConnectionItem::editConnection()
{
QgsNewHttpConnection nc( 0, QStringLiteral( "qgis/connections-arcgismapserver/" ), mName );
QgsNewHttpConnection nc( 0, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgismapserver/" ), mName );
nc.setWindowTitle( tr( "Modify ArcGisMapServer Connection" ) );

if ( nc.exec() )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void QgsArcGisServiceSourceSelect::refresh()
void QgsArcGisServiceSourceSelect::addEntryToServerList()
{

QgsNewHttpConnection nc( 0, QStringLiteral( "qgis/connections-%1/" ).arg( mServiceName.toLower() ) );
QgsNewHttpConnection nc( 0, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-%1/" ).arg( mServiceName.toLower() ) );
nc.setWindowTitle( tr( "Create a New %1 Connection" ).arg( mServiceName ) );

if ( nc.exec() )
Expand All @@ -221,7 +221,7 @@ void QgsArcGisServiceSourceSelect::addEntryToServerList()

void QgsArcGisServiceSourceSelect::modifyEntryOfServerList()
{
QgsNewHttpConnection nc( 0, QStringLiteral( "qgis/connections-%1/" ).arg( mServiceName.toLower() ), cmbConnections->currentText() );
QgsNewHttpConnection nc( 0, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-%1/" ).arg( mServiceName.toLower() ), cmbConnections->currentText() );
nc.setWindowTitle( tr( "Modify %1 Connection" ).arg( mServiceName ) );

if ( nc.exec() )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wcs/qgswcsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ QList<QAction *> QgsWCSConnectionItem::actions()

void QgsWCSConnectionItem::editConnection()
{
QgsNewHttpConnection nc( nullptr, QStringLiteral( "qgis/connections-wcs/" ), mName );
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWcs, QStringLiteral( "qgis/connections-wcs/" ), mName );

if ( nc.exec() )
{
Expand Down Expand Up @@ -272,7 +272,7 @@ void QgsWCSRootItem::connectionsChanged()

void QgsWCSRootItem::newConnection()
{
QgsNewHttpConnection nc( nullptr, QStringLiteral( "qgis/connections-wcs/" ) );
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWcs, QStringLiteral( "qgis/connections-wcs/" ) );

if ( nc.exec() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wfs/qgswfsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ QList<QAction *> QgsWfsConnectionItem::actions()

void QgsWfsConnectionItem::editConnection()
{
QgsNewHttpConnection nc( nullptr, QgsWFSConstants::CONNECTIONS_WFS, mName );
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS, mName );
nc.setWindowTitle( tr( "Modify WFS Connection" ) );

if ( nc.exec() )
Expand Down Expand Up @@ -191,7 +191,7 @@ void QgsWfsRootItem::connectionsChanged()

void QgsWfsRootItem::newConnection()
{
QgsNewHttpConnection nc( nullptr, QgsWFSConstants::CONNECTIONS_WFS );
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS );
nc.setWindowTitle( tr( "Create a New WFS Connection" ) );

if ( nc.exec() )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wfs/qgswfssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void QgsWFSSourceSelect::capabilitiesReplyFinished()

void QgsWFSSourceSelect::addEntryToServerList()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, QgsWFSConstants::CONNECTIONS_WFS );
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS );
nc->setAttribute( Qt::WA_DeleteOnClose );
nc->setWindowTitle( tr( "Create a New WFS Connection" ) );

Expand All @@ -302,7 +302,7 @@ void QgsWFSSourceSelect::addEntryToServerList()

void QgsWFSSourceSelect::modifyEntryOfServerList()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, QgsWFSConstants::CONNECTIONS_WFS, cmbConnections->currentText() );
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS, cmbConnections->currentText() );
nc->setAttribute( Qt::WA_DeleteOnClose );
nc->setWindowTitle( tr( "Modify WFS Connection" ) );

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ QList<QAction *> QgsWMSConnectionItem::actions()

void QgsWMSConnectionItem::editConnection()
{
QgsNewHttpConnection nc( nullptr, QStringLiteral( "qgis/connections-wms/" ), mName );
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWms, QStringLiteral( "qgis/connections-wms/" ), mName );

if ( nc.exec() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void QgsWMSSourceSelect::on_btnNew_clicked()

void QgsWMSSourceSelect::on_btnEdit_clicked()
{
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, QStringLiteral( "qgis/connections-wms/" ), cmbConnections->currentText() );
QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, QgsNewHttpConnection::ConnectionWms, QStringLiteral( "qgis/connections-wms/" ), cmbConnections->currentText() );

if ( nc->exec() )
{
Expand Down

0 comments on commit 6134950

Please sign in to comment.