summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>2012-03-21 15:27:21 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-23 11:25:21 +0100
commite264fbffc54741d769037ad7f53439caa018d815 (patch)
tree27ee428796617b1edc7c5cd589123e92ae0a8672
parenta7b68bf189fbae3a0add5660f8a95ed4359a67d5 (diff)
TextInput not to emit selection change signals if values do not change
Fixed also tests with QTBUG-24036 Test was assuming selectionStartChanged and selectionEndChanged to trigger even if their values did not change. Change-Id: I26e57cfb4ff06ec6c195ec2b0d997885c807670b Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp15
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp32
2 files changed, 21 insertions, 26 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index ce75617d..28e89fff 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -1920,16 +1920,15 @@ void QDeclarativeTextInput::selectionChanged()
updateRect();//TODO: Only update rect in selection
emit selectedTextChanged();
- if(d->lastSelectionStart != d->control->selectionStart()){
- d->lastSelectionStart = d->control->selectionStart();
- if(d->lastSelectionStart == -1)
- d->lastSelectionStart = d->control->cursor();
+ int newSelectionStart = d->control->hasSelectedText() ? d->control->selectionStart() : d->control->cursor();
+ int newSelectionEnd = d->control->hasSelectedText() ? d->control->selectionEnd() : d->control->cursor();
+
+ if (d->lastSelectionStart != newSelectionStart) {
+ d->lastSelectionStart = newSelectionStart;
emit selectionStartChanged();
}
- if(d->lastSelectionEnd != d->control->selectionEnd()){
- d->lastSelectionEnd = d->control->selectionEnd();
- if(d->lastSelectionEnd == -1)
- d->lastSelectionEnd = d->control->cursor();
+ if (d->lastSelectionEnd != newSelectionEnd) {
+ d->lastSelectionEnd = newSelectionEnd;
emit selectionEndChanged();
}
}
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index c785f4e3..6db26e1f 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -2733,7 +2733,7 @@ void tst_qdeclarativetextinput::deselect()
textInput->deselect();
QCOMPARE(selectionStartSpy.count(), 2);
- QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectionEndSpy.count(), 0);
QCOMPARE(selectedTextSpy.count(), 2);
QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
@@ -2743,7 +2743,7 @@ void tst_qdeclarativetextinput::deselect()
textInput->select(5, 6);
QCOMPARE(selectionStartSpy.count(), 3);
- QCOMPARE(selectionEndSpy.count(), 1);
+ QCOMPARE(selectionEndSpy.count(), 0);
QCOMPARE(selectedTextSpy.count(), 3);
QCOMPARE(textInput->selectionStart(), 5);
QCOMPARE(textInput->selectionEnd(), 6);
@@ -2755,8 +2755,8 @@ void tst_qdeclarativetextinput::deselect()
QApplication::sendEvent(canvas, &leftArrowPress);
QApplication::sendEvent(canvas, &leftArrowRelese);
- QCOMPARE(selectionStartSpy.count(), 4);
- QCOMPARE(selectionEndSpy.count(), 2);
+ QCOMPARE(selectionStartSpy.count(), 3);
+ QCOMPARE(selectionEndSpy.count(), 1);
QCOMPARE(selectedTextSpy.count(), 4);
QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
@@ -2765,8 +2765,8 @@ void tst_qdeclarativetextinput::deselect()
textInput->select(5, 6);
- QCOMPARE(selectionStartSpy.count(), 4);
- QCOMPARE(selectionEndSpy.count(), 3);
+ QCOMPARE(selectionStartSpy.count(), 3);
+ QCOMPARE(selectionEndSpy.count(), 2);
QCOMPARE(selectedTextSpy.count(), 5);
QCOMPARE(textInput->selectionStart(), 5);
QCOMPARE(textInput->selectionEnd(), 6);
@@ -2778,9 +2778,8 @@ void tst_qdeclarativetextinput::deselect()
QInputMethodEvent event(QLatin1String(""), attributes);
QApplication::sendEvent(canvas, &event);
- QCOMPARE(selectionStartSpy.count(), 5);
- QCOMPARE(selectionEndSpy.count(), 4);
- QEXPECT_FAIL("", "QTBUG-24036", Continue);
+ QCOMPARE(selectionStartSpy.count(), 4);
+ QCOMPARE(selectionEndSpy.count(), 3);
QCOMPARE(selectedTextSpy.count(), 6);
QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());
@@ -2789,9 +2788,8 @@ void tst_qdeclarativetextinput::deselect()
textInput->setCursorPosition(1);
- QCOMPARE(selectionStartSpy.count(), 6);
- QCOMPARE(selectionEndSpy.count(), 5);
- QEXPECT_FAIL("", "QTBUG-24036", Continue);
+ QCOMPARE(selectionStartSpy.count(), 5);
+ QCOMPARE(selectionEndSpy.count(), 4);
QCOMPARE(selectedTextSpy.count(), 6);
QKeyEvent leftArrowShiftPress(QEvent::KeyPress, Qt::Key_Left, Qt::ShiftModifier);
@@ -2799,9 +2797,8 @@ void tst_qdeclarativetextinput::deselect()
QApplication::sendEvent(canvas, &leftArrowShiftPress);
QApplication::sendEvent(canvas, &leftArrowShiftRelese);
- QCOMPARE(selectionStartSpy.count(), 7);
- QCOMPARE(selectionEndSpy.count(), 5);
- QEXPECT_FAIL("", "QTBUG-24036", Continue);
+ QCOMPARE(selectionStartSpy.count(), 6);
+ QCOMPARE(selectionEndSpy.count(), 4);
QCOMPARE(selectedTextSpy.count(), 7);
QCOMPARE(textInput->selectionStart(), 0);
QCOMPARE(textInput->selectionEnd(), 1);
@@ -2810,9 +2807,8 @@ void tst_qdeclarativetextinput::deselect()
QApplication::sendEvent(canvas, &event);
- QEXPECT_FAIL("", "QTBUG-24036", Abort);
- QCOMPARE(selectionStartSpy.count(), 8);
- QCOMPARE(selectionEndSpy.count(), 6);
+ QCOMPARE(selectionStartSpy.count(), 6);
+ QCOMPARE(selectionEndSpy.count(), 5);
QCOMPARE(selectedTextSpy.count(), 8);
QCOMPARE(textInput->selectionStart(), textInput->cursorPosition());
QCOMPARE(textInput->selectionEnd(), textInput->cursorPosition());