30#include <QRegularExpression>
31#include <QRegularExpressionValidator>
35 : QDialog( parent, fl )
37 , mServiceName( serviceName )
38 , mOriginalConnName( connectionName )
43 if ( mServiceName.startsWith( QLatin1String(
"qgis/" ) ) )
50 mServiceName = mServiceName.split(
'-' ).last().toUpper();
58 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
60 QString connectionType = mServiceName;
61 if ( mServiceName == QLatin1String(
"WMS" ) )
63 connectionType = QStringLiteral(
"WMS/WMTS" );
65 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
67 txtName->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"[^\\/]+" ), txtName ) );
76 cmbTilePixelRatio->clear();
82 cmbVersion->addItem( tr(
"Maximum" ) );
83 cmbVersion->addItem( tr(
"1.0" ) );
84 cmbVersion->addItem( tr(
"1.1" ) );
85 cmbVersion->addItem( tr(
"2.0" ) );
86 cmbVersion->addItem( tr(
"OGC API - Features" ) );
88 static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
89 this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
91 connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
92 this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
94 if ( !connectionName.isEmpty() )
99 txtName->setText( connectionName );
100 const QStringList detailParameters { mServiceName.toLower(), connectionName };
111 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
115 mWmsOptionsGroupBox->setVisible(
false );
116 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
120 mWfsOptionsGroupBox->setVisible(
false );
121 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
125 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)" ) );
130 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
131 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
134 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
136 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
137 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
139 cmbDpiMode->setVisible(
false );
140 mGroupBox->layout()->removeWidget( cmbDpiMode );
141 lblDpiMode->setVisible(
false );
142 mGroupBox->layout()->removeWidget( lblDpiMode );
143 cmbTilePixelRatio->setVisible(
false );
144 mGroupBox->layout()->removeWidget( cmbTilePixelRatio );
145 lblTilePixelRatio->setVisible(
false );
146 mGroupBox->layout()->removeWidget( lblTilePixelRatio );
152 mTestConnectionButton->hide();
153 mGroupBox->layout()->removeWidget( mTestConnectionButton );
158 mAuthGroupBox->hide();
159 mGroupBox->layout()->removeWidget( mAuthGroupBox );
162 const int w = width();
164 resize( w, height() );
166 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
167 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
169 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
170 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
171 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
173 nameChanged( connectionName );
176void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
187void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
189 lblPageSize->setEnabled( state == Qt::Checked );
190 txtPageSize->setEnabled( state == Qt::Checked );
195 return txtName->text();
200 return txtUrl->text();
203void QgsNewHttpConnection::nameChanged(
const QString &text )
206 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
209void QgsNewHttpConnection::urlChanged(
const QString &text )
212 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
213 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
216void QgsNewHttpConnection::updateOkButtonState()
218 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
219 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
224 const QString newConnectionName = txtName->text();
229 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( newConnectionName, Qt::CaseInsensitive ) != 0 ) &&
231 QMessageBox::question(
this,
232 tr(
"Save Connection" ),
233 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
234 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
239 if ( ! mAuthSettings->password().isEmpty() &&
240 QMessageBox::question(
this,
241 tr(
"Saving Passwords" ),
242 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." ),
243 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
253 return mTestConnectionButton;
258 return mAuthSettings;
263 return mWfsVersionDetectButton;
273 return cbxWfsFeaturePaging;
278 return cbxWfsUseGml2EncodingForTransactions;
288 return base + connectionName;
293 return base + connectionName;
298 QStringList detailsParameters = { mServiceName.toLower(), mOriginalConnName };
312 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
314 cmbTilePixelRatio->setCurrentIndex( cmbTilePixelRatio->findData(
static_cast<int>( tilePixelRatio ) ) );
318 if ( version == QLatin1String(
"1.0.0" ) )
320 else if ( version == QLatin1String(
"1.1.0" ) )
322 else if ( version == QLatin1String(
"2.0.0" ) )
324 else if ( version == QLatin1String(
"OGC_API_FEATURES" ) )
326 cmbVersion->setCurrentIndex( versionIdx );
329 wfsVersionCurrentIndexChanged( versionIdx );
338 cbxWfsFeaturePaging->setChecked( pagingEnabled );
343 QUrl
url( txtUrl->text().trimmed() );
344 QUrlQuery query(
url );
345 const QList<QPair<QString, QString> > items = query.queryItems( QUrl::FullyEncoded );
346 QHash< QString, QPair<QString, QString> > params;
347 for (
const QPair<QString, QString> &it : items )
349 params.insert( it.first.toUpper(), it );
352 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
353 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
354 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
356 query.removeQueryItem( params.value( QStringLiteral(
"SERVICE" ) ).first );
357 query.removeQueryItem( params.value( QStringLiteral(
"REQUEST" ) ).first );
358 query.removeQueryItem( params.value( QStringLiteral(
"FORMAT" ) ).first );
361 url.setQuery( query );
363 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
372 const QString newConnectionName = txtName->text();
380 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
386 QStringList detailsParameters = {mServiceName.toLower(), newConnectionName};
419 QString version = QStringLiteral(
"auto" );
420 switch ( cmbVersion->currentIndex() )
423 version = QStringLiteral(
"auto" );
426 version = QStringLiteral(
"1.0.0" );
429 version = QStringLiteral(
"1.1.0" );
432 version = QStringLiteral(
"2.0.0" );
435 version = QStringLiteral(
"OGC_API_FEATURES" );
444 QStringList credentialsParameters = {mServiceName.toLower(), newConnectionName};
449 if ( mHttpHeaders->isVisible() )
457void QgsNewHttpConnection::showHelp()
TilePixelRatio
DpiMode enum.
@ Undefined
Undefined (not scale)
@ StandardDpi
Standard (96 DPI)
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 * settingsPreferCoordinatesForWfsT11
static const QgsSettingsEntryBool * settingsPagingEnabled
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryBool * settingsReportedLayerExtents
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryBool * settingsInvertAxisOrientation
static const QgsSettingsEntryString * settingsVersion
static const QgsSettingsEntryString * settingsPagesize
static const QgsSettingsEntryString * settingsAuthCfg
static const QgsSettingsEntryEnumFlag< Qgis::TilePixelRatio > * settingsTilePixelRatio
static const QgsSettingsEntryVariantMap * settingsHeaders
static const QgsSettingsEntryString * settingsUsername
static const QgsSettingsEntryBool * settingsSmoothPixmapTransform
static const QgsSettingsEntryString * settingsUrl
static const QgsSettingsEntryBool * settingsIgnoreGetMapURI
T valueWithDefaultOverride(const T &defaultValueOverride, const QString &dynamicKeyPart=QString()) const
Returns the settings value with a defaultValueOverride and with an optional dynamicKeyPart.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
bool exists(const QString &dynamicKeyPart=QString()) const
Returns true if the settings is contained in the underlying QSettings.
void deleteItem(const QString &item, const QStringList &parentsNamedItems=QStringList()) SIP_THROW(QgsSettingsException)
Deletes a named item from the named list node.
void setSelectedItem(const QString &item, const QStringList &parentsNamedItems=QStringList()) SIP_THROW(QgsSettingsException)
Sets the selected named item from the named list node.
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)