summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDyami Caliri <dyami@dragonframe.com>2014-09-17 18:11:57 (GMT)
committerDyami Caliri <dyami@dragonframe.com>2014-09-29 16:03:26 (GMT)
commit45de76f8e071edcf77bc3bd006f052fe5b3f01fc (patch)
tree2c5ecb9dd2d2c8ccdeaaa284faf75904f1ccd706
parentd1b700ef29ab95ac999a9644f1b3c62333f8da19 (diff)
downloadQt-45de76f8e071edcf77bc3bd006f052fe5b3f01fc.zip
Qt-45de76f8e071edcf77bc3bd006f052fe5b3f01fc.tar.gz
Qt-45de76f8e071edcf77bc3bd006f052fe5b3f01fc.tar.bz2
QLineEdit: Disable standard key 'cut' when there is no selection.
(cherry-picked from qtbase/0aa84a619ea0a7c85a1ed48ed28817d4c7e40b33) Task-number: QTBUG-40477 Change-Id: I48aa7ecc4ee8a8e4e9feaf9b6cba5109d2d1f725 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r--src/gui/widgets/qlinecontrol.cpp2
-rw-r--r--tests/auto/qlineedit/tst_qlineedit.cpp29
2 files changed, 30 insertions, 1 deletions
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index 8ff2aea..df8269f 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -1699,7 +1699,7 @@ void QLineControl::processKeyEvent(QKeyEvent* event)
}
}
else if (event == QKeySequence::Cut) {
- if (!isReadOnly()) {
+ if (!isReadOnly() && hasSelectedText()) {
copy();
del();
}
diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp
index 6431e34..22f39f2 100644
--- a/tests/auto/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/qlineedit/tst_qlineedit.cpp
@@ -236,6 +236,7 @@ private slots:
#ifndef QT_NO_CLIPBOARD
void cut();
+ void cutWithoutSelection();
void copy();
void paste();
#endif
@@ -3013,6 +3014,34 @@ void tst_QLineEdit::cut()
QCOMPARE(testWidget->text(), QString("Abcdefg defg hijklmno"));
}
+void tst_QLineEdit::cutWithoutSelection()
+{
+ enum { selectionLength = 1 };
+
+ if (QKeySequence(QKeySequence::Cut).toString() != QLatin1String("Ctrl+X"))
+ QSKIP("Platform with non-standard keybindings", SkipAll);
+ QClipboard *clipboard = QApplication::clipboard();
+#ifdef Q_WS_X11
+ clipboard = 0; // Avoid unstable X11 clipboard
+#endif
+
+ if (clipboard)
+ clipboard->clear();
+ const QString origText("test");
+ QLineEdit lineEdit(origText);
+ lineEdit.setCursorPosition(0);
+ QVERIFY(!lineEdit.hasSelectedText());
+ QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier);
+ QCOMPARE(lineEdit.text(), origText); // No selection, unmodified.
+ if (clipboard)
+ QVERIFY(clipboard->text().isEmpty());
+ lineEdit.setSelection(0, selectionLength);
+ QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier);
+ QCOMPARE(lineEdit.text(), origText.right(origText.size() - selectionLength));
+ if (clipboard)
+ QCOMPARE(clipboard->text(), origText.left(selectionLength));
+}
+
void tst_QLineEdit::copy()
{
DEPENDS_ON("cut");