25 #include <QMessageBox>
27 #include <QPushButton>
28 #include <QRegularExpression>
29 #include <QRegularExpressionValidator>
33 : QDialog( parent, fl )
35 , mServiceName( serviceName )
36 , mOriginalConnName( connectionName )
41 if ( mServiceName.startsWith( QLatin1String(
"qgis/" ) ) )
48 mServiceName = mServiceName.split(
'-' ).last().toUpper();
56 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
58 QString connectionType = mServiceName;
59 if ( mServiceName == QLatin1String(
"WMS" ) )
61 connectionType = QStringLiteral(
"WMS/WMTS" );
63 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
65 txtName->setValidator(
new QRegularExpressionValidator( QRegularExpression(
"[^\\/]+" ), txtName ) );
76 cmbVersion->addItem( tr(
"Maximum" ) );
77 cmbVersion->addItem( tr(
"1.0" ) );
78 cmbVersion->addItem( tr(
"1.1" ) );
79 cmbVersion->addItem( tr(
"2.0" ) );
80 cmbVersion->addItem( tr(
"OGC API - Features" ) );
82 static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
83 this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
85 connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
86 this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
88 if ( !connectionName.isEmpty() )
95 txtName->setText( connectionName );
97 mHttpHeaders->setFromSettings( settings, QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), connectionName ) );
106 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
110 mWmsOptionsGroupBox->setVisible(
false );
111 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
115 mWfsOptionsGroupBox->setVisible(
false );
116 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
120 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)" ) );
125 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
126 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
129 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
131 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
132 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
134 cmbDpiMode->setVisible(
false );
135 mGroupBox->layout()->removeWidget( cmbDpiMode );
136 lblDpiMode->setVisible(
false );
137 mGroupBox->layout()->removeWidget( lblDpiMode );
143 mTestConnectionButton->hide();
144 mGroupBox->layout()->removeWidget( mTestConnectionButton );
149 mAuthGroupBox->hide();
150 mGroupBox->layout()->removeWidget( mAuthGroupBox );
153 const int w = width();
155 resize( w, height() );
157 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
158 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
160 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
161 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
162 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
164 nameChanged( connectionName );
167 void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
178 void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
180 lblPageSize->setEnabled( state == Qt::Checked );
181 txtPageSize->setEnabled( state == Qt::Checked );
186 return txtName->text();
191 return txtUrl->text();
194 void QgsNewHttpConnection::nameChanged(
const QString &text )
197 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
200 void QgsNewHttpConnection::urlChanged(
const QString &text )
203 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
204 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
207 void QgsNewHttpConnection::updateOkButtonState()
209 const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
210 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
215 const QString newConnectionName = txtName->text();
220 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( newConnectionName, Qt::CaseInsensitive ) != 0 ) &&
222 QMessageBox::question(
this,
223 tr(
"Save Connection" ),
224 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
225 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
230 if ( ! mAuthSettings->password().isEmpty() &&
231 QMessageBox::question(
this,
232 tr(
"Saving Passwords" ),
233 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." ),
234 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
244 return mTestConnectionButton;
249 return mAuthSettings;
254 return mWfsVersionDetectButton;
264 return cbxWfsFeaturePaging;
269 return cbxWfsUseGml2EncodingForTransactions;
279 return base + connectionName;
284 return base + connectionName;
289 QStringList detailsParameters = {mServiceName.toLower(), mOriginalConnName};
303 cmbDpiMode->setCurrentIndex( cmbDpiMode->findData(
static_cast<int>( dpiMode ) ) );
307 if ( version == QLatin1String(
"1.0.0" ) )
309 else if ( version == QLatin1String(
"1.1.0" ) )
311 else if ( version == QLatin1String(
"2.0.0" ) )
313 else if ( version == QLatin1String(
"OGC_API_FEATURES" ) )
315 cmbVersion->setCurrentIndex( versionIdx );
318 wfsVersionCurrentIndexChanged( versionIdx );
320 mHttpHeaders->setFromSettings(
QgsSettings(), QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), mOriginalConnName ) );
327 cbxWfsFeaturePaging->setChecked( pagingEnabled );
332 QUrl
url( txtUrl->text().trimmed() );
333 QUrlQuery query(
url );
334 const QList<QPair<QString, QString> > items = query.queryItems( QUrl::FullyEncoded );
335 QHash< QString, QPair<QString, QString> > params;
336 for (
const QPair<QString, QString> &it : items )
338 params.insert( it.first.toUpper(), it );
341 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
342 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
343 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
345 query.removeQueryItem( params.value( QStringLiteral(
"SERVICE" ) ).first );
346 query.removeQueryItem( params.value( QStringLiteral(
"REQUEST" ) ).first );
347 query.removeQueryItem( params.value( QStringLiteral(
"FORMAT" ) ).first );
350 url.setQuery( query );
352 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
361 const QString newConnectionName = txtName->text();
369 if ( !mOriginalConnName.isNull() && mOriginalConnName != newConnectionName )
376 QStringList detailsParameters = {mServiceName.toLower(), newConnectionName};
399 mHttpHeaders->updateSettings( settings, QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), newConnectionName ) );
407 QString version = QStringLiteral(
"auto" );
408 switch ( cmbVersion->currentIndex() )
411 version = QStringLiteral(
"auto" );
414 version = QStringLiteral(
"1.0.0" );
417 version = QStringLiteral(
"1.1.0" );
420 version = QStringLiteral(
"2.0.0" );
423 version = QStringLiteral(
"OGC_API_FEATURES" );
432 QStringList credentialsParameters = {mServiceName, newConnectionName};
437 if ( mHttpHeaders->isVisible() )
438 mHttpHeaders->updateSettings( settings, QStringLiteral(
"qgis/connections-%1/%2" ).arg( mServiceName.toLower(), newConnectionName ) );
445 void QgsNewHttpConnection::showHelp()