24 #include <QMessageBox> 
   26 #include <QPushButton> 
   27 #include <QRegularExpression> 
   28 #include <QRegularExpressionValidator> 
   32   : QDialog( parent, fl )
 
   35   , mOriginalConnName( connectionName )
 
   40     mHttpGroupBox->hide();
 
   44   connect( buttonBox, &QDialogButtonBox::helpRequested, 
this, &QgsNewHttpConnection::showHelp );
 
   46   const thread_local QRegularExpression rx( 
"/connections-([^/]+)/" );
 
   47   const QRegularExpressionMatch rxMatch = rx.match( baseKey );
 
   48   if ( rxMatch.hasMatch() )
 
   50     QString connectionType( rxMatch.captured( 1 ).toUpper() );
 
   51     if ( connectionType == QLatin1String( 
"WMS" ) )
 
   53       connectionType = QStringLiteral( 
"WMS/WMTS" );
 
   55     setWindowTitle( tr( 
"Create a New %1 Connection" ).arg( connectionType ) );
 
   63   mCredentialsBaseKey = mBaseKey.split( 
'-' ).last().toUpper();
 
   65   txtName->setValidator( 
new QRegularExpressionValidator( QRegularExpression( 
"[^\\/]+" ), txtName ) );
 
   68   cmbDpiMode->addItem( tr( 
"all" ) );
 
   69   cmbDpiMode->addItem( tr( 
"off" ) );
 
   70   cmbDpiMode->addItem( tr( 
"QGIS" ) );
 
   71   cmbDpiMode->addItem( tr( 
"UMN" ) );
 
   72   cmbDpiMode->addItem( tr( 
"GeoServer" ) );
 
   75   cmbVersion->addItem( tr( 
"Maximum" ) );
 
   76   cmbVersion->addItem( tr( 
"1.0" ) );
 
   77   cmbVersion->addItem( tr( 
"1.1" ) );
 
   78   cmbVersion->addItem( tr( 
"2.0" ) );
 
   79   cmbVersion->addItem( tr( 
"OGC API - Features" ) );
 
   81            static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ),
 
   82            this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged );
 
   84   connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged,
 
   85            this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged );
 
   87   if ( !connectionName.isEmpty() )
 
   94     const QString key = mBaseKey + connectionName;
 
   95     const QString credentialsKey = 
