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 )
39 setWindowTitle( tr(
"Create a New %1 Connection" ).arg( rx.cap( 1 ).toUpper() ) );
46 mCredentialsBaseKey = mBaseKey.split(
'-' ).last().toUpper();
48 txtName->setValidator(
new QRegExpValidator( QRegExp(
"[^\\/]+" ), txtName ) );
51 cmbDpiMode->addItem( tr(
"all" ) );
52 cmbDpiMode->addItem( tr(
"off" ) );
53 cmbDpiMode->addItem( tr(
"QGIS" ) );
54 cmbDpiMode->addItem( tr(
"UMN" ) );
55 cmbDpiMode->addItem( tr(
"GeoServer" ) );
58 cmbVersion->addItem( tr(
"Auto-detect" ) );
59 cmbVersion->addItem( tr(
"1.0" ) );
60 cmbVersion->addItem( tr(
"1.1" ) );
61 cmbVersion->addItem( tr(
"2.0" ) );
63 if ( !connectionName.isEmpty() )
70 QString key = mBaseKey + connectionName;
71 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + connectionName;
72 txtName->setText( connectionName );
73 txtUrl->setText( settings.
value( key +
"/url" ).toString() );
78 mAuthSettings->setUsername( settings.
value( credentialsKey +
"/username" ).toString() );
79 mAuthSettings->setPassword( settings.
value( credentialsKey +
"/password" ).toString() );
80 mAuthSettings->setConfigId( settings.
value( credentialsKey +
"/authcfg" ).toString() );
85 mWmsOptionsGroupBox->setVisible(
false );
86 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
90 mWfsOptionsGroupBox->setVisible(
false );
91 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
96 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
97 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
98 if ( !( mTypes & ConnectionWms ) )
100 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
102 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
103 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
105 cmbDpiMode->setVisible(
false );
106 mGroupBox->layout()->removeWidget( cmbDpiMode );
107 lblDpiMode->setVisible(
false );
108 mGroupBox->layout()->removeWidget( lblDpiMode );
110 txtReferer->setVisible(
false );
111 mGroupBox->layout()->removeWidget( txtReferer );
112 lblReferer->setVisible(
false );
113 mGroupBox->layout()->removeWidget( lblReferer );
120 mTestConnectionButton->hide();
121 mGroupBox->layout()->removeWidget( mTestConnectionButton );
126 mAuthGroupBox->hide();
127 mGroupBox->layout()->removeWidget( mAuthGroupBox );
132 resize( w, height() );
134 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
135 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
137 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
138 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
139 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
141 nameChanged( connectionName );
146 return txtName->text();
151 return txtUrl->text();
154 void QgsNewHttpConnection::nameChanged(
const QString &text )
157 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
160 void QgsNewHttpConnection::urlChanged(
const QString &text )
163 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
166 void QgsNewHttpConnection::updateOkButtonState()
168 bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
169 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
175 QString key = mBaseKey + txtName->text();
178 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
179 settings.
contains( key +
"/url" ) &&
180 QMessageBox::question(
this,
181 tr(
"Save Connection" ),
182 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
183 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
188 if ( ! mAuthSettings->password().isEmpty() &&
189 QMessageBox::question(
this,
190 tr(
"Saving Passwords" ),
191 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." ),
192 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
202 return mTestConnectionButton;
207 return base + connectionName;
212 return base + connectionName;
221 cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey +
"/ignoreGetMapURI",
false ).toBool() );
222 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
223 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
224 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
225 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
226 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
227 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
230 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
248 cmbDpiMode->setCurrentIndex( dpiIdx );
250 QString version = settings.
value( wfsKey +
"/version" ).toString();
252 if ( version == QLatin1String(
"1.0.0" ) )
254 else if ( version == QLatin1String(
"1.1.0" ) )
256 else if ( version == QLatin1String(
"2.0.0" ) )
258 cmbVersion->setCurrentIndex( versionIdx );
260 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
261 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
267 QString key = mBaseKey + txtName->text();
268 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
274 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
276 settings.
remove( mBaseKey + mOriginalConnName );
277 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
281 QUrl
url( txtUrl->text().trimmed() );
282 const QList< QPair<QByteArray, QByteArray> > &items =
url.encodedQueryItems();
283 QHash< QString, QPair<QByteArray, QByteArray> > params;
284 for ( QList< QPair<QByteArray, QByteArray> >::const_iterator it = items.constBegin(); it != items.constEnd(); ++it )
286 params.insert( QString( it->first ).toUpper(), *it );
289 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
290 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
291 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
293 url.removeEncodedQueryItem( params[QStringLiteral(
"SERVICE" )].first );
294 url.removeEncodedQueryItem( params[QStringLiteral(
"REQUEST" )].first );
295 url.removeEncodedQueryItem( params[QStringLiteral(
"FORMAT" )].first );
298 if (
url.encodedPath().isEmpty() )
300 url.setEncodedPath(
"/" );
310 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
311 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
315 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
316 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
318 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
319 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
322 switch ( cmbDpiMode->currentIndex() )
341 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
343 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
347 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
349 if ( mTypes & ConnectionWfs )
351 QString version = QStringLiteral(
"auto" );
352 switch ( cmbVersion->currentIndex() )
355 version = QStringLiteral(
"auto" );
358 version = QStringLiteral(
"1.0.0" );
361 version = QStringLiteral(
"1.1.0" );
364 version = QStringLiteral(
"2.0.0" );
367 settings.
setValue( wfsKey +
"/version", version );
369 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
372 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
373 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
375 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
377 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
382 void QgsNewHttpConnection::showHelp()
void remove(const QString &key, const QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
This class is a composition of two QSettings instances:
bool contains(const QString &key, const QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
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.
virtual QString wfsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WFS related settings for the connection.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
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.
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 ...