summaryrefslogtreecommitdiffstats
path: root/tests/auto/qlistview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qlistview')
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index b52bef0..2281fb7 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -48,10 +48,13 @@
#include <qitemdelegate.h>
#include <qstandarditemmodel.h>
#include <qstringlistmodel.h>
+#ifndef Q_OS_SYMBIAN
#include <cmath>
+#endif
#include <math.h>
#include <QtGui/QScrollBar>
#include <QtGui/QDialog>
+#include <QtGui/QStyledItemDelegate>
#if defined(Q_OS_WIN) || defined(Q_OS_WINCE)
#include <windows.h>
#endif
@@ -106,6 +109,10 @@ private slots:
void task228566_infiniteRelayout();
void task248430_crashWith0SizedItem();
void task250446_scrollChanged();
+ void task196118_visualRegionForSelection();
+ void task254449_draggingItemToNegativeCoordinates();
+ void keyboardSearch();
+ void shiftSelectionWithNonUniformItemSizes();
};
// Testing get/set functions
@@ -1555,6 +1562,168 @@ void tst_QListView::task250446_scrollChanged()
QCOMPARE(view.currentIndex(), index);
}
+void tst_QListView::task196118_visualRegionForSelection()
+{
+ class MyListView : public QListView
+ {
+ public:
+ QRegion visualRegionForSelection() const
+ { return QListView::visualRegionForSelection( selectionModel()->selection()); }
+ } view;
+
+ QStandardItemModel model;
+ QStandardItem top1("top1");
+ QStandardItem sub1("sub1");
+ top1.appendRow(QList<QStandardItem*>() << &sub1);
+ model.appendColumn(QList<QStandardItem*>() << &top1);
+ view.setModel(&model);
+ view.setRootIndex(top1.index());
+
+ view.selectionModel()->select(top1.index(), QItemSelectionModel::Select);
+
+ QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QVERIFY(view.visualRegionForSelection().isEmpty());
+}
+
+void tst_QListView::task254449_draggingItemToNegativeCoordinates()
+{
+ //we'll check that the items are painted correctly
+ class MyListView : public QListView
+ {
+ public:
+ void setPositionForIndex(const QPoint &position, const QModelIndex &index)
+ { QListView::setPositionForIndex(position, index); }
+
+ } list;
+
+ QStandardItemModel model(1,1);
+ QModelIndex index = model.index(0,0);
+ model.setData(index, QLatin1String("foo"));
+ list.setModel(&model);
+ list.setViewMode(QListView::IconMode);
+ list.show();
+ QTest::qWait(200); //makes sure the layout is done
+
+ const QPoint topLeft(-6, 0);
+
+
+ list.setPositionForIndex(topLeft, index);
+
+ class MyItemDelegate : public QStyledItemDelegate
+ {
+ public:
+ MyItemDelegate() : numPaints(0) { }
+ void paint(QPainter *painter,
+ const QStyleOptionViewItem &option, const QModelIndex &index) const
+ {
+ numPaints++;
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+
+ mutable int numPaints;
+ } delegate;
+
+ list.setItemDelegate(&delegate);
+
+ //we'll make sure the item is repainted
+ delegate.numPaints = 0;
+ list.viewport()->repaint();
+
+ QCOMPARE(list.visualRect(index).topLeft(), topLeft);
+ QCOMPARE(delegate.numPaints, 1);
+}
+
+
+void tst_QListView::keyboardSearch()
+{
+ QStringList items;
+ items << "AB" << "AC" << "BA" << "BB" << "BD" << "KAFEINE" << "KONQUEROR" << "KOPETE" << "KOOKA" << "OKULAR";
+ QStringListModel model(items);
+
+ QListView view;
+ view.setModel(&model);
+ view.show();
+ QTest::qWait(30);
+// QCOMPARE(view.currentIndex() , model.index(0,0));
+
+ QTest::keyClick(&view, Qt::Key_K);
+ QTest::qWait(10);
+ QCOMPARE(view.currentIndex() , model.index(5,0)); //KAFEINE
+
+ QTest::keyClick(&view, Qt::Key_O);
+ QTest::qWait(10);
+ QCOMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR
+
+ QTest::keyClick(&view, Qt::Key_N);
+ QTest::qWait(10);
+ QCOMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR
+}
+
+void tst_QListView::shiftSelectionWithNonUniformItemSizes()
+{
+ // This checks that no items are selected unexpectedly by Shift-Arrow
+ // when items with non-uniform sizes are laid out in a grid
+ { // First test: QListView::LeftToRight flow
+ QStringList items;
+ items << "Long\nText" << "Text" << "Text" << "Text";
+ QStringListModel model(items);
+
+ QListView view;
+ view.setFixedSize(250, 250);
+ view.setFlow(QListView::LeftToRight);
+ view.setGridSize(QSize(100, 100));
+ view.setSelectionMode(QListView::ExtendedSelection);
+ view.setViewMode(QListView::IconMode);
+ view.setModel(&model);
+ view.show();
+ QTest::qWait(30);
+
+ // Verfify that item sizes are non-uniform
+ QVERIFY(view.sizeHintForIndex(model.index(0, 0)).height() > view.sizeHintForIndex(model.index(1, 0)).height());
+
+ QModelIndex index = model.index(3, 0);
+ view.setCurrentIndex(index);
+ QCOMPARE(view.currentIndex(), index);
+
+ QTest::keyClick(&view, Qt::Key_Up, Qt::ShiftModifier);
+ QTest::qWait(10);
+ QCOMPARE(view.currentIndex(), model.index(1, 0));
+
+ QModelIndexList selected = view.selectionModel()->selectedIndexes();
+ QCOMPARE(selected.count(), 3);
+ QVERIFY(!selected.contains(model.index(0, 0)));
+ }
+ { // Second test: QListView::TopToBottom flow
+ QStringList items;
+ items << "ab" << "a" << "a" << "a";
+ QStringListModel model(items);
+
+ QListView view;
+ view.setFixedSize(250, 250);
+ view.setFlow(QListView::TopToBottom);
+ view.setGridSize(QSize(100, 100));
+ view.setSelectionMode(QListView::ExtendedSelection);
+ view.setViewMode(QListView::IconMode);
+ view.setModel(&model);
+ view.show();
+ QTest::qWait(30);
+
+ // Verfify that item sizes are non-uniform
+ QVERIFY(view.sizeHintForIndex(model.index(0, 0)).width() > view.sizeHintForIndex(model.index(1, 0)).width());
+
+ QModelIndex index = model.index(3, 0);
+ view.setCurrentIndex(index);
+ QCOMPARE(view.currentIndex(), index);
+
+ QTest::keyClick(&view, Qt::Key_Left, Qt::ShiftModifier);
+ QTest::qWait(10);
+ QCOMPARE(view.currentIndex(), model.index(1, 0));
+
+ QModelIndexList selected = view.selectionModel()->selectedIndexes();
+ QCOMPARE(selected.count(), 3);
+ QVERIFY(!selected.contains(model.index(0, 0)));
+ }
+}
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"