\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)
void QValidator::setLocale(const QLocale &locale)
{
Q_D(QValidator);
- d->locale = locale;
+ if (d->locale != locale) {
+ d->locale = locale;
+ emit changed();
+ }
}
/*!
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();
}
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();
}
/*!
if (d->notation != newNotation) {
d->notation = newNotation;
emit notationChanged(d->notation);
+ emit changed();
}
}
if (r != rx) {
r = rx;
emit regExpChanged(r);
+ emit changed();
}
}
}
void tst_QDoubleValidator::notifySignals()
{
+ QLocale::setDefault(QLocale("C"));
+
QDoubleValidator dv(0.1, 0.9, 10, 0);
QSignalSpy topSpy(&dv, SIGNAL(topChanged(double)));
QSignalSpy bottomSpy(&dv, SIGNAL(bottomChanged(double)));
QSignalSpy decSpy(&dv, SIGNAL(decimalsChanged(int)));
+ QSignalSpy changedSpy(&dv, SIGNAL(changed()));
qRegisterMetaType<QDoubleValidator::Notation>("QDoubleValidator::Notation");
QSignalSpy notSpy(&dv, SIGNAL(notationChanged(QDoubleValidator::Notation)));
dv.setTop(0.8);
QCOMPARE(topSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 1);
QVERIFY(dv.top() == 0.8);
dv.setBottom(0.2);
QCOMPARE(bottomSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 2);
QVERIFY(dv.bottom() == 0.2);
dv.setRange(0.2, 0.7);
QCOMPARE(topSpy.count(), 2);
QCOMPARE(bottomSpy.count(), 1);
QCOMPARE(decSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 3);
QVERIFY(dv.bottom() == 0.2);
QVERIFY(dv.top() == 0.7);
QVERIFY(dv.decimals() == 0.);
dv.setRange(0.3, 0.7);
QCOMPARE(topSpy.count(), 2);
QCOMPARE(bottomSpy.count(), 2);
+ QCOMPARE(changedSpy.count(), 4);
QVERIFY(dv.bottom() == 0.3);
QVERIFY(dv.top() == 0.7);
QVERIFY(dv.decimals() == 0.);
dv.setRange(0.4, 0.6);
QCOMPARE(topSpy.count(), 3);
QCOMPARE(bottomSpy.count(), 3);
+ QCOMPARE(changedSpy.count(), 5);
QVERIFY(dv.bottom() == 0.4);
QVERIFY(dv.top() == 0.6);
QVERIFY(dv.decimals() == 0.);
dv.setDecimals(10);
QCOMPARE(decSpy.count(), 2);
+ QCOMPARE(changedSpy.count(), 6);
QVERIFY(dv.decimals() == 10.);
QCOMPARE(topSpy.count(), 3);
QCOMPARE(bottomSpy.count(), 3);
QCOMPARE(decSpy.count(), 3);
+ QCOMPARE(changedSpy.count(), 7);
QVERIFY(dv.bottom() == 0.4);
QVERIFY(dv.top() == 0.6);
QVERIFY(dv.decimals() == 100.);
dv.setNotation(QDoubleValidator::StandardNotation);
QCOMPARE(notSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 8);
QVERIFY(dv.notation() == QDoubleValidator::StandardNotation);
+
+ dv.setRange(dv.bottom(), dv.top(), dv.decimals());
+ QCOMPARE(topSpy.count(), 3);
+ QCOMPARE(bottomSpy.count(), 3);
+ QCOMPARE(decSpy.count(), 3);
+ QCOMPARE(changedSpy.count(), 8);
+
+ dv.setNotation(dv.notation());
+ QCOMPARE(notSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 8);
+
+ dv.setLocale(QLocale("C"));
+ QCOMPARE(changedSpy.count(), 8);
+
+ dv.setLocale(QLocale("en"));
+ QCOMPARE(changedSpy.count(), 9);
}
void tst_QDoubleValidator::validateIntEquiv_data()
void tst_QIntValidator::notifySignals()
{
+ QLocale::setDefault(QLocale("C"));
+
QIntValidator iv(0, 10, 0);
QSignalSpy topSpy(&iv, SIGNAL(topChanged(int)));
QSignalSpy bottomSpy(&iv, SIGNAL(bottomChanged(int)));
+ QSignalSpy changedSpy(&iv, SIGNAL(changed()));
+
iv.setTop(9);
QCOMPARE(topSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 1);
QVERIFY(iv.top() == 9);
iv.setBottom(1);
QCOMPARE(bottomSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 2);
QVERIFY(iv.bottom() == 1);
iv.setRange(1, 8);
QCOMPARE(topSpy.count(), 2);
QCOMPARE(bottomSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 3);
QVERIFY(iv.top() == 8);
QVERIFY(iv.bottom() == 1);
iv.setRange(2, 8);
QCOMPARE(topSpy.count(), 2);
QCOMPARE(bottomSpy.count(), 2);
+ QCOMPARE(changedSpy.count(), 4);
QVERIFY(iv.top() == 8);
QVERIFY(iv.bottom() == 2);
iv.setRange(3, 7);
QCOMPARE(topSpy.count(), 3);
QCOMPARE(bottomSpy.count(), 3);
+ QCOMPARE(changedSpy.count(), 5);
QVERIFY(iv.top() == 7);
QVERIFY(iv.bottom() == 3);
+
+ iv.setRange(3, 7);
+ QCOMPARE(topSpy.count(), 3);
+ QCOMPARE(bottomSpy.count(), 3);
+ QCOMPARE(changedSpy.count(), 5);
+
+ iv.setLocale(QLocale("C"));
+ QCOMPARE(changedSpy.count(), 5);
+
+ iv.setLocale(QLocale("en"));
+ QCOMPARE(changedSpy.count(), 6);
}
QTEST_MAIN(tst_QIntValidator)