From df19bffbd9a3a8bd69acf1ff6f3ba9c4649d13be Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 9 Mar 2012 18:28:12 -0800 Subject: Move tst_qshortcut.cpp to QtWidgets QShortcut belongs to QtWidgets instead of QtGui. Change-Id: I9715399bb372a6ea4bd76109f87ba31a1e30a7e6 Reviewed-by: Gunnar Sletta Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/kernel.pro | 1 + tests/auto/widgets/kernel/qshortcut/.gitignore | 1 + tests/auto/widgets/kernel/qshortcut/qshortcut.pro | 12 + .../widgets/kernel/qshortcut/tst_qshortcut.cpp | 1259 ++++++++++++++++++++ 4 files changed, 1273 insertions(+) create mode 100644 tests/auto/widgets/kernel/qshortcut/.gitignore create mode 100644 tests/auto/widgets/kernel/qshortcut/qshortcut.pro create mode 100644 tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index 3a00300ac3..cf909b7e87 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -14,6 +14,7 @@ SUBDIRS=\ qwidget_window \ qwidgetaction \ qicon \ + qshortcut \ SUBDIRS -= qsound diff --git a/tests/auto/widgets/kernel/qshortcut/.gitignore b/tests/auto/widgets/kernel/qshortcut/.gitignore new file mode 100644 index 0000000000..3a17eb18e3 --- /dev/null +++ b/tests/auto/widgets/kernel/qshortcut/.gitignore @@ -0,0 +1 @@ +tst_qshortcut diff --git a/tests/auto/widgets/kernel/qshortcut/qshortcut.pro b/tests/auto/widgets/kernel/qshortcut/qshortcut.pro new file mode 100644 index 0000000000..7ac1dd2c9d --- /dev/null +++ b/tests/auto/widgets/kernel/qshortcut/qshortcut.pro @@ -0,0 +1,12 @@ +CONFIG += testcase +TARGET = tst_qshortcut + +# Project Configuration ---------------------------------------------- +INCLUDEPATH += ../ + +# Normal Test Files -------------------------------------------------- +QT += widgets testlib +HEADERS += +SOURCES += tst_qshortcut.cpp + + diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp new file mode 100644 index 0000000000..61efb6e3f3 --- /dev/null +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -0,0 +1,1259 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class AccelForm; +QT_BEGIN_NAMESPACE +class QMainWindow; +class QTextEdit; +QT_END_NAMESPACE + +class tst_QShortcut : public QObject +{ + Q_OBJECT +public: + tst_QShortcut(); + virtual ~tst_QShortcut(); + + + enum Action { + SetupAccel, + TestAccel, + ClearAll + } currentAction; + + enum Widget { + NoWidget, + TriggerSlot1, + TriggerSlot2, + TriggerSlot3, + TriggerSlot4, + TriggerSlot5, + TriggerSlot6, + TriggerSlot7 + }; + + enum Result { + NoResult, + Slot1Triggered, + Slot2Triggered, + Slot3Triggered, + Slot4Triggered, + Slot5Triggered, + Slot6Triggered, + Slot7Triggered, + Ambiguous + } currentResult; + +public slots: + void slotTrig1() { currentResult = Slot1Triggered; } + void slotTrig2() { currentResult = Slot2Triggered; } + void slotTrig3() { currentResult = Slot3Triggered; } + void slotTrig4() { currentResult = Slot4Triggered; } + void slotTrig5() { currentResult = Slot5Triggered; } + void slotTrig6() { currentResult = Slot6Triggered; } + void slotTrig7() { currentResult = Slot7Triggered; } + void ambigSlot1() { currentResult = Ambiguous; ambigResult = Slot1Triggered; } + void ambigSlot2() { currentResult = Ambiguous; ambigResult = Slot2Triggered; } + void ambigSlot3() { currentResult = Ambiguous; ambigResult = Slot3Triggered; } + void ambigSlot4() { currentResult = Ambiguous; ambigResult = Slot4Triggered; } + void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; } + void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; } + void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; } + void statusMessage( const QString& message ) { sbText = message; } + void shortcutDestroyed(QObject* obj); + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void number_data(); + void number(); + void text_data(); + void text(); + void disabledItems(); + void ambiguousItems(); + void ambiguousRotation(); + void keypressConsumption(); + void unicodeCompare(); + void context(); + +protected: + static Qt::KeyboardModifiers toButtons( int key ); + void defElements(); + + void clearAllShortcuts(); + QShortcut *setupShortcut(int testWidget, const QKeySequence &ks); + QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); + + QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); + QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); + + void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); + void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); + + void testElement(); + + QMainWindow *mainW; + QList shortcuts; + QTextEdit *edit; + QString sbText; + Result ambigResult; +}; + +Q_DECLARE_METATYPE(tst_QShortcut::Widget); +Q_DECLARE_METATYPE(tst_QShortcut::Result); +Q_DECLARE_METATYPE(tst_QShortcut::Action); + +class TestEdit : public QTextEdit +{ + Q_OBJECT +public: + TestEdit(QWidget *parent, const char *name) + : QTextEdit(parent) + { + setObjectName(name); + } + +protected: + bool event(QEvent *e) { + // Make testedit allow any Ctrl+Key as shortcut + if (e->type() == QEvent::ShortcutOverride) { + QKeyEvent *ke = static_cast(e); + if (ke->modifiers() == Qt::ControlModifier + && ke->key() > Qt::Key_Any + && ke->key() < Qt::Key_ydiaeresis) { + ke->ignore(); + return true; + } + } + + // If keypress not processed as normal, check for + // Ctrl+Key event, and input custom string for + // result comparison. + if (e->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(e); + if (ke->modifiers() && ke->key() > Qt::Key_Any + && ke->key() < Qt::Key_ydiaeresis) { + if (ke->modifiers() == Qt::ControlModifier) + insertPlainText(QString("").arg(char(ke->key()))); + else if (ke->modifiers() == Qt::AltModifier) + insertPlainText(QString("").arg(char(ke->key()))); + else if (ke->modifiers() == Qt::ShiftModifier) + insertPlainText(QString("").arg(char(ke->key()))); + return true; + } + } + return QTextEdit::event(e); + } +}; + +tst_QShortcut::tst_QShortcut(): mainW( 0 ) +{ +} + +tst_QShortcut::~tst_QShortcut() +{ + clearAllShortcuts(); +} + +void tst_QShortcut::initTestCase() +{ + currentResult = NoResult; + mainW = new QMainWindow(0); + mainW->setWindowFlags(Qt::X11BypassWindowManagerHint); + edit = new TestEdit(mainW, "test_edit"); + mainW->setFixedSize( 100, 100 ); + mainW->setCentralWidget( edit ); + mainW->show(); + QTest::qWaitForWindowShown(mainW); + mainW->activateWindow(); + QTest::qWait(100); + connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)), + this, SLOT(statusMessage(const QString&)) ); +} + +void tst_QShortcut::cleanupTestCase() +{ + delete mainW; +} + +Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) +{ + Qt::KeyboardModifiers result = Qt::NoModifier; + if ( key & Qt::SHIFT ) + result |= Qt::ShiftModifier; + if ( key & Qt::CTRL ) + result |= Qt::ControlModifier; + if ( key & Qt::META ) + result |= Qt::MetaModifier; + if ( key & Qt::ALT ) + result |= Qt::AltModifier; + return result; +} + +void tst_QShortcut::defElements() +{ + QTest::addColumn("action"); + QTest::addColumn("testWidget"); + QTest::addColumn("txt"); + QTest::addColumn("k1"); + QTest::addColumn("c1"); + QTest::addColumn("k2"); + QTest::addColumn("c2"); + QTest::addColumn("k3"); + QTest::addColumn("c3"); + QTest::addColumn("k4"); + QTest::addColumn("c4"); + QTest::addColumn("result"); +} + +void tst_QShortcut::number() +{ + // We expect a failure on these tests, until QtTestKeyboard is + // fixed to do real platform dependent keyboard simulations + if (QTest::currentDataTag() == QString("N006a:Shift+Tab - [BackTab]") + || QTest::currentDataTag() == QString("N006b:Shift+Tab - [Shift+BackTab]")) + QEXPECT_FAIL("", "FLAW IN QTESTKEYBOARD: Keyboard events not passed through " + "platform dependent key handling code", Continue); + testElement(); +} +void tst_QShortcut::text() +{ + testElement(); +} +// ------------------------------------------------------------------ +// Number Elements -------------------------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::number_data() +{ + defElements(); + + // Clear all + QTest::newRow("N00 - clear") << ClearAll << NoWidget <activateWindow(); + qApp->syncX(); + QTest::qWait(100); + + /* Testing Disabled Shortcuts + Qt::Key_M on slot1 + Shift + Qt::Key_M on slot1 + Qt::Key_M on slot2 (disabled) + Shift + Qt::Key_M on slot2 (disabled) + */ + + // Setup two identical shortcuts on different pushbuttons + QPushButton pb1(mainW); + QPushButton pb2(mainW); + pb1.setObjectName("pushbutton-1"); + pb2.setObjectName("pushbutton-2"); + pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger + pb2.show(); + + QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); + QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M"); + QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M"); + QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M"); + + cut3->setEnabled(false); + cut4->setEnabled(false); + + currentResult = NoResult; + sendKeyEvents(Qt::Key_M, 'm'); + QCOMPARE(currentResult, Slot1Triggered); + + currentResult = NoResult; + sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M'); + QCOMPARE(currentResult, Slot1Triggered); + + cut2->setEnabled(false); + cut4->setEnabled(true); + + /* Testing Disabled Shortcuts + Qt::Key_M on slot1 + Shift + Qt::Key_M on slot1 (disabled) + Qt::Key_M on slot2 (disabled) + Shift + Qt::Key_M on slot2 + */ + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Slot1Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' ); + QCOMPARE( currentResult, Slot2Triggered ); + + + /* Testing Disabled Accel + Qt::Key_F5 on slot1 + Shift + Qt::Key_F5 on slot2 (disabled) + */ + clearAllShortcuts(); + cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5"); + cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5"); + + cut1->setKey(QKeySequence("F5")); + cut4->setKey(QKeySequence("Shift+F5")); + + cut1->setEnabled(true); + cut4->setEnabled(false); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_F5, 0 ); + QCOMPARE( currentResult, Slot1Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 ); + QCOMPARE( currentResult, NoResult ); + +#if 0 + qFatal("Not testing statusbar text feedback yet, since not implemented"); + /* Testing Disabled Accel, and the corresponding statusbar feedback + Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1 + Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled) + */ + cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L")); + cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M")); + + cut1->setEnabled(true); + cut4->setEnabled(false); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); + sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 ); + QCOMPARE( currentResult, NoResult ); + if (over_330) + QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") ); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); + sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + QCOMPARE( currentResult, NoResult ); + if (over_330) + QCOMPARE( sbText, QString::null ); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); + sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 ); + QCOMPARE( currentResult, Slot1Triggered ); + if (over_330) + QCOMPARE( sbText, QString::null ); +#endif + clearAllShortcuts(); + cut1 = 0; + cut4 = 0; +} +// ------------------------------------------------------------------ +// Ambiguous Elements ----------------------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::ambiguousRotation() +{ + clearAllShortcuts(); + /* Testing Shortcut rotation scheme + Ctrl + Qt::Key_A on slot1 (disabled) + Ctrl + Qt::Key_A on slot2 (disabled) + Ctrl + Qt::Key_A on slot3 + Ctrl + Qt::Key_A on slot4 + Ctrl + Qt::Key_A on slot5 (disabled) + Ctrl + Qt::Key_A on slot6 + Ctrl + Qt::Key_A on slot7 (disabled) + */ + QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A"); + QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A"); + QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A"); + QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A"); + QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A"); + QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A"); + QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A"); + + cut1->setEnabled(false); + cut2->setEnabled(false); + cut5->setEnabled(false); + cut7->setEnabled(false); + + // Test proper rotation + // Start on first + // Go to last + // Go back to first + // Continue... + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot3Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot4Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot6Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot3Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot4Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot6Triggered); + + /* Testing Shortcut rotation scheme + Ctrl + Qt::Key_A on slot1 + Ctrl + Qt::Key_A on slot2 + Ctrl + Qt::Key_A on slot3 (disabled) + Ctrl + Qt::Key_A on slot4 (disabled) + Ctrl + Qt::Key_A on slot5 + Ctrl + Qt::Key_A on slot6 (disabled) + Ctrl + Qt::Key_A on slot7 + */ + + cut1->setEnabled(true); + cut2->setEnabled(true); + cut5->setEnabled(true); + cut7->setEnabled(true); + + cut3->setEnabled(false); + cut4->setEnabled(false); + cut6->setEnabled(false); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot1Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot2Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot5Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot7Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot1Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot2Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot5Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot7Triggered); + + clearAllShortcuts(); + cut1 = 0; cut2 = 0; + cut3 = 0; cut4 = 0; + cut5 = 0; cut6 = 0; + cut7 = 0; +} + +void tst_QShortcut::ambiguousItems() +{ + clearAllShortcuts(); + /* Testing Ambiguous Shortcuts + Qt::Key_M on Pushbutton 1 + Qt::Key_M on Pushbutton 2 + */ + + // Setup two identical shortcuts on different pushbuttons + QPushButton pb1(mainW); + QPushButton pb2(mainW); + pb1.setObjectName("pushbutton-1"); + pb2.setObjectName("pushbutton-2"); + pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger + pb2.show(); + + setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); + setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M"); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Ambiguous ); + QCOMPARE( ambigResult, Slot1Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Ambiguous ); + QCOMPARE( ambigResult, Slot2Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Ambiguous ); + QCOMPARE( ambigResult, Slot1Triggered ); + + clearAllShortcuts(); +} + + +// ------------------------------------------------------------------ +// Unicode and non-unicode Elements --------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::unicodeCompare() +{ + clearAllShortcuts(); + /* Testing Unicode/non-Unicode Shortcuts + Qt::Key_M on Pushbutton 1 + Qt::Key_M on Pushbutton 2 + */ + QPushButton pb1(mainW); + QPushButton pb2(mainW); + pb1.setObjectName("pushbutton-1"); + pb2.setObjectName("pushbutton-2"); + pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger + pb2.show(); + + QKeySequence ks1("Ctrl+M"); // Unicode + QKeySequence ks2(Qt::CTRL+Qt::Key_M); // non-Unicode + setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1); + setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + QCOMPARE( currentResult, Ambiguous ); + // They _are_ ambiguous, so the QKeySequence operator== + // should indicate the same + QVERIFY( ks1 == ks2 ); + QVERIFY( !(ks1 != ks2) ); + + clearAllShortcuts(); +} + +// ------------------------------------------------------------------ +// Keypress consumption verification -------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::keypressConsumption() +{ + clearAllShortcuts(); + edit->clear(); + QCOMPARE(edit->toPlainText().size(), 0); + + QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A"); + QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B"); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QCOMPARE(edit->toPlainText(), QString("")); + + // Make sure next keypress is eaten (failing multiple keysequence) + sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QCOMPARE(edit->toPlainText(), QString("")); + + // Next keypress should be normal + sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QCOMPARE(edit->toPlainText(), QString("c")); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + QCOMPARE(edit->toPlainText().size(), 0); + + cut1->setEnabled(false); + cut2->setEnabled(false); + + // Make sure keypresses is passed on, since all multiple keysequences + // with Ctrl+I are disabled + sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QVERIFY(edit->toPlainText().endsWith("")); + + sendKeyEvents(edit, Qt::Key_A, 'a'); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QVERIFY(edit->toPlainText().endsWith("a")); + + clearAllShortcuts(); +} + +// ------------------------------------------------------------------ +// Context Validation ----------------------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::context() +{ + clearAllShortcuts(); + + QWidget myBox; + TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1"); + TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2"); + QHBoxLayout *layout = new QHBoxLayout(&myBox); + layout->addWidget(other1); + layout->addWidget(other2); + myBox.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&myBox); +#endif + + setupShortcut(other1, "ActiveWindow", TriggerSlot1, QKeySequence("Alt+1"), Qt::WindowShortcut); + setupShortcut(other2, "Focus", TriggerSlot2, QKeySequence("Alt+2"), Qt::WidgetShortcut); + setupShortcut(edit, "Application", TriggerSlot3, QKeySequence("Alt+3"), Qt::ApplicationShortcut); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + // edit doesn't have focus, so ActiveWindow context should work + // ..but Focus context shouldn't.. + // Changing focus to edit should make focus context work + // Application context should always work + + + // Focus on 'other1' edit, so Active Window context should trigger + other1->activateWindow(); // <--- + QApplication::setActiveWindow(other1); + QCOMPARE(qApp->activeWindow(), other1->window()); + QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + sendKeyEvents(other1, Qt::ALT+Qt::Key_1); + QCOMPARE(currentResult, Slot1Triggered); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + // ..but not Focus context on 'other2'.. + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + sendKeyEvents(other1, Qt::ALT+Qt::Key_2); + QCOMPARE(currentResult, NoResult); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + // ..however, application global context on 'edit' should.. + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + sendKeyEvents(other1, Qt::ALT+Qt::Key_3); + QCOMPARE(currentResult, Slot3Triggered); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + // Changing focus to 'other2' should make the Focus context there work + other2->activateWindow(); + other2->setFocus(); // ### + qApp->syncX(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(other2); +#endif + QTest::qWait(100); + QCOMPARE(qApp->activeWindow(), other2->window()); + QCOMPARE(qApp->focusWidget(), (QWidget *)other2); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + sendKeyEvents(other2, Qt::ALT+Qt::Key_2); + QCOMPARE(currentResult, Slot2Triggered); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + clearAllShortcuts(); + delete other1; + delete other2; + edit->activateWindow(); + qApp->syncX(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(edit); +#endif + QTest::qWait(100); +} + +// ------------------------------------------------------------------ +// Element Testing helper functions --------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::clearAllShortcuts() +{ + QList shortcutsCpy = shortcuts; + qDeleteAll(shortcutsCpy); + shortcuts.clear(); +} + +QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks) +{ + return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks); +} + +QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4) +{ + return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, + (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); +} + +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4) +{ + return setupShortcut(parent, name, testWidget, + (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); +} + +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, + const QKeySequence &ks, Qt::ShortcutContext context) +{ + // Set up shortcut for next test + QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context); + cut->setObjectName(name); + cut->setKey(ks); + + const char *normal = 0; + const char *ambig = 0; + switch(testWidget) + { + case TriggerSlot1: + normal = SLOT(slotTrig1()); + ambig = SLOT(ambigSlot1()); + break; + case TriggerSlot2: + normal = SLOT(slotTrig2()); + ambig = SLOT(ambigSlot2()); + break; + case TriggerSlot3: + normal = SLOT(slotTrig3()); + ambig = SLOT(ambigSlot3()); + break; + case TriggerSlot4: + normal = SLOT(slotTrig4()); + ambig = SLOT(ambigSlot4()); + break; + case TriggerSlot5: + normal = SLOT(slotTrig5()); + ambig = SLOT(ambigSlot5()); + break; + case TriggerSlot6: + normal = SLOT(slotTrig6()); + ambig = SLOT(ambigSlot6()); + break; + case TriggerSlot7: + normal = SLOT(slotTrig7()); + ambig = SLOT(ambigSlot7()); + break; + } + connect(cut, SIGNAL(activated()), this, normal); + connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); + connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*))); + shortcuts.append(cut); + return cut; +} + +void tst_QShortcut::shortcutDestroyed(QObject* obj) +{ + shortcuts.removeAll(static_cast(obj)); +} + +void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) +{ + sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4); +} + +void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) +{ + Qt::KeyboardModifiers b1 = toButtons( k1 ); + Qt::KeyboardModifiers b2 = toButtons( k2 ); + Qt::KeyboardModifiers b3 = toButtons( k3 ); + Qt::KeyboardModifiers b4 = toButtons( k4 ); + k1 &= ~Qt::MODIFIER_MASK; + k2 &= ~Qt::MODIFIER_MASK; + k3 &= ~Qt::MODIFIER_MASK; + k4 &= ~Qt::MODIFIER_MASK; + + + if (k1 || c1.toAscii()) { + QString c(c1.unicode() == QChar::Null ? QString() : QString(c1)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k1), c, b1); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k1), c, b1); + } + + if (k2 || c2.toAscii()) { + QString c(c2.unicode() == QChar::Null ? QString() : QString(c2)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k2), c, b2); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k2), c, b2); + } + + if (k3 || c3.toAscii()) { + QString c(c3.unicode() == QChar::Null ? QString() : QString(c3)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k3), c, b3); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k3), c, b3); + } + + if (k4 || c4.toAscii()) { + QString c(c4.unicode() == QChar::Null ? QString() : QString(c4)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k4), c, b4); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k4), c, b4); + } +} + +void tst_QShortcut::testElement() +{ + currentResult = NoResult; + QFETCH(tst_QShortcut::Action, action); + QFETCH(tst_QShortcut::Widget, testWidget); + QFETCH(QString, txt); + QFETCH(int, k1); + QFETCH(int, c1); + QFETCH(int, k2); + QFETCH(int, c2); + QFETCH(int, k3); + QFETCH(int, c3); + QFETCH(int, k4); + QFETCH(int, c4); + QFETCH(tst_QShortcut::Result, result); + + if (action == ClearAll) { + clearAllShortcuts(); + } else if (action == SetupAccel) { + setupShortcut(testWidget, txt, k1, k2, k3, k4); + } else { + sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); + QCOMPARE(currentResult, result); + } +} + +QTEST_MAIN(tst_QShortcut) +#include "tst_qshortcut.moc" -- cgit v1.2.3 From b64426248d2212eb59535b2ca383d30fdb5e1c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Sat, 3 Mar 2012 06:05:54 +0100 Subject: QHeaderView - renaming functions in Qt5 This patch renames the functions in Qt5 according to the notes. It also renames resizeMode to be consistent. The old functions are both marked with both QT_DEPRECATED and '### Qt 6 - remove' All usage of the function within the qtbase are also changed to use the new functions. Change-Id: I9e05fa41d232e9ca43b945fcc949987017f3aedd Reviewed-by: Stephen Kelly --- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 2 +- .../itemviews/qheaderview/tst_qheaderview.cpp | 60 +++++++++++----------- 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index fe374b1e8d..1a3d083864 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -847,7 +847,7 @@ void tst_QFileSystemModel::sort() tree->resize(800, 800); QTest::qWait(500); tree->header()->setSortIndicator(1,Qt::DescendingOrder); - tree->header()->setResizeMode(0, QHeaderView::ResizeToContents); + tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); QStringList dirsToOpen; do { diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 3edc125b5a..9ad71771c5 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -502,20 +502,20 @@ void tst_QHeaderView::removeCols() void tst_QHeaderView::movable() { - QCOMPARE(view->isMovable(), false); - view->setMovable(false); - QCOMPARE(view->isMovable(), false); - view->setMovable(true); - QCOMPARE(view->isMovable(), true); + QCOMPARE(view->sectionsMovable(), false); + view->setSectionsMovable(false); + QCOMPARE(view->sectionsMovable(), false); + view->setSectionsMovable(true); + QCOMPARE(view->sectionsMovable(), true); } void tst_QHeaderView::clickable() { - QCOMPARE(view->isClickable(), false); - view->setClickable(false); - QCOMPARE(view->isClickable(), false); - view->setClickable(true); - QCOMPARE(view->isClickable(), true); + QCOMPARE(view->sectionsClickable(), false); + view->setSectionsClickable(false); + QCOMPARE(view->sectionsClickable(), false); + view->setSectionsClickable(true); + QCOMPARE(view->sectionsClickable(), true); } void tst_QHeaderView::hidden() @@ -1108,7 +1108,7 @@ void tst_QHeaderView::resizeWithResizeModes() view->setStretchLastSection(false); for (int i = 0; i < sections.count(); ++i) { view->resizeSection(i, sections.at(i)); - view->setResizeMode(i, (QHeaderView::ResizeMode)modes.at(i)); + view->setSectionResizeMode(i, (QHeaderView::ResizeMode)modes.at(i)); } topLevel->show(); view->resize(size, size); @@ -1150,27 +1150,27 @@ void tst_QHeaderView::resizeMode() // resizeMode must not be called with an invalid index int last = view->count() - 1; view->setResizeMode(QHeaderView::Interactive); - QCOMPARE(view->resizeMode(last), QHeaderView::Interactive); - QCOMPARE(view->resizeMode(1), QHeaderView::Interactive); + QCOMPARE(view->sectionResizeMode(last), QHeaderView::Interactive); + QCOMPARE(view->sectionResizeMode(1), QHeaderView::Interactive); view->setResizeMode(QHeaderView::Stretch); - QCOMPARE(view->resizeMode(last), QHeaderView::Stretch); - QCOMPARE(view->resizeMode(1), QHeaderView::Stretch); + QCOMPARE(view->sectionResizeMode(last), QHeaderView::Stretch); + QCOMPARE(view->sectionResizeMode(1), QHeaderView::Stretch); view->setResizeMode(QHeaderView::Custom); - QCOMPARE(view->resizeMode(last), QHeaderView::Custom); - QCOMPARE(view->resizeMode(1), QHeaderView::Custom); + QCOMPARE(view->sectionResizeMode(last), QHeaderView::Custom); + QCOMPARE(view->sectionResizeMode(1), QHeaderView::Custom); // test when sections have been moved view->setStretchLastSection(false); for (int i=0; i < (view->count() - 1); ++i) - view->setResizeMode(i, QHeaderView::Interactive); + view->setSectionResizeMode(i, QHeaderView::Interactive); int logicalIndex = view->count() / 2; - view->setResizeMode(logicalIndex, QHeaderView::Stretch); + view->setSectionResizeMode(logicalIndex, QHeaderView::Stretch); view->moveSection(view->visualIndex(logicalIndex), 0); for (int i=0; i < (view->count() - 1); ++i) { if (i == logicalIndex) - QCOMPARE(view->resizeMode(i), QHeaderView::Stretch); + QCOMPARE(view->sectionResizeMode(i), QHeaderView::Stretch); else - QCOMPARE(view->resizeMode(i), QHeaderView::Interactive); + QCOMPARE(view->sectionResizeMode(i), QHeaderView::Interactive); } } @@ -1209,12 +1209,12 @@ void tst_QHeaderView::resizeSection() view->resize(400, 400); topLevel->show(); - view->setMovable(true); + view->setSectionsMovable(true); view->setStretchLastSection(false); for (int i = 0; i < logical.count(); ++i) if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now - view->setResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i)); + view->setSectionResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i)); for (int j = 0; j < logical.count(); ++j) view->resizeSection(logical.at(j), initial); @@ -1447,7 +1447,7 @@ void tst_QHeaderView::stretchSectionCount() view->setStretchLastSection(true); QCOMPARE(view->stretchSectionCount(), 0); - view->setResizeMode(0, QHeaderView::Stretch); + view->setSectionResizeMode(0, QHeaderView::Stretch); QCOMPARE(view->stretchSectionCount(), 1); } @@ -1693,7 +1693,7 @@ void tst_QHeaderView::globalResizeMode() h.setResizeMode((QHeaderView::ResizeMode)mode); m.insertRow(insert); for (int i = 0; i < h.count(); ++i) - QCOMPARE(h.resizeMode(i), (QHeaderView::ResizeMode)mode); + QCOMPARE(h.sectionResizeMode(i), (QHeaderView::ResizeMode)mode); } @@ -1725,7 +1725,7 @@ void tst_QHeaderView::sectionPressedSignal() h.setModel(&m); h.show(); - h.setClickable(clickable); + h.setSectionsClickable(clickable); QSignalSpy spy(&h, SIGNAL(sectionPressed(int))); @@ -1745,7 +1745,7 @@ void tst_QHeaderView::sectionClickedSignal() h.setModel(&m); h.show(); - h.setClickable(clickable); + h.setSectionsClickable(clickable); h.setSortIndicatorShown(true); QSignalSpy spy(&h, SIGNAL(sectionClicked(int))); @@ -1869,7 +1869,7 @@ void tst_QHeaderView::preserveHiddenSectionWidth() view.resizeSection(0, 100); view.resizeSection(1, 10); view.resizeSection(2, 50); - view.setResizeMode(3, QHeaderView::Stretch); + view.setSectionResizeMode(3, QHeaderView::Stretch); view.show(); view.hideSection(2); @@ -2066,7 +2066,7 @@ void tst_QHeaderView::QTBUG7833_sectionClicked() tv.setSortingEnabled(true); tv.horizontalHeader()->setSortIndicatorShown(true); - tv.horizontalHeader()->setClickable(true); + tv.horizontalHeader()->setSectionsClickable(true); tv.horizontalHeader()->setStretchLastSection(true); tv.horizontalHeader()->setResizeMode(QHeaderView::Interactive); @@ -2126,7 +2126,7 @@ void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting() for (int j = 0; j< model->columnCount(); ++j) model->setData(model->index(i,j), QString("item [%1,%2]").arg(i).arg(j)); view.setModel(model); - view.horizontalHeader()->setMovable(true); + view.horizontalHeader()->setSectionsMovable(true); view.setSortingEnabled(true); view.sortByColumn(1, Qt::AscendingOrder); view.horizontalHeader()->moveSection(0,2); -- cgit v1.2.3 From d6311a06515221e41edb69722b571080c08d11ce Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Fri, 16 Dec 2011 13:12:39 +0100 Subject: Cocoa: Improve basic window handling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor NSWindow creation into createNSWindow and setNSWindow. This is necessary to support QMacNativeWidget where we re-use an already created window. Implement popup window handling. Make sure the window is displayed correctly and closes when it should. Take control over window activation in order to prevent infinite loops involving the QtCreator "cmd-k" window. Activation events are for now not sent to popup-type windows. There is now a different set of test failures: add and remove some QEXPECT_FAILs. Change-Id: I229761b59f90c9815b968eacc2cbc9c20cc5047e Reviewed-by: Morten Johan Sørvig --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 3 --- .../qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 3 --- tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp | 17 ++--------------- tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 3 --- .../widgets/widgets/qdockwidget/tst_qdockwidget.cpp | 3 +++ 5 files changed, 5 insertions(+), 24 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 5c99e48388..98c3866dd2 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1069,9 +1069,6 @@ void tst_QGraphicsItem::toolTip() foundTipLabel = true; } QVERIFY(foundView); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23707", Continue); -#endif QVERIFY(foundTipLabel); } diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 843b584ce5..fef21c19f7 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -2640,9 +2640,6 @@ void tst_QGraphicsProxyWidget::tooltip_basic() foundTipLabel = true; } QVERIFY(foundView); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23707", Continue); -#endif QVERIFY(foundTipLabel); } } diff --git a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp index b47ef659be..e20111c652 100644 --- a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp +++ b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp @@ -90,12 +90,8 @@ void tst_QToolTip::task183679_data() { QTest::addColumn("key"); QTest::addColumn("visible"); -#ifdef Q_OS_MAC - const bool visibleAfterNonModifier = false; -#else - const bool visibleAfterNonModifier = true; -#endif - QTest::newRow("non-modifier") << Qt::Key_A << visibleAfterNonModifier; + + QTest::newRow("non-modifier") << Qt::Key_A << true; QTest::newRow("Shift") << Qt::Key_Shift << true; QTest::newRow("Control") << Qt::Key_Control << true; QTest::newRow("Alt") << Qt::Key_Alt << true; @@ -116,9 +112,6 @@ void tst_QToolTip::task183679() widget.showDelayedToolTip(100); QTest::qWait(300); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23707", Continue); -#endif QTRY_VERIFY(QToolTip::isVisible()); QTest::keyPress(&widget, key); @@ -128,12 +121,6 @@ void tst_QToolTip::task183679() // auto-close timeout (currently 10000 msecs) QTest::qWait(1500); -#ifdef Q_OS_MAC - QEXPECT_FAIL("Shift", "QTBUG-23707", Continue); - QEXPECT_FAIL("Control", "QTBUG-23707", Continue); - QEXPECT_FAIL("Alt", "QTBUG-23707", Continue); - QEXPECT_FAIL("Meta", "QTBUG-23707", Continue); -#endif QCOMPARE(QToolTip::isVisible(), visible); } diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index f9eb8b6159..4730d7d556 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -909,9 +909,6 @@ void tst_QComboBox::hide() QTRY_VERIFY(testWidget->view()->isVisible()); testWidget->hidePopup(); //allow combobox effect to complete -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23678", Continue); -#endif QTRY_VERIFY(!testWidget->view()->isVisible()); testWidget->hide(); QVERIFY(!testWidget->isVisible()); diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 43c0022c25..7e7b049166 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -764,6 +764,9 @@ void tst_QDockWidget::task169808_setFloating() qt_x11_wait_for_window_manager(&mw); #endif +#ifdef Q_OS_MAC + QEXPECT_FAIL("", "Window handling: QTBUG-24774", Abort); +#endif QCOMPARE(dw->widget()->size(), dw->widget()->sizeHint()); //and now we try to test if the contents margin is taken into account -- cgit v1.2.3 From 9e87104295b019a1afa49f856ddcef07249d1afb Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 13 Mar 2012 11:40:25 +0100 Subject: QTableView: call model->submit() on row change QTreeView already does this in the exact same way. It's necessary to call submit() so edit strategy OnRowChange in QSqlTableModel will work as expected. Change-Id: Ib430143e8a71f3b0bcd842fcc772cc7ee4525f0a Reviewed-by: Olivier Goffart --- .../itemviews/qtableview/tst_qtableview.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 9144a023d7..0c396aac60 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -175,6 +175,7 @@ private slots: void tabFocus(); void bigModel(); void selectionSignal(); + void setCurrentIndex(); // task-specific tests: void task173773_updateVerticalHeader(); @@ -254,11 +255,15 @@ class QtTestTableModel: public QAbstractTableModel signals: void invalidIndexEncountered() const; +public slots: + bool submit() { ++submit_count; return QAbstractTableModel::submit(); } + public: QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) : QAbstractTableModel(parent), row_count(rows), column_count(columns), + submit_count(0), can_fetch_more(false), fetch_more_count(0), disabled_rows(), @@ -400,6 +405,7 @@ public: int row_count; int column_count; + int submit_count; bool can_fetch_more; int fetch_more_count; QSet disabled_rows; @@ -3480,6 +3486,27 @@ void tst_QTableView::selectionSignal() QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center()); } +void tst_QTableView::setCurrentIndex() +{ + QtTestTableModel model(4, 4); + QtTestTableView view; + view.setModel(&model); + + // submit() slot should be called in model when current row changes + view.setCurrentIndex(model.index(0,0)); + QCOMPARE(model.submit_count, 1); + view.setCurrentIndex(model.index(0,2)); + QCOMPARE(model.submit_count, 1); + view.setCurrentIndex(model.index(1,0)); + QCOMPARE(model.submit_count, 2); + view.setCurrentIndex(model.index(3,3)); + QCOMPARE(model.submit_count, 3); + view.setCurrentIndex(model.index(0,1)); + QCOMPARE(model.submit_count, 4); + view.setCurrentIndex(model.index(0,0)); + QCOMPARE(model.submit_count, 4); +} + class task173773_EventFilter : public QObject { int paintEventCount_; -- cgit v1.2.3