Skip to content

Commit dfdf2ce

Browse files
committedOct 2, 2017
[auth] Added support for "Store" checkboxes
1 parent 7ee03a6 commit dfdf2ce

File tree

5 files changed

+248
-41
lines changed

5 files changed

+248
-41
lines changed
 

‎python/gui/auth/qgsauthsettingswidget.sip

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ class QgsAuthSettingsWidget : QWidget
8888
param configId the authentication configuration id
8989
%End
9090

91-
int currentTabIndex( ) const;
91+
void setDataprovider( const QString &dataprovider );
9292
%Docstring
93-
currentTabIndex, mainly useful for unit tests
94-
:return: active tab index
95-
:rtype: int
93+
setDataprovider set the data provider key for filtering compatible authentication configurations
94+
\param dataprovider data provider key
95+
%End
96+
97+
const QString dataprovider( ) const;
98+
%Docstring
99+
dataprovider
100+
:return: the data provider key used to filter compatible authentication configurations
101+
:rtype: str
96102
%End
97103

98104
bool btnConvertToEncryptedIsEnabled( ) const;
@@ -102,6 +108,51 @@ class QgsAuthSettingsWidget : QWidget
102108
:rtype: bool
103109
%End
104110

111+
void showStoreCheckboxes( bool enabled );
112+
%Docstring
113+
showStoreCheckboxes show the "Store" checkboxes for basic auth.
114+
Some connection configurations allow the user to enter credentials
115+
for testing the connection without storing them in the project.
116+
"Store" checkboxes are disabled by default.
117+
\param enabled
118+
%End
119+
120+
void setStoreUsername( bool checked );
121+
%Docstring
122+
setStoreUsername check the "Store" checkbox for the username
123+
\param checked
124+
.. seealso:: showStoreCheckboxes
125+
%End
126+
127+
void setStorePassword( bool checked );
128+
%Docstring
129+
updateStorePasswordcheck the "Store" checkbox for the password
130+
\param checked
131+
.. seealso:: showStoreCheckboxes
132+
%End
133+
134+
bool storePasswordIsChecked( ) const;
135+
%Docstring
136+
storePassword
137+
:return: true if "Store" checkbox for the password is checked
138+
:rtype: bool
139+
%End
140+
141+
bool storeUsernameIsChecked( ) const;
142+
%Docstring
143+
storeUsername
144+
:return: true if "Store" checkbox for the username is checked
145+
:rtype: bool
146+
%End
147+
148+
149+
bool configurationTabIsSelected( );
150+
%Docstring
151+
configurationTabIsSelected
152+
:return: true if the configuration tab is the currently selected tab
153+
:rtype: bool
154+
%End
155+
105156
public slots:
106157

107158
bool convertToEncrypted( );

‎src/gui/auth/qgsauthsettingswidget.cpp

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent,
2525
const QString &password,
2626
const QString &dataprovider )
2727
: QWidget( parent )
28+
, mDataprovider( dataprovider )
2829
{
2930
setupUi( this );
3031
txtPassword->setText( password );
@@ -40,6 +41,8 @@ QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent,
4041
connect( btnConvertToEncrypted, &QPushButton::clicked, this, &QgsAuthSettingsWidget::convertToEncrypted );
4142
connect( txtUserName, &QLineEdit::textChanged, this, &QgsAuthSettingsWidget::userNameTextChanged );
4243
connect( txtPassword, &QLineEdit::textChanged, this, &QgsAuthSettingsWidget::passwordTextChanged );
44+
// Hide store password and username by default
45+
showStoreCheckboxes( false );
4346
updateSelectedTab();
4447
updateConvertBtnState();
4548
}
@@ -82,21 +85,66 @@ void QgsAuthSettingsWidget::setConfigId( const QString &configId )
8285
updateSelectedTab();
8386
}
8487

85-
const QString QgsAuthSettingsWidget::configId() const
88+
void QgsAuthSettingsWidget::setDataprovider( const QString &dataprovider )
8689
{
87-
return mAuthConfigSelect->configId();
90+
mDataprovider = dataprovider;
91+
mAuthConfigSelect->setDataProviderKey( dataprovider );
92+
}
93+
94+
const QString QgsAuthSettingsWidget::dataprovider() const
95+
{
96+
return mDataprovider;
8897
}
8998

