22 #include <QMessageBox> 24 #include <QPushButton> 26 #include <QRegExpValidator> 29 : QDialog( parent, fl )
32 , mOriginalConnName( connectionName )
35 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsNewHttpConnection::showHelp );
37 QRegExp rx(
"/connections-([^/]+)/" );
38 if ( rx.indexIn( baseKey ) != -1 )
40 QString connectionType( rx.cap( 1 ).toUpper() );
41 if ( connectionType == QLatin1String(
"WMS" ) )
43 connectionType = QStringLiteral(
"WMS/WMTS" );
45 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( connectionType ) );
53 mCredentialsBaseKey = mBaseKey.split(
'-' ).last().toUpper();
55 txtName->setValidator(
new QRegExpValidator( QRegExp(
"[^\\/]+" ), txtName ) );
58 cmbDpiMode->addItem( tr(
"all" ) );
59 cmbDpiMode->addItem( tr(
"off" ) );
60 cmbDpiMode->addItem( tr(
"QGIS" ) );
61 cmbDpiMode->addItem( tr(
"UMN" ) );
62 cmbDpiMode->addItem( tr(
"GeoServer" ) );
65 cmbVersion->addItem( tr(
"Auto-detect" ) );
66 cmbVersion->addItem( tr(
"1.0" ) );
67 cmbVersion->addItem( tr(
"1.1" ) );
68 cmbVersion->addItem( tr(
"2.0" ) );
70 if ( !connectionName.isEmpty() )
77 QString key = mBaseKey + connectionName;
78 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + connectionName;
79 txtName->setText( connectionName );
80 txtUrl->setText( settings.
value( key +
"/url" ).toString() );
85 mAuthSettings->setUsername( settings.
value( credentialsKey +
"/username" ).toString() );
86 mAuthSettings->setPassword( settings.
value( credentialsKey +
"/password" ).toString() );
87 mAuthSettings->setConfigId( settings.
value( credentialsKey +
"/authcfg" ).toString() );
92 mWmsOptionsGroupBox->setVisible(
false );
93 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
97 mWfsOptionsGroupBox->setVisible(
false );
98 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
103 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
104 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
105 if ( !( mTypes & ConnectionWms ) )
107 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
109 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
110 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
112 cmbDpiMode->setVisible(
false );
113 mGroupBox->layout()->removeWidget( cmbDpiMode );
114 lblDpiMode->setVisible(
false );
115 mGroupBox->layout()->removeWidget( lblDpiMode );
117 txtReferer->setVisible(
false );
118 mGroupBox->layout()->removeWidget( txtReferer );
119 lblReferer->setVisible(
false );
120 mGroupBox->layout()->removeWidget( lblReferer );
127 mTestConnectionButton->hide();
128 mGroupBox->layout()->removeWidget( mTestConnectionButton );
133 mAuthGroupBox->hide();
134 mGroupBox->layout()->removeWidget( mAuthGroupBox );
139 resize( w, height() );
141 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
142 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
144 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
145 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
146 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
148 nameChanged( connectionName );
153 return txtName->text();
158 return txtUrl->text();
161 void QgsNewHttpConnection::nameChanged(
const QString &text )
164 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
167 void QgsNewHttpConnection::urlChanged(
const QString &text )
170 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
173 void QgsNewHttpConnection::updateOkButtonState()
175 bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
176 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
182 QString key = mBaseKey + txtName->text();
185 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
186 settings.
contains( key +
"/url" ) &&
187 QMessageBox::question(
this,
188 tr(
"Save Connection" ),
189 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
190 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
195 if ( ! mAuthSettings->password().isEmpty() &&
196 QMessageBox::question(
this,
197 tr(
"Saving Passwords" ),
198 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." ),
199 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
209 return mTestConnectionButton;
214 return base + connectionName;
219 return base + connectionName;
228 cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey +
"/ignoreGetMapURI",
false ).toBool() );
229 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
230 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
231 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
232 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
233 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
234 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
237 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
255 cmbDpiMode->setCurrentIndex( dpiIdx );
257 QString version = settings.
value( wfsKey +
"/version" ).toString();
259 if ( version == QLatin1String(
"1.0.0" ) )
261 else if ( version == QLatin1String(
"1.1.0" ) )
263 else if ( version == QLatin1String(
"2.0.0" ) )
265 cmbVersion->setCurrentIndex( versionIdx );
267 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
268 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
274 QString key = mBaseKey + txtName->text();
275 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
281 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
283 settings.
remove( mBaseKey + mOriginalConnName );
284 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
288 QUrl
url( txtUrl->text().trimmed() );
289 const QList< QPair<QByteArray, QByteArray> > &items =
url.encodedQueryItems();
290 QHash< QString, QPair<QByteArray, QByteArray> > params;
291 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
293 params.insert( QString( it->first ).toUpper(), *it );
296 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
297 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
298 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
300 url.removeEncodedQueryItem( params[QStringLiteral(
"SERVICE" )].first );
301 url.removeEncodedQueryItem( params[QStringLiteral(
"REQUEST" )].first );
302 url.removeEncodedQueryItem( params[QStringLiteral(
"FORMAT" )].first );
305 if (
url.encodedPath().isEmpty() )
307 url.setEncodedPath(
"/" );
317 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
318 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
322 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
323 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
325 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
326 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
329 switch ( cmbDpiMode->currentIndex() )
348 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
350 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
354 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
356 if ( mTypes & ConnectionWfs )
358 QString version = QStringLiteral(
"auto" );
359 switch ( cmbVersion->currentIndex() )
362 version = QStringLiteral(
"auto" );
365 version = QStringLiteral(
"1.0.0" );
368 version = QStringLiteral(
"1.1.0" );
371 version = QStringLiteral(
"2.0.0" );
374 settings.
setValue( wfsKey +
"/version", version );
376 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
379 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
380 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
382 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
384 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
389 void QgsNewHttpConnection::showHelp()
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.
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 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.
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.
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 ...