QTBUG-16850: QLineEdit::setSelection removes blank characters

Changed checking of the start position so that it does not call d->control->text() because this removes blank characters when an input mask is used. Thus the
selection fails. Instead d->control->end() is used for checking the start position.

Task-number: QTBUG-16850
Change-Id: I62992fb81bd47d432bade9f219782d48eb309956
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
bb10
Tarja Sundqvist 2012-05-25 08:39:08 +03:00 committed by Qt by Nokia
parent 79ab7c170d
commit 7266e11297
2 changed files with 12 additions and 1 deletions

View File

@ -907,7 +907,7 @@ int QLineEdit::selectionStart() const
void QLineEdit::setSelection(int start, int length)
{
Q_D(QLineEdit);
if (start < 0 || start > (int)d->control->text().length()) {
if (start < 0 || start > (int)d->control->end()) {
qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
return;
}

View File

@ -272,6 +272,7 @@ private slots:
void QTBUG697_paletteCurrentColorGroup();
void QTBUG13520_textNotVisible();
void QTBUG7174_inputMaskCursorBlink();
void QTBUG16850_setSelection();
void bidiVisualMovement_data();
void bidiVisualMovement();
@ -3722,6 +3723,16 @@ void tst_QLineEdit::QTBUG7174_inputMaskCursorBlink()
QVERIFY(edit.updateRegion.contains(cursorRect));
}
void tst_QLineEdit::QTBUG16850_setSelection()
{
QLineEdit le;
le.setInputMask("00:0");
le.setText(" 1");
le.setSelection(3, 1);
QCOMPARE(le.selectionStart(), 3);
QCOMPARE(le.selectedText(), QString("1"));
}
void tst_QLineEdit::bidiVisualMovement_data()
{
QTest::addColumn<QString>("logical");