90-
int QgsAuthSettingsWidget::currentTabIndex() const
99+
const QString QgsAuthSettingsWidget::configId() const
91100
{
92-
return tabAuth->currentIndex( );
101+
return mAuthConfigSelect->configId();
93102
}
94103

95104
bool QgsAuthSettingsWidget::btnConvertToEncryptedIsEnabled() const
96105
{
97106
return btnConvertToEncrypted->isEnabled( );
98107
}
99108

109+
void QgsAuthSettingsWidget::showStoreCheckboxes( bool enabled )
110+
{
111+
if ( enabled )
112+
{
113+
cbStorePassword->show();
114+
cbStoreUsername->show();
115+
}
116+
else
117+
{
118+
cbStorePassword->hide();
119+
cbStoreUsername->hide();
120+
}
121+
}
122+
123+
void QgsAuthSettingsWidget::setStoreUsername( bool checked )
124+
{
125+
cbStoreUsername->setChecked( checked );
126+
}
127+
128+
void QgsAuthSettingsWidget::setStorePassword( bool checked )
129+
{
130+
cbStorePassword->setChecked( checked );
131+
}
132+
133+
bool QgsAuthSettingsWidget::storePasswordIsChecked() const
134+
{
135+
return cbStorePassword->isChecked( );
136+
}
137+
138+
bool QgsAuthSettingsWidget::storeUsernameIsChecked() const
139+
{
140+
return cbStoreUsername->isChecked( );
141+
}
142+
143+
bool QgsAuthSettingsWidget::configurationTabIsSelected()
144+
{
145+
return tabAuth->currentIndex( ) == tabAuth->indexOf( tabConfigurations );
146+
}
147+
100148
bool QgsAuthSettingsWidget::convertToEncrypted( )
101149
{
102150
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) );

‎src/gui/auth/qgsauthsettingswidget.h

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,65 @@ class GUI_EXPORT QgsAuthSettingsWidget : public QWidget, private Ui::QgsAuthSett
9999
void setConfigId( const QString &configId );
100100

101101
/**
102-
* \brief currentTabIndex, mainly useful for unit tests
103-
* \return active tab index
102+
* \brief setDataprovider set the data provider key for filtering compatible authentication configurations
103+
* \param dataprovider data provider key
104104
*/
105-
int currentTabIndex( ) const;
105+
void setDataprovider( const QString &dataprovider );
106+
107+
/**
108+
* \brief dataprovider
109+
* \return the data provider key used to filter compatible authentication configurations
110+
*/
111+
const QString dataprovider( ) const;
106112

107113
/**
108114
* \brief convertButtonEnabled, mainly useful for unit tests
109115
* \return true if the convert button is enabled
110116
*/
111117
bool btnConvertToEncryptedIsEnabled( ) const;
112118

119+
/**
120+
* \brief showStoreCheckboxes show the "Store" checkboxes for basic auth.
121+
* Some connection configurations allow the user to enter credentials
122+
* for testing the connection without storing them in the project.
123+
* "Store" checkboxes are disabled by default.
124+
* \param enabled
125+
*/
126+
void showStoreCheckboxes( bool enabled );
127+
128+
/**
129+
* \brief setStoreUsername check the "Store" checkbox for the username
130+
* \param checked
131+
* \see showStoreCheckboxes
132+
*/
133+
void setStoreUsername( bool checked );
134+
135+
/**
136+
* \brief updateStorePasswordcheck the "Store" checkbox for the password
137+
* \param checked
138+
* \see showStoreCheckboxes
139+
*/
140+
void setStorePassword( bool checked );
141+
142+
/**
143+
* \brief storePassword
144+
* \return true if "Store" checkbox for the password is checked
145+
*/
146+
bool storePasswordIsChecked( ) const;
147+
148+
/**
149+
* \brief storeUsername
150+
* \return true if "Store" checkbox for the username is checked
151+
*/
152+
bool storeUsernameIsChecked( ) const;
153+
154+
155+
/**
156+
* \brief configurationTabIsSelected
157+
* \return true if the configuration tab is the currently selected tab
158+
*/
159+
bool configurationTabIsSelected( );
160+
113161
public slots:
114162

