summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtreeview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qtreeview')
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp222
1 files changed, 209 insertions, 13 deletions
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index dd18b09..f42d5f6 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -1,7 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
@@ -21,9 +20,10 @@
** 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.
+** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
@@ -51,7 +51,9 @@
//TESTED_FILES=
Q_DECLARE_METATYPE(QModelIndex)
+#ifndef QT_NO_DRAGANDDROP
Q_DECLARE_METATYPE(QAbstractItemView::DragDropMode)
+#endif
Q_DECLARE_METATYPE(QAbstractItemView::EditTriggers)
Q_DECLARE_METATYPE(QAbstractItemView::EditTrigger)
@@ -137,11 +139,13 @@ private slots:
void alternatingRowColors();
void currentIndex_data();
void currentIndex();
+#ifndef QT_NO_DRAGANDDROP
void dragDropMode_data();
void dragDropMode();
void dragDropModeFromDragEnabledAndAcceptDrops_data();
void dragDropModeFromDragEnabledAndAcceptDrops();
void dragDropOverwriteMode();
+#endif
void editTriggers_data();
void editTriggers();
void hasAutoScroll();
@@ -208,8 +212,8 @@ private slots:
void indexRowSizeHint();
void addRowsWhileSectionsAreHidden();
-
void filterProxyModelCrash();
+ void styleOptionViewItem();
// task-specific tests:
void task174627_moveLeftToRoot();
@@ -225,7 +229,11 @@ private slots:
void task238873_avoidAutoReopening();
void task244304_clickOnDecoration();
void task246536_scrollbarsNotWorking();
+ void task250683_wrongSectionSize();
+ void task239271_addRowsWithFirstColumnHidden();
void task254234_proxySort();
+ void task248022_changeSelection();
+ void task245654_changeModelAndExpandAll();
};
class QtTestModel: public QAbstractItemModel
@@ -466,9 +474,11 @@ void tst_QTreeView::construction()
// QAbstractItemView properties
QVERIFY(!view.alternatingRowColors());
QCOMPARE(view.currentIndex(), QModelIndex());
+#ifndef QT_NO_DRAGANDDROP
QCOMPARE(view.dragDropMode(), QAbstractItemView::NoDragDrop);
QVERIFY(!view.dragDropOverwriteMode());
QVERIFY(!view.dragEnabled());
+#endif
QCOMPARE(view.editTriggers(), QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked);
QVERIFY(view.hasAutoScroll());
QCOMPARE(view.horizontalScrollMode(), QAbstractItemView::ScrollPerPixel);
@@ -487,7 +497,9 @@ void tst_QTreeView::construction()
QCOMPARE(view.selectionBehavior(), QAbstractItemView::SelectRows);
QCOMPARE(view.selectionMode(), QAbstractItemView::SingleSelection);
QVERIFY(!view.selectionModel());
+#ifndef QT_NO_DRAGANDDROP
QVERIFY(view.showDropIndicator());
+#endif
QCOMPARE(view.QAbstractItemView::sizeHintForColumn(-1), -1); // <- protected in QTreeView
QCOMPARE(view.QAbstractItemView::sizeHintForColumn(0), -1); // <- protected in QTreeView
QCOMPARE(view.QAbstractItemView::sizeHintForColumn(1), -1); // <- protected in QTreeView
@@ -594,12 +606,13 @@ void tst_QTreeView::currentIndex()
// ### Test child and grandChild indexes.
}
+#ifndef QT_NO_DRAGANDDROP
+
void tst_QTreeView::dragDropMode_data()
{
QTest::addColumn<QAbstractItemView::DragDropMode>("dragDropMode");
QTest::addColumn<bool>("acceptDrops");
QTest::addColumn<bool>("dragEnabled");
-
QTest::newRow("NoDragDrop") << QAbstractItemView::NoDragDrop << false << false;
QTest::newRow("DragOnly") << QAbstractItemView::DragOnly << false << true;
QTest::newRow("DropOnly") << QAbstractItemView::DropOnly << true << false;
@@ -694,6 +707,7 @@ void tst_QTreeView::dragDropOverwriteMode()
// QTableWidget, from their reimplementations of dropMimeData(). Hard to
// test.
}
+#endif
void tst_QTreeView::editTriggers_data()
{
@@ -2027,6 +2041,8 @@ void tst_QTreeView::scrollTo()
//
view.show();
+ view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); //some styles change that in Polish
+
view.resize(300, 200);
//view.verticalScrollBar()->setValue(0);
@@ -2039,6 +2055,7 @@ void tst_QTreeView::scrollTo()
QCOMPARE(view.verticalScrollBar()->value(), 5);
view.scrollTo(model.index(60, 60, QModelIndex()));
+
CHECK_VISIBLE(60,60);
view.scrollTo(model.index(60, 30, QModelIndex()));
CHECK_VISIBLE(60,30);
@@ -2847,6 +2864,74 @@ void tst_QTreeView::filterProxyModelCrash()
view.repaint(); //used to crash
}
+void tst_QTreeView::styleOptionViewItem()
+{
+ class MyDelegate : public QStyledItemDelegate
+ {
+ public:
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
+ {
+ QVERIFY(qstyleoption_cast<const QStyleOptionViewItemV4 *>(&option));
+ QStyleOptionViewItemV4 opt(option);
+ initStyleOption(&opt, index);
+
+ QVERIFY(!opt.text.isEmpty());
+ QCOMPARE(opt.index, index);
+ QCOMPARE(!(opt.features & QStyleOptionViewItemV2::Alternate), !(index.row() % 2));
+ QCOMPARE(!(opt.features & QStyleOptionViewItemV2::HasCheckIndicator), !opt.text.contains("Checkable"));
+
+ if (opt.text.contains("Beginning"))
+ QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Beginning);
+
+ if (opt.text.contains("Middle"))
+ QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Middle);
+
+ if (opt.text.contains("End"))
+ QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::End);
+
+ if (opt.text.contains("OnlyOne"))
+ QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::OnlyOne);
+
+ if (opt.text.contains("Checked"))
+ QCOMPARE(opt.checkState, Qt::Checked);
+ else
+ QCOMPARE(opt.checkState, Qt::Unchecked);
+
+ QVERIFY(!opt.text.contains("Assert"));
+
+ QStyledItemDelegate::paint(painter, option, index);
+ count++;
+ }
+ mutable int count;
+ };
+
+ QTreeView view;
+ QStandardItemModel model;
+ view.setModel(&model);
+ MyDelegate delegate;
+ view.setItemDelegate(&delegate);
+ model.appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ model.appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ model.appendRow(QList<QStandardItem*>()
+ << new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") );
+ QStandardItem *checkable = new QStandardItem("Checkable");
+ checkable->setCheckable(true);
+ QStandardItem *checked = new QStandardItem("Checkable Checked");
+ checkable->setCheckable(true);
+ checked->setCheckState(Qt::Checked);
+ model.appendRow(QList<QStandardItem*>()
+ << new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") );
+
+ view.setFirstColumnSpanned(2, QModelIndex(), true);
+ view.setAlternatingRowColors(true);
+
+ delegate.count = 0;
+ view.showMaximized();
+ QTRY_VERIFY(delegate.count >= 13);
+}
+
class task174627_TreeView : public QTreeView
{
Q_OBJECT
@@ -2974,12 +3059,12 @@ void tst_QTreeView::task216717_updateChildren()
tree.refreshed = false;
QTreeWidgetItem *parent = new QTreeWidgetItem(QStringList() << "parent");
tree.addTopLevelItem(parent);
- QTest::qWait(100);
- QVERIFY(tree.refreshed);
+ QTest::qWait(10);
+ QTRY_VERIFY(tree.refreshed);
tree.refreshed = false;
parent->addChild(new QTreeWidgetItem(QStringList() << "child"));
- QTest::qWait(100);
- QVERIFY(tree.refreshed);
+ QTest::qWait(10);
+ QTRY_VERIFY(tree.refreshed);
}
@@ -3174,7 +3259,7 @@ void tst_QTreeView::task202039_closePersistentEditor()
view.closePersistentEditor(current);
QVERIFY(view.indexWidget(current) == 0);
- //here was the bug: closing the persistent editor would not reset the state
+ //here was the bug: closing the persistent editor would not reset the state
//and it was impossible to go into editinon again
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center());
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center());
@@ -3228,7 +3313,7 @@ void tst_QTreeView::task244304_clickOnDecoration()
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2));
QVERIFY(!view.currentIndex().isValid());
QVERIFY(view.isExpanded(item0.index()));
-
+
rect = view.visualRect(item1.index());
//the item has no decoration, it should get selected
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2));
@@ -3269,7 +3354,61 @@ void tst_QTreeView::task246536_scrollbarsNotWorking()
o.count = 0;
tree.verticalScrollBar()->setValue(50);
QTest::qWait(100);
- QVERIFY(o.count > 0);
+ QTRY_VERIFY(o.count > 0);
+}
+
+void tst_QTreeView::task250683_wrongSectionSize()
+{
+ QDirModel model;
+ QTreeView treeView;
+ treeView.header()->setResizeMode(QHeaderView::ResizeToContents);
+ treeView.setModel(&model);
+ treeView.setColumnHidden(2, true);
+ treeView.setColumnHidden(3, true);
+
+ treeView.show();
+ QTest::qWait(100);
+
+ QCOMPARE(treeView.header()->sectionSize(0) + treeView.header()->sectionSize(1), treeView.viewport()->width());
+}
+
+void tst_QTreeView::task239271_addRowsWithFirstColumnHidden()
+{
+ class MyDelegate : public QStyledItemDelegate
+ {
+ public:
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
+ {
+ paintedIndexes << index;
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+
+ mutable QSet<QModelIndex> paintedIndexes;
+ };
+
+ QTreeView view;
+ QStandardItemModel model;
+ view.setModel(&model);
+ MyDelegate delegate;
+ view.setItemDelegate(&delegate);
+ QStandardItem root0("root0"), root1("root1");
+ model.invisibleRootItem()->appendRow(QList<QStandardItem*>() << &root0 << &root1);
+ QStandardItem sub0("sub0"), sub00("sub00");
+ root0.appendRow(QList<QStandardItem*>() << &sub0 << &sub00);
+ view.expand(root0.index());
+
+ view.hideColumn(0);
+ view.show();
+ QTest::qWait(200);
+ delegate.paintedIndexes.clear();
+ QStandardItem sub1("sub1"), sub11("sub11");
+ root0.appendRow(QList<QStandardItem*>() << &sub1 << &sub11);
+
+ QTest::qWait(20);
+ //items in the 2nd column should have been painted
+ QTRY_VERIFY(!delegate.paintedIndexes.isEmpty());
+ QVERIFY(delegate.paintedIndexes.contains(sub00.index()));
+ QVERIFY(delegate.paintedIndexes.contains(sub11.index()));
}
void tst_QTreeView::task254234_proxySort()
@@ -3299,5 +3438,62 @@ void tst_QTreeView::task254234_proxySort()
QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g"));
}
+class TreeView : public QTreeView
+{
+ Q_OBJECT
+public slots:
+ void handleSelectionChanged()
+ {
+ //let's select the last item
+ QModelIndex idx = model()->index(0, 0);
+ selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select);
+ disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(handleSelectionChanged()));
+ }
+};
+
+void tst_QTreeView::task248022_changeSelection()
+{
+ //we check that changing the selection between the mouse press and the mouse release
+ //works correctly
+ TreeView view;
+ QStringList list = QStringList() << "1" << "2";
+ QStringListModel model(list);
+ view.setSelectionMode(QAbstractItemView::ExtendedSelection);
+ view.setModel(&model);
+ view.connect(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(handleSelectionChanged()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(1)).center());
+ QCOMPARE(view.selectionModel()->selectedIndexes().count(), list.count());
+}
+
+void tst_QTreeView::task245654_changeModelAndExpandAll()
+{
+ QTreeView view;
+ QStandardItemModel *model = new QStandardItemModel;
+ QStandardItem *top = new QStandardItem("top");
+ QStandardItem *sub = new QStandardItem("sub");
+ top->appendRow(sub);
+ model->appendRow(top);
+ view.setModel(model);
+ view.expandAll();
+ QApplication::processEvents();
+ QVERIFY(view.isExpanded(top->index()));
+
+ //now let's try to delete the model
+ //then repopulate and expand again
+ delete model;
+ model = new QStandardItemModel;
+ top = new QStandardItem("top");
+ sub = new QStandardItem("sub");
+ top->appendRow(sub);
+ model->appendRow(top);
+ view.setModel(model);
+ view.expandAll();
+ QApplication::processEvents();
+ QVERIFY(view.isExpanded(top->index()));
+
+}
+
+
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"