From c0d30db45ca0af9c3010097d8cd8b1ae92cf83ea Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 18 Jan 2012 13:04:21 +1000 Subject: Add a changed() signal to QValidator. This provides a general notification of changes that may change the validity of previously validated input. Change-Id: I5ec6f127af60fdca68605fee903a08758bc01360 Reviewed-by: Jonas Gastal Reviewed-by: Lars Knoll --- src/gui/util/qvalidator.cpp | 25 ++++++++++++++++++++++++- src/gui/util/qvalidator.h | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/gui/util') diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index b4478cfaa5..d806a18b64 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -131,6 +131,12 @@ QT_BEGIN_NAMESPACE \omitvalue Valid */ +/*! + \fn void QValidator::changed() + + This signal is emitted when any property that may affect the validity of + a string has changed. +*/ /*! \fn void QIntValidator::topChanged(int top) @@ -247,7 +253,10 @@ QLocale QValidator::locale() const void QValidator::setLocale(const QLocale &locale) { Q_D(QValidator); - d->locale = locale; + if (d->locale != locale) { + d->locale = locale; + emit changed(); + } } /*! @@ -452,15 +461,21 @@ void QIntValidator::fixup(QString &input) const void QIntValidator::setRange(int bottom, int top) { + bool rangeChanged = false; if (b != bottom) { b = bottom; + rangeChanged = true; emit bottomChanged(b); } if (t != top) { t = top; + rangeChanged = true; emit topChanged(t); } + + if (rangeChanged) + emit changed(); } @@ -697,20 +712,26 @@ QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QL void QDoubleValidator::setRange(double minimum, double maximum, int decimals) { + bool rangeChanged = false; if (b != minimum) { b = minimum; + rangeChanged = true; emit bottomChanged(b); } if (t != maximum) { t = maximum; + rangeChanged = true; emit topChanged(t); } if (dec != decimals) { dec = decimals; + rangeChanged = true; emit decimalsChanged(dec); } + if (rangeChanged) + emit changed(); } /*! @@ -772,6 +793,7 @@ void QDoubleValidator::setNotation(Notation newNotation) if (d->notation != newNotation) { d->notation = newNotation; emit notationChanged(d->notation); + emit changed(); } } @@ -888,6 +910,7 @@ void QRegExpValidator::setRegExp(const QRegExp& rx) if (r != rx) { r = rx; emit regExpChanged(r); + emit changed(); } } diff --git a/src/gui/util/qvalidator.h b/src/gui/util/qvalidator.h index 0ae0e52833..a5f6beec55 100644 --- a/src/gui/util/qvalidator.h +++ b/src/gui/util/qvalidator.h @@ -76,6 +76,9 @@ public: virtual State validate(QString &, int &) const = 0; virtual void fixup(QString &) const; +Q_SIGNALS: + void changed(); + protected: QValidator(QObjectPrivate &d, QObject *parent); QValidator(QValidatorPrivate &d, QObject *parent); -- cgit v1.2.3