QInputMethodEvent::Attribute: add ctor that doesn't take a QVariant

Many callers passed QVariant() as the last ctor argument.
Micro-optimize by providing an overload that default-
constructs the variant in-place.

Change-Id: I9aab40c6e5a025c9a502c706e4cc7b10879ac418
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Takao Fujiwara <takao.fujiwara1@gmail.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-07-19 11:17:34 +02:00
parent d87242968f
commit 20af1ad7ef
4 changed files with 19 additions and 10 deletions

View File

@ -1995,6 +1995,16 @@ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
attribute, and \a value the value of the attribute.
*/
/*!
\fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length)
\overload
\since 5.7
Constructs an input method attribute with no value. \a type
specifies the type of attribute, and \a start and \a length
the position of the attribute.
*/
/*!
Constructs an event of type QEvent::InputMethod. The
attributes(), preeditString(), commitString(), replacementStart(),

View File

@ -528,8 +528,9 @@ public:
class Attribute {
public:
Attribute(AttributeType t, int s, int l, QVariant val) : type(t), start(s), length(l), value(qMove(val)) {}
AttributeType type;
Attribute(AttributeType t, int s, int l) : type(t), start(s), length(l), value() {}
AttributeType type;
int start;
int length;
QVariant value;

View File

@ -278,7 +278,7 @@ void QIBusPlatformInputContext::updatePreeditText(const QDBusVariant &text, uint
QList<QInputMethodEvent::Attribute> attributes = t.attributes.imAttributes();
if (!t.text.isEmpty())
attributes += QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, visible ? 1 : 0, QVariant());
attributes += QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, visible ? 1 : 0);
QInputMethodEvent event(t.text, attributes);
QCoreApplication::sendEvent(input, &event);

View File

@ -640,7 +640,7 @@ jboolean QAndroidInputContext::commitText(const QString &text, jint newCursorPos
: localPos - text.length() + newCursorPosition;
//move the cursor
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection,
newLocalPos, 0, QVariant()));
newLocalPos, 0));
}
}
m_blockUpdateSelection = updateSelectionWasBlocked;
@ -686,7 +686,7 @@ jboolean QAndroidInputContext::finishComposingText()
// Moving Qt's cursor to where the preedit cursor used to be
QList<QInputMethodEvent::Attribute> attributes;
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0, QVariant()));
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0));
QInputMethodEvent event(QString(), attributes);
event.setCommitString(m_composingText);
@ -843,8 +843,7 @@ jboolean QAndroidInputContext::setComposingText(const QString &text, jint newCur
QList<QInputMethodEvent::Attribute> attributes;
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
newCursorPosition,
1,
QVariant()));
1));
// Show compose text underlined
QTextCharFormat underlined;
underlined.setFontUnderline(true);
@ -916,7 +915,7 @@ jboolean QAndroidInputContext::setComposingRegion(jint start, jint end)
QVariant(underlined)));
// Keep the cursor position unchanged (don't move to end of preedit)
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, currentCursor - start, 1, QVariant()));
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, currentCursor - start, 1));
QInputMethodEvent event(m_composingText, attributes);
event.setCommitString(QString(), relativeStart, length);
@ -950,7 +949,7 @@ jboolean QAndroidInputContext::setSelection(jint start, jint end)
// preedit cursor
int localOldPos = query->value(Qt::ImCursorPosition).toInt();
int pos = localCursorPos - localOldPos;
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, pos, 1, QVariant()));
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, pos, 1));
//but we have to tell Qt about the compose text all over again
@ -965,8 +964,7 @@ jboolean QAndroidInputContext::setSelection(jint start, jint end)
// actually changing the selection
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection,
localCursorPos,
end - start,
QVariant()));
end - start));
}
QInputMethodEvent event(m_composingText, attributes);
sendInputMethodEventThreadSafe(&event);