summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-24 15:44:29 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-24 15:52:21 (GMT)
commit346887e731df4143699ce0c2310ded4fec849d30 (patch)
tree5d56093ddf83401b47ca65c6808997115507a61e
parentbd73818849b181ac29109ed580a60e99a38bf63d (diff)
downloadQt-346887e731df4143699ce0c2310ded4fec849d30.zip
Qt-346887e731df4143699ce0c2310ded4fec849d30.tar.gz
Qt-346887e731df4143699ce0c2310ded4fec849d30.tar.bz2
Fix QTreeWidgetItem::setChildIndicatorPolicy not updating.
The problem is that the ChildIndicatorPolicy change the hasChildren in the model. But this is cached in the QTreeView layout. We must do a relayout to clear the cache. Reviewed-by: Thierry Task-number: QTBUG-3071
-rw-r--r--src/gui/itemviews/qtreewidget.cpp2
-rw-r--r--tests/auto/qtreewidget/tst_qtreewidget.cpp53
2 files changed, 54 insertions, 1 deletions
diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp
index c133ae4..948ca79 100644
--- a/src/gui/itemviews/qtreewidget.cpp
+++ b/src/gui/itemviews/qtreewidget.cpp
@@ -1580,7 +1580,7 @@ void QTreeWidgetItem::setChildIndicatorPolicy(QTreeWidgetItem::ChildIndicatorPol
if (!view)
return;
- view->viewport()->update( view->d_func()->itemDecorationRect(view->d_func()->index(this)));
+ view->scheduleDelayedItemsLayout();
}
/*!
diff --git a/tests/auto/qtreewidget/tst_qtreewidget.cpp b/tests/auto/qtreewidget/tst_qtreewidget.cpp
index 621072c..0c6df4f 100644
--- a/tests/auto/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/qtreewidget/tst_qtreewidget.cpp
@@ -168,6 +168,8 @@ private slots:
void task239150_editorWidth();
void setTextUpdate();
void taskQTBUG2844_visualItemRect();
+ void setChildIndicatorPolicy();
+
public slots:
void itemSelectionChanged();
@@ -3290,6 +3292,57 @@ void tst_QTreeWidget::taskQTBUG2844_visualItemRect()
QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol1);
}
+void tst_QTreeWidget::setChildIndicatorPolicy()
+{
+ QTreeWidget treeWidget;
+ treeWidget.setColumnCount(1);
+
+ class MyItemDelegate : public QStyledItemDelegate
+ {
+ public:
+ MyItemDelegate() : numPaints(0), expectChildren(false) { }
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+ {
+ numPaints++;
+ QCOMPARE(!(option.state & QStyle::State_Children), !expectChildren);
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+ mutable int numPaints;
+ bool expectChildren;
+ } delegate;
+
+ treeWidget.setItemDelegate(&delegate);
+ treeWidget.show();
+
+ QTreeWidgetItem *item = new QTreeWidgetItem(QStringList("Hello"));
+ treeWidget.insertTopLevelItem(0, item);
+ QTest::qWait(50);
+ QTRY_VERIFY(delegate.numPaints > 0);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = true;
+ item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = false;
+ item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = true;
+ new QTreeWidgetItem(item);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = false;
+ item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+}