30#include <QRegularExpression>
31#include <QRegularExpressionValidator>
35#include "moc_qgsnewhttpconnection.cpp"
40 : QDialog( parent, fl )
42 , mServiceName( serviceName )
43 , mOriginalConnName( connectionName )
48 if ( mServiceName.startsWith( QLatin1String(
"qgis/" ) ) )
55 mServiceName = mServiceName.split(
'-' ).last().toUpper();
63 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
65 QString connectionType = mServiceName;
66 if ( mServiceName == QLatin1String(
"WMS" ) )
68 connectionType = QStringLiteral(
"WMS/WMTS" );
71 if ( connectionName.isEmpty() )
73 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
77 setWindowTitle( tr(
"Edit %1 Connection \"%2\"" ).arg( connectionType, connectionName ) );
80 txtName->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"[^\\/]+" ), txtName ) );
89 cmbTilePixelRatio->clear();
95 cmbVersion->addItem( tr(
"Maximum" ) );
96 cmbVersion->addItem( tr(
"1.0" ) );
97 cmbVersion->addItem( tr(
"1.1" ) );
98 cmbVersion->addItem( tr(
"2.0" ) );
99 cmbVersion->addItem( tr(
"OGC API - Features" ) );
100 connect( cmbVersion,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
102 mFeatureFormatComboBox->clear();
103 mFeatureFormatComboBox->addItem( tr(
"Default" ), QStringLiteral(
"default" ) );
105 mComboWfsFeatureMode->clear();
106 mComboWfsFeatureMode->addItem( tr(
"Default" ), QStringLiteral(
"default" ) );
107 mComboWfsFeatureMode->addItem( tr(
"Simple Features" ), QStringLiteral(
"simpleFeatures" ) );
108 mComboWfsFeatureMode->addItem( tr(
"Complex Features" ), QStringLiteral(
"complexFeatures" ) );
112 mComboHttpMethod->setCurrentIndex( mComboHttpMethod->findData( QVariant::fromValue(
Qgis::HttpMethod::Get ) ) );
114 cmbFeaturePaging->clear();
115 cmbFeaturePaging->addItem( tr(
"Default (trust server capabilities)" ) );
116 cmbFeaturePaging->addItem( tr(
"Enabled" ) );
117 cmbFeaturePaging->addItem( tr(
"Disabled" ) );
118 connect( cmbFeaturePaging,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged );
122 if ( !connectionName.isEmpty() )
127 txtName->setText( connectionName );
128 const QStringList detailParameters { mServiceName.toLower(), connectionName };
140 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
144 mWmsOptionsGroupBox->setVisible(
false );
145 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
149 mWfsOptionsGroupBox->setVisible(
false );
150 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
154 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)" ) );
159 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
160 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
163 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
165 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
166 mWmsOptionsGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
168 sbFeatureCount->setVisible(
false );
169 mWmsOptionsGroupBox->layout()->removeWidget( sbFeatureCount );
170 lblFeatureCount->setVisible(
false );
171 mWmsOptionsGroupBox->layout()->removeWidget( lblFeatureCount );
173 cmbDpiMode->setVisible(
false );
174 mWmsOptionsGroupBox->layout()->removeWidget( cmbDpiMode );
175 lblDpiMode->setVisible(
false );
176 mWmsOptionsGroupBox->layout()->removeWidget( lblDpiMode );
177 cmbTilePixelRatio->setVisible(
false );
178 mWmsOptionsGroupBox->layout()->removeWidget( cmbTilePixelRatio );
179 lblTilePixelRatio->setVisible(
false );
180 mWmsOptionsGroupBox->layout()->removeWidget( lblTilePixelRatio );
186 mTestConnectionButton->hide();
187 mGroupBox->layout()->removeWidget( mTestConnectionButton );
192 mAuthGroupBox->hide();
193 mGroupBox->layout()->removeWidget( mAuthGroupBox );
196 mWmsFormatDetectButton->setDisabled( txtUrl->text().isEmpty() );
198 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
199 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
201 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
202 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
203 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
205 nameChanged( connectionName );
208void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
212 lblFeaturePaging->setEnabled( pagingOptionsEnabled );
213 cmbFeaturePaging->setEnabled( pagingOptionsEnabled );
214 lblPageSize->setEnabled( pagingOptionsEnabled );
215 txtPageSize->setEnabled( pagingOptionsEnabled );
224void QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged(
int index )
227 lblPageSize->setEnabled( pagingNotDisabled );
228 txtPageSize->setEnabled( pagingNotDisabled );
233 return txtName->text();
238 return txtUrl->text();
241void QgsNewHttpConnection::nameChanged(
const QString &text )
244 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
247void QgsNewHttpConnection::urlChanged(
const QString &text )
250 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
251 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
252 mWmsFormatDetectButton->setDisabled( txtUrl->text().isEmpty() );
255void QgsNewHttpConnection::updateOkButtonState()
257 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
258 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
263 const QString newConnectionName = txtName->text();
268 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( newConnectionName, Qt::CaseInsensitive ) != 0 ) && urlExists && QMessageBox::question(
this, tr(
"Save Connection" ), tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
273 if ( !mAuthSettings->password().isEmpty() && QMessageBox::question(
this, tr(
"Saving Passwords" ), 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." ), QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
283 return mTestConnectionButton;
288 return mWmsFormatDetectButton;
293 return mAuthSettings;
298 return QgsAuthorizationSettings( mAuthSettings->username(), mAuthSettings->password(), mHttpHeaders->httpHeaders(), mAuthSettings->configId() );
303 return cbxWmsIgnoreAxisOrientation->isChecked();
308 return mWmsPreferredFormatCombo;
313 return cbxWmsInvertAxisOrientation->isChecked();
319 return mWfsVersionDetectButton;
329 return mFeatureFormatDetectButton;
334 return mFeatureFormatComboBox;
339 return cmbFeaturePaging;
344 return cbxWfsUseGml2EncodingForTransactions;
359 return base + connectionName;
364 return base + connectionName;
369 QStringList detailsParameters = { mServiceName.toLower(), mOriginalConnName };
384 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
387 cmbTilePixelRatio->setCurrentIndex( cmbTilePixelRatio->findData(
static_cast<int>( tilePixelRatio ) ) );
393 if ( version == QLatin1String(
"1.0.0" ) )
395 else if ( version == QLatin1String(
"1.1.0" ) )
397 else if ( version == QLatin1String(
"2.0.0" ) )
399 else if ( version == QLatin1String(
"OGC_API_FEATURES" ) )
401 cmbVersion->setCurrentIndex( versionIdx );
404 wfsVersionCurrentIndexChanged( versionIdx );
412 if ( pagingEnabled == QLatin1String(
"enabled" ) )
414 else if ( pagingEnabled == QLatin1String(
"disabled" ) )
420 mComboWfsFeatureMode->setCurrentIndex( std::max( mComboWfsFeatureMode->findData( wfsFeatureMode ), 0 ) );
428 QDialog::showEvent( event );
433 return mOriginalConnName;
438 QUrl
url( txtUrl->text().trimmed() );
439 QUrlQuery query(
url );
440 const QList<QPair<QString, QString>> items = query.queryItems( QUrl::FullyEncoded );
441 QHash<QString, QPair<QString, QString>> params;
442 for (
const QPair<QString, QString> &it : items )
444 params.insert( it.first.toUpper(), it );
447 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" || params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" || params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
449 query.removeQueryItem( params.value( QStringLiteral(
"SERVICE" ) ).first );
450 query.removeQueryItem( params.value( QStringLiteral(
"REQUEST" ) ).first );
451 query.removeQueryItem( params.value( QStringLiteral(
"FORMAT" ) ).first );
454 url.setQuery( query );
456 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
465 const QString newConnectionName = txtName->text();
473 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
479 QStringList detailsParameters = { mServiceName.toLower(), newConnectionName };
492 QStringList availableFormats;
493 for (
int i = 0; i < mFeatureFormatComboBox->count(); ++i )
495 availableFormats.append( mFeatureFormatComboBox->itemData( i ).toString() );
497 QString format = mFeatureFormatComboBox->currentData().toString();
499 settings.
setValue( QStringLiteral(
"/qgis/lastFeatureFormatEncoding" ), format );
514 QStringList availableFormats;
515 for (
int i = 0; i < mWmsPreferredFormatCombo->count(); ++i )
517 availableFormats.append( mWmsPreferredFormatCombo->itemData( i ).toString() );
533 QString version = QStringLiteral(
"auto" );
534 switch ( cmbVersion->currentIndex() )
537 version = QStringLiteral(
"auto" );
540 version = QStringLiteral(
"1.0.0" );
543 version = QStringLiteral(
"1.1.0" );
546 version = QStringLiteral(
"2.0.0" );
549 version = QStringLiteral(
"OGC_API_FEATURES" );
557 QString pagingEnabled = QStringLiteral(
"default" );
558 switch ( cmbFeaturePaging->currentIndex() )
561 pagingEnabled = QStringLiteral(
"default" );
564 pagingEnabled = QStringLiteral(
"enabled" );
567 pagingEnabled = QStringLiteral(
"disabled" );
572 const QString featureMode = mComboWfsFeatureMode->currentData().toString();
576 QStringList credentialsParameters = { mServiceName.toLower(), newConnectionName };
581 if ( mHttpHeaders->isVisible() )
589void QgsNewHttpConnection::showHelp()
TilePixelRatio
DpiMode enum.
@ Undefined
Undefined (not scale).
@ StandardDpi
Standard (96 DPI).
HttpMethod
Different methods of HTTP requests.
Utility class that contains authorization information.
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.
Qgis::HttpMethod preferredHttpMethod() const
Returns the selected preferred HTTP method.
QgsAuthorizationSettings authorizationSettings() const
Returns the authorization settings.
QPushButton * testConnectButton()
Returns the "test connection" button.
bool invertAxisOrientation() const
Returns the invert axis orientation checkbox status.
void showEvent(QShowEvent *event) override
Adjust height of dialog to fit the content.
QComboBox * featureFormatComboBox()
Returns the "Feature format" combobox.
QgsAuthSettingsWidget * authSettingsWidget()
Returns the current authentication settings widget.
QComboBox * wfsPagingComboBox()
Returns the "WFS paging" combobox.
QPushButton * featureFormatDetectButton()
Returns the "Feature format detect" button.
virtual bool validate()
Returns true if dialog settings are valid, or false if current settings are not valid and the dialog ...
QgsNewHttpConnection(QWidget *parent=nullptr, QgsNewHttpConnection::ConnectionTypes types=ConnectionWms, const QString &serviceName="WMS", const QString &connectionName=QString(), QgsNewHttpConnection::Flags flags=QgsNewHttpConnection::Flags(), Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsNewHttpConnection.
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.
QPushButton * wmsFormatDetectButton()
Returns the WMS Format Detect Button.
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.
QString originalConnectionName() const
Returns the original connection name (might be empty).
@ WFS_VERSION_API_FEATURES_1_0
static const QgsSettingsEntryBool * settingsIgnoreReportedLayerExtentsDefault
QUrl urlTrimmed() const
Returns the url.
QLineEdit * wfsPageSizeLineEdit()
Returns the "WFS page size" edit.
bool ignoreAxisOrientation() const
Returns the ignore axis orientation checkbox status.
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.
QFlags< ConnectionType > ConnectionTypes
QComboBox * wmsPreferredFormatCombo() const
Returns the "WMS preferred format" combobox.
static const QgsSettingsEntryInteger * settingsFeatureCount
static const QgsSettingsEntryStringList * settingsAvailableImageFormats
static const QgsSettingsEntryBool * settingsPreferCoordinatesForWfsT11
static const QgsSettingsEntryEnumFlag< Qgis::HttpMethod > * settingsPreferredHttpMethod
static const QgsSettingsEntryString * settingsPagingEnabled
static const QgsSettingsEntryString * settingsDefaultImageFormat
static const QgsSettingsEntryString * settingsMaxNumFeatures
static QgsSettingsTreeNamedListNode * sTreeOwsConnections
static const QgsSettingsEntryBool * settingsIgnoreGetFeatureInfoURI
static const QgsSettingsEntryString * settingsPassword
static const QgsSettingsEntryBool * settingsReportedLayerExtents
static const QgsSettingsEntryString * settingsWfsFeatureMode
static const QgsSettingsEntryEnumFlag< Qgis::DpiMode > * settingsDpiMode
static const QgsSettingsEntryBool * settingsWfsForceInitialGetFeature
static const QgsSettingsEntryBool * settingsIgnoreAxisOrientation
static const QgsSettingsEntryString * settingsDefaultFeatureFormat
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
static const QgsSettingsEntryStringList * settingsAvailableFeatureFormats
A boolean settings entry.
Stores settings for use within QGIS.
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QString fromEncodedComponent_helper(const QByteArray &ba)