23 #include <QMessageBox> 25 #include <QPushButton> 27 #include <QRegExpValidator> 30 : QDialog( parent, fl )
33 , mOriginalConnName( connectionName )
38 mHttpGroupBox->hide();
42 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
44 QRegExp rx(
"/connections-([^/]+)/" );
45 if ( rx.indexIn( baseKey ) != -1 )
47 QString connectionType( rx.cap( 1 ).toUpper() );
48 if ( connectionType == QLatin1String(
"WMS" ) )
50 connectionType = QStringLiteral(
"WMS/WMTS" );
52 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
60 mCredentialsBaseKey = mBaseKey.split(
'-' ).last().toUpper();
62 txtName->setValidator(
new QRegExpValidator( QRegExp(
"[^\\/]+" ), txtName ) );
65 cmbDpiMode->addItem( tr(
"all" ) );
66 cmbDpiMode->addItem( tr(
"off" ) );
67 cmbDpiMode->addItem( tr(
"QGIS" ) );
68 cmbDpiMode->addItem( tr(
"UMN" ) );
69 cmbDpiMode->addItem( tr(
"GeoServer" ) );
72 cmbVersion->addItem( tr(
"Maximum" ) );
73 cmbVersion->addItem( tr(
"1.0" ) );
74 cmbVersion->addItem( tr(
"1.1" ) );
75 cmbVersion->addItem( tr(
"2.0" ) );
77 static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
78 this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
80 connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
81 this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
83 if ( !connectionName.isEmpty() )
90 QString key = mBaseKey + connectionName;
91 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + connectionName;
92 txtName->setText( connectionName );
93 txtUrl->setText( settings.
value( key +
"/url" ).toString() );
94 mRefererLineEdit->setText( settings.
value( key +
"/referer" ).toString() );
99 mAuthSettings->setUsername( settings.
value( credentialsKey +
"/username" ).toString() );
100 mAuthSettings->setPassword( settings.
value( credentialsKey +
"/password" ).toString() );
101 mAuthSettings->setConfigId( settings.
value( credentialsKey +
"/authcfg" ).toString() );
103 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
107 mWmsOptionsGroupBox->setVisible(
false );
108 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
112 mWfsOptionsGroupBox->setVisible(
false );
113 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
118 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
119 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
120 if ( !( mTypes & ConnectionWms ) )
122 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
124 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
125 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
127 cmbDpiMode->setVisible(
false );
128 mGroupBox->layout()->removeWidget( cmbDpiMode );
129 lblDpiMode->setVisible(
false );
130 mGroupBox->layout()->removeWidget( lblDpiMode );
132 txtReferer->setVisible(
false );
133 mGroupBox->layout()->removeWidget( txtReferer );
134 lblReferer->setVisible(
false );
135 mGroupBox->layout()->removeWidget( lblReferer );
142 mTestConnectionButton->hide();
143 mGroupBox->layout()->removeWidget( mTestConnectionButton );
148 mAuthGroupBox->hide();
149 mGroupBox->layout()->removeWidget( mAuthGroupBox );
154 resize( w, height() );
156 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
157 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
159 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
160 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
161 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
163 nameChanged( connectionName );
166 void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
169 cbxWfsFeaturePaging->setEnabled( index == 0 || index >= 2 );
170 lblPageSize->setEnabled( cbxWfsFeaturePaging->isChecked() && ( index == 0 || index >= 2 ) );
171 txtPageSize->setEnabled( cbxWfsFeaturePaging->isChecked() && ( index == 0 || index >= 2 ) );
172 cbxWfsIgnoreAxisOrientation->setEnabled( index != 1 );
175 void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
177 lblPageSize->setEnabled( state == Qt::Checked );
178 txtPageSize->setEnabled( state == Qt::Checked );
183 return txtName->text();
188 return txtUrl->text();
191 void QgsNewHttpConnection::nameChanged(
const QString &text )
194 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
197 void QgsNewHttpConnection::urlChanged(
const QString &text )
200 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
201 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
204 void QgsNewHttpConnection::updateOkButtonState()
206 bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
207 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
213 QString key = mBaseKey + txtName->text();
216 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
217 settings.
contains( key +
"/url" ) &&
218 QMessageBox::question(
this,
219 tr(
"Save Connection" ),
220 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
221 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
226 if ( ! mAuthSettings->password().isEmpty() &&
227 QMessageBox::question(
this,
228 tr(
"Saving Passwords" ),
229 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." ),
230 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
240 return mTestConnectionButton;
245 return mAuthSettings;
250 return mWfsVersionDetectButton;
260 return cbxWfsFeaturePaging;
270 return base + connectionName;
275 return base + connectionName;
284 cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey +
"/ignoreGetMapURI",
false ).toBool() );
285 cbxWmsIgnoreReportedLayerExtents->setChecked( settings.
value( wmsKey + QStringLiteral(
"/ignoreReportedLayerExtents" ),
false ).toBool() );
286 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
287 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
288 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
289 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
290 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
291 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
294 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
312 cmbDpiMode->setCurrentIndex( dpiIdx );
314 QString version = settings.
value( wfsKey +
"/version" ).toString();
316 if ( version == QLatin1String(
"1.0.0" ) )
318 else if ( version == QLatin1String(
"1.1.0" ) )
320 else if ( version == QLatin1String(
"2.0.0" ) )
322 cmbVersion->setCurrentIndex( versionIdx );
324 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
325 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
328 bool pagingEnabled = settings.
value( wfsKey +
"/pagingenabled", ( versionIdx == 0 || versionIdx >= 3 ) ).toBool();
329 txtPageSize->setText( settings.
value( wfsKey +
"/pagesize" ).toString() );
330 cbxWfsFeaturePaging->setChecked( pagingEnabled );
334 txtPageSize->setEnabled( pagingEnabled && ( versionIdx == 0 || versionIdx >= 2 ) );
335 lblPageSize->setEnabled( pagingEnabled && ( versionIdx == 0 || versionIdx >= 2 ) );
336 cbxWfsFeaturePaging->setEnabled( versionIdx == 0 || versionIdx >= 2 );
337 cbxWfsIgnoreAxisOrientation->setEnabled( versionIdx != 1 );
343 QUrl
url( txtUrl->text().trimmed() );
344 const QList< QPair<QByteArray, QByteArray> > &items =
url.encodedQueryItems();
345 QHash< QString, QPair<QByteArray, QByteArray> > params;
346 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
348 params.insert( QString( it->first ).toUpper(), *it );
351 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
352 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
353 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
355 url.removeEncodedQueryItem( params[QStringLiteral(
"SERVICE" )].first );
356 url.removeEncodedQueryItem( params[QStringLiteral(
"REQUEST" )].first );
357 url.removeEncodedQueryItem( params[QStringLiteral(
"FORMAT" )].first );
360 if (
url.encodedPath().isEmpty() )
362 url.setEncodedPath(
"/" );
370 QString key = mBaseKey + txtName->text();
371 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
377 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
379 settings.
remove( mBaseKey + mOriginalConnName );
380 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
385 settings.
setValue( key +
"/url", url.toString() );
392 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
393 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
397 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
398 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
400 settings.
setValue( wmsKey + QStringLiteral(
"/ignoreReportedLayerExtents" ), cbxWmsIgnoreReportedLayerExtents->isChecked() );
401 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
402 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
405 switch ( cmbDpiMode->currentIndex() )
424 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
426 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
430 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
432 if ( mTypes & ConnectionWfs )
434 QString version = QStringLiteral(
"auto" );
435 switch ( cmbVersion->currentIndex() )
438 version = QStringLiteral(
"auto" );
441 version = QStringLiteral(
"1.0.0" );
444 version = QStringLiteral(
"1.1.0" );
447 version = QStringLiteral(
"2.0.0" );
450 settings.
setValue( wfsKey +
"/version", version );
452 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
454 settings.
setValue( wfsKey +
"/pagesize", txtPageSize->text() );
455 settings.
setValue( wfsKey +
"/pagingenabled", cbxWfsFeaturePaging->isChecked() );
458 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
459 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
461 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
463 if ( mHttpGroupBox->isVisible() )
464 settings.
setValue( key +
"/referer", mRefererLineEdit->text() );
466 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
471 void QgsNewHttpConnection::showHelp()
Display the 'http' group.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
void updateServiceSpecificSettings()
Triggers a resync of the GUI widgets for the service specific settings (i.e.
QString url() const
Returns the current connection url.
virtual QString wmsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WMS related settings for the connection.
Hide the Authentication group.
QString name() const
Returns the current connection name.
QComboBox * wfsVersionComboBox()
Returns the "WFS version" combobox.
QUrl urlTrimmed() const
Returns the url.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
virtual QString wfsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WFS related settings for the connection.
QPushButton * testConnectButton()
Returns the "test connection" button.
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.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
QCheckBox * wfsPagingEnabledCheckBox()
Returns the "WFS paging enabled" checkbox.
QgsNewHttpConnection(QWidget *parent=nullptr, QgsNewHttpConnection::ConnectionTypes types=ConnectionWms, const QString &baseKey="qgis/connections-wms/", const QString &connectionName=QString(), QgsNewHttpConnection::Flags flags=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsNewHttpConnection.
QLineEdit * wfsPageSizeLineEdit()
Returns the "WFS page size" edit.
QPushButton * wfsVersionDetectButton()
Returns the "WFS version detect" button.
Display the 'test connection' button.
QgsAuthSettingsWidget * authSettingsWidget()
Returns the current authentication settings widget.
virtual bool validate()
Returns true if dialog settings are valid, or false if current settings are not valid and the dialog ...