Skip to content
Permalink
Browse files

Merge pull request #4256 from alexbruy/password-lineedit

[FEATURE][needs-docs] new custom widget PasswordLineEdit
  • Loading branch information
alexbruy committed Mar 14, 2017
2 parents b132738 + 0dc61cb commit 85776a1b82ac3078c956391df9d71dc2b8f27ea6
@@ -134,6 +134,7 @@
%Include qgsowssourceselect.sip
%Include qgspanelwidget.sip
%Include qgspanelwidgetstack.sip
%Include qgspasswordlineedit.sip
%Include qgspixmaplabel.sip
%Include qgspluginmanagerinterface.sip
%Include qgspresetcolorrampdialog.sip
@@ -0,0 +1,28 @@
/** \class QgsPasswordLineEdit
* \ingroup gui
* QLineEdit subclass with built in support for showing/hiding
* entered password.
* @note added in QGIS 3.0
**/
class QgsPasswordLineEdit : QLineEdit
{
%TypeHeaderCode
#include <qgspasswordlineedit.h>
%End

public:

/** Constructor for QgsPasswordLineEdit.
* @param parent parent widget
*/
QgsPasswordLineEdit( QWidget *parent = nullptr );

/** Define if a lock icon shall be shown on the left of the widget
* @param visible set to false to hide the lock icon
*/
void setShowLockIcon( bool visible );

/** Returns if a lock icon shall be shown on the left of the widget
*/
bool showLockIcon() const;
};
@@ -14,7 +14,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
qgiscustomwidgets.cpp
qgscollapsiblegroupboxplugin.cpp
qgscolorbuttonplugin.cpp
qgsdatetimeeditplugin.cpp
qgsdatetimeeditplugin.cpp
qgsdockwidgetplugin.cpp
qgsdoublespinboxplugin.cpp
qgsexpressionbuilderwidgetplugin.cpp
@@ -25,6 +25,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
qgsfilewidgetplugin.cpp
qgsfilterlineeditplugin.cpp
qgsmaplayercomboboxplugin.cpp
qgspasswordlineeditplugin.cpp
qgsprojectionselectionwidgetplugin.cpp
qgspropertyoverridebuttonplugin.cpp
qgsrelationeditorwidgetplugin.cpp
@@ -49,6 +50,7 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
qgsfilewidgetplugin.h
qgsfilterlineeditplugin.h
qgsmaplayercomboboxplugin.h
qgspasswordlineeditplugin.h
qgsprojectionselectionwidgetplugin.h
qgspropertyoverridebuttonplugin.h
qgsrelationeditorwidgetplugin.h
@@ -0,0 +1,97 @@
/***************************************************************************
qgsfilterlineeditplugin.cpp
--------------------------------------
Date : March 13, 2017
Copyright : (C) 2017 Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgiscustomwidgets.h"
#include "qgspasswordlineedit.h"
#include "qgspasswordlineeditplugin.h"


QgsPasswordLineEditPlugin::QgsPasswordLineEditPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsPasswordLineEditPlugin::name() const
{
return "QgsPasswordLineEdit";
}

QString QgsPasswordLineEditPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsPasswordLineEditPlugin::includeFile() const
{
return "qgspasswordlineedit.h";
}

QIcon QgsPasswordLineEditPlugin::icon() const
{
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
}

bool QgsPasswordLineEditPlugin::isContainer() const
{
return false;
}

QWidget *QgsPasswordLineEditPlugin::createWidget( QWidget *parent )
{
return new QgsPasswordLineEdit( parent );
}

bool QgsPasswordLineEditPlugin::isInitialized() const
{
return mInitialized;
}

void QgsPasswordLineEditPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsPasswordLineEditPlugin::toolTip() const
{
return "";
}

QString QgsPasswordLineEditPlugin::whatsThis() const
{
return "";
}

QString QgsPasswordLineEditPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mLineEdit\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>60</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
@@ -0,0 +1,51 @@
/***************************************************************************
qgspasswordlineeditplugin.h
--------------------------------------
Date : March 13, 2017
Copyright : (C) 2017 Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSPASSWORDLINEEDITPLUGIN_H
#define QGSPASSWORDLINEEDITPLUGIN_H


#include <QtGlobal>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
#include <QtUiPlugin/QDesignerExportWidget>
#include "qgis_customwidgets.h"


class CUSTOMWIDGETS_EXPORT QgsPasswordLineEditPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsPasswordLineEditPlugin( QObject *parent = 0 );

private:
bool mInitialized = false;

// QDesignerCustomWidgetInterface interface
public:
QString name() const override;
QString group() const override;
QString includeFile() const override;
QIcon icon() const override;
bool isContainer() const override;
QWidget *createWidget( QWidget *parent ) override;
bool isInitialized() const override;
void initialize( QDesignerFormEditorInterface *core ) override;
QString toolTip() const override;
QString whatsThis() const override;
QString domXml() const override;
};
#endif // QGSPASSWORDLINEEDITPLUGIN_H
@@ -276,6 +276,7 @@ SET(QGIS_GUI_SRCS
qgssourceselectdialog.cpp
qgspanelwidget.cpp
qgspanelwidgetstack.cpp
qgspasswordlineedit.cpp
qgspixmaplabel.cpp
qgspluginmanagerinterface.cpp
qgspresetcolorrampdialog.cpp
@@ -422,6 +423,7 @@ SET(QGIS_GUI_MOC_HDRS
qgssourceselectdialog.h
qgspanelwidget.h
qgspanelwidgetstack.h
qgspasswordlineedit.h
qgspixmaplabel.h
qgspluginmanagerinterface.h
qgspresetcolorrampdialog.h
@@ -80,16 +80,6 @@ void QgsMasterPasswordResetDialog::on_leMasterPassNew_textChanged( const QString
validatePasswords();
}

void QgsMasterPasswordResetDialog::on_chkPassShowCurrent_stateChanged( int state )
{
leMasterPassCurrent->setEchoMode( ( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
}

void QgsMasterPasswordResetDialog::on_chkPassShowNew_stateChanged( int state )
{
leMasterPassNew->setEchoMode( ( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
}

void QgsMasterPasswordResetDialog::validatePasswords()
{
QString ss1 = mPassCurOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
@@ -45,9 +45,6 @@ class GUI_EXPORT QgsMasterPasswordResetDialog : public QDialog, private Ui::QgsM
void on_leMasterPassCurrent_textChanged( const QString &pass );
void on_leMasterPassNew_textChanged( const QString &pass );

void on_chkPassShowCurrent_stateChanged( int state );
void on_chkPassShowNew_stateChanged( int state );

private:
void validatePasswords();

@@ -0,0 +1,73 @@
/***************************************************************************
qgspasswordlineedit.cpp
------------------------
begin : March 13, 2017
copyright : (C) 2017 by Alexander Bruy
email : alexander dot bruy at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgspasswordlineedit.h"
#include "qgsapplication.h"

QgsPasswordLineEdit::QgsPasswordLineEdit( QWidget *parent )
: QLineEdit( parent )
, mActionShowHidePassword( nullptr )
, mActionLock( nullptr )
, mLockIconVisible( false )
{
mShowPasswordIcon = QgsApplication::getThemeIcon( "/mActionShowAllLayers.svg" );
mHidePasswordIcon = QgsApplication::getThemeIcon( "/mActionHideAllLayers.svg" );

mActionShowHidePassword = addAction( mShowPasswordIcon, QLineEdit::TrailingPosition );
mActionShowHidePassword->setCheckable( true );

if ( mLockIconVisible )
{
mActionLock = addAction( QgsApplication::getThemeIcon( "/lockedGray.svg" ), QLineEdit::LeadingPosition );
}

connect( mActionShowHidePassword, &QAction::triggered, this, &QgsPasswordLineEdit::togglePasswordVisibility );
}

void QgsPasswordLineEdit::togglePasswordVisibility( bool toggled )
{
if ( toggled )
{
setEchoMode( QLineEdit::Normal );
mActionShowHidePassword->setIcon( mHidePasswordIcon );
}
else
{
setEchoMode( QLineEdit::Password );
mActionShowHidePassword->setIcon( mShowPasswordIcon );
}
}

void QgsPasswordLineEdit::setShowLockIcon( bool visible )
{
mLockIconVisible = visible;
if ( mLockIconVisible )
{
if ( !mActionLock )
{
mActionLock = addAction( QgsApplication::getThemeIcon( "/lockedGray.svg" ), QLineEdit::LeadingPosition );
}
}
else
{
if ( mActionLock )
{
removeAction( mActionLock );
mActionLock = nullptr;
}
}
}
@@ -0,0 +1,68 @@
/***************************************************************************
qgspasswordlineedit.h
------------------------
begin : March 13, 2017
copyright : (C) 2017 by Alexander Bruy
email : alexander dot bruy at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSPASSWORDLINEEDIT_H
#define QGSPASSWORDLINEEDIT_H

#include <QLineEdit>
#include <QAction>

#include "qgis_gui.h"

/** \class QgsPasswordLineEdit
* \ingroup gui
* QLineEdit subclass with built in support for showing/hiding
* entered password.
* @note added in QGIS 3.0
**/
class GUI_EXPORT QgsPasswordLineEdit : public QLineEdit
{
Q_OBJECT
Q_PROPERTY( bool showLockIcon READ showLockIcon WRITE setShowLockIcon )

public:

/** Constructor for QgsPasswordLineEdit.
* @param parent parent widget
*/
QgsPasswordLineEdit( QWidget *parent = nullptr );

/** Define if a lock icon shall be shown on the left of the widget
* @param visible set to false to hide the lock icon
*/
void setShowLockIcon( bool visible );

/** Returns if a lock icon shall be shown on the left of the widget
*/
bool showLockIcon() const { return mLockIconVisible; }

private slots:
void togglePasswordVisibility( bool toggled );

private:

QAction *mActionShowHidePassword = nullptr;
QAction *mActionLock = nullptr;

QIcon mShowPasswordIcon;
QIcon mHidePasswordIcon;

bool mLockIconVisible;
QSize mIconsSize;
};

#endif // QGSPASSWORDLINEEDIT_H

0 comments on commit 85776a1

Please sign in to comment.
You can’t perform that action at this time.