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 cmbVersion->addItem(
tr(
"Auto-detect" ) );
55 cmbVersion->addItem(
tr(
"1.0" ) );
56 cmbVersion->addItem(
tr(
"1.1" ) );
57 cmbVersion->addItem(
tr(
"2.0" ) );
60 tabAuth->insertTab( 1, mAuthConfigSelect,
tr(
"Configurations" ) );
69 QString key = mBaseKey + connName;
70 QString credentialsKey =
"/Qgis/" + mCredentialsBaseKey +
'/' + connName;
71 txtName->setText( connName );
74 cbxIgnoreGetMapURI->setChecked( settings.
value( key +
"/ignoreGetMapURI",
false ).
toBool() );
75 cbxIgnoreAxisOrientation->setChecked( settings.
value( key +
"/ignoreAxisOrientation",
false ).
toBool() );
76 cbxInvertAxisOrientation->setChecked( settings.
value( key +
"/invertAxisOrientation",
false ).
toBool() );
77 cbxIgnoreGetFeatureInfoURI->setChecked( settings.
value( key +
"/ignoreGetFeatureInfoURI",
false ).
toBool() );
78 cbxSmoothPixmapTransform->setChecked( settings.
value( key +
"/smoothPixmapTransform",
false ).
toBool() );
81 switch ( settings.
value( key +
"/dpiMode", 7 ).
toInt() )
99 cmbDpiMode->setCurrentIndex( dpiIdx );
103 if ( version ==
"1.0.0" )
105 else if ( version ==
"1.1.0" )
107 else if ( version ==
"2.0.0" )
109 cmbVersion->setCurrentIndex( versionIdx );
111 txtReferer->setText( settings.
value( key +
"/referer" ).
toString() );
112 txtMaxNumFeatures->setText( settings.
value( key +
"/maxnumfeatures" ).
toString() );
114 txtUserName->setText( settings.
value( credentialsKey +
"/username" ).
toString() );
115 txtPassword->setText( settings.
value( credentialsKey +
"/password" ).
toString() );
121 tabAuth->setCurrentIndex( tabAuth->indexOf( mAuthConfigSelect ) );
125 if ( mBaseKey !=
"/Qgis/connections-wms/" )
127 if ( mBaseKey !=
"/Qgis/connections-wcs/" &&
128 mBaseKey !=
"/Qgis/connections-wfs/" )
130 cbxIgnoreAxisOrientation->setVisible(
false );
131 cbxInvertAxisOrientation->setVisible(
false );
132 mGroupBox->layout()->removeWidget( cbxIgnoreAxisOrientation );
133 mGroupBox->layout()->removeWidget( cbxInvertAxisOrientation );
136 if ( mBaseKey ==
"/Qgis/connections-wfs/" )
138 cbxIgnoreAxisOrientation->setText(
tr(
"Ignore axis orientation (WFS 1.1/WFS 2.0)" ) );
141 if ( mBaseKey ==
"/Qgis/connections-wcs/" )
143 cbxIgnoreGetMapURI->setText(
tr(
"Ignore GetCoverage URI reported in capabilities" ) );
144 cbxIgnoreAxisOrientation->setText(
tr(
"Ignore axis orientation" ) );
148 cbxIgnoreGetMapURI->setVisible(
false );
149 cbxSmoothPixmapTransform->setVisible(
false );
150 mGroupBox->layout()->removeWidget( cbxIgnoreGetMapURI );
151 mGroupBox->layout()->removeWidget( cbxSmoothPixmapTransform );
154 cbxIgnoreGetFeatureInfoURI->setVisible(
false );
155 mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
157 cmbDpiMode->setVisible(
false );
158 mGroupBox->layout()->removeWidget( cmbDpiMode );
159 lblDpiMode->setVisible(
false );
160 mGroupBox->layout()->removeWidget( lblDpiMode );
162 txtReferer->setVisible(
false );
163 mGroupBox->layout()->removeWidget( txtReferer );
164 lblReferer->setVisible(
false );
165 mGroupBox->layout()->removeWidget( lblReferer );
168 if ( mBaseKey !=
"/Qgis/connections-wfs/" )
170 cmbVersion->setVisible(
false );
171 mGroupBox->layout()->removeWidget( cmbVersion );
172 lblMaxNumFeatures->setVisible(
false );
173 mGroupBox->layout()->removeWidget( lblMaxNumFeatures );
174 txtMaxNumFeatures->setVisible(
false );
175 mGroupBox->layout()->removeWidget( txtMaxNumFeatures );
193 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
199 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( txtName->text().isEmpty() || txtUrl->text().isEmpty() );
205 QString key = mBaseKey + txtName->text();
206 QString credentialsKey =
"/Qgis/" + mCredentialsBaseKey +
'/' + txtName->text();
209 if (( mOriginalConnName.
isNull() || mOriginalConnName.
compare( txtName->text(), Qt::CaseInsensitive ) != 0 ) &&
210 settings.
contains( key +
"/url" ) &&
212 tr(
"Save connection" ),
213 tr(
"Should the existing connection %1 be overwritten?" ).arg( txtName->text() ),
214 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
219 if ( !txtPassword->text().isEmpty() &&
221 tr(
"Saving passwords" ),
222 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." ),
223 QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Cancel )
229 if ( !mOriginalConnName.
isNull() && mOriginalConnName != key )
231 settings.
remove( mBaseKey + mOriginalConnName );
232 settings.
remove(
"/Qgis/" + mCredentialsBaseKey +
'/' + mOriginalConnName );
236 QUrl url( txtUrl->text().trimmed() );
244 if ( params[
"SERVICE"].second.toUpper() ==
"WMS" ||
245 params[
"SERVICE"].second.toUpper() ==
"WFS" ||
246 params[
"SERVICE"].second.toUpper() ==
"WCS" )
248 url.removeEncodedQueryItem( params[
"SERVICE"].first );
249 url.removeEncodedQueryItem( params[
"REQUEST"].first );
250 url.removeEncodedQueryItem( params[
"FORMAT"].first );
253 if ( url.encodedPath().isEmpty() )
255 url.setEncodedPath(
"/" );
258 settings.
setValue( key +
"/url", url.toString() );
260 if ( mBaseKey ==
"/Qgis/connections-wms/" ||
261 mBaseKey ==
"/Qgis/connections-wcs/" ||
262 mBaseKey ==
"/Qgis/connections-wfs/" )
264 settings.
setValue( key +
"/ignoreAxisOrientation", cbxIgnoreAxisOrientation->isChecked() );
265 settings.
setValue( key +
"/invertAxisOrientation", cbxInvertAxisOrientation->isChecked() );
268 if ( mBaseKey ==
"/Qgis/connections-wms/" || mBaseKey ==
"/Qgis/connections-wcs/" )
270 settings.
setValue( key +
"/ignoreGetMapURI", cbxIgnoreGetMapURI->isChecked() );
271 settings.
setValue( key +
"/smoothPixmapTransform", cbxSmoothPixmapTransform->isChecked() );
274 switch ( cmbDpiMode->currentIndex() )
293 settings.
setValue( key +
"/dpiMode", dpiMode );
295 if ( mBaseKey ==
"/Qgis/connections-wms/" )
297 settings.
setValue( key +
"/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
299 if ( mBaseKey ==
"/Qgis/connections-wfs/" )
302 switch ( cmbVersion->currentIndex() )
317 settings.
setValue( key +
"/version", version );
319 settings.
setValue( key +
"/maxnumfeatures", txtMaxNumFeatures->text() );
322 settings.
setValue( key +
"/referer", txtReferer->text() );
324 settings.
setValue( credentialsKey +
"/username", txtUserName->text() );
325 settings.
setValue( credentialsKey +
"/password", txtPassword->text() );
327 settings.
setValue( credentialsKey +
"/authcfg", mAuthConfigSelect->
configId() );
329 settings.
setValue( mBaseKey +
"/selected", txtName->text() );
~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.
const QString configId() const
Get the authentication config id for the resource.