20 #include <QMessageBox> 22 #include <QPushButton> 23 #include <QRegExpValidator> 29 , mOriginalConnName( connName )
30 , mAuthConfigSelect( nullptr )
42 mCredentialsBaseKey = mBaseKey.
split(
'-' ).
last().toUpper();
47 cmbDpiMode->addItem(
tr(
"all" ) );
48 cmbDpiMode->addItem(
tr(
"off" ) );
49 cmbDpiMode->addItem(
tr(
"QGIS" ) );
50 cmbDpiMode->addItem(
tr(
"UMN" ) );
51 cmbDpiMode->addItem(
tr(
"GeoServer" ) );
54 tabAuth->insertTab( 1, mAuthConfigSelect,
tr(
"Configurations" ) );
63 QString key = mBaseKey + connName;
64 QString credentialsKey =
"/Qgis/" + mCredentialsBaseKey +
'/' + connName;
65 txtName->setText( connName );
68 cbxIgnoreGetMapURI->setChecked( settings.
value( key +
"/ignoreGetMapURI",
false ).
toBool() );
69 cbxIgnoreAxisOrientation->setChecked( settings.
value( key +
"/ignoreAxisOrientation",
false ).
toBool() );
70 cbxInvertAxisOrientation->setChecked( settings.
value( key +
"/invertAxisOrientation",
false ).
toBool() );
71 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( key +
"/ignoreGetFeatureInfoURI",
false ).
toBool() );
72 cbxSmoothPixmapTransform->setChecked( settings.
value( key +
"/smoothPixmapTransform",
false ).
toBool() );
75 switch ( settings.
value( key +
"/dpiMode", 7 ).
toInt() )
93 cmbDpiMode->setCurrentIndex( dpiIdx );
95 txtReferer->setText( settings.
value( key +
"/referer" ).
toString() );
97 txtUserName->setText( settings.
value( credentialsKey +
"/username" ).
toString() );
98 txtPassword->setText( settings.
value( credentialsKey +
"/password" ).
toString() );
104 tabAuth->setCurrentIndex( tabAuth->indexOf( mAuthConfigSelect ) );
108 if ( mBaseKey !=
"/Qgis/connections-wms/" )
110 if ( mBaseKey ==
"/Qgis/connections-wcs/" )
112 cbxIgnoreGetMapURI->setText(
tr(
"Ignore GetCoverage URI reported in capabilities" ) );
113 cbxIgnoreAxisOrientation->setText(
tr(
"Ignore axis orientation" ) );
117 cbxIgnoreGetMapURI->setVisible(
false );
118 cbxIgnoreAxisOrientation->setVisible(
false );
119 cbxInvertAxisOrientation->setVisible(
false );
120 cbxSmoothPixmapTransform->setVisible(
false );
121 mGroupBox->layout()->removeWidget( cbxIgnoreGetMapURI );
122 mGroupBox->layout()->removeWidget( cbxIgnoreAxisOrientation );
123 mGroupBox->layout()->removeWidget( cbxInvertAxisOrientation );
124 mGroupBox->layout()->removeWidget( cbxSmoothPixmapTransform );
127 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
128 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
130 cmbDpiMode->setVisible(
false );
131 mGroupBox->layout()->removeWidget( cmbDpiMode );
132 lblDpiMode->setVisible(
false );
133 mGroupBox->layout()->removeWidget( lblDpiMode );
135 txtReferer->setVisible(
false );
136 mGroupBox->layout()->removeWidget( txtReferer );
137 lblReferer->setVisible(
false );
138 mGroupBox->layout()->removeWidget( lblReferer );
156 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
162 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
168 QString key = mBaseKey + txtName->text();
169 QString credentialsKey =
"/Qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
172 if (( mOriginalConnName.
isNull() || mOriginalConnName.
compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
173 settings.
contains( key +
"/url" ) &&
175 tr(
"Save connection" ),
176 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
177 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
182 if ( !txtPassword->text().isEmpty() &&
184 tr(
"Saving passwords" ),
185 tr(
"WARNING: You have entered a password. It will be stored in plain text in your project files and in your home directory on Unix-like systems, or in your user profile on Windows. If you do not want this to happen, please press the Cancel button.\nNote: giving the password is optional. It will be requested interactivly, when needed." ),
186 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
192 if ( !mOriginalConnName.
isNull() && mOriginalConnName != key )
194 settings.
remove( mBaseKey + mOriginalConnName );
195 settings.
remove(
"/Qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
199 QUrl url( txtUrl->text().trimmed() );
207 if ( params[
"SERVICE"].second.toUpper() ==
"WMS" ||
208 params[
"SERVICE"].second.toUpper() ==
"WFS" ||
209 params[
"SERVICE"].second.toUpper() ==
"WCS" )
211 url.removeEncodedQueryItem( params[
"SERVICE"].first );
212 url.removeEncodedQueryItem( params[
"REQUEST"].first );
213 url.removeEncodedQueryItem( params[
"FORMAT"].first );
216 if ( url.encodedPath().isEmpty() )
218 url.setEncodedPath(
"/" );
221 settings.
setValue( key +
"/url", url.toString() );
222 if ( mBaseKey ==
"/Qgis/connections-wms/" || mBaseKey ==
"/Qgis/connections-wcs/" )
224 settings.
setValue( key +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
225 settings.
setValue( key +
"/ignoreAxisOrientation", cbxIgnoreAxisOrientation->isChecked() );
226 settings.
setValue( key +
"/invertAxisOrientation", cbxInvertAxisOrientation->isChecked() );
227 settings.
setValue( key +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
230 switch ( cmbDpiMode->currentIndex() )
249 settings.
setValue( key +
"/dpiMode", dpiMode );
251 if ( mBaseKey ==
"/Qgis/connections-wms/" )
253 settings.
setValue( key +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
256 settings.
setValue( key +
"/referer", txtReferer->text() );
258 settings.
setValue( credentialsKey +
"/username", txtUserName->text() );
259 settings.
setValue( credentialsKey +
"/password", txtPassword->text() );
261 settings.
setValue( credentialsKey +
"/authcfg", mAuthConfigSelect->
configId() );
263 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
const QString configId() const
Get the authentication config id for the resource.
~QgsNewHttpConnection()
Destructor.
iterator insert(const Key &key, const T &value)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString tr(const char *sourceText, const char *disambiguation, int n)
void on_txtName_textChanged(const QString &)
void setValue(const QString &key, const QVariant &value)
int toInt(bool *ok) const
void setConfigId(const QString &authcfg)
Set the authentication config id for the resource.
StandardButton question(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void accept() override
Saves the connection to ~/.qt/qgisrc.
bool contains(const QString &key) const
void remove(const QString &key)
QVariant value(const QString &key, const QVariant &defaultValue) const
QString mid(int position, int n) const
void on_txtUrl_textChanged(const QString &)
QgsNewHttpConnection(QWidget *parent=nullptr, const QString &baseKey="/Qgis/connections-wms/", const QString &connName=QString::null, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
Constructor.
int compare(const QString &other) const
Selector widget for authentication configs.