-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4256 from alexbruy/password-lineedit
[FEATURE][needs-docs] new custom widget PasswordLineEdit
- Loading branch information
Showing
19 changed files
with
463 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.