From 0f924a64646ef22ab4e3df40316c3a0034dc64ca Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 2 Mar 2011 10:02:59 +1000 Subject: Add QML file for TextEdit positionAt test. Change-Id: I4632f77f87e8ced55a9959baaebd2b1624d0b568 --- tests/auto/declarative/qdeclarativetextedit/data/positionAt.qml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/positionAt.qml diff --git a/tests/auto/declarative/qdeclarativetextedit/data/positionAt.qml b/tests/auto/declarative/qdeclarativetextedit/data/positionAt.qml new file mode 100644 index 0000000..e010135 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/positionAt.qml @@ -0,0 +1,9 @@ +import QtQuick 1.0 + +TextEdit { + focus: true + objectName: "myInput" + width: 50 + height: 25 + text: "This is\n a long piece of text" +} -- cgit v0.12 From e68b1829384632e4428893e2aad56e9b72ee6fb7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 2 Mar 2011 11:28:06 +1000 Subject: Doc: remove experimental GestureArea from contents and add PinchArea Change-Id: I5eb6d2826f673c7067fde1447f25d3fc97b5aa5e Reviewed-by: Bea Lam --- doc/src/declarative/elements.qdoc | 2 +- doc/src/declarative/qmlinuse.qdoc | 2 +- src/imports/gestures/qdeclarativegesturearea.cpp | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 466b940..e2d9350 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -76,7 +76,7 @@ To see the QML elements listed by functional area, see the \o \l {FocusScope} - Element that mediate keyboard focus changes \o \l {Flickable} - Provides a surface that can be "flicked" \o \l {Flipable} - Provides a surface that produces "flipping" effects -\o \l {GestureArea} - Enables simple gesture handling +\o \l {PinchArea} - Enables simple pinch gesture handling \endlist \section1 Positioners and Repeater diff --git a/doc/src/declarative/qmlinuse.qdoc b/doc/src/declarative/qmlinuse.qdoc index 7380ef5..131be1b 100644 --- a/doc/src/declarative/qmlinuse.qdoc +++ b/doc/src/declarative/qmlinuse.qdoc @@ -207,7 +207,7 @@
  • Flipable Element - The Flipable item provides a surface that can be flipped or reflected.
  • FocusPanel Element - The FocusPanel item explicitly creates a focus panel.
  • FocusScope Element - The FocusScope object explicitly creates a focus scope for focus management.
  • -
  • GestureArea Element - The GestureArea item enables simple gesture handling.
  • +
  • PinchArea Element - The PinchArea item enables simple pinch gesture handling.
  • KeyNavigation Element - The KeyNavigation attached property supports key navigation by arrow keys.
  • Keys Element - The Keys attached property provides key handling to Items.
  • MouseArea Element - The MouseArea item enables simple mouse handling.
  • diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp index 1b6e723..c2a2e98 100644 --- a/src/imports/gestures/qdeclarativegesturearea.cpp +++ b/src/imports/gestures/qdeclarativegesturearea.cpp @@ -89,6 +89,10 @@ public: \warning Elements in the Qt.labs module are not guaranteed to remain compatible in future versions. + \warning GestureArea is an experimental element whose development has + been discontinued. PinchArea is available in QtQuick 1.1 and handles + two finger gesture input. + \note This element is only functional on devices with touch input. \qml -- cgit v0.12 From 7bc4222be9369463219656539d7f8085f426e576 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 2 Mar 2011 12:57:55 +1000 Subject: Don't assert if font engine creates new glyphs Change-Id: Id18f58822f990788b511cbce02f8e4cf7d787c21 Task-number: QTBUG-14734 --- src/declarative/graphicsitems/qdeclarativetextlayout.cpp | 11 ++++++----- .../auto/declarative/qdeclarativetext/data/qtbug_14734.qml | 10 ++++++++++ .../declarative/qdeclarativetext/tst_qdeclarativetext.cpp | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativetext/data/qtbug_14734.qml diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp index b24dd2c..31819f5 100644 --- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp @@ -99,7 +99,6 @@ class DrawTextItemRecorder: public QPaintEngine needFreshCurrentItem = false; last.numChars += ti.num_chars; - last.numGlyphs += ti.glyphs.numGlyphs; } } @@ -111,7 +110,7 @@ class DrawTextItemRecorder: public QPaintEngine currentItem.font = ti.font(); currentItem.charOffset = charOffset; currentItem.numChars = ti.num_chars; - currentItem.numGlyphs = ti.glyphs.numGlyphs; + currentItem.numGlyphs = 0; currentItem.glyphOffset = glyphOffset; currentItem.positionOffset = positionOffset; currentItem.useBackendOptimizations = m_useBackendOptimizations; @@ -121,6 +120,8 @@ class DrawTextItemRecorder: public QPaintEngine m_inertText->items.append(currentItem); } + QStaticTextItem ¤tItem = m_inertText->items.last(); + QTransform matrix = m_untransformedCoordinates ? QTransform() : state->transform(); matrix.translate(position.x(), position.y()); @@ -129,18 +130,18 @@ class DrawTextItemRecorder: public QPaintEngine ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); int size = glyphs.size(); - Q_ASSERT(size == ti.glyphs.numGlyphs); Q_ASSERT(size == positions.size()); + currentItem.numGlyphs += size; m_inertText->glyphs.resize(m_inertText->glyphs.size() + size); m_inertText->positions.resize(m_inertText->glyphs.size()); m_inertText->chars.resize(m_inertText->chars.size() + ti.num_chars); glyph_t *glyphsDestination = m_inertText->glyphs.data() + glyphOffset; - qMemCopy(glyphsDestination, glyphs.constData(), sizeof(glyph_t) * ti.glyphs.numGlyphs); + qMemCopy(glyphsDestination, glyphs.constData(), sizeof(glyph_t) * size); QFixedPoint *positionsDestination = m_inertText->positions.data() + positionOffset; - qMemCopy(positionsDestination, positions.constData(), sizeof(QFixedPoint) * ti.glyphs.numGlyphs); + qMemCopy(positionsDestination, positions.constData(), sizeof(QFixedPoint) * size); QChar *charsDestination = m_inertText->chars.data() + charOffset; qMemCopy(charsDestination, ti.chars, sizeof(QChar) * ti.num_chars); diff --git a/tests/auto/declarative/qdeclarativetext/data/qtbug_14734.qml b/tests/auto/declarative/qdeclarativetext/data/qtbug_14734.qml new file mode 100644 index 0000000..bd07d66 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/qtbug_14734.qml @@ -0,0 +1,10 @@ +import QtQuick 1.0 + +Rectangle { + width: 640 + height: 480 + + Text { + text: "í " + } +} diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 05546cb..7e0069f 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -109,6 +109,7 @@ private slots: void testQtQuick11Attributes(); void testQtQuick11Attributes_data(); + void qtbug_14734(); private: QStringList standard; QStringList richText; @@ -1202,6 +1203,19 @@ void tst_qdeclarativetext::testQtQuick11Attributes_data() << ""; } +void tst_qdeclarativetext::qtbug_14734() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/qtbug_14734.qml"); + QVERIFY(canvas); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + delete canvas; +} + QTEST_MAIN(tst_qdeclarativetext) #include "tst_qdeclarativetext.moc" -- cgit v0.12 From 2123a7ff6a04aec331fada5e03aa99395a0de1db Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 2 Mar 2011 15:53:48 +1000 Subject: Make the TextInput cursorRectangle relative to the item. The rectangle returned was relative to the text and didn't adjust for horizontal scrolling. Change-Id: I09227d73bbd8b32d830744d5911d785246051c2f Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativetextinput.cpp | 1 + .../tst_qdeclarativetextinput.cpp | 42 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index c873172..dc44bfe 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -482,6 +482,7 @@ QRect QDeclarativeTextInput::cursorRectangle() const Q_D(const QDeclarativeTextInput); QRect r = d->control->cursorRect(); r.setHeight(r.height()-1); // Make consistent with TextEdit (QLineControl inexplicably adds 1) + r.moveLeft(r.x() - d->hscroll); return r; } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 045f60e..0d228e2 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -111,6 +111,7 @@ private slots: void passwordCharacter(); void cursorDelegate(); void cursorVisible(); + void cursorRectangle(); void navigation(); void copyAndPaste(); void readOnly(); @@ -1414,6 +1415,41 @@ void tst_qdeclarativetextinput::cursorVisible() #endif } +void tst_qdeclarativetextinput::cursorRectangle() +{ + QString text = "Hello World!"; + + QDeclarativeTextInput input; + input.setText(text); + QFontMetricsF fm(input.font()); + input.setWidth(fm.width(text.mid(0, 5))); + + QRect r; + + for (int i = 0; i <= 5; ++i) { + input.setCursorPosition(i); + r = input.cursorRectangle(); + int textWidth = fm.width(text.mid(0, i)); + + QVERIFY(r.left() < textWidth); + QVERIFY(r.right() > textWidth); + } + + // Check the cursor rectangle remains within the input bounding rect when auto scrolling. + QVERIFY(r.left() < input.boundingRect().width()); + QVERIFY(r.right() >= input.width()); + + for (int i = 6; i < text.length(); ++i) { + input.setCursorPosition(i); + QCOMPARE(r, input.cursorRectangle()); + } + + for (int i = text.length() - 2; i >= 0; --i) { + input.setCursorPosition(i); + QVERIFY(r.right() >= 0); + } +} + void tst_qdeclarativetextinput::readOnly() { QDeclarativeView *canvas = createView(SRCDIR "/data/readOnly.qml"); @@ -1882,7 +1918,7 @@ void tst_qdeclarativetextinput::preeditAutoScroll() // test the text is scrolled so the preedit is visible. ic.sendPreeditText(preeditText.mid(0, 3), 1); QVERIFY(input.positionAt(0) != 0); - QVERIFY(input.cursorRectangle().x() - 1 <= input.width()); + QVERIFY(input.cursorRectangle().left() < input.boundingRect().width()); // test the text is scrolled back when the preedit is removed. ic.sendEvent(QInputMethodEvent()); @@ -1894,13 +1930,13 @@ void tst_qdeclarativetextinput::preeditAutoScroll() qreal x = input.positionToRectangle(0).x(); for (int i = 0; i < 3; ++i) { ic.sendPreeditText(preeditText, i + 1); - QVERIFY(input.cursorRectangle().x() >= fm.width(preeditText.at(i))); + QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i))); QVERIFY(input.positionToRectangle(0).x() < x); x = input.positionToRectangle(0).x(); } for (int i = 1; i >= 0; --i) { ic.sendPreeditText(preeditText, i + 1); - QVERIFY(input.cursorRectangle().x() >= fm.width(preeditText.at(i))); + QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i))); QVERIFY(input.positionToRectangle(0).x() > x); x = input.positionToRectangle(0).x(); } -- cgit v0.12 From 585ddb51909db49c51e9e8019d3b5d45c48a1a08 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 2 Mar 2011 17:30:53 +1000 Subject: Position the TextInput cursor correctly after IM text is commited. If text is removed before the cursor position decrement not increment the cursor by the by the difference. Change-Id: If9558c88157cc884652af7aaf9bd5fad0ea822d8 Task-number: QTBUG-17863 Reviewed-by: Martin Jones --- src/gui/widgets/qlinecontrol.cpp | 2 +- .../tst_qdeclarativetextinput.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index d108ad9..bffc2b5 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -420,7 +420,7 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event) int c = m_cursor; // cursor position after insertion of commit string if (event->replacementStart() <= 0) - c += event->commitString().length() + qMin(-event->replacementStart(), event->replacementLength()); + c += event->commitString().length() - qMin(-event->replacementStart(), event->replacementLength()); m_cursor += event->replacementStart(); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 0d228e2..24ce0e4 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1174,6 +1174,24 @@ void tst_qdeclarativetextinput::inputMethods() QApplication::sendEvent(canvas, &event); QCOMPARE(input->text(), QString("My Hello world!")); + input->setCursorPosition(2); + event.setCommitString("Your", -2, 2); + QApplication::sendEvent(canvas, &event); + QCOMPARE(input->text(), QString("Your Hello world!")); + QCOMPARE(input->cursorPosition(), 4); + + input->setCursorPosition(7); + event.setCommitString("Goodbye", -2, 5); + QApplication::sendEvent(canvas, &event); + QCOMPARE(input->text(), QString("Your Goodbye world!")); + QCOMPARE(input->cursorPosition(), 12); + + input->setCursorPosition(8); + event.setCommitString("Our", -8, 4); + QApplication::sendEvent(canvas, &event); + QCOMPARE(input->text(), QString("Our Goodbye world!")); + QCOMPARE(input->cursorPosition(), 7); + delete canvas; } -- cgit v0.12 From e1d1b65e63223e8705b8df09645f8740ab7fb80d Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 3 Mar 2011 10:18:21 +1000 Subject: Compensate for horizontal scroll in TextInput micro focus. Return the adjusted cursore rectangle rather than the one returned by QLineControl. Change-Id: I343ecdb47ef2ea59519c8d155bbb9917d9c8ce56 Task-number: QTBUG-17864 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 2 +- .../declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index dc44bfe..f41ab03 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1288,7 +1288,7 @@ QVariant QDeclarativeTextInput::inputMethodQuery(Qt::InputMethodQuery property) Q_D(const QDeclarativeTextInput); switch(property) { case Qt::ImMicroFocus: - return d->control->cursorRect(); + return cursorRectangle(); case Qt::ImFont: return font(); case Qt::ImCursorPosition: diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 24ce0e4..0320ce2 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1451,6 +1451,7 @@ void tst_qdeclarativetextinput::cursorRectangle() QVERIFY(r.left() < textWidth); QVERIFY(r.right() > textWidth); + QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } // Check the cursor rectangle remains within the input bounding rect when auto scrolling. @@ -1460,11 +1461,14 @@ void tst_qdeclarativetextinput::cursorRectangle() for (int i = 6; i < text.length(); ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); + QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } for (int i = text.length() - 2; i >= 0; --i) { input.setCursorPosition(i); + r = input.cursorRectangle(); QVERIFY(r.right() >= 0); + QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r); } } -- cgit v0.12 From 9c1549371e86c95e08f7fc2e11242de12fb1e1da Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Wed, 2 Mar 2011 11:19:07 +1000 Subject: QDeclarativePropertyMap::keys() cannot be called from qml Not allow create dynamic properties which are same with existing method (method, signal, slot) names. Change-Id: I0ae64c8a6a89ef4f7614169088f7c005edad40b0 Task-number:QTBUG-17868 Reviewed-by:Martin Jones --- .../util/qdeclarativeopenmetaobject.cpp | 14 +++++---- src/declarative/util/qdeclarativepropertymap.cpp | 15 ++++++++-- .../tst_qdeclarativepropertymap.cpp | 34 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp index 0ceda35..8a8d05e 100644 --- a/src/declarative/util/qdeclarativeopenmetaobject.cpp +++ b/src/declarative/util/qdeclarativeopenmetaobject.cpp @@ -289,17 +289,19 @@ void QDeclarativeOpenMetaObject::setValue(const QByteArray &name, const QVariant int id = -1; if (iter == d->type->d->names.end()) { - id = d->type->createProperty(name.constData()) - d->type->d->propertyOffset; + id = createProperty(name.constData(), "") - d->type->d->propertyOffset; } else { id = *iter; } - QVariant &dataVal = d->getData(id); - if (dataVal == val) - return; + if (id >= 0) { + QVariant &dataVal = d->getData(id); + if (dataVal == val) + return; - dataVal = val; - activate(d->object, id + d->type->d->signalOffset, 0); + dataVal = val; + activate(d->object, id + d->type->d->signalOffset, 0); + } } // returns true if this value has been initialized by a call to either value() or setValue() diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp index 1a3e0be..915f027 100644 --- a/src/declarative/util/qdeclarativepropertymap.cpp +++ b/src/declarative/util/qdeclarativepropertymap.cpp @@ -182,7 +182,18 @@ QVariant QDeclarativePropertyMap::value(const QString &key) const void QDeclarativePropertyMap::insert(const QString &key, const QVariant &value) { Q_D(QDeclarativePropertyMap); - d->mo->setValue(key.toUtf8(), value); + //The following strings shouldn't be used as property names + if (key != QLatin1String("keys") + && key != QLatin1String("valueChanged") + && key != QLatin1String("QObject") + && key != QLatin1String("destroyed") + && key != QLatin1String("deleteLater")) { + d->mo->setValue(key.toUtf8(), value); + } else { + qWarning() << "Creating property with name" + << key + << "is not permitted, conflicts with internal symbols."; + } } /*! @@ -258,7 +269,7 @@ QVariant &QDeclarativePropertyMap::operator[](const QString &key) Q_D(QDeclarativePropertyMap); QByteArray utf8key = key.toUtf8(); if (!d->keys.contains(key)) - d->mo->setValue(utf8key, QVariant()); //force creation -- needed below + insert(key, QVariant());//force creation -- needed below return (*(d->mo))[utf8key]; } diff --git a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp index 7d746a7..e3a4723 100644 --- a/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp +++ b/tests/auto/declarative/qdeclarativepropertymap/tst_qdeclarativepropertymap.cpp @@ -76,6 +76,40 @@ void tst_QDeclarativePropertyMap::insert() map.insert(QLatin1String("key1"),"Hello World"); QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); + + //inserting property names same with existing method(signal, slot, method) names is not allowed + //QDeclarativePropertyMap has an invokable keys() method + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols. "); + map.insert(QLatin1String("keys"), 1); + QVERIFY(map.keys().count() == 2); + QVERIFY(!map.contains(QLatin1String("keys"))); + QVERIFY(map.value(QLatin1String("keys")).isNull()); + + //QDeclarativePropertyMap has a deleteLater() slot + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols. "); + map.insert(QLatin1String("deleteLater"), 1); + QVERIFY(map.keys().count() == 2); + QVERIFY(!map.contains(QLatin1String("deleteLater"))); + QVERIFY(map.value(QLatin1String("deleteLater")).isNull()); + + //QDeclarativePropertyMap has an valueChanged() signal + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols. "); + map.insert(QLatin1String("valueChanged"), 1); + QVERIFY(map.keys().count() == 2); + QVERIFY(!map.contains(QLatin1String("valueChanged"))); + QVERIFY(map.value(QLatin1String("valueChanged")).isNull()); + + //but 'valueChange' should be ok + map.insert(QLatin1String("valueChange"), 1); + QVERIFY(map.keys().count() == 3); + QVERIFY(map.contains(QLatin1String("valueChange"))); + QCOMPARE(map.value(QLatin1String("valueChange")), QVariant(1)); + + //'valueCHANGED' should be ok, too + map.insert(QLatin1String("valueCHANGED"), 1); + QVERIFY(map.keys().count() == 4); + QVERIFY(map.contains(QLatin1String("valueCHANGED"))); + QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1)); } void tst_QDeclarativePropertyMap::operatorInsert() -- cgit v0.12 From d893ad027570ae7b3127636a4622f9cb4d5bb7a0 Mon Sep 17 00:00:00 2001 From: Lasse Holmstedt Date: Fri, 4 Mar 2011 10:34:57 +1000 Subject: Fix potential crash in QTextControl. inputContext() is only safe to call if there is a current contextWidget. Change-Id: I6cbccf5f5fbb2d8c9ca6acf5f7e02f680eb84483 Reviewed-by: Andrew den Exter --- src/gui/text/qtextcontrol.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index b25588d..f4054d3 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -1649,8 +1649,10 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons emit q->cursorPositionChanged(); _q_updateCurrentCharFormatAndSelection(); #ifndef QT_NO_IM - if (QInputContext *ic = inputContext()) { - ic->update(); + if (contextWidget) { + if (QInputContext *ic = inputContext()) { + ic->update(); + } } #endif //QT_NO_IM } else { -- cgit v0.12 From 7d22f04a0d2af6752fbbcaa970808a6e8d33399b Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 3 Mar 2011 15:26:57 +1000 Subject: Fix word selection locking on string boundaries. QTextBoundaryFinder will return the position -1 if it reaches the end of a string without finding a boundary, reset the cursor and anchor to 0 or the string length as appropriate in those cases. Also allow selection to lock onto the string limits as if they were words. Change-Id: Ie9d233967c73eb6a61f19c76494f04bca18612f8 Task-number: QTBUG-17860 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativetextinput.cpp | 25 ++++---- .../tst_qdeclarativetextinput.cpp | 73 +++++++++++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index f41ab03..8b21008 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1570,38 +1570,41 @@ void QDeclarativeTextInput::moveCursorSelection(int pos, SelectionMode mode) anchor = d->control->selectionStart(); if (anchor < pos || (anchor == pos && cursor < pos)) { - QTextBoundaryFinder finder(QTextBoundaryFinder::Word, d->control->text()); + const QString text = d->control->text(); + QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text); finder.setPosition(anchor); const QTextBoundaryFinder::BoundaryReasons reasons = finder.boundaryReasons(); - if (!(reasons & QTextBoundaryFinder::StartWord) + if (anchor < text.length() && !(reasons & QTextBoundaryFinder::StartWord) || ((reasons & QTextBoundaryFinder::EndWord) && anchor > cursor)) { finder.toPreviousBoundary(); } - anchor = finder.position(); + anchor = finder.position() != -1 ? finder.position() : 0; finder.setPosition(pos); - if (!finder.isAtBoundary()) + if (pos > 0 && !finder.boundaryReasons()) finder.toNextBoundary(); + const int cursor = finder.position() != -1 ? finder.position() : text.length(); - d->control->setSelection(anchor, finder.position() - anchor); + d->control->setSelection(anchor, cursor - anchor); } else if (anchor > pos || (anchor == pos && cursor > pos)) { - QTextBoundaryFinder finder(QTextBoundaryFinder::Word, d->control->text()); + const QString text = d->control->text(); + QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text); finder.setPosition(anchor); const QTextBoundaryFinder::BoundaryReasons reasons = finder.boundaryReasons(); - if (!(reasons & QTextBoundaryFinder::EndWord) + if (anchor > 0 && !(reasons & QTextBoundaryFinder::EndWord) || ((reasons & QTextBoundaryFinder::StartWord) && anchor < cursor)) { finder.toNextBoundary(); } - - anchor = finder.position(); + anchor = finder.position() != -1 ? finder.position() : text.length(); finder.setPosition(pos); - if (!finder.isAtBoundary()) + if (pos < text.length() && !finder.boundaryReasons()) finder.toPreviousBoundary(); + const int cursor = finder.position() != -1 ? finder.position() : 0; - d->control->setSelection(anchor, finder.position() - anchor); + d->control->setSelection(anchor, cursor - anchor); } } } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 0320ce2..e7235f7 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -145,7 +145,8 @@ tst_qdeclarativetextinput::tst_qdeclarativetextinput() standard << "the quick brown fox jumped over the lazy dog" << "It's supercalifragisiticexpialidocious!" << "Hello, world!" - << "!dlrow ,olleH"; + << "!dlrow ,olleH" + << " spacey text "; colorStrings << "aliceblue" << "antiquewhite" @@ -446,6 +447,9 @@ void tst_qdeclarativetextinput::moveCursorSelection_data() QTest::addColumn("selectionEnd"); QTest::addColumn("reversible"); + // () contains the text selected by the cursor. + // <> contains the actual selection. + QTest::newRow("(t)he|characters") << standard[0] << 0 << 1 << QDeclarativeTextInput::SelectCharacters << 0 << 1 << true; QTest::newRow("do(g)|characters") @@ -583,6 +587,24 @@ void tst_qdeclarativetextinput::moveCursorSelection_data() << standard[3] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << true; QTest::newRow("!<()>dlrow|words") << standard[3] << 1 << 1 << QDeclarativeTextInput::SelectWords << 1 << 1 << true; + + QTest::newRow(" text |words") + << standard[4] << 1 << 4 << QDeclarativeTextInput::SelectWords << 1 << 7 << true; + QTest::newRow(" spacey |words") + << standard[4] << 11 << 13 << QDeclarativeTextInput::SelectWords << 10 << 14 << false; // Should be reversible. QTBUG-11365 + QTest::newRow("<( )>spacey text |words|ltr") + << standard[4] << 0 << 1 << QDeclarativeTextInput::SelectWords << 0 << 1 << false; + QTest::newRow("<( )spacey> text |words|rtl") + << standard[4] << 1 << 0 << QDeclarativeTextInput::SelectWords << 0 << 7 << false; + QTest::newRow("spacey |words|ltr") + << standard[4] << 14 << 15 << QDeclarativeTextInput::SelectWords << 10 << 15 << false; +// QTBUG-11365 +// QTest::newRow("spacey text<( )>|words|rtl") +// << standard[4] << 15 << 14 << QDeclarativeTextInput::SelectWords << 14 << 15 << false; + QTest::newRow("<()> spacey text |words") + << standard[4] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << false; + QTest::newRow(" spacey text <()>|words") + << standard[4] << 15 << 15 << QDeclarativeTextInput::SelectWords << 15 << 15 << false; } void tst_qdeclarativetextinput::moveCursorSelection() @@ -629,6 +651,11 @@ void tst_qdeclarativetextinput::moveCursorSelectionSequence_data() QTest::addColumn("selection2Start"); QTest::addColumn("selection2End"); + // () contains the text selected by the cursor. + // <> contains the actual selection. + // ^ is the revised cursor position. + // {} contains the revised selection. + QTest::newRow("the { f^ox} jumped|ltr") << standard[0] << 9 << 13 << 17 @@ -741,6 +768,50 @@ void tst_qdeclarativetextinput::moveCursorSelectionSequence_data() << 11 << 9 << 5 << 8 << 13 << 1 << 13; + + QTest::newRow("{<(^} sp)acey> text |ltr") + << standard[4] + << 0 << 3 << 0 + << 0 << 7 + << 0 << 0; + QTest::newRow("{<( ^}sp)acey> text |ltr") + << standard[4] + << 0 << 3 << 1 + << 0 << 7 + << 0 << 1; + QTest::newRow("<( {s^p)acey>} text |rtl") + << standard[4] + << 3 << 0 << 2 + << 0 << 7 + << 1 << 7; + QTest::newRow("<( {^sp)acey>} text |rtl") + << standard[4] + << 3 << 0 << 1 + << 0 << 7 + << 1 << 7; + + QTest::newRow(" spacey }|rtl") + << standard[4] + << 15 << 12 << 15 + << 10 << 15 + << 15 << 15; +// QTBUG-11365 +// QTest::newRow(" spacey }|rtl") +// << standard[4] +// << 15 << 12 << 14 +// << 10 << 15 +// << 14 << 15; + QTest::newRow(" spacey {|ltr") + << standard[4] + << 12 << 15 << 13 + << 10 << 15 + << 10 << 14; +// QTBUG-11365 +// QTest::newRow(" spacey {|ltr") +// << standard[4] +// << 12 << 15 << 14 +// << 10 << 15 +// << 10 << 14; } void tst_qdeclarativetextinput::moveCursorSelectionSequence() -- cgit v0.12 From 818d3e56bda4829398ceb633a7271c5c99fcdbda Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 4 Mar 2011 10:52:13 +1000 Subject: Fix TextInput auto test failure on mac. Disable auto scroll so the relative position of the text isn't changed when inserting text and changing the cursor position. Change-Id: I6a18e91e98014f1e94216bc85241ebb0d604dd84 Reviewed-by: Bea Lam --- .../auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index e7235f7..ef64dd9 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -2066,6 +2066,7 @@ void tst_qdeclarativetextinput::preeditMicroFocus() view.setInputContext(&ic); QDeclarativeTextInput input; input.setPos(0, 0); + input.setAutoScroll(false); input.setFocus(true); scene.addItem(&input); view.show(); -- cgit v0.12