aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarno Malmari <ext-jarno.malmari@nokia.com>2010-09-08 15:34:37 +0300
committerPekka Vuorela <pekka.ta.vuorela@nokia.com>2010-09-08 18:03:17 +0300
commit1de4aa4319b36fe8a6018e3a4db12d8a72b68d96 (patch)
tree328f0c1649c6616207e592a20982644eda597733
parent8e3c358a5b1e3170fa3ad5741736dfca970ece71 (diff)
Fixes: NB#189072, QValidator is not invoked when selected text is removed with backspace
RevBy: Pekka Vuorela
-rw-r--r--src/corelib/widgets/mtextedit.cpp6
-rw-r--r--tests/ut_mtextedit/ut_mtextedit.cpp31
-rw-r--r--tests/ut_mtextedit/ut_mtextedit.h2
3 files changed, 37 insertions, 2 deletions
diff --git a/src/corelib/widgets/mtextedit.cpp b/src/corelib/widgets/mtextedit.cpp
index d3ad0679..5f61b6bb 100644
--- a/src/corelib/widgets/mtextedit.cpp
+++ b/src/corelib/widgets/mtextedit.cpp
@@ -1519,14 +1519,16 @@ void MTextEdit::keyPressEvent(QKeyEvent *event)
d->commitPreedit();
}
+ // Whether text was modified, excluding the removal of 'needRemoveFirst' text above.
bool modified = false;
switch (key) {
case Qt::Key_Backspace:
// backspace and delete in selection mode are special cases, only selection is removed
+ // These also need explicit validation here.
if (wasSelecting == false) {
modified = d->doBackspace();
- } else {
+ } else if (d->validateCurrentBlock()) {
d->cursor()->setCharFormat(format);
modified = true;
}
@@ -1535,7 +1537,7 @@ void MTextEdit::keyPressEvent(QKeyEvent *event)
case Qt::Key_Delete:
if (wasSelecting == false) {
modified = d->doDelete();
- } else {
+ } else if (d->validateCurrentBlock()) {
modified = true;
}
break;
diff --git a/tests/ut_mtextedit/ut_mtextedit.cpp b/tests/ut_mtextedit/ut_mtextedit.cpp
index fdde4d37..66fc47cb 100644
--- a/tests/ut_mtextedit/ut_mtextedit.cpp
+++ b/tests/ut_mtextedit/ut_mtextedit.cpp
@@ -1264,6 +1264,37 @@ void Ut_MTextEdit::testValidator()
}
+void Ut_MTextEdit::testValidatorSelectionRemoval_data()
+{
+ QTest::addColumn<int>("selectionRemovingKey");
+
+ QTest::newRow("removing selection with backspace") << static_cast<int>(Qt::Key_Backspace);
+ QTest::newRow("removing selection with delete") << static_cast<int>(Qt::Key_Delete);
+}
+
+void Ut_MTextEdit::testValidatorSelectionRemoval()
+{
+ QFETCH(int, selectionRemovingKey);
+
+ m_appWindow->scene()->addItem(m_subject.get());
+
+ QRegExpValidator abValidator(QRegExp("ab"), 0);
+
+ m_subject->setValidator(&abValidator);
+ m_subject->setText("ab");
+ QCOMPARE(m_subject->text(), QString("ab"));
+
+ // Select "a" and delete it. The result "b" should not be acceptable nor
+ // plausible string, thus original content should still remain.
+ m_subject->setSelection(0, 1);
+
+ QKeyEvent keyEvent(QEvent::KeyPress, selectionRemovingKey, Qt::NoModifier);
+ m_subject->scene()->sendEvent(m_subject.get(), &keyEvent);
+
+ QCOMPARE(m_subject->text(), QString("ab"));
+}
+
+
void Ut_MTextEdit::testClear()
{
// test that clear() works. first set content and then test that after clear the state has reset
diff --git a/tests/ut_mtextedit/ut_mtextedit.h b/tests/ut_mtextedit/ut_mtextedit.h
index 0c713224..2c2aa9f3 100644
--- a/tests/ut_mtextedit/ut_mtextedit.h
+++ b/tests/ut_mtextedit/ut_mtextedit.h
@@ -93,6 +93,8 @@ private slots:
void testAutoSelection();
void testPrompt();
void testValidator();
+ void testValidatorSelectionRemoval_data();
+ void testValidatorSelectionRemoval();
void testClear();
void testCursorPositionChanged();
void testCopyPaste();