23 #include <QMessageBox> 25 #include <QPushButton> 27 #include <QRegExpValidator> 30 : QDialog( parent, fl )
33 , mOriginalConnName( connectionName )
39 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
41 QRegExp rx(
"/connections-([^/]+)/" );
42 if ( rx.indexIn( baseKey ) != -1 )
44 QString connectionType( rx.cap( 1 ).toUpper() );
45 if ( connectionType == QLatin1String(
"WMS" ) )
47 connectionType = QStringLiteral(
"WMS/WMTS" );
49 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
57 mCredentialsBaseKey = mBaseKey.split(
'-' ).last().toUpper();
59 txtName->setValidator(
new QRegExpValidator( QRegExp(
"[^\\/]+" ), txtName ) );
62 cmbDpiMode->addItem( tr(
"all" ) );
63 cmbDpiMode->addItem( tr(
"off" ) );
64 cmbDpiMode->addItem( tr(
"QGIS" ) );
65 cmbDpiMode->addItem( tr(
"UMN" ) );
66 cmbDpiMode->addItem( tr(
"GeoServer" ) );
69 cmbVersion->addItem( tr(
"Maximum" ) );
70 cmbVersion->addItem( tr(
"1.0" ) );
71 cmbVersion->addItem( tr(
"1.1" ) );
72 cmbVersion->addItem( tr(
"2.0" ) );
74 static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
75 this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
77 connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
78 this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
80 if ( !connectionName.isEmpty() )
87 QString key = mBaseKey + connectionName;
88 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + connectionName;
89 txtName->setText( connectionName );
90 txtUrl->setText( settings.
value( key +
"/url" ).toString() );
95 mAuthSettings->setUsername( settings.
value( credentialsKey +
"/username" ).toString() );
96 mAuthSettings->setPassword( settings.
value( credentialsKey +
"/password" ).toString() );
97 mAuthSettings->setConfigId( settings.
value( credentialsKey +
"/authcfg" ).toString() );
99 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
103 mWmsOptionsGroupBox->setVisible(
false );
104 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
108 mWfsOptionsGroupBox->setVisible(
false );
109 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
114 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
115 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
116 if ( !( mTypes & ConnectionWms ) )
118 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
120 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
121 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
123 cmbDpiMode->setVisible(
false );
124 mGroupBox->layout()->removeWidget( cmbDpiMode );
125 lblDpiMode->setVisible(
false );
126 mGroupBox->layout()->removeWidget( lblDpiMode );
128 txtReferer->setVisible(
false );
129 mGroupBox->layout()->removeWidget( txtReferer );
130 lblReferer->setVisible(
false );
131 mGroupBox->layout()->removeWidget( lblReferer );
138 mTestConnectionButton->hide();
139 mGroupBox->layout()->removeWidget( mTestConnectionButton );
144 mAuthGroupBox->hide();
145 mGroupBox->layout()->removeWidget( mAuthGroupBox );
150 resize( w, height() );
152 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
153 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
155 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
156 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
157 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
159 nameChanged( connectionName );
162 void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
165 cbxWfsFeaturePaging->setEnabled( index == 0 || index >= 2 );
166 lblPageSize->setEnabled( cbxWfsFeaturePaging->isChecked() && ( index == 0 || index >= 2 ) );
167 txtPageSize->setEnabled( cbxWfsFeaturePaging->isChecked() && ( index == 0 || index >= 2 ) );
168 cbxWfsIgnoreAxisOrientation->setEnabled( index != 1 );
171 void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
173 lblPageSize->setEnabled( state == Qt::Checked );
174 txtPageSize->setEnabled( state == Qt::Checked );
179 return txtName->text();
184 return txtUrl->text();
187 void QgsNewHttpConnection::nameChanged(
const QString &text )
190 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
193 void QgsNewHttpConnection::urlChanged(
const QString &text )
196 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
197 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
200 void QgsNewHttpConnection::updateOkButtonState()
202 bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
203 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
209 QString key = mBaseKey + txtName->text();
212 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
213 settings.
contains( key +
"/url" ) &&
214 QMessageBox::question(
this,
215 tr(
"Save Connection" ),
216 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
217 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
222 if ( ! mAuthSettings->password().isEmpty() &&
223 QMessageBox::question(
this,
224 tr(
"Saving Passwords" ),
225 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." ),
226 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
236 return mTestConnectionButton;
241 return mAuthSettings;
246 return mWfsVersionDetectButton;
256 return cbxWfsFeaturePaging;
266 return base + connectionName;
271 return base + connectionName;
280 cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey +
"/ignoreGetMapURI",
false ).toBool() );
281 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
282 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
283 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
284 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
285 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
286 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
289 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
307 cmbDpiMode->setCurrentIndex( dpiIdx );
309 QString version = settings.
value( wfsKey +
"/version" ).toString();
311 if ( version == QLatin1String(
"1.0.0" ) )
313 else if ( version == QLatin1String(
"1.1.0" ) )
315 else if ( version == QLatin1String(
"2.0.0" ) )
317 cmbVersion->setCurrentIndex( versionIdx );
319 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
320 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
323 bool pagingEnabled = settings.
value( wfsKey +
"/pagingenabled", ( versionIdx == 0 || versionIdx >= 3 ) ).toBool();
324 txtPageSize->setText( settings.
value( wfsKey +
"/pagesize" ).toString() );
325 cbxWfsFeaturePaging->setChecked( pagingEnabled );
329 txtPageSize->setEnabled( pagingEnabled && ( versionIdx == 0 || versionIdx >= 2 ) );
330 lblPageSize->setEnabled( pagingEnabled && ( versionIdx == 0 || versionIdx >= 2 ) );
331 cbxWfsFeaturePaging->setEnabled( versionIdx == 0 || versionIdx >= 2 );
332 cbxWfsIgnoreAxisOrientation->setEnabled( versionIdx != 1 );
338 QUrl
url( txtUrl->text().trimmed() );
339 const QList< QPair<QByteArray, QByteArray> > &items =
url.encodedQueryItems();
340 QHash< QString, QPair<QByteArray, QByteArray> > params;
341 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
343 params.insert( QString( it->first ).toUpper(), *it );
346 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
347 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
348 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
350 url.removeEncodedQueryItem( params[QStringLiteral(
"SERVICE" )].first );
351 url.removeEncodedQueryItem( params[QStringLiteral(
"REQUEST" )].first );
352 url.removeEncodedQueryItem( params[QStringLiteral(
"FORMAT" )].first );
355 if (
url.encodedPath().isEmpty() )
357 url.setEncodedPath(
"/" );
365 QString key = mBaseKey + txtName->text();
366 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
372 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
374 settings.
remove( mBaseKey + mOriginalConnName );
375 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
380 settings.
setValue( key +
"/url", url.toString() );
387 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
388 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
392 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
393 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
395 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
396 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
399 switch ( cmbDpiMode->currentIndex() )
418 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
420 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
424 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
426 if ( mTypes & ConnectionWfs )
428 QString version = QStringLiteral(
"auto" );
429 switch ( cmbVersion->currentIndex() )
432 version = QStringLiteral(
"auto" );
435 version = QStringLiteral(
"1.0.0" );
438 version = QStringLiteral(
"1.1.0" );
441 version = QStringLiteral(
"2.0.0" );
444 settings.
setValue( wfsKey +
"/version", version );
446 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
448 settings.
setValue( wfsKey +
"/pagesize", txtPageSize->text() );
449 settings.
setValue( wfsKey +
"/pagingenabled", cbxWfsFeaturePaging->isChecked() );
452 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
453 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
455 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
457 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
462 void QgsNewHttpConnection::showHelp()
QString url() const
Returns the current connection url.
This class is a composition of two QSettings instances:
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.
Hide the Authentication group.
QComboBox * wfsVersionComboBox()
Returns the "WFS version" combobox.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QPushButton * testConnectButton()
Returns the "test connection" button.
virtual QString wfsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WFS related settings for the connection.
QUrl urlTrimmed() const
Returns the url.
virtual QString wmsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WMS related settings for the connection.
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.
QCheckBox * wfsPagingEnabledCheckBox()
Returns the "WFS paging enabled" checkbox.
QString name() const
Returns the current connection name.
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 ...