18#include "moc_qgsnewhttpconnection.cpp"
31#include <QRegularExpression>
32#include <QRegularExpressionValidator>
38 : QDialog( parent, fl )
40 , mServiceName( serviceName )
41 , mOriginalConnName( connectionName )
46 if ( mServiceName.startsWith( QLatin1String(
"qgis/" ) ) )
53 mServiceName = mServiceName.split(
'-' ).last().toUpper();
61 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
63 QString connectionType = mServiceName;
64 if ( mServiceName == QLatin1String(
"WMS" ) )
66 connectionType = QStringLiteral(
"WMS/WMTS" );
68 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
70 txtName->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"[^\\/]+" ), txtName ) );
79 cmbTilePixelRatio->clear();
85 cmbVersion->addItem( tr(
"Maximum" ) );
86 cmbVersion->addItem( tr(
"1.0" ) );
87 cmbVersion->addItem( tr(
"1.1" ) );
88 cmbVersion->addItem( tr(
"2.0" ) );
89 cmbVersion->addItem( tr(
"OGC API - Features" ) );
90 connect( cmbVersion,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
92 cmbFeaturePaging->clear();
93 cmbFeaturePaging->addItem( tr(
"Default (trust server capabilities)" ) );
94 cmbFeaturePaging->addItem( tr(
"Enabled" ) );
95 cmbFeaturePaging->addItem( tr(
"Disabled" ) );
96 connect( cmbFeaturePaging,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged );
98 if ( !connectionName.isEmpty() )
103 txtName->setText( connectionName );
104 const QStringList detailParameters { mServiceName.toLower(), connectionName };
115 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
119 mWmsOptionsGroupBox->setVisible(
false );
120 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
124 mWfsOptionsGroupBox->setVisible(
false );
125 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
129 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)" ) );
134 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
135 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
138 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
140 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
141 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
143 sbFeatureCount->setVisible(
false );
144 mGroupBox->layout()->removeWidget( sbFeatureCount );
145 lblFeatureCount->setVisible(
false );
146 mGroupBox->layout()->removeWidget( lblFeatureCount );
148 cmbDpiMode->setVisible(
false );
149 mGroupBox->layout()->removeWidget( cmbDpiMode );
150 lblDpiMode->setVisible(
false );
151 mGroupBox->layout()->removeWidget( lblDpiMode );
152 cmbTilePixelRatio->setVisible(
false );
153 mGroupBox->layout()->removeWidget( cmbTilePixelRatio );
154 lblTilePixelRatio->setVisible(
false );
155 mGroupBox->layout()->removeWidget( lblTilePixelRatio );
163 mTestConnectionButton->hide();
164 mGroupBox->layout()->removeWidget( mTestConnectionButton );
169 mAuthGroupBox->hide();
170 mGroupBox->layout()->removeWidget( mAuthGroupBox );
173 const int w = width();
175 resize( w, height() );
177 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
178 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
180 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
181 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
182 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
184 nameChanged( connectionName );
187void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
199void QgsNewHttpConnection::wfsFeaturePagingCurrentIndexChanged(
int index )
202 lblPageSize->setEnabled( pagingNotDisabled );
203 txtPageSize->setEnabled( pagingNotDisabled );
208 return txtName->text();
213 return txtUrl->text();
216void QgsNewHttpConnection::nameChanged(
const QString &text )
219 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
222void QgsNewHttpConnection::urlChanged(
const QString &text )
225 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
226 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
229void QgsNewHttpConnection::updateOkButtonState()
231 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
232 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
237 const QString newConnectionName = txtName->text();
242 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 )
247 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 )
257 return mTestConnectionButton;
262 return mAuthSettings;
267 return mWfsVersionDetectButton;
277 return cmbFeaturePaging;
282 return cbxWfsUseGml2EncodingForTransactions;
292 return base + connectionName;
297 return base + connectionName;
302 QStringList detailsParameters = { mServiceName.toLower(), mOriginalConnName };
316 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
318 cmbTilePixelRatio->setCurrentIndex( cmbTilePixelRatio->findData(
static_cast<int>( tilePixelRatio ) ) );
324 if ( version == QLatin1String(
"1.0.0" ) )
326 else if ( version == QLatin1String(
"1.1.0" ) )
328 else if ( version == QLatin1String(
"2.0.0" ) )
330 else if ( version == QLatin1String(
"OGC_API_FEATURES" ) )
332 cmbVersion->setCurrentIndex( versionIdx );
335 wfsVersionCurrentIndexChanged( versionIdx );
343 if ( pagingEnabled == QLatin1String(
"enabled" ) )
345 else if ( pagingEnabled == QLatin1String(
"disabled" ) )
355 QUrl
url( txtUrl->text().trimmed() );
356 QUrlQuery query(
url );
357 const QList<QPair<QString, QString>> items = query.queryItems( QUrl::FullyEncoded );
358 QHash<QString, QPair<QString, QString>> params;
359 for (
const QPair<QString, QString> &it : items )
361 params.insert( it.first.toUpper(), it );
364 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" || params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" || params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
366 query.removeQueryItem( params.value( QStringLiteral(
"SERVICE" ) ).first );
367 query.removeQueryItem( params.value( QStringLiteral(
"REQUEST" ) ).first );
368 query.removeQueryItem( params.value( QStringLiteral(
"FORMAT" ) ).first );
371 url.setQuery( query );
373 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
382 const QString newConnectionName = txtName->text();
390 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
396 QStringList detailsParameters = { mServiceName.toLower(), newConnectionName };
430 QString version = QStringLiteral(
"auto" );
431 switch ( cmbVersion->currentIndex() )
434 version = QStringLiteral(
"auto" );
437 version = QStringLiteral(
"1.0.0" );
440 version = QStringLiteral(
"1.1.0" );
443 version = QStringLiteral(
"2.0.0" );
446 version = QStringLiteral(
"OGC_API_FEATURES" );
453 QString pagingEnabled = QStringLiteral(
"default" );
454 switch ( cmbFeaturePaging->currentIndex() )
457 pagingEnabled = QStringLiteral(
"default" );
460 pagingEnabled = QStringLiteral(
"enabled" );
463 pagingEnabled = QStringLiteral(
"disabled" );
469 QStringList credentialsParameters = { mServiceName.toLower(), newConnectionName };
474 if ( mHttpHeaders->isVisible() )
482void 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.
QComboBox * wfsPagingComboBox()
Returns the "WFS paging" combobox.
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.
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
static const QgsSettingsEntryBool * settingsIgnoreReportedLayerExtentsDefault
QUrl urlTrimmed() const
Returns the url.
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.
QFlags< ConnectionType > ConnectionTypes
static const QgsSettingsEntryInteger * settingsFeatureCount
static const QgsSettingsEntryBool * settingsPreferCoordinatesForWfsT11
static const QgsSettingsEntryString * 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 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.
A boolean settings entry.
void deleteItem(const QString &item, const QStringList &parentsNamedItems=QStringList())
Deletes a named item from the named list node.
void setSelectedItem(const QString &item, const QStringList &parentsNamedItems=QStringList())
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)