165 void setSelectionModel(); |
165 void setSelectionModel(); |
166 void task217309(); |
166 void task217309(); |
167 void setCurrentItemExpandsParent(); |
167 void setCurrentItemExpandsParent(); |
168 void task239150_editorWidth(); |
168 void task239150_editorWidth(); |
169 void setTextUpdate(); |
169 void setTextUpdate(); |
|
170 void taskQTBUG2844_visualItemRect(); |
|
171 void setChildIndicatorPolicy(); |
|
172 |
170 |
173 |
171 public slots: |
174 public slots: |
172 void itemSelectionChanged(); |
175 void itemSelectionChanged(); |
173 void emitDataChanged(); |
176 void emitDataChanged(); |
174 |
177 |
599 |
602 |
600 testWidget->expandItem(parent); |
603 testWidget->expandItem(parent); |
601 testWidget->scrollToItem(child); |
604 testWidget->scrollToItem(child); |
602 |
605 |
603 QVERIFY(testWidget->visualItemRect(parent).isValid() |
606 QVERIFY(testWidget->visualItemRect(parent).isValid() |
604 && testWidget->viewport()->rect().contains(testWidget->visualItemRect(parent))); |
607 && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent))); |
605 QVERIFY(testWidget->visualItemRect(child).isValid() |
608 QVERIFY(testWidget->visualItemRect(child).isValid() |
606 && testWidget->viewport()->rect().contains(testWidget->visualItemRect(child))); |
609 && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child))); |
607 |
610 |
608 QVERIFY(!testWidget->isItemHidden(parent)); |
611 QVERIFY(!testWidget->isItemHidden(parent)); |
609 QVERIFY(!testWidget->isItemHidden(child)); |
612 QVERIFY(!testWidget->isItemHidden(child)); |
610 |
613 |
611 testWidget->setItemHidden(parent, true); |
614 testWidget->setItemHidden(parent, true); |
612 |
615 |
613 QVERIFY(!(testWidget->visualItemRect(parent).isValid() |
616 QVERIFY(!(testWidget->visualItemRect(parent).isValid() |
614 && testWidget->viewport()->rect().contains(testWidget->visualItemRect(parent)))); |
617 && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent)))); |
615 QVERIFY(!(testWidget->visualItemRect(child).isValid() |
618 QVERIFY(!(testWidget->visualItemRect(child).isValid() |
616 && testWidget->viewport()->rect().contains(testWidget->visualItemRect(child)))); |
619 && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child)))); |
617 |
620 |
618 QVERIFY(testWidget->isItemHidden(parent)); |
621 QVERIFY(testWidget->isItemHidden(parent)); |
619 QVERIFY(!testWidget->isItemHidden(child)); |
622 QVERIFY(!testWidget->isItemHidden(child)); |
620 |
623 |
621 // From task 78670 (This caused an core dump) |
624 // From task 78670 (This caused an core dump) |
3269 item->setText(1, "42"); |
3272 item->setText(1, "42"); |
3270 QApplication::processEvents(); |
3273 QApplication::processEvents(); |
3271 QTRY_VERIFY(delegate.numPaints > 0); |
3274 QTRY_VERIFY(delegate.numPaints > 0); |
3272 } |
3275 } |
3273 |
3276 |
|
3277 void tst_QTreeWidget::taskQTBUG2844_visualItemRect() |
|
3278 { |
|
3279 CustomTreeWidget tree; |
|
3280 tree.resize(150, 100); |
|
3281 tree.setColumnCount(3); |
|
3282 QTreeWidgetItem item(&tree); |
|
3283 |
|
3284 QRect itemRect = tree.visualItemRect(&item); |
|
3285 |
|
3286 QRect rectCol0 = tree.visualRect(tree.indexFromItem(&item, 0)); |
|
3287 QRect rectCol1 = tree.visualRect(tree.indexFromItem(&item, 1)); |
|
3288 QRect rectCol2 = tree.visualRect(tree.indexFromItem(&item, 2)); |
|
3289 |
|
3290 QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol2); |
|
3291 tree.setColumnHidden(2, true); |
|
3292 QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol1); |
|
3293 } |
|
3294 |
|
3295 void tst_QTreeWidget::setChildIndicatorPolicy() |
|
3296 { |
|
3297 QTreeWidget treeWidget; |
|
3298 treeWidget.setColumnCount(1); |
|
3299 |
|
3300 class MyItemDelegate : public QStyledItemDelegate |
|
3301 { |
|
3302 public: |
|
3303 MyItemDelegate() : numPaints(0), expectChildren(false) { } |
|
3304 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
|
3305 { |
|
3306 numPaints++; |
|
3307 QCOMPARE(!(option.state & QStyle::State_Children), !expectChildren); |
|
3308 QStyledItemDelegate::paint(painter, option, index); |
|
3309 } |
|
3310 mutable int numPaints; |
|
3311 bool expectChildren; |
|
3312 } delegate; |
|
3313 |
|
3314 treeWidget.setItemDelegate(&delegate); |
|
3315 treeWidget.show(); |
|
3316 |
|
3317 QTreeWidgetItem *item = new QTreeWidgetItem(QStringList("Hello")); |
|
3318 treeWidget.insertTopLevelItem(0, item); |
|
3319 QTest::qWait(50); |
|
3320 QTRY_VERIFY(delegate.numPaints > 0); |
|
3321 |
|
3322 delegate.numPaints = 0; |
|
3323 delegate.expectChildren = true; |
|
3324 item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); |
|
3325 QApplication::processEvents(); |
|
3326 QTRY_COMPARE(delegate.numPaints, 1); |
|
3327 |
|
3328 delegate.numPaints = 0; |
|
3329 delegate.expectChildren = false; |
|
3330 item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); |
|
3331 QApplication::processEvents(); |
|
3332 QTRY_COMPARE(delegate.numPaints, 1); |
|
3333 |
|
3334 delegate.numPaints = 0; |
|
3335 delegate.expectChildren = true; |
|
3336 new QTreeWidgetItem(item); |
|
3337 QApplication::processEvents(); |
|
3338 QTRY_COMPARE(delegate.numPaints, 1); |
|
3339 |
|
3340 delegate.numPaints = 0; |
|
3341 delegate.expectChildren = false; |
|
3342 item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); |
|
3343 QApplication::processEvents(); |
|
3344 QTRY_COMPARE(delegate.numPaints, 1); |
|
3345 } |
|
3346 |
3274 |
3347 |
3275 |
3348 |
3276 QTEST_MAIN(tst_QTreeWidget) |
3349 QTEST_MAIN(tst_QTreeWidget) |
3277 #include "tst_qtreewidget.moc" |
3350 #include "tst_qtreewidget.moc" |