diff options
author | David Faure <faure@kde.org> | 2011-11-29 19:55:26 (GMT) |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2011-11-30 14:01:56 (GMT) |
commit | fd25323de7b5d5f3e0ffb1bd81ea4d251e071566 (patch) | |
tree | 6d318b2e72b617c7f126263af522849bd99b1ab1 /tests | |
parent | 53d854eb3ba095f2e13a35f4d7eb01670d9874b4 (diff) | |
download | Qt-fd25323de7b5d5f3e0ffb1bd81ea4d251e071566.zip Qt-fd25323de7b5d5f3e0ffb1bd81ea4d251e071566.tar.gz Qt-fd25323de7b5d5f3e0ffb1bd81ea4d251e071566.tar.bz2 |
QTreeView: fix crash when starting a drag with hidden columns.
Crash was introduced by d639105759491 (Qt-4.8 only)
Amended to remove "unused variable" warning.
Task-number: QTBUG-15834
Merge-request: MR-2725
Reviewed-by: Gabriel
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index c37a4ea..be991dc 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -113,7 +113,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()); } }; @@ -2906,6 +2905,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 { @@ -2922,16 +2925,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); @@ -2956,41 +2959,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); @@ -3011,10 +3018,10 @@ void tst_QTreeView::styleOptionViewItem() // test that the rendering of drag pixmap sets the correct options too (QTBUG-15834) 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); //test dynamic models { |