tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
branchRCL_3
changeset 14 c0432d11811c
parent 8 3f74d0d4af4c
equal deleted inserted replaced
13:cc75c76972ee 14:c0432d11811c
   109     void fontChangedEvent();
   109     void fontChangedEvent();
   110     void fontPropagationWidgetItemWidget();
   110     void fontPropagationWidgetItemWidget();
   111     void fontPropagationSceneChange();
   111     void fontPropagationSceneChange();
   112     void geometry_data();
   112     void geometry_data();
   113     void geometry();
   113     void geometry();
   114     void width();
       
   115     void height();
       
   116     void getContentsMargins_data();
   114     void getContentsMargins_data();
   117     void getContentsMargins();
   115     void getContentsMargins();
   118     void initStyleOption_data();
   116     void initStyleOption_data();
   119     void initStyleOption();
   117     void initStyleOption();
   120     void layout_data();
   118     void layout_data();
   165     void addChildInpolishEvent();
   163     void addChildInpolishEvent();
   166     void polishEvent();
   164     void polishEvent();
   167     void polishEvent2();
   165     void polishEvent2();
   168     void initialShow();
   166     void initialShow();
   169     void initialShow2();
   167     void initialShow2();
       
   168     void itemChangeEvents();
   170 
   169 
   171     // Task fixes
   170     // Task fixes
   172     void task236127_bspTreeIndexFails();
   171     void task236127_bspTreeIndexFails();
   173     void task243004_setStyleCrash();
   172     void task243004_setStyleCrash();
   174     void task250119_shortcutContext();
   173     void task250119_shortcutContext();
   765 // QRectF geometry() const public
   764 // QRectF geometry() const public
   766 void tst_QGraphicsWidget::geometry()
   765 void tst_QGraphicsWidget::geometry()
   767 {
   766 {
   768     SubQGraphicsWidget widget;
   767     SubQGraphicsWidget widget;
   769     QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size()));
   768     QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size()));
   770     QSignalSpy spy(&widget, SIGNAL(geometryChanged()));
   769 
   771     QFETCH(QPointF, pos);
   770     QFETCH(QPointF, pos);
   772     QFETCH(QSizeF, size);
   771     QFETCH(QSizeF, size);
   773     widget.setPos(pos);
   772     widget.setPos(pos);
   774     widget.resize(size);
   773     widget.resize(size);
   775     if (!size.isNull())
       
   776         QCOMPARE(spy.count(), 1);
       
   777     QCOMPARE(widget.geometry(), QRectF(pos, size));
   774     QCOMPARE(widget.geometry(), QRectF(pos, size));
   778 }
       
   779 
       
   780 void tst_QGraphicsWidget::width()
       
   781 {
       
   782     QGraphicsWidget w;
       
   783     QCOMPARE(w.property("width").toReal(), qreal(0));
       
   784     QSignalSpy spy(&w, SIGNAL(widthChanged()));
       
   785     w.setProperty("width", qreal(50));
       
   786     QCOMPARE(w.property("width").toReal(), qreal(50));
       
   787     QCOMPARE(spy.count(), 1);
       
   788     //calling old school setGeometry should work too
       
   789     w.setGeometry(0, 0, 200, 200);
       
   790     QCOMPARE(spy.count(), 2);
       
   791 }
       
   792 
       
   793 void tst_QGraphicsWidget::height()
       
   794 {
       
   795     QGraphicsWidget w;
       
   796     QCOMPARE(w.property("height").toReal(), qreal(0));
       
   797     QSignalSpy spy(&w, SIGNAL(heightChanged()));
       
   798     w.setProperty("height", qreal(50));
       
   799     QCOMPARE(w.property("height").toReal(), qreal(50));
       
   800     QCOMPARE(spy.count(), 1);
       
   801     //calling old school setGeometry should work too
       
   802     w.setGeometry(0, 0, 200, 200);
       
   803     QCOMPARE(spy.count(), 2);
       
   804 }
   775 }
   805 
   776 
   806 void tst_QGraphicsWidget::getContentsMargins_data()
   777 void tst_QGraphicsWidget::getContentsMargins_data()
   807 {
   778 {
   808     QTest::addColumn<qreal>("left");
   779     QTest::addColumn<qreal>("left");
  2914     QTest::qWaitForWindowShown(&view);
  2885     QTest::qWaitForWindowShown(&view);
  2915 
  2886 
  2916     QTRY_COMPARE(widget->repaints, expectedRepaintCount);
  2887     QTRY_COMPARE(widget->repaints, expectedRepaintCount);
  2917 }
  2888 }
  2918 
  2889 
       
  2890 void tst_QGraphicsWidget::itemChangeEvents()
       
  2891 {
       
  2892     class TestGraphicsWidget : public QGraphicsWidget
       
  2893     { public:
       
  2894         TestGraphicsWidget() : QGraphicsWidget() {}
       
  2895         QHash<QEvent::Type, QVariant> valueDuringEvents;
       
  2896         bool event(QEvent *event) {
       
  2897             Q_UNUSED(event);
       
  2898             switch (event->type()) {
       
  2899             case QEvent::EnabledChange: {
       
  2900                 valueDuringEvents.insert(QEvent::EnabledChange, isEnabled());
       
  2901                 break;
       
  2902             }
       
  2903             case QEvent::ParentAboutToChange: {
       
  2904                 valueDuringEvents.insert(QEvent::ParentAboutToChange, qVariantFromValue(parentItem()));
       
  2905                 break;
       
  2906             }
       
  2907             case QEvent::ParentChange: {
       
  2908                 valueDuringEvents.insert(QEvent::ParentChange, qVariantFromValue(parentItem()));
       
  2909                 break;
       
  2910             }
       
  2911             case QEvent::CursorChange: {
       
  2912                 valueDuringEvents.insert(QEvent::CursorChange, int(cursor().shape()));
       
  2913                 break;
       
  2914             }
       
  2915             case QEvent::ToolTipChange: {
       
  2916                 valueDuringEvents.insert(QEvent::ToolTipChange, toolTip());
       
  2917                 break;
       
  2918             }
       
  2919             default: {
       
  2920                 break;
       
  2921             }
       
  2922             }
       
  2923             return true;
       
  2924         }
       
  2925         void showEvent(QShowEvent *event) {
       
  2926             Q_UNUSED(event);
       
  2927             valueDuringEvents.insert(QEvent::Show, isVisible());
       
  2928         }
       
  2929         void hideEvent(QHideEvent *event) {
       
  2930             Q_UNUSED(event);
       
  2931             valueDuringEvents.insert(QEvent::Hide, isVisible());
       
  2932         }
       
  2933     };
       
  2934 
       
  2935     QGraphicsScene scene;
       
  2936     QGraphicsView view(&scene);
       
  2937     QGraphicsWidget *parent = new QGraphicsWidget;
       
  2938     scene.addItem(parent);
       
  2939     view.show();
       
  2940     QTest::qWaitForWindowShown(&view);
       
  2941 
       
  2942     TestGraphicsWidget *item = new TestGraphicsWidget;
       
  2943     item->setParentItem(parent);
       
  2944     // ParentAboutToChange should be triggered before the parent has changed
       
  2945     QTRY_COMPARE(qVariantValue<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentAboutToChange)),
       
  2946              static_cast<QGraphicsItem *>(0));
       
  2947     // ParentChange should be triggered after the parent has changed
       
  2948     QTRY_COMPARE(qVariantValue<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentChange)),
       
  2949              static_cast<QGraphicsItem *>(parent));
       
  2950 
       
  2951     // ShowEvent should be triggered before the item is shown
       
  2952     QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Show).toBool());
       
  2953 
       
  2954     // HideEvent should be triggered after the item is hidden
       
  2955     QVERIFY(item->isVisible());
       
  2956     item->setVisible(false);
       
  2957     QVERIFY(!item->isVisible());
       
  2958     QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Hide).toBool());
       
  2959 
       
  2960     // CursorChange should be triggered after the cursor has changed
       
  2961     item->setCursor(Qt::PointingHandCursor);
       
  2962     QTRY_COMPARE(item->valueDuringEvents.value(QEvent::CursorChange).toInt(), int(item->cursor().shape()));
       
  2963 
       
  2964     // ToolTipChange should be triggered after the tooltip has changed
       
  2965     item->setToolTip("tooltipText");
       
  2966     QTRY_COMPARE(item->valueDuringEvents.value(QEvent::ToolTipChange).toString(), item->toolTip());
       
  2967 
       
  2968     // EnabledChange should be triggered after the enabled state has changed
       
  2969     QVERIFY(item->isEnabled());
       
  2970     item->setEnabled(false);
       
  2971     QVERIFY(!item->isEnabled());
       
  2972     QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::EnabledChange).toBool());
       
  2973 }
       
  2974 
  2919 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()
  2975 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()
  2920 {
  2976 {
  2921     QGraphicsScene scene;
  2977     QGraphicsScene scene;
  2922     QGraphicsWidget* parent1 = new QGraphicsWidget;
  2978     QGraphicsWidget* parent1 = new QGraphicsWidget;
  2923     QGraphicsWidget* child1_0 = new QGraphicsWidget;
  2979     QGraphicsWidget* child1_0 = new QGraphicsWidget;