17#include "ui_qgsauthconfigidedit.h"
24#include <QRegularExpression>
27#include "moc_qgsauthconfigidedit.cpp"
29using namespace Qt::StringLiterals;
33 , mAuthCfgOrig( authcfg )
34 , mAllowEmpty( allowEmpty )
37 connect( btnLock, &QToolButton::toggled,
this, &QgsAuthConfigIdEdit::btnLock_toggled );
38 connect( leAuthCfg, &QLineEdit::textChanged,
this, &QgsAuthConfigIdEdit::leAuthCfg_textChanged );
40 leAuthCfg->setReadOnly(
true );
44 leAuthCfg->setText( authcfg );
52 return leAuthCfg->text();
59 const QString authcfg( leAuthCfg->text() );
60 bool curvalid = ( ( authcfg == mAuthCfgOrig && authcfg.size() == 7 ) || ( mAllowEmpty && authcfg.isEmpty() ) );
67 if ( mValid != curvalid )
78 if ( mAuthCfgOrig.isEmpty() )
80 mAuthCfgOrig = authcfg;
82 leAuthCfg->setText( authcfg );
88 mAllowEmpty = allowed;
94 leAuthCfg->setText( mAuthCfgOrig );
95 updateValidityStyle(
true );
98void QgsAuthConfigIdEdit::updateValidityStyle(
bool valid )
100 QString ss( u
"QLineEdit{"_s );
101 ss += valid ? QString() : u
"color: %1;"_s.arg(
QgsAuthGuiUtils::redColor().name() );
105 leAuthCfg->setStyleSheet( ss );
108void QgsAuthConfigIdEdit::btnLock_toggled(
bool checked )
110 leAuthCfg->setReadOnly( !checked );
112 leAuthCfg->setFocus();
117void QgsAuthConfigIdEdit::leAuthCfg_textChanged(
const QString &txt )
123bool QgsAuthConfigIdEdit::isAlphaNumeric(
const QString &authcfg )
125 const thread_local QRegularExpression alphaNumericRegExp(
"([a-z]|[A-Z]|[0-9]){7}" );
126 return authcfg.indexOf( alphaNumericRegExp ) != -1;
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
bool validate()
Validate the widget state and ID.
QgsAuthConfigIdEdit(QWidget *parent=nullptr, const QString &authcfg=QString(), bool allowEmpty=true)
Widget to unlock and edit an authentication configuration ID.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID, storing it, and validating the passed value.
void validityChanged(bool valid)
Validity of the ID has changed.
void setAllowEmptyId(bool allowed)
Sets whether to allow no ID to be set.
void clear()
Clear all of the widget's editing state and contents.
QString configId()
The authentication configuration ID, if valid, otherwise an empty QString.
Utility functions for use by authentication GUI widgets or standalone apps.
static QColor yellowColor()
Yellow color representing caution regarding action.
bool configIdUnique(const QString &id) const
Verify if provided authentication id is unique.