30#include <QRegularExpression>
31#include <QRegularExpressionValidator>
36#include "moc_qgsnewhttpconnection.cpp"
38using namespace Qt::StringLiterals;
43 : QDialog( parent, fl )
45 , mServiceName( serviceName )
46 , mOriginalConnName( connectionName )
51 if ( mServiceName.startsWith(
"qgis/"_L1 ) )
58 mServiceName = mServiceName.split(
'-' ).last().toUpper();
66 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
68 QString connectionType = mServiceName;
69 if ( mServiceName ==
"WMS"_L1 )
71 connectionType = u
"WMS/WMTS"_s;
74 if ( connectionName.isEmpty() )
76 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
80 setWindowTitle( tr(
"Edit %1 Connection \"%2\"" ).arg( connectionType, connectionName ) );
83 txtName->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"[^\\/]+" ), txtName ) );
92 cmbTilePixelRatio->clear();
98 cmbVersion->addItem( tr(
"Maximum" ) );
99 cmbVersion->addItem( tr(
"1.0" ) );
100 cmbVersion->addItem( tr(
"1.1" ) );
101 cmbVersion->addItem( tr(
"2.0" ) );
102 cmbVersion->addItem( tr(
"OGC API - Features" ) );
103 connect( cmbVersion,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
105 mFeatureFormatComboBox->clear();
106 mFeatureFormatComboBox->addItem( tr(
"Default" ), u
"default"_s );
107 connect( mFeatureFormatComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::featureFormatCurrentIndexChanged );
109 mComboWfsFeatureMode->clear();
110 mComboWfsFeatureMode->addItem( tr(
"Default" ), u
"default"_s );
111 mComboWfsFeatureMode->addItem( tr(
"Simple Features" ), u
"simpleFeatures"_s );
112 mComboWfsFeatureMode->addItem( tr(
"Complex Features" ), u
"complexFeatures"_s );
116 mComboHttpMethod->setCurrentIndex( mComboHttpMethod->findData( QVariant::fromValue(
Qgis::HttpMethod::Get ) ) );
118 cmbFeaturePaging->clear();
119 cmbFeaturePaging->addItem( tr(
"Default (trust server capabilities)" ) );
120 cmbFeaturePaging->addItem( tr(
"Enabled" ) );
121 cmbFeaturePaging->addItem( tr(
"Disabled" ) );
122 connect( cmbFeaturePaging,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged );
126 if ( !connectionName.isEmpty() )
131 txtName->setText( connectionName );
132 const QStringList detailParameters { mServiceName.toLower(), connectionName };
144 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
148 mWmsOptionsGroupBox->setVisible(
false );
149 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
153 mWfsOptionsGroupBox->setVisible(
false );
154 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
158 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)" ) );
163 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
164 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
167 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
169 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
170 mWmsOptionsGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
172 sbFeatureCount->setVisible(
false );
173 mWmsOptionsGroupBox->layout()->removeWidget( sbFeatureCount );
174 lblFeatureCount->setVisible(
false );
175 mWmsOptionsGroupBox->layout()->removeWidget( lblFeatureCount );
177 cmbDpiMode->setVisible(
false );
178 mWmsOptionsGroupBox->layout()->removeWidget( cmbDpiMode );
179 lblDpiMode->setVisible(
false );
180 mWmsOptionsGroupBox->layout()->removeWidget( lblDpiMode );
181 cmbTilePixelRatio->setVisible(
false );
182 mWmsOptionsGroupBox->layout()->removeWidget( cmbTilePixelRatio );
183 lblTilePixelRatio->setVisible(
false );
184 mWmsOptionsGroupBox->layout()->removeWidget( lblTilePixelRatio );
190 mTestConnectionButton->hide();
191 mGroupBox->layout()->removeWidget( mTestConnectionButton );
196 mAuthGroupBox->hide();
197 mGroupBox->layout()->removeWidget( mAuthGroupBox );
200 mWmsFormatDetectButton->setDisabled( txtUrl->text().isEmpty() );
202 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
203 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
205 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
206 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
207 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
209 nameChanged( connectionName );
212void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
216 lblFeaturePaging->setEnabled( pagingOptionsEnabled );
217 cmbFeaturePaging->setEnabled( pagingOptionsEnabled );
218 lblPageSize->setEnabled( pagingOptionsEnabled );
219 txtPageSize->setEnabled( pagingOptionsEnabled );
230void QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged(
int index )
233 lblPageSize->setEnabled( pagingNotDisabled );
234 txtPageSize->setEnabled( pagingNotDisabled );
237void QgsNewHttpConnection::featureFormatCurrentIndexChanged(
int index )
245 return txtName->text();
250 return txtUrl->text();
253void QgsNewHttpConnection::nameChanged(
const QString &text )
256 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
259void QgsNewHttpConnection::urlChanged(
const QString &text )
262 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
263 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
264 mWmsFormatDetectButton->setDisabled( txtUrl->text().isEmpty() );
267void QgsNewHttpConnection::updateOkButtonState()
269 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
270 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
275 const QString newConnectionName = txtName->text();
280 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( newConnectionName, Qt::CaseInsensitive ) != 0 )
282 && QMessageBox::question(
this, tr(
"Save Connection" ), tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ), QMessageBox::Ok | QMessageBox::Cancel )
283 == QMessageBox::Cancel )
288 if ( !mAuthSettings->password().isEmpty()
289 && QMessageBox::question(
291 tr(
"Saving Passwords" ),
293 "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 "
294 "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 "
295 "your credentials in an HTTP Basic Authentication method and store them in an encrypted database."
297 QMessageBox::Ok | QMessageBox::Cancel
298 ) == QMessageBox::Cancel )
308 return mTestConnectionButton;
313 return mWmsFormatDetectButton;
318 return mAuthSettings;
323 return QgsAuthorizationSettings( mAuthSettings->username(), mAuthSettings->password(), mHttpHeaders->httpHeaders(), mAuthSettings->configId() );
328 return cbxWmsIgnoreAxisOrientation->isChecked();
333 return mWmsPreferredFormatCombo;
338 return cbxWmsInvertAxisOrientation->isChecked();
344 return mWfsVersionDetectButton;
354 return mFeatureFormatDetectButton;
359 return mFeatureFormatComboBox;
364 return cmbFeaturePaging;
369 return cbxWfsUseGml2EncodingForTransactions;
384 return base + connectionName;
389 return base + connectionName;
394 QStringList detailsParameters = { mServiceName.toLower(), mOriginalConnName };
409 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
412 cmbTilePixelRatio->setCurrentIndex( cmbTilePixelRatio->findData(
static_cast<int>( tilePixelRatio ) ) );
418 if ( version ==
"1.0.0"_L1 )
420 else if ( version ==
"1.1.0"_L1 )
422 else if ( version ==
"2.0.0"_L1 )
424 else if ( version ==
"OGC_API_FEATURES"_L1 )
426 cmbVersion->setCurrentIndex( versionIdx );
429 wfsVersionCurrentIndexChanged( versionIdx );
437 if ( pagingEnabled ==
"enabled"_L1 )
439 else if ( pagingEnabled ==
"disabled"_L1 )
445 mComboWfsFeatureMode->setCurrentIndex( std::max( mComboWfsFeatureMode->findData( wfsFeatureMode ), 0 ) );
453 QDialog::showEvent( event );
458 return mOriginalConnName;
463 QUrl
url( txtUrl->text().trimmed() );
464 QUrlQuery query(
url );
465 const QList<QPair<QString, QString>> items = query.queryItems( QUrl::FullyEncoded );
466 QHash<QString, QPair<QString, QString>> params;
467 for (
const QPair<QString, QString> &it : items )
469 params.insert( it.first.toUpper(), it );
472 if ( params[u
"SERVICE"_s].second.toUpper() ==
"WMS" || params[u
"SERVICE"_s].second.toUpper() ==
"WFS" || params[u
"SERVICE"_s].second.toUpper() ==
"WCS" )
474 query.removeQueryItem( params.value( u
"SERVICE"_s ).first );
475 query.removeQueryItem( params.value( u
"REQUEST"_s ).first );
476 query.removeQueryItem( params.value( u
"FORMAT"_s ).first );
479 url.setQuery( query );
481 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
490 const QString newConnectionName = txtName->text();
498 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
504 QStringList detailsParameters = { mServiceName.toLower(), newConnectionName };
517 QStringList availableFormats;
518 for (
int i = 0; i < mFeatureFormatComboBox->count(); ++i )
520 availableFormats.append( mFeatureFormatComboBox->itemData( i ).toString() );
522 QString format = mFeatureFormatComboBox->currentData().toString();
524 settings.
setValue( u
"/qgis/lastFeatureFormatEncoding"_s, format );
539 QStringList availableFormats;
540 for (
int i = 0; i < mWmsPreferredFormatCombo->count(); ++i )
542 availableFormats.append( mWmsPreferredFormatCombo->itemData( i ).toString() );
558 QString version = u
"auto"_s;
559 switch ( cmbVersion->currentIndex() )
565 version = u
"1.0.0"_s;
568 version = u
"1.1.0"_s;
571 version = u
"2.0.0"_s;
574 version = u
"OGC_API_FEATURES"_s;
582 QString pagingEnabled = u
"default"_s;
583 switch ( cmbFeaturePaging->currentIndex() )
586 pagingEnabled = u
"default"_s;
589 pagingEnabled = u
"enabled"_s;
592 pagingEnabled = u
"disabled"_s;
597 const QString featureMode = mComboWfsFeatureMode->currentData().toString();
601 QStringList credentialsParameters = { mServiceName.toLower(), newConnectionName };
606 if ( mHttpHeaders->isVisible() )
614void 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)