Removed inputMethodHints setter and getter from QQuickItem.
No need to consume memory for input method hints on every item when
only QQuickTextInput and QQuickTextEdit actually use them.
Additionally introduced change signals on the editor hint properties.
Change-Id: Ice380d4f4dd47fdde73d2468f4a44a7d1540ad45
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
z(0), scale(1), rotation(0), opacity(1),
attachedLayoutDirection(0), acceptedMouseButtons(0),
- imHints(Qt::ImhNone),
keyHandler(0),
}
}
-Qt::InputMethodHints QQuickItem::inputMethodHints() const
-{
- Q_D(const QQuickItem);
- return d->imHints;
-}
-
-void QQuickItem::setInputMethodHints(Qt::InputMethodHints hints)
-{
- Q_D(QQuickItem);
- d->imHints = hints;
-
- if (!d->canvas || d->canvas->activeFocusItem() != this)
- return;
-
- if (qApp->focusObject() == this)
- qApp->inputMethod()->update(Qt::ImHints);
-}
-
QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const
{
Q_D(const QQuickItem);
v = (bool)(flags() & ItemAcceptsInputMethod);
break;
case Qt::ImHints:
- v = (int)inputMethodHints();
- break;
case Qt::ImCursorRectangle:
case Qt::ImFont:
case Qt::ImCursorPosition:
Q_INVOKABLE void forceActiveFocus();
Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
- Qt::InputMethodHints inputMethodHints() const;
- void setInputMethodHints(Qt::InputMethodHints hints);
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
struct UpdatePaintNodeData {
QQuickLayoutMirroringAttached* attachedLayoutDirection;
Qt::MouseButtons acceptedMouseButtons;
- Qt::InputMethodHints imHints;
void setAccessibleFlagAndListener();
\endlist
*/
+Qt::InputMethodHints QQuickTextEdit::inputMethodHints() const
+{
+ Q_D(const QQuickTextEdit);
+ return d->inputMethodHints;
+}
+
+void QQuickTextEdit::setInputMethodHints(Qt::InputMethodHints hints)
+{
+ Q_D(QQuickTextEdit);
+
+ if (hints == d->inputMethodHints)
+ return;
+
+ d->inputMethodHints = hints;
+ updateInputMethod(Qt::ImHints);
+ emit inputMethodHintsChanged();
+}
+
void QQuickTextEdit::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry)
{
Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
- Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
+ Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
qreal textMargin() const;
void setTextMargin(qreal margin);
+ Qt::InputMethodHints inputMethodHints() const;
+ void setInputMethodHints(Qt::InputMethodHints hints);
+
bool selectByMouse() const;
void setSelectByMouse(bool);
void inputMethodComposingChanged();
void effectiveHorizontalAlignmentChanged();
void baseUrlChanged();
+ void inputMethodHintsChanged();
public Q_SLOTS:
void selectAll();
textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), cursorComponent(0), cursor(0),
format(QQuickTextEdit::PlainText), document(0), wrapMode(QQuickTextEdit::NoWrap),
mouseSelectionMode(QQuickTextEdit::SelectCharacters),
- lineCount(0), yoff(0), updateType(UpdatePaintNode)
+ lineCount(0), yoff(0), inputMethodHints(Qt::ImhNone), updateType(UpdatePaintNode)
{
}
int lineCount;
int yoff;
QSize contentSize;
+ Qt::InputMethodHints inputMethodHints;
enum UpdateType {
UpdateNone,
hints &= ~Qt::ImhHiddenText;
if (m_echoMode != QQuickTextInput::Normal)
hints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
- q->setInputMethodHints(hints);
+ effectiveInputMethodHints = hints;
+ q->updateInputMethod(Qt::ImHints);
}
/*!
\qmlproperty enumeration QtQuick2::TextInput::echoMode
\endlist
*/
-Qt::InputMethodHints QQuickTextInput::imHints() const
+Qt::InputMethodHints QQuickTextInput::inputMethodHints() const
{
Q_D(const QQuickTextInput);
return d->inputMethodHints;
}
-void QQuickTextInput::setIMHints(Qt::InputMethodHints hints)
+void QQuickTextInput::setInputMethodHints(Qt::InputMethodHints hints)
{
Q_D(QQuickTextInput);
- if (d->inputMethodHints == hints)
+
+ if (hints == d->inputMethodHints)
return;
+
d->inputMethodHints = hints;
d->updateInputMethodHints();
+ emit inputMethodHintsChanged();
}
/*!
case Qt::ImEnabled:
return QVariant((bool)(flags() & ItemAcceptsInputMethod));
case Qt::ImHints:
- return QVariant((int)inputMethodHints());
+ return QVariant((int) d->effectiveInputMethodHints);
case Qt::ImCursorRectangle:
return cursorRectangle();
case Qt::ImFont:
Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
#endif
Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
- Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
+ Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
bool isInputMethodComposing() const;
- Qt::InputMethodHints imHints() const;
- void setIMHints(Qt::InputMethodHints hints);
+ Qt::InputMethodHints inputMethodHints() const;
+ void setInputMethodHints(Qt::InputMethodHints hints);
Q_INVOKABLE QString getText(int start, int end) const;
void inputMethodComposingChanged();
void effectiveHorizontalAlignmentChanged();
void contentSizeChanged();
+ void inputMethodHintsChanged();
protected:
virtual void geometryChanged(const QRectF &newGeometry,
, wrapMode(QQuickTextInput::NoWrap)
, mouseSelectionMode(QQuickTextInput::SelectCharacters)
, inputMethodHints(Qt::ImhNone)
+ , effectiveInputMethodHints(Qt::ImhNone)
, m_layoutDirection(Qt::LayoutDirectionAuto)
, m_passwordCharacter(QLatin1Char('*'))
, focused(false)
QQuickTextInput::WrapMode wrapMode;
QQuickTextInput::SelectionMode mouseSelectionMode;
Qt::InputMethodHints inputMethodHints;
+ Qt::InputMethodHints effectiveInputMethodHints;
Qt::LayoutDirection m_layoutDirection;
QChar m_blank;
QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit *>(canvas.rootObject());
QVERIFY(textEditObject != 0);
QVERIFY(textEditObject->inputMethodHints() & Qt::ImhNoPredictiveText);
+ QSignalSpy inputMethodHintSpy(textEditObject, SIGNAL(inputMethodHintsChanged()));
textEditObject->setInputMethodHints(Qt::ImhUppercaseOnly);
QVERIFY(textEditObject->inputMethodHints() & Qt::ImhUppercaseOnly);
+ QCOMPARE(inputMethodHintSpy.count(), 1);
+ textEditObject->setInputMethodHints(Qt::ImhUppercaseOnly);
+ QCOMPARE(inputMethodHintSpy.count(), 1);
+
+ QQuickTextEdit plainTextEdit;
+ QCOMPARE(plainTextEdit.inputMethodHints(), Qt::ImhNone);
}
void tst_qquicktextedit::positionAt()
QQuickTextInput *input = qobject_cast<QQuickTextInput *>(canvas.rootObject());
QVERIFY(input != 0);
QVERIFY(input->inputMethodHints() & Qt::ImhNoPredictiveText);
+ QSignalSpy inputMethodHintSpy(input, SIGNAL(inputMethodHintsChanged()));
input->setInputMethodHints(Qt::ImhUppercaseOnly);
QVERIFY(input->inputMethodHints() & Qt::ImhUppercaseOnly);
+ QCOMPARE(inputMethodHintSpy.count(), 1);
+ input->setInputMethodHints(Qt::ImhUppercaseOnly);
+ QCOMPARE(inputMethodHintSpy.count(), 1);
+
+ // default value
+ QQuickTextInput plainInput;
+ QCOMPARE(plainInput.inputMethodHints(), Qt::ImhNone);
input->setFocus(true);
QVERIFY(input->hasActiveFocus() == true);
// test that input method event is committed
QInputMethodEvent event;
event.setCommitString( "My ", -12, 0);
+ QTRY_COMPARE(qGuiApp->focusObject(), input);
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
QCOMPARE(input->text(), QString("My Hello world!"));
//Normal
ref &= ~Qt::ImhHiddenText;
ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
- QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref);
input->setEchoMode(QQuickTextInput::NoEcho);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String(""));
//NoEcho
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
- QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref);
input->setEchoMode(QQuickTextInput::Password);
//Password
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String("********"));
- QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref);
+ // clearing input hints do not clear bits set by echo mode
+ input->setInputMethodHints(Qt::ImhNone);
+ QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref);
input->setPasswordCharacter(QChar('Q'));
QCOMPARE(input->passwordCharacter(), QLatin1String("Q"));
QCOMPARE(input->text(), initial);
//PasswordEchoOnEdit
ref &= ~Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
- QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ"));
QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("QQQQQQQQ"));