mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-21 11:08:55 +00:00
- make it possible to configure the locale of the validator - use the correct default decimal point in AmountValidator - update/add the relevant tests for AmountToSendNew
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <QValidator>
|
|
#include <QQmlScriptString>
|
|
#include <QQmlPropertyMap>
|
|
|
|
#include <memory>
|
|
|
|
class QQmlExpression;
|
|
|
|
class GenericValidator : public QValidator
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QQmlScriptString fixup
|
|
READ fixupScriptString WRITE setFixupScriptString
|
|
NOTIFY fixupScriptStringChanged)
|
|
|
|
Q_PROPERTY(QQmlScriptString validate
|
|
READ validateScriptString WRITE setValidateScriptString
|
|
NOTIFY validateScriptStringChanged)
|
|
|
|
Q_PROPERTY(QString locale READ localeName WRITE setLocaleName NOTIFY localeChanged FINAL) ///< locale name, defaults to user's own
|
|
|
|
public:
|
|
enum State {
|
|
Invalid = QValidator::Invalid,
|
|
Intermediate = QValidator::Intermediate,
|
|
Acceptable = QValidator::Acceptable
|
|
};
|
|
Q_ENUM(State)
|
|
|
|
explicit GenericValidator(QObject* parent = nullptr);
|
|
|
|
const QQmlScriptString& fixupScriptString() const;
|
|
void setFixupScriptString(const QQmlScriptString& scriptString);
|
|
|
|
const QQmlScriptString& validateScriptString() const;
|
|
void setValidateScriptString(const QQmlScriptString& scriptString);
|
|
|
|
void fixup(QString& input) const override;
|
|
QValidator::State validate(QString& input, int& pos) const override;
|
|
|
|
signals:
|
|
void fixupScriptStringChanged();
|
|
void validateScriptStringChanged();
|
|
|
|
void localeChanged();
|
|
|
|
private:
|
|
bool isValidState(int state) const;
|
|
|
|
QString localeName() const;
|
|
void setLocaleName(const QString& newLocaleName);
|
|
|
|
QQmlScriptString m_fixupScriptString;
|
|
QQmlScriptString m_validateScriptString;
|
|
|
|
mutable QQmlPropertyMap m_fixupScope;
|
|
mutable QQmlPropertyMap m_validateScope;
|
|
|
|
std::unique_ptr<QQmlExpression> m_fixupExpression;
|
|
std::unique_ptr<QQmlExpression> m_validateExpression;
|
|
};
|