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 );
227 mComboWfsFeatureMode->setEnabled(
232void QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged(
int index )
235 lblPageSize->setEnabled( pagingNotDisabled );
236 txtPageSize->setEnabled( pagingNotDisabled );
239void QgsNewHttpConnection::featureFormatCurrentIndexChanged(
int index )
242 mComboWfsFeatureMode->setEnabled(
249 return txtName->text();
254 return txtUrl->text();
257void QgsNewHttpConnection::nameChanged(
const QString &text )
260 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
263void QgsNewHttpConnection::urlChanged(
const QString &text )
266 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
267 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
268 mWmsFormatDetectButton->setDisabled( txtUrl->text().isEmpty() );
271void QgsNewHttpConnection::updateOkButtonState()
273 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
274 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
279 const QString newConnectionName = txtName->text();
284 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 )
289 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 )
299 return mTestConnectionButton;
304 return mWmsFormatDetectButton;
309 return mAuthSettings;
314 return QgsAuthorizationSettings( mAuthSettings->username(), mAuthSettings->password(), mHttpHeaders->httpHeaders(), mAuthSettings->configId() );
319 return cbxWmsIgnoreAxisOrientation->isChecked();
324 return mWmsPreferredFormatCombo;
329 return cbxWmsInvertAxisOrientation->isChecked();
335 return mWfsVersionDetectButton;
345 return mFeatureFormatDetectButton;
350 return mFeatureFormatComboBox;
355 return cmbFeaturePaging;
360 return cbxWfsUseGml2EncodingForTransactions;
375 return base + connectionName;
380 return base + connectionName;
385 QStringList detailsParameters = { mServiceName.toLower(), mOriginalConnName };
400 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
403 cmbTilePixelRatio->setCurrentIndex( cmbTilePixelRatio->findData(
static_cast<int>( tilePixelRatio ) ) );
409 if ( version ==
"1.0.0"_L1 )
411 else if ( version ==
"1.1.0"_L1 )
413 else if ( version ==
"2.0.0"_L1 )
415 else if ( version ==
"OGC_API_FEATURES"_L1 )
417 cmbVersion->setCurrentIndex( versionIdx );
420 wfsVersionCurrentIndexChanged( versionIdx );
428 if ( pagingEnabled ==
"enabled"_L1 )
430 else if ( pagingEnabled ==
"disabled"_L1 )
436 mComboWfsFeatureMode->setCurrentIndex( std::max( mComboWfsFeatureMode->findData( wfsFeatureMode ), 0 ) );
444 QDialog::showEvent( event );
449 return mOriginalConnName;
454 QUrl
url( txtUrl->text().trimmed() );
455 QUrlQuery query(
url );
456 const QList<QPair<QString, QString>> items = query.queryItems( QUrl::FullyEncoded );
457 QHash<QString, QPair<QString, QString>> params;
458 for (
const QPair<QString, QString> &it : items )
460 params.insert( it.first.toUpper(), it );
463 if ( params[u
"SERVICE"_s].second.toUpper() ==
"WMS" || params[u
"SERVICE"_s].second.toUpper() ==
"WFS" || params[u
"SERVICE"_s].second.toUpper() ==
"WCS" )
465 query.removeQueryItem( params.value( u
"SERVICE"_s ).first );
466 query.removeQueryItem( params.value( u
"REQUEST"_s ).first );
467 query.removeQueryItem( params.value( u
"FORMAT"_s ).first );
470 url.setQuery( query );
472 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
481 const QString newConnectionName = txtName->text();
489 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
495 QStringList detailsParameters = { mServiceName.toLower(), newConnectionName };
508 QStringList availableFormats;
509 for (
int i = 0; i < mFeatureFormatComboBox->count(); ++i )
511 availableFormats.append( mFeatureFormatComboBox->itemData( i ).toString() );
513 QString format = mFeatureFormatComboBox->currentData().toString();
515 settings.
setValue( u
"/qgis/lastFeatureFormatEncoding"_s, format );
530 QStringList availableFormats;
531 for (
int i = 0; i < mWmsPreferredFormatCombo->count(); ++i )
533 availableFormats.append( mWmsPreferredFormatCombo->itemData( i ).toString() );
549 QString version = u
"auto"_s;
550 switch ( cmbVersion->currentIndex() )
556 version = u
"1.0.0"_s;
559 version = u
"1.1.0"_s;
562 version = u
"2.0.0"_s;
565 version = u
"OGC_API_FEATURES"_s;
573 QString pagingEnabled = u
"default"_s;
574 switch ( cmbFeaturePaging->currentIndex() )
577 pagingEnabled = u
"default"_s;
580 pagingEnabled = u
"enabled"_s;
583 pagingEnabled = u
"disabled"_s;
588 const QString featureMode = mComboWfsFeatureMode->currentData().toString();
592 QStringList credentialsParameters = { mServiceName.toLower(), newConnectionName };
597 if ( mHttpHeaders->isVisible() )
605void 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)