Commit de532af0 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Manage lifetime of validator with shared pointer

This makes it much easier to change the validator during the lifetime
of the form text input.

GnuPG-bug-id: 5832
parent 72999509
......@@ -107,7 +107,7 @@ public:
ui.nameInput->setValueRequiredErrorMessage(i18n("Enter a name."));
const auto regexp = config.readEntry("NAME_regex");
if (regexp.isEmpty()) {
ui.nameInput->setValidator(Validation::simpleName(Validation::Optional, q));
ui.nameInput->setValidator(std::shared_ptr<QValidator>{Validation::simpleName(Validation::Optional)});
ui.nameInput->setHint(i18n("Must not include <, >, and @."),
i18nc("text for screen readers",
"Must not include less-than sign, greater-than sign, and at sign."));
......@@ -116,7 +116,7 @@ public:
i18nc("text for screen readers",
"The name must not include less-than sign, greater-than sign, and at sign."));
} else {
ui.nameInput->setValidator(Validation::simpleName(regexp, Validation::Optional, q));
ui.nameInput->setValidator(std::shared_ptr<QValidator>{Validation::simpleName(regexp, Validation::Optional)});
ui.nameInput->setHint(i18n("Must be in the format required by your organization and "
"must not include <, >, and @."),
i18nc("text for screen readers",
......@@ -145,11 +145,11 @@ public:
ui.emailInput->setValueRequiredErrorMessage(i18n("Enter an email address."));
const auto regexp = config.readEntry(QLatin1String("EMAIL_regex"));
if (regexp.isEmpty()) {
ui.emailInput->setValidator(Validation::email(Validation::Optional, q));
ui.emailInput->setValidator(std::shared_ptr<QValidator>{Validation::email(Validation::Optional)});
ui.emailInput->setInvalidEntryErrorMessage(i18n(
"Enter an email address in the correct format, like name@example.com."));
} else {
ui.emailInput->setValidator(Validation::email(regexp, Validation::Optional, q));
ui.emailInput->setValidator(std::shared_ptr<QValidator>{Validation::email(regexp, Validation::Optional)});
ui.emailInput->setHint(i18n(
"Must be in the format required by your organization"));
ui.emailInput->setInvalidEntryErrorMessage(i18n(
......
......@@ -68,7 +68,7 @@ public:
QPointer<QLabel> mHintLabel;
QPointer<QWidget> mWidget;
QPointer<ErrorLabel> mErrorLabel;
QPointer<const QValidator> mValidator;
std::shared_ptr<QValidator> mValidator;
QString mLabelText;
QString mAccessibleName;
QString mValueRequiredErrorMessage;
......@@ -277,8 +277,10 @@ bool FormTextInputBase::isRequired() const
return d->mRequired;
}
void FormTextInputBase::setValidator(const QValidator *validator)
void FormTextInputBase::setValidator(const std::shared_ptr<QValidator> &validator)
{
Q_ASSERT(!validator || !validator->parent());
d->mValidator = validator;
}
......
......@@ -84,7 +84,7 @@ public:
* Note: If you wrap a QLineEdit, then do not set a validator (or an input mask)
* on it because this will break the correct displaying of the error message.
*/
void setValidator(const QValidator *validator);
void setValidator(const std::shared_ptr<QValidator> &validator);
/**
* Sets \p text as error message to display if a value is required for the
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment