Skip to content
Permalink
Browse files
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
  • Loading branch information
dakcarto committed Mar 17, 2017
1 parent 16cf366 commit 921a0c75e3347c3ba973e817612fcf32ee2d9b66
Showing with 19 additions and 2 deletions.
  1. +4 −0 python/gui/qgspasswordlineedit.sip
  2. +9 −1 src/gui/qgspasswordlineedit.cpp
  3. +6 −1 src/gui/qgspasswordlineedit.h
@@ -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 );

0 comments on commit 921a0c7

Please sign in to comment.