summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiewen Wang <jiewen.wang@logicpd.com>2012-05-31 12:20:49 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-05-31 21:45:30 (GMT)
commitebaaff84fc0355d2e026da7f5ca015280b2c7d82 (patch)
tree11a1ac00570afe696bccb2bcb8ba24270b4992ed
parent4ec0baf312ec2b26b1dfbee34a22b2ef7dfeccf1 (diff)
downloadQt-ebaaff84fc0355d2e026da7f5ca015280b2c7d82.zip
Qt-ebaaff84fc0355d2e026da7f5ca015280b2c7d82.tar.gz
Qt-ebaaff84fc0355d2e026da7f5ca015280b2c7d82.tar.bz2
Eliminate QTreeWidget drag crash
In QTreeViewPrivate::adjustViewOptionsForIndex() wrong index had been used when referencing to array of viewItems. Variable row is set to the index of the QModelIndex, however it is not as same as the index in viewItems[] when there was hidden item in treeWidget. Index of viewItems[] should be used here. Unit test is added as well. Change-Id: Ie129cb63445bf1239ef7c5b2bc61b04dd9e81982 Task-Id: QTBUG-25333 Backport of <3be6ca3ee8c2c72f85b26a57538fd329ed811261> from Qt5 Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
-rw-r--r--src/gui/itemviews/qtreeview.cpp2
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp43
2 files changed, 44 insertions, 1 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index 1a8a686..ffd1ad0 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -1357,7 +1357,7 @@ QItemViewPaintPairs QTreeViewPrivate::draggablePaintPairs(const QModelIndexList
void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, const QModelIndex &current) const
{
- const int row = current.row();
+ const int row = viewIndex(current); // get the index in viewItems[]
option->state = option->state | (viewItems.at(row).expanded ? QStyle::State_Open : QStyle::State_None)
| (viewItems.at(row).hasChildren ? QStyle::State_Children : QStyle::State_None)
| (viewItems.at(row).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None);
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index c0747a8..07a5a7d 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -245,6 +245,7 @@ private slots:
void taskQTBUG_9216_setSizeAndUniformRowHeightsWrongRepaint();
void taskQTBUG_11466_keyboardNavigationRegression();
void taskQTBUG_13567_removeLastItemRegression();
+ void taskQTBUG_25333_adjustViewOptionsForIndex();
};
class QtTestModel: public QAbstractItemModel
@@ -3038,6 +3039,7 @@ void tst_QTreeView::styleOptionViewItem()
// Test the rendering to pixmap before painting the widget.
// The rendering to pixmap should not depend on having been
// painted already yet.
+ delegate.count = 0;
QItemSelection sel(model.index(0,0), model.index(0,modelColumns-1));
QRect rect;
view.aiv_priv()->renderToPixmap(sel.indexes(), &rect);
@@ -4008,5 +4010,46 @@ void tst_QTreeView::taskQTBUG_13567_removeLastItemRegression()
CHECK_VISIBLE(198, 0);
}
+// From QTBUG-25333 (QTreeWidget drag crashes when there was a hidden item in tree)
+// The test passes simply if it doesn't crash, hence there are no calls
+// to QCOMPARE() or QVERIFY().
+// Note: define QT_BUILD_INTERNAL to run this test
+void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex()
+{
+ PublicView view;
+ QStandardItemModel model;
+ QStandardItem *item1 = new QStandardItem("Item1");
+ QStandardItem *item2 = new QStandardItem("Item2");
+ QStandardItem *item3 = new QStandardItem("Item3");
+ QStandardItem *data1 = new QStandardItem("Data1");
+ QStandardItem *data2 = new QStandardItem("Data2");
+ QStandardItem *data3 = new QStandardItem("Data3");
+
+ // Create a treeview
+ model.appendRow(QList<QStandardItem*>() << item1 << data1 );
+ model.appendRow(QList<QStandardItem*>() << item2 << data2 );
+ model.appendRow(QList<QStandardItem*>() << item3 << data3 );
+
+ view.setModel(&model);
+
+ // Hide a row
+ view.setRowHidden(1, QModelIndex(), true);
+ view.expandAll();
+
+ view.show();
+
+#ifdef QT_BUILD_INTERNAL
+ {
+ QStyleOptionViewItemV4 option;
+
+ view.aiv_priv()->adjustViewOptionsForIndex(&option, model.indexFromItem(item1));
+
+ view.aiv_priv()->adjustViewOptionsForIndex(&option, model.indexFromItem(item3));
+ }
+#endif
+
+}
+
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"