28#include <QRegularExpression>
29#include <QRegularExpressionValidator>
33 : QDialog( parent, fl )
35 , mServiceName( serviceName )
36 , mOriginalConnName( connectionName )
41 if ( mServiceName.startsWith( QLatin1String(
"qgis/" ) ) )
48 mServiceName = mServiceName.split(
'-' ).last().toUpper();
56 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
58 QString connectionType = mServiceName;
59 if ( mServiceName == QLatin1String(
"WMS" ) )
61 connectionType = QStringLiteral(
"WMS/WMTS" );
63 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
65 txtName->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"[^\\/]+" ), txtName ) );
76 cmbVersion->addItem( tr(
"Maximum" ) );
77 cmbVersion->addItem( tr(
"1.0" ) );
78 cmbVersion->addItem( tr(
"1.1" ) );
79 cmbVersion->addItem( tr(
"2.0" ) );
80 cmbVersion->addItem( tr(
"OGC API - Features" ) );
82 static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
83 this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
85 connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
86 this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
88 if ( !connectionName.isEmpty() )
95 txtName->setText( connectionName );
97 mHttpHeaders->setFromSettings( settings, QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), connectionName ) );
106 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
110 mWmsOptionsGroupBox->setVisible(
false );
111 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
115 mWfsOptionsGroupBox->setVisible(
false );
116 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
120 txtUrl->setToolTip( tr(
"HTTP address of the WFS service, or landing page of a OGC API service<br>(an ending slash might be needed for some OGC API servers)" ) );
125 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
126 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
129 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
131 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
132 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
134 cmbDpiMode->setVisible(
false );
135 mGroupBox->layout()->removeWidget( cmbDpiMode );
136 lblDpiMode->setVisible(
false );
137 mGroupBox->layout()->removeWidget( lblDpiMode );
143 mTestConnectionButton->hide();
144 mGroupBox->layout()->removeWidget( mTestConnectionButton );
149 mAuthGroupBox->hide();
150 mGroupBox->layout()->removeWidget( mAuthGroupBox );
153 const int w = width();
155 resize( w, height() );
157 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
158 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
160 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
161 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
162 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
164 nameChanged( connectionName );
167void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
178void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
180 lblPageSize->setEnabled( state == Qt::Checked );
181 txtPageSize->setEnabled( state == Qt::Checked );
186 return txtName->text();
191 return txtUrl->text();
194void QgsNewHttpConnection::nameChanged(
const QString &text )
197 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
200void QgsNewHttpConnection::urlChanged(
const QString &text )
203 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
204 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
207void QgsNewHttpConnection::updateOkButtonState()
209 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
210 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
215 const QString newConnectionName = txtName->text();
220 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( newConnectionName, Qt::CaseInsensitive ) != 0 ) &&
222 QMessageBox::question(
this,
223 tr(
"Save Connection" ),
224 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
225 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
230 if ( ! mAuthSettings->password().isEmpty() &&
231 QMessageBox::question(
this,
232 tr(
"Saving Passwords" ),
233 tr(
"WARNING: You have entered a password. It will be stored in unsecured plain text in your project files and your home directory (Unix-like OS) or user profile (Windows). If you want to avoid this, press Cancel and either:\n\na) Don't provide a password in the connection settings — it will be requested interactively when needed;\nb) Use the Configuration tab to add your credentials in an HTTP Basic Authentication method and store them in an encrypted database." ),
234 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
244 return mTestConnectionButton;
249 return mAuthSettings;
254 return mWfsVersionDetectButton;
264 return cbxWfsFeaturePaging;
269 return cbxWfsUseGml2EncodingForTransactions;
279 return base + connectionName;
284 return base + connectionName;
289 QStringList detailsParameters = {mServiceName.toLower(), mOriginalConnName};
303 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
307 if ( version == QLatin1String(
"1.0.0" ) )
309 else if ( version == QLatin1String(
"1.1.0" ) )
311 else if ( version == QLatin1String(
"2.0.0" ) )
313 else if ( version == QLatin1String(
"OGC_API_FEATURES" ) )
315 cmbVersion->setCurrentIndex( versionIdx );
318 wfsVersionCurrentIndexChanged( versionIdx );
320 mHttpHeaders->setFromSettings(
QgsSettings(), QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), mOriginalConnName ) );
327 cbxWfsFeaturePaging->setChecked( pagingEnabled );
332 QUrl
url( txtUrl->text().trimmed() );
333 QUrlQuery query(
url );
334 const QList<QPair<QString, QString> > items = query.queryItems( QUrl::FullyEncoded );
335 QHash< QString, QPair<QString, QString> > params;
336 for (
const QPair<QString, QString> &it : items )
338 params.insert( it.first.toUpper(), it );
341 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
342 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
343 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
345 query.removeQueryItem( params.value( QStringLiteral(
"SERVICE" ) ).first );
346 query.removeQueryItem( params.value( QStringLiteral(
"REQUEST" ) ).first );
347 query.removeQueryItem( params.value( QStringLiteral(
"FORMAT" ) ).first );
350 url.setQuery( query );
352 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
361 const QString newConnectionName = txtName->text();
369 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
376 QStringList detailsParameters = {mServiceName.toLower(), newConnectionName};
399 mHttpHeaders->updateSettings( settings, QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), newConnectionName ) );
407 QString version = QStringLiteral(
"auto" );
408 switch ( cmbVersion->currentIndex() )
411 version = QStringLiteral(
"auto" );
414 version = QStringLiteral(
"1.0.0" );
417 version = QStringLiteral(
"1.1.0" );
420 version = QStringLiteral(
"2.0.0" );
423 version = QStringLiteral(
"OGC_API_FEATURES" );
432 QStringList credentialsParameters = {mServiceName, newConnectionName};
437 if ( mHttpHeaders->isVisible() )
438 mHttpHeaders->updateSettings( settings, QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), newConnectionName ) );
445void QgsNewHttpConnection::showHelp()
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QPushButton * testConnectButton()
Returns the "test connection" button.
QgsAuthSettingsWidget * authSettingsWidget()
Returns the current authentication settings widget.
QCheckBox * wfsPagingEnabledCheckBox()
Returns the "WFS paging enabled" checkbox.
virtual bool validate()
Returns true if dialog settings are valid, or false if current settings are not valid and the dialog ...
QString name() const
Returns the current connection name.
@ FlagShowHttpSettings
Display the 'http' group.
@ FlagHideAuthenticationGroup
Hide the Authentication group.
@ FlagShowTestConnection
Display the 'test connection' button.
QCheckBox * wfsUseGml2EncodingForTransactions()
Returns the "Use GML2 encoding for transactions" checkbox.
QComboBox * wfsVersionComboBox()
Returns the "WFS version" combobox.
virtual QString wmsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WMS related settings for the connection.
virtual QString wfsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WFS related settings for the connection.
QString url() const
Returns the current connection url.
QPushButton * wfsVersionDetectButton()
Returns the "WFS version detect" button.
@ WFS_VERSION_API_FEATURES_1_0
QUrl urlTrimmed() const
Returns the url.
QgsNewHttpConnection(QWidget *parent=nullptr, QgsNewHttpConnection::ConnectionTypes types=ConnectionWms, const QString &serviceName SIP_PYARGRENAME(settingsKey)="WMS", const QString &connectionName=QString(), QgsNewHttpConnection::Flags flags=QgsNewHttpConnection::Flags(), Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsNewHttpConnection.
QLineEdit * wfsPageSizeLineEdit()
Returns the "WFS page size" edit.
void updateServiceSpecificSettings()
Triggers a resync of the GUI widgets for the service specific settings (i.e.
@ ConnectionWms
WMS connection.
@ ConnectionWfs
WFS connection.
@ ConnectionWcs
WCS connection.
static const QgsSettingsEntryBool settingsConnectionIgnoreGetMapURI
static const QgsSettingsEntryString settingsConnectionPagesize
static const QgsSettingsEntryString settingsConnectionUrl
static const QgsSettingsEntryBool settingsConnectionPagingEnabled
static const QgsSettingsEntryString settingsConnectionPassword
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > settingsConnectionDpiMode
static const QgsSettingsEntryBool settingsConnectionIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString settingsConnectionVersion
static const QgsSettingsEntryString settingsConnectionUsername
static const QgsSettingsEntryGroup settingsServiceConnectionDetailsGroup
static const QgsSettingsEntryBool settingsConnectionReportedLayerExtents
static const QgsSettingsEntryString settingsConnectionMaxNumFeatures
static const QgsSettingsEntryBool settingsConnectionSmoothPixmapTransform
static const QgsSettingsEntryString settingsConnectionSelected
static const QgsSettingsEntryBool settingsConnectionPreferCoordinatesForWfsT11
static const QgsSettingsEntryBool settingsConnectionIgnoreAxisOrientation
static const QgsSettingsEntryGroup settingsServiceConnectionCredentialsGroup
static const QgsSettingsEntryString settingsConnectionAuthCfg
static const QgsSettingsEntryBool settingsConnectionInvertAxisOrientation
bool exists(const QString &dynamicKeyPart=QString()) const
Returns true if the settings is contained in the underlying QSettings.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
T valueWithDefaultOverride(T defaultValueOverride, const QString &dynamicKeyPart=QString()) const
Returns the settings value with a defaultValueOverride and with an optional dynamicKeyPart.
bool setValue(T value, const QString &dynamicKeyPart=QString()) const
Set settings value.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
void removeAllChildrenSettings(const QString &dynamicKeyPart=QString()) const
Removes all the settings from this group The dynamicKeyPart argument specifies the dynamic part of th...
This class is a composition of two QSettings instances:
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
QString fromEncodedComponent_helper(const QByteArray &ba)