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 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
286 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
287 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
288 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
289 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
290 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
293 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
311 cmbDpiMode->setCurrentIndex( dpiIdx );
313 QString version = settings.
value( wfsKey +
"/version" ).toString();
315 if ( version == QLatin1String(
"1.0.0" ) )
317 else if ( version == QLatin1String(
"1.1.0" ) )
319 else if ( version == QLatin1String(
"2.0.0" ) )
321 cmbVersion->setCurrentIndex( versionIdx );
323 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
324 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
327 bool pagingEnabled = settings.
value( wfsKey +
"/pagingenabled", ( versionIdx == 0 || versionIdx >= 3 ) ).toBool();
328 txtPageSize->setText( settings.
value( wfsKey +
"/pagesize" ).toString() );
329 cbxWfsFeaturePaging->setChecked( pagingEnabled );
333 txtPageSize->setEnabled( pagingEnabled && ( versionIdx == 0 || versionIdx >= 2 ) );
334 lblPageSize->setEnabled( pagingEnabled && ( versionIdx == 0 || versionIdx >= 2 ) );
335 cbxWfsFeaturePaging->setEnabled( versionIdx == 0 || versionIdx >= 2 );
336 cbxWfsIgnoreAxisOrientation->setEnabled( versionIdx != 1 );
342 QUrl
url( txtUrl->text().trimmed() );
343 const QList< QPair<QByteArray, QByteArray> > &items =
url.encodedQueryItems();
344 QHash< QString, QPair<QByteArray, QByteArray> > params;
345 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
347 params.insert( QString( it->first ).toUpper(), *it );
350 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
351 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
352 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
354 url.removeEncodedQueryItem( params[QStringLiteral(
"SERVICE" )].first );
355 url.removeEncodedQueryItem( params[QStringLiteral(
"REQUEST" )].first );
356 url.removeEncodedQueryItem( params[QStringLiteral(
"FORMAT" )].first );
359 if (
url.encodedPath().isEmpty() )
361 url.setEncodedPath(
"/" );
369 QString key = mBaseKey + txtName->text();
370 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
376 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
378 settings.
remove( mBaseKey + mOriginalConnName );
379 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
384 settings.
setValue( key +
"/url", url.toString() );
391 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
392 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
396 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
397 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
399 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
400 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
403 switch ( cmbDpiMode->currentIndex() )
422 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
424 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
428 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
430 if ( mTypes & ConnectionWfs )
432 QString version = QStringLiteral(
"auto" );
433 switch ( cmbVersion->currentIndex() )
436 version = QStringLiteral(
"auto" );
439 version = QStringLiteral(
"1.0.0" );
442 version = QStringLiteral(
"1.1.0" );
445 version = QStringLiteral(
"2.0.0" );
448 settings.
setValue( wfsKey +
"/version", version );
450 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
452 settings.
setValue( wfsKey +
"/pagesize", txtPageSize->text() );
453 settings.
setValue( wfsKey +
"/pagingenabled", cbxWfsFeaturePaging->isChecked() );
456 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
457 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
459 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
461 if ( mHttpGroupBox->isVisible() )
462 settings.
setValue( key +
"/referer", mRefererLineEdit->text() );
464 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
469 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 ...