115163
/**
@@ -137,6 +185,9 @@ class GUI_EXPORT QgsAuthSettingsWidget : public QWidget, private Ui::QgsAuthSett
137185

138186
private:
139187

188+
// Mainly for tests
189+
QString mDataprovider;
190+
140191
void updateConvertBtnState( );
141192

142193
void updateSelectedTab( );

‎src/ui/auth/qgsauthsettingswidget.ui

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>400</width>
9+
<width>405</width>
1010
<height>264</height>
1111
</rect>
1212
</property>
@@ -89,16 +89,6 @@
8989
<string>Basic</string>
9090
</attribute>
9191
<layout class="QGridLayout" name="gridLayout_3">
92-
<item row="3" column="0" colspan="2">
93-
<widget class="QLabel" name="lblWarning">
94-
<property name="text">
95-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;Warning: credentials are stored unencrypted (in clear text) in the project file!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
96-
</property>
97-
<property name="wordWrap">
98-
<bool>true</bool>
99-
</property>
100-
</widget>
101-
</item>
10292
<item row="5" column="1">
10393
<spacer name="verticalSpacer">
10494
<property name="orientation">
@@ -142,7 +132,44 @@
142132
<item row="1" column="1">
143133
<widget class="QLineEdit" name="txtUserName"/>
144134
</item>
145-
<item row="0" column="0" colspan="2">
135+
<item row="1" column="2">
136+
<widget class="QCheckBox" name="cbStoreUsername">
137+
<property name="text">
138+
<string>Store</string>
139+
</property>
140+
<property name="checked">
141+
<bool>false</bool>
142+
</property>
143+
</widget>
144+
</item>
145+
<item row="2" column="2">
146+
<widget class="QCheckBox" name="cbStorePassword">
147+
<property name="text">
148+
<string>Store</string>
149+
</property>
150+
<property name="checked">
151+
<bool>false</bool>
152+
</property>
153+
</widget>
154+
</item>
155+
<item row="4" column="0" colspan="3">
156+
<widget class="QPushButton" name="btnConvertToEncrypted">
157+
<property name="text">
158+
<string>Convert to configuration</string>
159+
</property>
160+
</widget>
161+
</item>
162+
<item row="3" column="0" colspan="3">
163+
<widget class="QLabel" name="lblWarning">
164+
<property name="text">
165+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;Warning: credentials are stored unencrypted (in clear text) in the project file!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
166+
</property>
167+
<property name="wordWrap">
168+
<bool>true</bool>
169+
</property>
170+
</widget>
171+
</item>
172+
<item row="0" column="0" colspan="3">
146173
<widget class="QLabel" name="lblBasic">
147174
<property name="sizePolicy">
148175
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@@ -161,13 +188,6 @@
161188
</property>
162189
</widget>
163190
</item>
164-
<item row="4" column="0" colspan="2">
165-
<widget class="QPushButton" name="btnConvertToEncrypted">
166-
<property name="text">
167-
<string>Convert to configuration</string>
168-
</property>
169-
</widget>
170-
</item>
171191
</layout>
172192
</widget>
173193
</widget>
@@ -186,6 +206,15 @@
186206
<header>qgsauthconfigselect.h</header>
187207
</customwidget>
188208
</customwidgets>
209+
<tabstops>
210+
<tabstop>tabAuth</tabstop>
211+
<tabstop>mAuthConfigSelect</tabstop>
212+
<tabstop>txtUserName</tabstop>
213+
<tabstop>cbStoreUsername</tabstop>
214+
<tabstop>txtPassword</tabstop>
215+
<tabstop>cbStorePassword</tabstop>
216+
<tabstop>btnConvertToEncrypted</tabstop>
217+
</tabstops>
189218
<resources/>
190219
<connections/>
191220
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.