2909 if (opt.text.contains("Checked")) |
2913 if (opt.text.contains("Checked")) |
2910 QCOMPARE(opt.checkState, Qt::Checked); |
2914 QCOMPARE(opt.checkState, Qt::Checked); |
2911 else |
2915 else |
2912 QCOMPARE(opt.checkState, Qt::Unchecked); |
2916 QCOMPARE(opt.checkState, Qt::Unchecked); |
2913 |
2917 |
|
2918 QCOMPARE(!(opt.state & QStyle::State_Children) , !opt.text.contains("HasChildren")); |
|
2919 QCOMPARE(!!(opt.state & QStyle::State_Sibling) , !opt.text.contains("Last")); |
|
2920 |
2914 QVERIFY(!opt.text.contains("Assert")); |
2921 QVERIFY(!opt.text.contains("Assert")); |
2915 |
2922 |
2916 QStyledItemDelegate::paint(painter, option, index); |
2923 QStyledItemDelegate::paint(painter, option, index); |
2917 count++; |
2924 count++; |
2918 } |
2925 } |
2919 mutable int count; |
2926 mutable int count; |
|
2927 bool allCollapsed; |
2920 }; |
2928 }; |
2921 |
2929 |
2922 QTreeView view; |
2930 QTreeView view; |
2923 QStandardItemModel model; |
2931 QStandardItemModel model; |
2924 view.setModel(&model); |
2932 view.setModel(&model); |
2925 MyDelegate delegate; |
2933 MyDelegate delegate; |
2926 view.setItemDelegate(&delegate); |
2934 view.setItemDelegate(&delegate); |
2927 model.appendRow(QList<QStandardItem*>() |
2935 model.appendRow(QList<QStandardItem*>() |
2928 << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); |
2936 << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); |
|
2937 QStandardItem *par1 = new QStandardItem("Beginning HasChildren"); |
2929 model.appendRow(QList<QStandardItem*>() |
2938 model.appendRow(QList<QStandardItem*>() |
2930 << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); |
2939 << par1 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); |
2931 model.appendRow(QList<QStandardItem*>() |
2940 model.appendRow(QList<QStandardItem*>() |
2932 << new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") ); |
2941 << new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") ); |
2933 QStandardItem *checkable = new QStandardItem("Checkable"); |
2942 QStandardItem *checkable = new QStandardItem("Checkable"); |
2934 checkable->setCheckable(true); |
2943 checkable->setCheckable(true); |
2935 QStandardItem *checked = new QStandardItem("Checkable Checked"); |
2944 QStandardItem *checked = new QStandardItem("Checkable Checked"); |
2936 checkable->setCheckable(true); |
2945 checkable->setCheckable(true); |
2937 checked->setCheckState(Qt::Checked); |
2946 checked->setCheckState(Qt::Checked); |
2938 model.appendRow(QList<QStandardItem*>() |
2947 model.appendRow(QList<QStandardItem*>() |
2939 << new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") ); |
2948 << new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") ); |
|
2949 model.appendRow(QList<QStandardItem*>() |
|
2950 << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); |
|
2951 |
|
2952 par1->appendRow(QList<QStandardItem*>() |
|
2953 << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); |
|
2954 QStandardItem *par2 = new QStandardItem("Beginning HasChildren"); |
|
2955 par1->appendRow(QList<QStandardItem*>() |
|
2956 << par2 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); |
|
2957 par2->appendRow(QList<QStandardItem*>() |
|
2958 << new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); |
|
2959 |
|
2960 QStandardItem *par3 = new QStandardItem("Beginning Last"); |
|
2961 par1->appendRow(QList<QStandardItem*>() |
|
2962 << par3 << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); |
|
2963 par3->appendRow(QList<QStandardItem*>() |
|
2964 << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); |
|
2965 view.setRowHidden(0, par3->index(), true); |
|
2966 par1->appendRow(QList<QStandardItem*>() |
|
2967 << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); |
|
2968 view.setRowHidden(3, par1->index(), true); |
|
2969 |
2940 |
2970 |
2941 view.setFirstColumnSpanned(2, QModelIndex(), true); |
2971 view.setFirstColumnSpanned(2, QModelIndex(), true); |
2942 view.setAlternatingRowColors(true); |
2972 view.setAlternatingRowColors(true); |
2943 |
2973 |
2944 delegate.count = 0; |
2974 delegate.count = 0; |
|
2975 delegate.allCollapsed = true; |
2945 view.showMaximized(); |
2976 view.showMaximized(); |
|
2977 QApplication::processEvents(); |
2946 QTRY_VERIFY(delegate.count >= 13); |
2978 QTRY_VERIFY(delegate.count >= 13); |
|
2979 delegate.count = 0; |
|
2980 delegate.allCollapsed = false; |
|
2981 view.expandAll(); |
|
2982 QApplication::processEvents(); |
|
2983 QTRY_VERIFY(delegate.count >= 13); |
|
2984 delegate.count = 0; |
|
2985 view.collapse(par2->index()); |
|
2986 QApplication::processEvents(); |
|
2987 QTRY_VERIFY(delegate.count >= 4); |
|
2988 |
|
2989 |
|
2990 //test dynamic models |
|
2991 { |
|
2992 delegate.count = 0; |
|
2993 QStandardItemModel model2; |
|
2994 QStandardItem *item0 = new QStandardItem("OnlyOne Last"); |
|
2995 model2.appendRow(QList<QStandardItem*>() << item0); |
|
2996 view.setModel(&model2); |
|
2997 QApplication::processEvents(); |
|
2998 QTRY_VERIFY(delegate.count >= 1); |
|
2999 QApplication::processEvents(); |
|
3000 |
|
3001 QStandardItem *item00 = new QStandardItem("OnlyOne Last"); |
|
3002 item0->appendRow(QList<QStandardItem*>() << item00); |
|
3003 item0->setText("OnlyOne Last HasChildren"); |
|
3004 QApplication::processEvents(); |
|
3005 delegate.count = 0; |
|
3006 view.expandAll(); |
|
3007 QApplication::processEvents(); |
|
3008 QTRY_VERIFY(delegate.count >= 2); |
|
3009 QApplication::processEvents(); |
|
3010 |
|
3011 QStandardItem *item1 = new QStandardItem("OnlyOne Last"); |
|
3012 delegate.count = 0; |
|
3013 item0->setText("OnlyOne HasChildren"); |
|
3014 model2.appendRow(QList<QStandardItem*>() << item1); |
|
3015 QApplication::processEvents(); |
|
3016 QTRY_VERIFY(delegate.count >= 3); |
|
3017 QApplication::processEvents(); |
|
3018 |
|
3019 QStandardItem *item01 = new QStandardItem("OnlyOne Last"); |
|
3020 delegate.count = 0; |
|
3021 item00->setText("OnlyOne"); |
|
3022 item0->appendRow(QList<QStandardItem*>() << item01); |
|
3023 QApplication::processEvents(); |
|
3024 QTRY_VERIFY(delegate.count >= 4); |
|
3025 QApplication::processEvents(); |
|
3026 |
|
3027 QStandardItem *item000 = new QStandardItem("OnlyOne Last"); |
|
3028 delegate.count = 0; |
|
3029 item00->setText("OnlyOne HasChildren"); |
|
3030 item00->appendRow(QList<QStandardItem*>() << item000); |
|
3031 QApplication::processEvents(); |
|
3032 QTRY_VERIFY(delegate.count >= 5); |
|
3033 QApplication::processEvents(); |
|
3034 |
|
3035 delegate.count = 0; |
|
3036 item0->removeRow(0); |
|
3037 QApplication::processEvents(); |
|
3038 QTRY_VERIFY(delegate.count >= 3); |
|
3039 QApplication::processEvents(); |
|
3040 |
|
3041 item00 = new QStandardItem("OnlyOne"); |
|
3042 item0->insertRow(0, QList<QStandardItem*>() << item00); |
|
3043 QApplication::processEvents(); |
|
3044 delegate.count = 0; |
|
3045 view.expandAll(); |
|
3046 QApplication::processEvents(); |
|
3047 QTRY_VERIFY(delegate.count >= 4); |
|
3048 QApplication::processEvents(); |
|
3049 |
|
3050 delegate.count = 0; |
|
3051 item0->removeRow(1); |
|
3052 item00->setText("OnlyOne Last"); |
|
3053 QApplication::processEvents(); |
|
3054 QTRY_VERIFY(delegate.count >= 3); |
|
3055 QApplication::processEvents(); |
|
3056 |
|
3057 delegate.count = 0; |
|
3058 item0->removeRow(0); |
|
3059 item0->setText("OnlyOne"); |
|
3060 QApplication::processEvents(); |
|
3061 QTRY_VERIFY(delegate.count >= 2); |
|
3062 QApplication::processEvents(); |
|
3063 |
|
3064 //with hidden items |
|
3065 item0->setText("OnlyOne HasChildren"); |
|
3066 item00 = new QStandardItem("OnlyOne"); |
|
3067 item0->appendRow(QList<QStandardItem*>() << item00); |
|
3068 item01 = new QStandardItem("Assert"); |
|
3069 item0->appendRow(QList<QStandardItem*>() << item01); |
|
3070 view.setRowHidden(1, item0->index(), true); |
|
3071 view.expandAll(); |
|
3072 QStandardItem *item02 = new QStandardItem("OnlyOne Last"); |
|
3073 item0->appendRow(QList<QStandardItem*>() << item02); |
|
3074 delegate.count = 0; |
|
3075 QApplication::processEvents(); |
|
3076 QTRY_VERIFY(delegate.count >= 4); |
|
3077 QApplication::processEvents(); |
|
3078 |
|
3079 item0->removeRow(2); |
|
3080 item00->setText("OnlyOne Last"); |
|
3081 delegate.count = 0; |
|
3082 QApplication::processEvents(); |
|
3083 QTRY_VERIFY(delegate.count >= 3); |
|
3084 QApplication::processEvents(); |
|
3085 } |
2947 } |
3086 } |
2948 |
3087 |
2949 class task174627_TreeView : public QTreeView |
3088 class task174627_TreeView : public QTreeView |
2950 { |
3089 { |
2951 Q_OBJECT |
3090 Q_OBJECT |
3505 QApplication::processEvents(); |
3644 QApplication::processEvents(); |
3506 QVERIFY(view.isExpanded(top->index())); |
3645 QVERIFY(view.isExpanded(top->index())); |
3507 |
3646 |
3508 } |
3647 } |
3509 |
3648 |
3510 |
3649 void tst_QTreeView::doubleClickedWithSpans() |
|
3650 { |
|
3651 QTreeView view; |
|
3652 QStandardItemModel model(1, 2); |
|
3653 view.setModel(&model); |
|
3654 view.setFirstColumnSpanned(0, QModelIndex(), true); |
|
3655 view.show(); |
|
3656 QApplication::setActiveWindow(&view); |
|
3657 QTest::qWaitForWindowShown(&view); |
|
3658 QTRY_VERIFY(view.isActiveWindow()); |
|
3659 |
|
3660 QPoint p(10, 10); |
|
3661 QCOMPARE(view.indexAt(p), model.index(0, 0)); |
|
3662 QSignalSpy spy(&view, SIGNAL(doubleClicked(QModelIndex))); |
|
3663 QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); |
|
3664 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); |
|
3665 QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); |
|
3666 QCOMPARE(spy.count(), 1); |
|
3667 |
|
3668 //let's click on the 2nd column |
|
3669 p.setX(p.x() + view.header()->sectionSize(0)); |
|
3670 QCOMPARE(view.indexAt(p), model.index(0, 0)); |
|
3671 |
|
3672 //end the previous edition |
|
3673 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p); |
|
3674 QTest::qWait(150); |
|
3675 QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); |
|
3676 QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); |
|
3677 QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); |
|
3678 QTRY_COMPARE(spy.count(), 2); |
|
3679 } |
3511 |
3680 |
3512 QTEST_MAIN(tst_QTreeView) |
3681 QTEST_MAIN(tst_QTreeView) |
3513 #include "tst_qtreeview.moc" |
3682 #include "tst_qtreeview.moc" |