Skip to content

Commit 89ffecb

Browse files
authoredJul 21, 2017
Merge pull request #4881 from boundlessgeo/xyz-auth-gui
[feature][needs-docs] XYZ authentication and referer added to GUI
2 parents 0cba29c + e423eea commit 89ffecb

File tree

5 files changed

+241
-74
lines changed

5 files changed

+241
-74
lines changed
 

‎src/providers/wms/qgsxyzconnection.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ QString QgsXyzConnection::encodedUri() const
2727
uri.setParam( QStringLiteral( "zmin" ), QString::number( zMin ) );
2828
if ( zMax != -1 )
2929
uri.setParam( QStringLiteral( "zmax" ), QString::number( zMax ) );
30+
if ( ! authCfg.isEmpty() )
31+
uri.setParam( QStringLiteral( "authcfg" ), authCfg );
32+
if ( ! username.isEmpty() )
33+
uri.setParam( QStringLiteral( "username" ), username );
34+
if ( ! password.isEmpty() )
35+
uri.setParam( QStringLiteral( "password" ), password );
36+
if ( ! referer.isEmpty() )
37+
uri.setParam( QStringLiteral( "referer" ), referer );
3038
return uri.encodedUri();
3139
}
3240

@@ -47,6 +55,10 @@ QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
4755
conn.url = settings.value( QStringLiteral( "url" ) ).toString();
4856
conn.zMin = settings.value( QStringLiteral( "zmin" ), -1 ).toInt();
4957
conn.zMax = settings.value( QStringLiteral( "zmax" ), -1 ).toInt();
58+
conn.authCfg = settings.value( QStringLiteral( "authcfg" ) ).toString();
59+
conn.username = settings.value( QStringLiteral( "username" ) ).toString();
60+
conn.password = settings.value( QStringLiteral( "password" ) ).toString();
61+
conn.referer = settings.value( QStringLiteral( "referer" ) ).toString();
5062
return conn;
5163
}
5264

@@ -63,4 +75,8 @@ void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
6375
settings.setValue( QStringLiteral( "url" ), conn.url );
6476
settings.setValue( QStringLiteral( "zmin" ), conn.zMin );
6577
settings.setValue( QStringLiteral( "zmax" ), conn.zMax );
78+
settings.setValue( QStringLiteral( "authcfg" ), conn.authCfg );
79+
settings.setValue( QStringLiteral( "username" ), conn.username );
80+
settings.setValue( QStringLiteral( "password" ), conn.password );
81+
settings.setValue( QStringLiteral( "referer" ), conn.referer );
6682
}

‎src/providers/wms/qgsxyzconnection.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ struct QgsXyzConnection
2424
QString url;
2525
int zMin = -1;
2626
int zMax = -1;
27+
// Authentication configuration id
28+
QString authCfg;
29+
// HTTP Basic username
30+
QString username;
31+
// HTTP Basic password
32+
QString password;
33+
// Referer
34+
QString referer;
2735

2836
QString encodedUri() const;
2937
};

‎src/providers/wms/qgsxyzconnectiondialog.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313
* *
1414
***************************************************************************/
1515

16+
#include "qgsauthconfigselect.h"
1617
#include "qgsxyzconnectiondialog.h"
17-
1818
#include "qgsxyzconnection.h"
1919

2020
QgsXyzConnectionDialog::QgsXyzConnectionDialog( QWidget *parent )
2121
: QDialog( parent )
22+
, mAuthConfigSelect( nullptr )
2223
{
2324
setupUi( this );
2425

26+
mAuthConfigSelect = new QgsAuthConfigSelect( this );
27+
mTabAuth->insertTab( 1, mAuthConfigSelect, tr( "Configurations" ) );
2528
// Behavior for min and max zoom checkbox
2629
connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
2730
connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
@@ -35,6 +38,18 @@ void QgsXyzConnectionDialog::setConnection( const QgsXyzConnection &conn )
3538
mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
3639
mCheckBoxZMax->setChecked( conn.zMax != -1 );
3740
mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 18 );
41+
mEditUsername->setText( conn.username );
42+
mEditPassword->setText( conn.password );
43+
mEditReferer->setText( conn.referer );
44+
mAuthConfigSelect->setConfigId( conn.authCfg );
45+
if ( ! conn.authCfg.isEmpty( ) )
46+
{
47+
mTabAuth->setCurrentIndex( mTabAuth->indexOf( mAuthConfigSelect ) );
48+
}
49+
else
50+
{
51+
mTabAuth->setCurrentIndex( 0 );
52+
}
3853
}
3954

4055
QgsXyzConnection QgsXyzConnectionDialog::connection() const
@@ -46,5 +61,9 @@ QgsXyzConnection QgsXyzConnectionDialog::connection() const
4661
conn.zMin = mSpinZMin->value();
4762
if ( mCheckBoxZMax->isChecked() )
4863
conn.zMax = mSpinZMax->value();
64+
conn.username = mEditUsername->text();
65+
conn.password = mEditPassword->text();
66+
conn.referer = mEditReferer->text();
67+
conn.authCfg = mAuthConfigSelect->configId( );
4968
return conn;
5069
}

