QAbstractSpinBox::inputMethodQuery(): Consider input method hints set on the spin box.

The derived classes (QSpinBox, QDoubleSpinBox, QDateTimeEdit, QTimeEdit)
set various input method hints on the spin box in the init() methods
of their private classes which did not have any effect since
QAbstractSpinBox::inputMethodQuery() was implemented to return the
hints of the embedded QLineEdit only. Change it so that hints set
on the QAbstractSpinBox are also considered.

Change-Id: I76b7c4d3e0869589c110cf3a0b2c3f94201db5d5
Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-09-22 09:15:33 +02:00
parent 7edd10e6cc
commit d417f81f28
3 changed files with 18 additions and 1 deletions

View File

@ -720,7 +720,16 @@ void QAbstractSpinBox::interpretText()
QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const
{
Q_D(const QAbstractSpinBox);
return d->edit->inputMethodQuery(query);
const QVariant lineEditValue = d->edit->inputMethodQuery(query);
switch (query) {
case Qt::ImHints:
if (const int hints = inputMethodHints())
return QVariant(hints | lineEditValue.toInt());
break;
default:
break;
}
return lineEditValue;
}
/*!

View File

@ -285,6 +285,7 @@ typedef QList<Qt::Key> KeyList;
void tst_QDateTimeEdit::getSetCheck()
{
QDateTimeEdit obj1;
QCOMPARE(obj1.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers)));
obj1.setDisplayFormat("dd/MM/yyyy hh:mm:ss.zzz d/M/yy h:m:s.z AP");
// Section QDateTimeEdit::currentSection()
// void QDateTimeEdit::setCurrentSection(Section)
@ -306,6 +307,11 @@ void tst_QDateTimeEdit::getSetCheck()
QCOMPARE(QDateTimeEdit::MonthSection, obj1.currentSection());
obj1.setCurrentSection(QDateTimeEdit::YearSection);
QCOMPARE(QDateTimeEdit::YearSection, obj1.currentSection());
QDateEdit dateEdit;
QCOMPARE(dateEdit.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers)));
QTimeEdit timeEdit;
QCOMPARE(timeEdit.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhPreferNumbers)));
}
tst_QDateTimeEdit::tst_QDateTimeEdit()

View File

@ -165,6 +165,7 @@ Q_DECLARE_METATYPE(QLocale::Country)
void tst_QSpinBox::getSetCheck()
{
QSpinBox obj1;
QCOMPARE(obj1.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhDigitsOnly)));
// int QSpinBox::singleStep()
// void QSpinBox::setSingleStep(int)
obj1.setSingleStep(0);
@ -202,6 +203,7 @@ void tst_QSpinBox::getSetCheck()
QCOMPARE(INT_MAX, obj1.value());
QDoubleSpinBox obj2;
QCOMPARE(obj2.inputMethodQuery(Qt::ImHints), QVariant(int(Qt::ImhFormattedNumbersOnly)));
// double QDoubleSpinBox::singleStep()
// void QDoubleSpinBox::setSingleStep(double)
obj2.setSingleStep(0.0);