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 )
168 cbxWfsFeaturePaging->setEnabled( index == 0 || index == 3 );
169 lblPageSize->setEnabled( index == 0 || index == 3 );
170 txtPageSize->setEnabled( index == 0 || index == 3 );
171 cbxWfsIgnoreAxisOrientation->setEnabled( index != 1 );
174 void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
176 lblPageSize->setEnabled( state == Qt::Checked );
177 txtPageSize->setEnabled( state == Qt::Checked );
182 return txtName->text();
187 return txtUrl->text();
190 void QgsNewHttpConnection::nameChanged(
const QString &text )
193 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
196 void QgsNewHttpConnection::urlChanged(
const QString &text )
199 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
200 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
203 void QgsNewHttpConnection::updateOkButtonState()
205 bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
206 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
212 QString key = mBaseKey + txtName->text();
215 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
216 settings.
contains( key +
"/url" ) &&
217 QMessageBox::question(
this,
218 tr(
"Save Connection" ),
219 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
220 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
225 if ( ! mAuthSettings->password().isEmpty() &&
226 QMessageBox::question(
this,
227 tr(
"Saving Passwords" ),
228 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." ),
229 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
239 return mTestConnectionButton;
244 return mWfsVersionDetectButton;
254 return cbxWfsFeaturePaging;
264 return base + connectionName;
269 return base + connectionName;
278 cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey +
"/ignoreGetMapURI",
false ).toBool() );
279 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
280 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
281 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
282 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
283 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
284 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
287 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
305 cmbDpiMode->setCurrentIndex( dpiIdx );
307 QString version = settings.
value( wfsKey +
"/version" ).toString();
309 if ( version == QLatin1String(
"1.0.0" ) )
311 else if ( version == QLatin1String(
"1.1.0" ) )
313 else if ( version == QLatin1String(
"2.0.0" ) )
315 cmbVersion->setCurrentIndex( versionIdx );
317 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
318 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
320 bool pagingEnabled = settings.
value( wfsKey +
"/pagingenabled",
true ).toBool();
321 txtPageSize->setText( settings.
value( wfsKey +
"/pagesize" ).toString() );
322 cbxWfsFeaturePaging->setChecked( pagingEnabled );
324 txtPageSize->setEnabled( pagingEnabled );
325 lblPageSize->setEnabled( pagingEnabled );
326 cbxWfsFeaturePaging->setEnabled( pagingEnabled );
332 QUrl
url( txtUrl->text().trimmed() );
333 const QList< QPair<QByteArray, QByteArray> > &items =
url.encodedQueryItems();
334 QHash< QString, QPair<QByteArray, QByteArray> > params;
335 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
337 params.insert( QString( it->first ).toUpper(), *it );
340 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
341 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
342 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
344 url.removeEncodedQueryItem( params[QStringLiteral(
"SERVICE" )].first );
345 url.removeEncodedQueryItem( params[QStringLiteral(
"REQUEST" )].first );
346 url.removeEncodedQueryItem( params[QStringLiteral(
"FORMAT" )].first );
349 if (
url.encodedPath().isEmpty() )
351 url.setEncodedPath(
"/" );
359 QString key = mBaseKey + txtName->text();
360 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
366 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
368 settings.
remove( mBaseKey + mOriginalConnName );
369 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
374 settings.
setValue( key +
"/url", url.toString() );
381 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
382 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
386 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
387 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
389 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
390 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
393 switch ( cmbDpiMode->currentIndex() )
412 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
414 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
418 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
420 if ( mTypes & ConnectionWfs )
422 QString version = QStringLiteral(
"auto" );
423 switch ( cmbVersion->currentIndex() )
426 version = QStringLiteral(
"auto" );
429 version = QStringLiteral(
"1.0.0" );
432 version = QStringLiteral(
"1.1.0" );
435 version = QStringLiteral(
"2.0.0" );
438 settings.
setValue( wfsKey +
"/version", version );
440 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
442 settings.
setValue( wfsKey +
"/pagesize", txtPageSize->text() );
443 settings.
setValue( wfsKey +
"/pagingenabled", cbxWfsFeaturePaging->isChecked() );
446 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
447 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
449 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
451 if ( mHttpGroupBox->isVisible() )
452 settings.
setValue( key +
"/referer", mRefererLineEdit->text() );
454 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
459 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.
virtual bool validate()
Returns true if dialog settings are valid, or false if current settings are not valid and the dialog ...