‎src/providers/wms/qgsxyzconnectiondialog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "ui_qgsxyzconnectiondialog.h"
2222

23+
class QgsAuthConfigSelect;
24+
2325
struct QgsXyzConnection;
2426

2527

@@ -33,6 +35,12 @@ class QgsXyzConnectionDialog : public QDialog, public Ui::QgsXyzConnectionDialog
3335

3436
QgsXyzConnection connection() const;
3537

38+
private:
39+
40+
QString mBaseKey;
41+
QString mCredentialsBaseKey;
42+
QgsAuthConfigSelect *mAuthConfigSelect = nullptr;
43+
3644
};
3745

3846
#endif // QGSXYZCONNECTIONDIALOG_H

‎src/ui/qgsxyzconnectiondialog.ui

Lines changed: 189 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,84 +6,195 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>746</width>
10-
<height>426</height>
9+
<width>869</width>
10+
<height>787</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>XYZ Connection</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
18-
<layout class="QGridLayout" name="gridLayout">
19-
<item row="1" column="1">
20-
<widget class="QLineEdit" name="mEditUrl">
21-
<property name="placeholderText">
22-
<string>http://example.com/{z}/{x}/{y}.png</string>
23-
</property>
24-
</widget>
25-
</item>
26-
<item row="1" column="0">
27-
<widget class="QLabel" name="label_2">
28-
<property name="text">
29-
<string>URL</string>
30-
</property>
31-
</widget>
32-
</item>
33-
<item row="2" column="0">
34-
<widget class="QCheckBox" name="mCheckBoxZMin">
35-
<property name="text">
36-
<string>Min. Zoom Level</string>
37-
</property>
38-
<property name="checked">
39-
<bool>true</bool>
40-
</property>
41-
</widget>
42-
</item>
43-
<item row="0" column="0">
44-
<widget class="QLabel" name="label">
45-
<property name="text">
46-
<string>Name</string>
47-
</property>
48-
</widget>
49-
</item>
50-
<item row="2" column="1">
51-
<widget class="QSpinBox" name="mSpinZMin">
52-
<property name="sizePolicy">
53-
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
54-
<horstretch>0</horstretch>
55-
<verstretch>0</verstretch>
56-
</sizepolicy>
57-
</property>
58-
</widget>
59-
</item>
60-
<item row="3" column="0">
61-
<widget class="QCheckBox" name="mCheckBoxZMax">
62-
<property name="text">
63-
<string>Max. Zoom Level</string>
64-
</property>
65-
<property name="checked">
66-
<bool>true</bool>
67-
</property>
68-
</widget>
69-
</item>
70-
<item row="3" column="1">
71-
<widget class="QSpinBox" name="mSpinZMax">
72-
<property name="sizePolicy">
73-
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
74-
<horstretch>0</horstretch>
75-
<verstretch>0</verstretch>
76-
</sizepolicy>
77-
</property>
78-
<property name="value">
79-
<number>18</number>
80-
</property>
81-
</widget>
82-
</item>
83-
<item row="0" column="1">
84-
<widget class="QLineEdit" name="mEditName"/>
85-
</item>
86-
</layout>
18+
<widget class="QGroupBox" name="mGroupBox">
19+
<property name="title">
20+
<string>Connection details</string>
21+
</property>
22+
<layout class="QGridLayout" name="gridLayout">
23+
<item row="3" column="0">
24+
<widget class="QCheckBox" name="mCheckBoxZMin">
25+
<property name="text">
26+
<string>Min. Zoom Level</string>
27+
</property>
28+
<property name="checked">
29+
<bool>true</bool>
30+
</property>
31+
</widget>
32+
</item>
33+
<item row="2" column="0" colspan="2">
34+
<widget class="QTabWidget" name="mTabAuth">
35+
<property name="sizePolicy">
36+
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
37+
<horstretch>0</horstretch>
38+
<verstretch>0</verstretch>
39+
</sizepolicy>
40+
</property>
41+
<property name="currentIndex">
42+
<number>0</number>
43+
</property>
44+
<widget class="QWidget" name="tab">
45+
<attribute name="title">
46+
<string>Authentication</string>
47+
</attribute>
48+
<layout class="QGridLayout" name="gridLayout_3">
49+
<item row="1" column="0">
50+
<widget class="QLabel" name="label_3">
51+
<property name="text">
52+
<string>&amp;User name</string>
53+
</property>
54+
<property name="buddy">
55+
<cstring>mEditUsername</cstring>
56+
</property>
57+
</widget>
58+
</item>
59+
<item row="1" column="1">
60+
<widget class="QLineEdit" name="mEditUsername"/>
61+
</item>
62+
<item row="0" column="0" colspan="2">
63+
<widget class="QLabel" name="label_4">
64+
<property name="sizePolicy">
65+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
66+
<horstretch>0</horstretch>
67+
<verstretch>0</verstretch>
68+
</sizepolicy>
69+
</property>
70+
<property name="text">
71+
<string>If the service requires basic authentication, enter a user name and optional password</string>
72+
</property>
73+
<property name="textFormat">
74+
<enum>Qt::PlainText</enum>
75+
</property>
76+
<property name="wordWrap">
77+
<bool>true</bool>
78+
</property>
79+
</widget>
80+
</item>
81+
<item row="2" column="0">
82+
<widget class="QLabel" name="label_5">
83+
<property name="text">
84+
<string>Password</string>
85+
</property>
86+
<property name="buddy">
87+
<cstring>mEditPassword</cstring>
88+
</property>
89+
</widget>
90+
</item>
91+
<item row="2" column="1">
92+
<widget class="QgsPasswordLineEdit" name="mEditPassword">
93+
<property name="echoMode">
94+
<enum>QLineEdit::Password</enum>
95+
</property>
96+
</widget>
97+
</item>
98+
<item row="3" column="1">
99+
<spacer name="verticalSpacer_2">
100+
<property name="orientation">
101+
<enum>Qt::Vertical</enum>
102+
</property>
103+
<property name="sizeHint" stdset="0">
104+
<size>
105+
<width>0</width>
106+
<height>0</height>
107+
</size>
108+
</property>
109+
</spacer>
110+
</item>
111+
</layout>
112+
</widget>
113+
</widget>
114+
</item>
115+
<item row="0" column="1">
116+
<widget class="QLineEdit" name="mEditName">
117+
<property name="toolTip">
118+
<string>Name of the new connection</string>
119+
</property>
120+
</widget>
121+
</item>
122+
<item row="6" column="1">
123+
<widget class="QSpinBox" name="mSpinZMax">
124+
<property name="sizePolicy">
125+
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
126+
<horstretch>0</horstretch>
127+
<verstretch>0</verstretch>
128+
</sizepolicy>
129+
</property>
130+
<property name="value">
131+
<number>18</number>
132+
</property>
133+
</widget>
134+
</item>
135+
<item row="3" column="1">
136+
<widget class="QSpinBox" name="mSpinZMin">
137+
<property name="sizePolicy">
138+
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
139+
<horstretch>0</horstretch>
140+
<verstretch>0</verstretch>
141+
</sizepolicy>
142+
</property>
143+
</widget>
144+
</item>
145+
<item row="1" column="0">
146+
<widget class="QLabel" name="label_2">
147+
<property name="text">
148+
<string>URL</string>
149+
</property>
150+
</widget>
151+
</item>
152+
<item row="0" column="0">
153+
<widget class="QLabel" name="label">
154+
<property name="text">
155+
<string>Name</string>
156+
</property>
157+
</widget>
158+
</item>
159+
<item row="1" column="1">
160+
<widget class="QLineEdit" name="mEditUrl">
161+
<property name="toolTip">
162+
<string>URL of the connection, {z}, {y}, and {z} will be replaced with actual values. Use {-y} for inverted y axis.</string>
163+
</property>
164+
<property name="placeholderText">
165+
<string>http://example.com/{z}/{x}/{y}.png</string>
166+
</property>
167+
</widget>
168+
</item>
169+
<item row="6" column="0">
170+
<widget class="QCheckBox" name="mCheckBoxZMax">
171+
<property name="text">
172+
<string>Max. Zoom Level</string>
173+
</property>
174+
<property name="checked">
175+
<bool>true</bool>
176+
</property>
177+
</widget>
178+
</item>
179+
<item row="7" column="0">
180+
<widget class="QLabel" name="lblReferer">
181+
<property name="text">
182+
<string>Referer</string>
183+
</property>
184+
<property name="buddy">
185+
<cstring>mEditReferer</cstring>
186+
</property>
187+
</widget>
188+
</item>
189+
<item row="7" column="1">
190+
<widget class="QLineEdit" name="mEditReferer">
191+
<property name="toolTip">
192+
<string>Optional custom referer</string>
193+
</property>
194+
</widget>
195+
</item>
196+
</layout>
197+
</widget>
87198
</item>
88199
<item>
89200
<spacer name="verticalSpacer">
@@ -110,13 +221,18 @@
110221
</item>
111222
</layout>
112223
</widget>
224+
<customwidgets>
225+
<customwidget>
226+
<class>QgsPasswordLineEdit</class>
227+
<extends>QLineEdit</extends>
228+
<header>qgspasswordlineedit.h</header>
229+
</customwidget>
230+
</customwidgets>
113231
<tabstops>
114-
<tabstop>mEditName</tabstop>
115232
<tabstop>mEditUrl</tabstop>
116233
<tabstop>mCheckBoxZMin</tabstop>
117234
<tabstop>mSpinZMin</tabstop>
118235
<tabstop>mCheckBoxZMax</tabstop>
119-
<tabstop>mSpinZMax</tabstop>
120236
<tabstop>buttonBox</tabstop>
121237
</tabstops>
122238
<resources/>

0 commit comments

Comments
 (0)
Please sign in to comment.