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;