summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2011-11-29 20:55:26 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-12 08:31:17 +0100
commit1319bd48c8c21e1fadaf572f8f39528f52672035 (patch)
tree3287fc83fe15679f4169141e779895a0af3b11bd /tests
parent22b7d211865c1505862627a2e65bcd063e314e45 (diff)
QTreeView: fix crash when starting a drag with hidden columns.
Crash was introduced by d639105759491 (pre-Qt-4.8 only) Task-number: QTBUG-15834 Merge-request: MR-2725 (cherry picked from qt4 commit fd25323de7b5d5f3e0ffb1bd81ea4d251e071566) Change-Id: I59959d3ba4c9bcb0d39bdbe58432817bbbfdd9f1 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 380683a99e..5d0ef9d09b 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -107,7 +107,6 @@ struct PublicView : public QTreeView
inline QStyleOptionViewItem viewOptions() const { return QTreeView::viewOptions(); }
inline int sizeHintForColumn(int column) const { return QTreeView::sizeHintForColumn(column); }
- inline void startDrag(Qt::DropActions supportedActions) { QTreeView::startDrag(supportedActions); }
QAbstractItemViewPrivate* aiv_priv() { return static_cast<QAbstractItemViewPrivate*>(d_ptr.data()); }
};
@@ -2892,6 +2891,10 @@ void tst_QTreeView::styleOptionViewItem()
{
class MyDelegate : public QStyledItemDelegate
{
+ static QString posToString(QStyleOptionViewItemV4::ViewItemPosition pos) {
+ static const char* s_pos[] = { "Invalid", "Beginning", "Middle", "End", "OnlyOne" };
+ return s_pos[pos];
+ }
public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
@@ -2908,16 +2911,16 @@ void tst_QTreeView::styleOptionViewItem()
QCOMPARE(!(opt.features & QStyleOptionViewItemV2::HasCheckIndicator), !opt.text.contains("Checkable"));
if (opt.text.contains("Beginning"))
- QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Beginning);
+ QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItemV4::Beginning));
if (opt.text.contains("Middle"))
- QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Middle);
+ QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItemV4::Middle));
if (opt.text.contains("End"))
- QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::End);
+ QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItemV4::End));
if (opt.text.contains("OnlyOne"))
- QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::OnlyOne);
+ QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItemV4::OnlyOne));
if (opt.text.contains("Checked"))
QCOMPARE(opt.checkState, Qt::Checked);
@@ -2942,41 +2945,45 @@ void tst_QTreeView::styleOptionViewItem()
MyDelegate delegate;
view.setItemDelegate(&delegate);
model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ << new QStandardItem("Beginning") << new QStandardItem("Hidden") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
QStandardItem *par1 = new QStandardItem("Beginning HasChildren");
model.appendRow(QList<QStandardItem*>()
- << par1 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
+ << par1 << new QStandardItem("Hidden") << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") );
+ << new QStandardItem("OnlyOne") << new QStandardItem("Hidden") << 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->setCheckable(true);
checked->setCheckState(Qt::Checked);
model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") );
+ << new QStandardItem("Beginning") << new QStandardItem("Hidden") << checkable << checked << new QStandardItem("End") );
model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
+ << new QStandardItem("Beginning Last") << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
par1->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ << new QStandardItem("Beginning") << new QStandardItem("Hidden") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
QStandardItem *par2 = new QStandardItem("Beginning HasChildren");
par1->appendRow(QList<QStandardItem*>()
- << par2 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
+ << par2 << new QStandardItem("Hidden") << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
par2->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
+ << new QStandardItem("Beginning Last") << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
QStandardItem *par3 = new QStandardItem("Beginning Last");
par1->appendRow(QList<QStandardItem*>()
- << par3 << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
+ << par3 << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
par3->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
+ << new QStandardItem("Assert") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
view.setRowHidden(0, par3->index(), true);
par1->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
+ << new QStandardItem("Assert") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
view.setRowHidden(3, par1->index(), true);
+ view.setColumnHidden(1, true);
+ const int visibleColumns = 4;
+ const int modelColumns = 5;
+ view.header()->swapSections(2, 3);
view.setFirstColumnSpanned(2, QModelIndex(), true);
view.setAlternatingRowColors(true);
@@ -2998,10 +3005,10 @@ void tst_QTreeView::styleOptionViewItem()
// test that the rendering of drag pixmap sets the correct options too (QTBUG-15834)
#ifdef QT_BUILD_INTERNAL
delegate.count = 0;
- QItemSelection sel(model.index(0,0), model.index(0,3));
+ QItemSelection sel(model.index(0,0), model.index(0,modelColumns-1));
QRect rect;
view.aiv_priv()->renderToPixmap(sel.indexes(), &rect);
- QTRY_VERIFY(delegate.count >= 4);
+ QTRY_VERIFY(delegate.count == visibleColumns);
#endif
//test dynamic models