Skip to content
Permalink
Browse files

Use explicit flags to set behavior of QgsNewHttpConnection instead of…

… key parsing
  • Loading branch information
nyalldawson committed Sep 11, 2017
1 parent 88b8741 commit 61349506097263dc7a4fa54d7a2fad707e976bf2
@@ -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:
@@ -34,6 +52,9 @@ Constructor

};

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


/************************************************************************
* This file has been generated automatically from *
* *
@@ -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 );
@@ -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() );
@@ -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" ) );
@@ -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 );
@@ -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 )
@@ -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
@@ -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
@@ -52,4 +79,6 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsNewHttpConnection::ConnectionTypes )

#endif // QGSNEWHTTPCONNECTION_H
@@ -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() )
{
@@ -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() )
{
@@ -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() )
@@ -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() )
@@ -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() )
@@ -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() )
@@ -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() )
@@ -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() )
@@ -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() )
{
@@ -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() )
{
@@ -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() )
@@ -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() )
@@ -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" ) );

@@ -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" ) );

@@ -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() )
{
@@ -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() )
{

0 comments on commit 6134950

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