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" ) );
76 cmbVersion->addItem( tr(
"OGC API - Features" ) );
78 static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
79 this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
81 connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
82 this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
84 if ( !connectionName.isEmpty() )
91 QString key = mBaseKey + connectionName;
92 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + connectionName;
93 txtName->setText( connectionName );
94 txtUrl->setText( settings.
value( key +
"/url" ).toString() );
95 mRefererLineEdit->setText( settings.
value( key +
"/referer" ).toString() );
100 mAuthSettings->setUsername( settings.
value( credentialsKey +
"/username" ).toString() );
101 mAuthSettings->setPassword( settings.
value( credentialsKey +
"/password" ).toString() );
102 mAuthSettings->setConfigId( settings.
value( credentialsKey +
"/authcfg" ).toString() );
104 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
108 mWmsOptionsGroupBox->setVisible(
false );
109 mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
113 mWfsOptionsGroupBox->setVisible(
false );
114 mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
119 cbxIgnoreGetMapURI->setText( tr(
"Ignore GetCoverage URI reported in capabilities" ) );
120 cbxWmsIgnoreAxisOrientation->setText( tr(
"Ignore axis orientation" ) );
121 if ( !( mTypes & ConnectionWms ) )
123 mWmsOptionsGroupBox->setTitle( tr(
"WCS Options" ) );
125 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
126 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
128 cmbDpiMode->setVisible(
false );
129 mGroupBox->layout()->removeWidget( cmbDpiMode );
130 lblDpiMode->setVisible(
false );
131 mGroupBox->layout()->removeWidget( lblDpiMode );
133 txtReferer->setVisible(
false );
134 mGroupBox->layout()->removeWidget( txtReferer );
135 lblReferer->setVisible(
false );
136 mGroupBox->layout()->removeWidget( lblReferer );
143 mTestConnectionButton->hide();
144 mGroupBox->layout()->removeWidget( mTestConnectionButton );
149 mAuthGroupBox->hide();
150 mGroupBox->layout()->removeWidget( mAuthGroupBox );
155 resize( w, height() );
157 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::nameChanged );
158 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::urlChanged );
160 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
161 connect( txtName, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
162 connect( txtUrl, &QLineEdit::textChanged,
this, &QgsNewHttpConnection::updateOkButtonState );
164 nameChanged( connectionName );
167 void QgsNewHttpConnection::wfsVersionCurrentIndexChanged(
int index )
177 void QgsNewHttpConnection::wfsFeaturePagingStateChanged(
int state )
179 lblPageSize->setEnabled( state == Qt::Checked );
180 txtPageSize->setEnabled( state == Qt::Checked );
185 return txtName->text();
190 return txtUrl->text();
193 void QgsNewHttpConnection::nameChanged(
const QString &text )
196 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
199 void QgsNewHttpConnection::urlChanged(
const QString &text )
202 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
203 mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
206 void QgsNewHttpConnection::updateOkButtonState()
208 bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
209 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
215 QString key = mBaseKey + txtName->text();
218 if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
219 settings.
contains( key +
"/url" ) &&
220 QMessageBox::question(
this,
221 tr(
"Save Connection" ),
222 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
223 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
228 if ( ! mAuthSettings->password().isEmpty() &&
229 QMessageBox::question(
this,
230 tr(
"Saving Passwords" ),
231 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." ),
232 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
242 return mTestConnectionButton;
247 return mAuthSettings;
252 return mWfsVersionDetectButton;
262 return cbxWfsFeaturePaging;
272 return base + connectionName;
277 return base + connectionName;
286 cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey +
"/ignoreGetMapURI",
false ).toBool() );
287 cbxWmsIgnoreReportedLayerExtents->setChecked( settings.
value( wmsKey + QStringLiteral(
"/ignoreReportedLayerExtents" ),
false ).toBool() );
288 cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey +
"/ignoreAxisOrientation",
false ).toBool() );
289 cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey +
"/invertAxisOrientation",
false ).toBool() );
290 cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey +
"/ignoreAxisOrientation",
false ).toBool() );
291 cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey +
"/invertAxisOrientation",
false ).toBool() );
292 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey +
"/ignoreGetFeatureInfoURI",
false ).toBool() );
293 cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey +
"/smoothPixmapTransform",
false ).toBool() );
296 switch ( settings.
value( wmsKey +
"/dpiMode", 7 ).toInt() )
314 cmbDpiMode->setCurrentIndex( dpiIdx );
316 QString version = settings.
value( wfsKey +
"/version" ).toString();
318 if ( version == QLatin1String(
"1.0.0" ) )
320 else if ( version == QLatin1String(
"1.1.0" ) )
322 else if ( version == QLatin1String(
"2.0.0" ) )
324 else if ( version == QLatin1String(
"OGC_API_FEATURES" ) )
326 cmbVersion->setCurrentIndex( versionIdx );
329 wfsVersionCurrentIndexChanged( versionIdx );
331 txtReferer->setText( settings.
value( wmsKey +
"/referer" ).toString() );
332 txtMaxNumFeatures->setText( settings.
value( wfsKey +
"/maxnumfeatures" ).toString() );
336 txtPageSize->setText( settings.
value( wfsKey +
"/pagesize" ).toString() );
337 cbxWfsFeaturePaging->setChecked( pagingEnabled );
347 return "0123456789ABCDEF"[value & 0xF];
350 static inline ushort encodeNibble( ushort
c )
357 while ( ptr + 4 <= end )
359 quint32 data = qFromUnaligned<quint32>( ptr );
360 if ( data &= 0x80808080U )
362 #if Q_BYTE_ORDER == Q_BIG_ENDIAN 363 uint idx = qCountLeadingZeroBits( data );
365 uint idx = qCountTrailingZeroBits( data );
374 if ( quint8( *ptr ) & 0x80 )
387 const char *in = ba.constData();
388 const char *
const end = ba.constEnd();
392 return QString::fromLatin1( ba, ba.size() );
395 QByteArray intermediate = ba;
396 intermediate.resize( ba.size() * 3 - ( in - ba.constData() ) );
397 uchar *out =
reinterpret_cast<uchar *
>( intermediate.data() + ( in - ba.constData() ) );
398 for ( ; in < end; ++in )
404 *out++ = encodeNibble( uchar( *in ) >> 4 );
405 *out++ = encodeNibble( uchar( *in ) & 0xf );
410 *out++ = uchar( *in );
414 return QString::fromLatin1( intermediate, out - reinterpret_cast<uchar *>( intermediate.data() ) );
420 QUrl
url( txtUrl->text().trimmed() );
421 QUrlQuery query(
url );
422 const QList<QPair<QString, QString> > items = query.queryItems( QUrl::FullyEncoded );
423 QHash< QString, QPair<QString, QString> > params;
424 for (
const QPair<QString, QString> &it : items )
426 params.insert( it.first.toUpper(), it );
429 if ( params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WMS" ||
430 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WFS" ||
431 params[QStringLiteral(
"SERVICE" )].second.toUpper() ==
"WCS" )
433 query.removeQueryItem( params.value( QStringLiteral(
"SERVICE" ) ).first );
434 query.removeQueryItem( params.value( QStringLiteral(
"REQUEST" ) ).first );
435 query.removeQueryItem( params.value( QStringLiteral(
"FORMAT" ) ).first );
438 url.setQuery( query );
440 if (
url.path( QUrl::FullyEncoded ).isEmpty() )
450 QString key = mBaseKey + txtName->text();
451 QString credentialsKey =
"qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
457 if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
459 settings.
remove( mBaseKey + mOriginalConnName );
460 settings.
remove(
"qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
465 settings.
setValue( key +
"/url", url.toString() );
472 settings.
setValue( wfsKey +
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
473 settings.
setValue( wfsKey +
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
477 settings.
setValue( wmsKey +
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
478 settings.
setValue( wmsKey +
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
480 settings.
setValue( wmsKey + QStringLiteral(
"/ignoreReportedLayerExtents" ), cbxWmsIgnoreReportedLayerExtents->isChecked() );
481 settings.
setValue( wmsKey +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
482 settings.
setValue( wmsKey +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
485 switch ( cmbDpiMode->currentIndex() )
504 settings.
setValue( wmsKey +
"/dpiMode", dpiMode );
506 settings.
setValue( wmsKey +
"/referer", txtReferer->text() );
510 settings.
setValue( wmsKey +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
512 if ( mTypes & ConnectionWfs )
514 QString version = QStringLiteral(
"auto" );
515 switch ( cmbVersion->currentIndex() )
518 version = QStringLiteral(
"auto" );
521 version = QStringLiteral(
"1.0.0" );
524 version = QStringLiteral(
"1.1.0" );
527 version = QStringLiteral(
"2.0.0" );
530 version = QStringLiteral(
"OGC_API_FEATURES" );
533 settings.
setValue( wfsKey +
"/version", version );
535 settings.
setValue( wfsKey +
"/maxnumfeatures", txtMaxNumFeatures->text() );
537 settings.
setValue( wfsKey +
"/pagesize", txtPageSize->text() );
538 settings.
setValue( wfsKey +
"/pagingenabled", cbxWfsFeaturePaging->isChecked() );
541 settings.
setValue( credentialsKey +
"/username", mAuthSettings->username() );
542 settings.
setValue( credentialsKey +
"/password", mAuthSettings->password() );
544 settings.
setValue( credentialsKey +
"/authcfg", mAuthSettings->configId() );
546 if ( mHttpGroupBox->isVisible() )
547 settings.
setValue( key +
"/referer", mRefererLineEdit->text() );
549 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
554 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.
QString fromEncodedComponent_helper(const QByteArray &ba)
void sync()
Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in t...
char toHexUpper(uint value) noexcept
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qt_is_ascii(const char *&ptr, const char *end) noexcept
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 ...