tests/auto/qabstractitemview/tst_qabstractitemview.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -46,7 +46,9 @@
 #include <qstandarditemmodel.h>
 #include <qapplication.h>
 #include <qlistview.h>
+#include <qlistwidget.h>
 #include <qtableview.h>
+#include <qtablewidget.h>
 #include <qtreeview.h>
 #include <qtreewidget.h>
 #include <qheaderview.h>
@@ -224,6 +226,8 @@
     void shiftArrowSelectionAfterScrolling();
     void shiftSelectionAfterRubberbandSelection();
     void ctrlRubberbandSelection();
+    void QTBUG6407_extendedSelection();
+    void QTBUG6753_selectOnSelection();
 };
 
 class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -1433,5 +1437,66 @@
     QVERIFY(selected.contains(index2));
 }
 
+void tst_QAbstractItemView::QTBUG6407_extendedSelection()
+{
+    QListWidget view;
+    view.setSelectionMode(QAbstractItemView::ExtendedSelection);
+    for(int i = 0; i < 50; ++i)
+        view.addItem(QString::number(i));
+
+    view.resize(200,200);
+
+    view.show();
+    QApplication::setActiveWindow(&view);
+    QTest::qWaitForWindowShown(&view);
+    QTRY_COMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
+
+    view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum());
+    QTest::qWait(20);
+
+    QModelIndex index49 = view.model()->index(49,0);
+    QPoint p = view.visualRect(index49).center();
+    QVERIFY(view.viewport()->rect().contains(p));
+    QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+    QCOMPARE(view.currentIndex(), index49);
+    QCOMPARE(view.selectedItems().count(), 1);
+
+    QModelIndex index47 = view.model()->index(47,0);
+    p = view.visualRect(index47).center();
+    QVERIFY(view.viewport()->rect().contains(p));
+    QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, p);
+    QCOMPARE(view.currentIndex(), index47);
+    QCOMPARE(view.selectedItems().count(), 3); //49, 48, 47;
+
+    QModelIndex index44 = view.model()->index(44,0);
+    p = view.visualRect(index44).center();
+    QVERIFY(view.viewport()->rect().contains(p));
+    QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, p);
+    QCOMPARE(view.currentIndex(), index44);
+    QCOMPARE(view.selectedItems().count(), 6); //49 .. 44;
+
+}
+
+void tst_QAbstractItemView::QTBUG6753_selectOnSelection()
+{
+    QTableWidget table(5, 5);
+    for (int i = 0; i < table.rowCount(); ++i)
+        for (int j = 0; j < table.columnCount(); ++j)
+            table.setItem(i, j, new QTableWidgetItem("choo-be-doo-wah"));
+
+    table.show();
+    table.setSelectionMode(QAbstractItemView::ExtendedSelection);
+    table.selectAll();
+    QTest::qWaitForWindowShown(&table);
+    QModelIndex item = table.model()->index(1,1);
+    QRect itemRect = table.visualRect(item);
+    QTest::mouseMove(table.viewport(), itemRect.center());
+    QTest::mouseClick(table.viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());
+    QTest::qWait(20);
+
+    QCOMPARE(table.selectedItems().count(), 1);
+    QCOMPARE(table.selectedItems().first(), table.item(item.row(), item.column()));
+}
+
 QTEST_MAIN(tst_QAbstractItemView)
 #include "tst_qabstractitemview.moc"