18 #include "ui_qgsauthconfigidedit.h"
24 #include <QRegularExpression>
29 , mAuthCfgOrig( authcfg )
30 , mAllowEmpty( allowEmpty )
33 connect( btnLock, &QToolButton::toggled,
this, &QgsAuthConfigIdEdit::btnLock_toggled );
34 connect( leAuthCfg, &QLineEdit::textChanged,
this, &QgsAuthConfigIdEdit::leAuthCfg_textChanged );
36 leAuthCfg->setReadOnly(
true );
40 leAuthCfg->setText( authcfg );
48 return leAuthCfg->text();
55 const QString authcfg( leAuthCfg->text() );
56 bool curvalid = ( ( authcfg == mAuthCfgOrig && authcfg.size() == 7 )
57 || ( mAllowEmpty && authcfg.isEmpty() ) );
64 if ( mValid != curvalid )
75 if ( mAuthCfgOrig.isEmpty() )
77 mAuthCfgOrig = authcfg;
79 leAuthCfg->setText( authcfg );
85 mAllowEmpty = allowed;
91 leAuthCfg->setText( mAuthCfgOrig );
92 updateValidityStyle(
true );
95 void QgsAuthConfigIdEdit::updateValidityStyle(
bool valid )
97 QString ss( QStringLiteral(
"QLineEdit{" ) );
98 ss += valid ? QString() : QStringLiteral(
"color: %1;" ).arg(
QgsAuthGuiUtils::redColor().name() );
99 ss += !btnLock->isChecked() ? QString() : QStringLiteral(
"background-color: %1;" ).arg(
QgsAuthGuiUtils::yellowColor().name() );
102 leAuthCfg->setStyleSheet( ss );
105 void QgsAuthConfigIdEdit::btnLock_toggled(
bool checked )
107 leAuthCfg->setReadOnly( !checked );
109 leAuthCfg->setFocus();
114 void QgsAuthConfigIdEdit::leAuthCfg_textChanged(
const QString &txt )
120 bool QgsAuthConfigIdEdit::isAlphaNumeric(
const QString &authcfg )
122 const thread_local QRegularExpression alphaNumericRegExp(
"([a-z]|[A-Z]|[0-9]){7}" );
123 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 const configId()
The authentication configuration ID, if valid, otherwise null QString.
Utility functions for use by authentication GUI widgets or standalone apps.
bool isDisabled() const
Whether QCA has the qca-ossl plugin, which a base run-time requirement.
bool configIdUnique(const QString &id) const
Verify if provided authentication id is unique.