"qgis/" + mCredentialsBaseKey + 
'/' + connectionName;
 
   96     txtName->setText( connectionName );
 
   97     txtUrl->setText( settings.
value( key + 
"/url" ).toString() );
 
   98     mRefererLineEdit->setText( settings.
value( key + 
"/referer" ).toString() );
 
  103     mAuthSettings->setUsername( settings.
value( credentialsKey + 
"/username" ).toString() );
 
  104     mAuthSettings->setPassword( settings.
value( credentialsKey + 
"/password" ).toString() );
 
  105     mAuthSettings->setConfigId( settings.
value( credentialsKey + 
"/authcfg" ).toString() );
 
  107   mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
 
  111     mWmsOptionsGroupBox->setVisible( 
false );
 
  112     mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox );
 
  116     mWfsOptionsGroupBox->setVisible( 
false );
 
  117     mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox );
 
  121     txtUrl->setToolTip( tr( 
"HTTP address of the WFS service, or landing page of a OGC API service<br>(an ending slash might be needed for some OGC API servers)" ) );
 
  126     cbxIgnoreGetMapURI->setText( tr( 
"Ignore GetCoverage URI reported in capabilities" ) );
 
  127     cbxWmsIgnoreAxisOrientation->setText( tr( 
"Ignore axis orientation" ) );
 
  130       mWmsOptionsGroupBox->setTitle( tr( 
"WCS Options" ) );
 
  132       cbxIgnoreGetFeatureInfoURI->setVisible( 
false );
 
  133       mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
 
  135       cmbDpiMode->setVisible( 
false );
 
  136       mGroupBox->layout()->removeWidget( cmbDpiMode );
 
  137       lblDpiMode->setVisible( 
false );
 
  138       mGroupBox->layout()->removeWidget( lblDpiMode );
 
  144     mTestConnectionButton->hide();
 
  145     mGroupBox->layout()->removeWidget( mTestConnectionButton );
 
  150     mAuthGroupBox->hide();
 
  151     mGroupBox->layout()->removeWidget( mAuthGroupBox );
 
  154   const int w = width();
 
  156   resize( w, height() );
 
  158   connect( txtName, &QLineEdit::textChanged, 
this, &QgsNewHttpConnection::nameChanged );
 
  159   connect( txtUrl, &QLineEdit::textChanged, 
this, &QgsNewHttpConnection::urlChanged );
 
  161   buttonBox->button( QDialogButtonBox::Ok )->setDisabled( 
true );
 
  162   connect( txtName, &QLineEdit::textChanged, 
this, &QgsNewHttpConnection::updateOkButtonState );
 
  163   connect( txtUrl, &QLineEdit::textChanged, 
this, &QgsNewHttpConnection::updateOkButtonState );
 
  165   nameChanged( connectionName );
 
  168 void QgsNewHttpConnection::wfsVersionCurrentIndexChanged( 
int index )
 
  179 void QgsNewHttpConnection::wfsFeaturePagingStateChanged( 
int state )
 
  181   lblPageSize->setEnabled( state == Qt::Checked );
 
  182   txtPageSize->setEnabled( state == Qt::Checked );
 
  187   return txtName->text();
 
  192   return txtUrl->text();
 
  195 void QgsNewHttpConnection::nameChanged( 
const QString &text )
 
  198   buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
 
  201 void QgsNewHttpConnection::urlChanged( 
const QString &text )
 
  204   buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
 
  205   mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() );
 
  208 void QgsNewHttpConnection::updateOkButtonState()
 
  210   const bool enabled = !txtName->text().isEmpty() && !txtUrl->text().isEmpty();
 
  211   buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
 
  217   const QString key = mBaseKey + txtName->text();
 
  220   if ( ( mOriginalConnName.isNull() || mOriginalConnName.compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
 
  221        settings.
contains( key + 
"/url" ) &&
 
  222        QMessageBox::question( 
this,
 
  223                               tr( 
"Save Connection" ),
 
  224                               tr( 
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
 
  225                               QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
 
  230   if ( ! mAuthSettings->password().isEmpty() &&
 
  231        QMessageBox::question( 
this,
 
  232                               tr( 
"Saving Passwords" ),
 
  233                               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." ),
 
  234                               QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
 
  244   return mTestConnectionButton;
 
  249   return mAuthSettings;
 
  254   return mWfsVersionDetectButton;
 
  264   return cbxWfsFeaturePaging;
 
  269   return cbxWfsUseGml2EncodingForTransactions;
 
  279   return base + connectionName;
 
  284   return base + connectionName;
 
  290   const QString wfsKey = 
wfsSettingsKey( mBaseKey, mOriginalConnName );
 
  291   const QString wmsKey = 
wmsSettingsKey( mBaseKey, mOriginalConnName );
 
  293   cbxIgnoreGetMapURI->setChecked( settings.
value( wmsKey + 
"/ignoreGetMapURI", 
false ).toBool() );
 
  294   cbxWmsIgnoreReportedLayerExtents->setChecked( settings.
value( wmsKey + QStringLiteral( 
"/ignoreReportedLayerExtents" ), 
false ).toBool() );
 
  295   cbxWfsIgnoreAxisOrientation->setChecked( settings.
value( wfsKey + 
"/ignoreAxisOrientation", 
false ).toBool() );
 
  296   cbxWfsInvertAxisOrientation->setChecked( settings.
value( wfsKey + 
"/invertAxisOrientation", 
false ).toBool() );
 
  297   cbxWfsUseGml2EncodingForTransactions->setChecked( settings.
value( wfsKey + 
"/preferCoordinatesForWfsT11", 
false ).toBool() );
 
  299   cbxWmsIgnoreAxisOrientation->setChecked( settings.
value( wmsKey + 
"/ignoreAxisOrientation", 
false ).toBool() );
 
  300   cbxWmsInvertAxisOrientation->setChecked( settings.
value( wmsKey + 
"/invertAxisOrientation", 
false ).toBool() );
 
  301   cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( wmsKey + 
"/ignoreGetFeatureInfoURI", 
false ).toBool() );
 
  302   cbxSmoothPixmapTransform->setChecked( settings.
value( wmsKey + 
"/smoothPixmapTransform", 
false ).toBool() );
 
  305   switch ( settings.
value( wmsKey + 
"/dpiMode", 7 ).toInt() )
 
  323   cmbDpiMode->setCurrentIndex( dpiIdx );
 
  325   const QString version = settings.
value( wfsKey + 
"/version" ).toString();
 
  327   if ( version == QLatin1String( 
"1.0.0" ) )
 
  329   else if ( version == QLatin1String( 
"1.1.0" ) )
 
  331   else if ( version == QLatin1String( 
"2.0.0" ) )
 
  333   else if ( version == QLatin1String( 
"OGC_API_FEATURES" ) )
 
  335   cmbVersion->setCurrentIndex( versionIdx );
 
  338   wfsVersionCurrentIndexChanged( versionIdx );
 
  340   mRefererLineEdit->setText( settings.
value( wmsKey + 
"/referer" ).toString() );
 
  341   txtMaxNumFeatures->setText( settings.
value( wfsKey + 
"/maxnumfeatures" ).toString() );
 
  345   txtPageSize->setText( settings.
value( wfsKey + 
"/pagesize" ).toString() );
 
  346   cbxWfsFeaturePaging->setChecked( pagingEnabled );
 
  351   QUrl 
url( txtUrl->text().trimmed() );
 
  352   QUrlQuery query( 
url );
 
  353   const QList<QPair<QString, QString> > items = query.queryItems( QUrl::FullyEncoded );
 
  354   QHash< QString, QPair<QString, QString> > params;
 
  355   for ( 
const QPair<QString, QString> &it : items )
 
  357     params.insert( it.first.toUpper(), it );
 
  360   if ( params[QStringLiteral( 
"SERVICE" )].second.toUpper() == 
"WMS" ||
 
  361        params[QStringLiteral( 
"SERVICE" )].second.toUpper() == 
"WFS" ||
 
  362        params[QStringLiteral( 
"SERVICE" )].second.toUpper() == 
"WCS" )
 
  364     query.removeQueryItem( params.value( QStringLiteral( 
"SERVICE" ) ).first );
 
  365     query.removeQueryItem( params.value( QStringLiteral( 
"REQUEST" ) ).first );
 
  366     query.removeQueryItem( params.value( QStringLiteral( 
"FORMAT" ) ).first );
 
  369   url.setQuery( query );
 
  371   if ( 
url.path( QUrl::FullyEncoded ).isEmpty() )
 
  381   const QString key = mBaseKey + txtName->text();
 
  382   const QString credentialsKey = 
"qgis/" + mCredentialsBaseKey + 
'/' + txtName->text();
 
  388   if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
 
  390     settings.
remove( mBaseKey + mOriginalConnName );
 
  391     settings.
remove( 
"qgis/" + mCredentialsBaseKey + 
'/' + mOriginalConnName );
 
  398   const QString wfsKey = 
wfsSettingsKey( mBaseKey, txtName->text() );
 
  399   const QString wmsKey = 
wmsSettingsKey( mBaseKey, txtName->text() );
 
  403     settings.
setValue( wfsKey + 
"/ignoreAxisOrientation", cbxWfsIgnoreAxisOrientation->isChecked() );
 
  404     settings.
setValue( wfsKey + 
"/invertAxisOrientation", cbxWfsInvertAxisOrientation->isChecked() );
 
  405     settings.
setValue( wfsKey + 
"/preferCoordinatesForWfsT11", cbxWfsUseGml2EncodingForTransactions->isChecked() );
 
  409     settings.
setValue( wmsKey + 
"/ignoreAxisOrientation", cbxWmsIgnoreAxisOrientation->isChecked() );
 
  410     settings.
setValue( wmsKey + 
"/invertAxisOrientation", cbxWmsInvertAxisOrientation->isChecked() );
 
  412     settings.
setValue( wmsKey + QStringLiteral( 
"/ignoreReportedLayerExtents" ), cbxWmsIgnoreReportedLayerExtents->isChecked() );
 
  413     settings.
setValue( wmsKey + 
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
 
  414     settings.
setValue( wmsKey + 
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
 
  417     switch ( cmbDpiMode->currentIndex() )
 
  436     settings.
setValue( wmsKey + 
"/dpiMode", dpiMode );
 
  438     settings.
setValue( wmsKey + 
"/referer", mRefererLineEdit->text() );
 
  442     settings.
setValue( wmsKey + 
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
 
  446     QString version = QStringLiteral( 
"auto" );
 
  447     switch ( cmbVersion->currentIndex() )
 
  450         version = QStringLiteral( 
"auto" );
 
  453         version = QStringLiteral( 
"1.0.0" );
 
  456         version = QStringLiteral( 
"1.1.0" );
 
  459         version = QStringLiteral( 
"2.0.0" );
 
  462         version = QStringLiteral( 
"OGC_API_FEATURES" );
 
  465     settings.
setValue( wfsKey + 
"/version", version );
 
  467     settings.
setValue( wfsKey + 
"/maxnumfeatures", txtMaxNumFeatures->text() );
 
  469     settings.
setValue( wfsKey + 
"/pagesize", txtPageSize->text() );
 
  470     settings.
setValue( wfsKey + 
"/pagingenabled", cbxWfsFeaturePaging->isChecked() );
 
  473   settings.
setValue( credentialsKey + 
"/username", mAuthSettings->username() );
 
  474   settings.
setValue( credentialsKey + 
"/password", mAuthSettings->password() );
 
  476   settings.
setValue( credentialsKey + 
"/authcfg", mAuthSettings->configId() );
 
  478   if ( mHttpGroupBox->isVisible() )
 
  479     settings.
setValue( key + 
"/referer", mRefererLineEdit->text() );
 
  481   settings.
setValue( mBaseKey + 
"/selected", txtName->text() );
 
  486 void QgsNewHttpConnection::showHelp()
 
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.
QgsNewHttpConnection(QWidget *parent=nullptr, QgsNewHttpConnection::ConnectionTypes types=ConnectionWms, const QString &baseKey="qgis/connections-wms/", const QString &connectionName=QString(), QgsNewHttpConnection::Flags flags=QgsNewHttpConnection::Flags(), Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsNewHttpConnection.
QPushButton * testConnectButton()
Returns the "test connection" button.
QgsAuthSettingsWidget * authSettingsWidget()
Returns the current authentication settings widget.
QCheckBox * wfsPagingEnabledCheckBox()
Returns the "WFS paging enabled" checkbox.
virtual bool validate()
Returns true if dialog settings are valid, or false if current settings are not valid and the dialog ...
QString name() const
Returns the current connection name.
@ FlagShowHttpSettings
Display the 'http' group.
@ FlagHideAuthenticationGroup
Hide the Authentication group.
@ FlagShowTestConnection
Display the 'test connection' button.
QCheckBox * wfsUseGml2EncodingForTransactions()
Returns the "Use GML2 encoding for transactions" checkbox.
QComboBox * wfsVersionComboBox()
Returns the "WFS version" combobox.
virtual QString wmsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WMS related settings for the connection.
virtual QString wfsSettingsKey(const QString &base, const QString &connectionName) const
Returns the QSettings key for WFS related settings for the connection.
QString url() const
Returns the current connection url.
QPushButton * wfsVersionDetectButton()
Returns the "WFS version detect" button.
@ WFS_VERSION_API_FEATURES_1_0
QUrl urlTrimmed() const
Returns the url.
QLineEdit * wfsPageSizeLineEdit()
Returns the "WFS page size" edit.
void updateServiceSpecificSettings()
Triggers a resync of the GUI widgets for the service specific settings (i.e.
@ ConnectionWms
WMS connection.
@ ConnectionWfs
WFS connection.
@ ConnectionWcs
WCS connection.
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.
bool contains(const QString &key, 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 remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QString fromEncodedComponent_helper(const QByteArray &ba)