mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Updates to QgsPasswordLineEdit
- Add public func to set password visibility (instead of exposing slot) - Add initial password visibility param; default to obfuscated (false) - Fix bug where initial visibility was true, but show/hide was opposite - Add generic tool tips to show/hide action
This commit is contained in:
parent
16cf3665e1
commit
921a0c75e3
@ -25,4 +25,8 @@ class QgsPasswordLineEdit : QLineEdit
|
||||
/** Returns if a lock icon shall be shown on the left of the widget
|
||||
*/
|
||||
bool showLockIcon() const;
|
||||
|
||||
/** Set state of the password's visibility
|
||||
*/
|
||||
void setPasswordVisibility( bool visible );
|
||||
};
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "qgspasswordlineedit.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
QgsPasswordLineEdit::QgsPasswordLineEdit( QWidget *parent )
|
||||
QgsPasswordLineEdit::QgsPasswordLineEdit( QWidget *parent, bool passwordVisible )
|
||||
: QLineEdit( parent )
|
||||
, mActionShowHidePassword( nullptr )
|
||||
, mActionLock( nullptr )
|
||||
@ -35,20 +35,28 @@ QgsPasswordLineEdit::QgsPasswordLineEdit( QWidget *parent )
|
||||
mActionLock = addAction( QgsApplication::getThemeIcon( "/lockedGray.svg" ), QLineEdit::LeadingPosition );
|
||||
}
|
||||
|
||||
setPasswordVisibility( passwordVisible );
|
||||
connect( mActionShowHidePassword, &QAction::triggered, this, &QgsPasswordLineEdit::togglePasswordVisibility );
|
||||
}
|
||||
|
||||
void QgsPasswordLineEdit::setPasswordVisibility( bool visible )
|
||||
{
|
||||
togglePasswordVisibility( visible );
|
||||
}
|
||||
|
||||
void QgsPasswordLineEdit::togglePasswordVisibility( bool toggled )
|
||||
{
|
||||
if ( toggled )
|
||||
{
|
||||
setEchoMode( QLineEdit::Normal );
|
||||
mActionShowHidePassword->setIcon( mHidePasswordIcon );
|
||||
mActionShowHidePassword->setToolTip( tr( "Hide text" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
setEchoMode( QLineEdit::Password );
|
||||
mActionShowHidePassword->setIcon( mShowPasswordIcon );
|
||||
mActionShowHidePassword->setToolTip( tr( "Show text" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,9 @@ class GUI_EXPORT QgsPasswordLineEdit : public QLineEdit
|
||||
|
||||
/** Constructor for QgsPasswordLineEdit.
|
||||
* @param parent parent widget
|
||||
* @param passwordVisible Initial state of the password's visibility
|
||||
*/
|
||||
QgsPasswordLineEdit( QWidget *parent = nullptr );
|
||||
QgsPasswordLineEdit( QWidget *parent = nullptr, bool passwordVisible = false );
|
||||
|
||||
/** Define if a lock icon shall be shown on the left of the widget
|
||||
* @param visible set to false to hide the lock icon
|
||||
@ -50,6 +51,10 @@ class GUI_EXPORT QgsPasswordLineEdit : public QLineEdit
|
||||
*/
|
||||
bool showLockIcon() const { return mLockIconVisible; }
|
||||
|
||||
/** Set state of the password's visibility
|
||||
*/
|
||||
void setPasswordVisibility( bool visible );
|
||||
|
||||
private slots:
|
||||
void togglePasswordVisibility( bool toggled );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user