diff options
author | Yoann Lopes <yoann.lopes@nokia.com> | 2010-04-07 11:36:02 (GMT) |
---|---|---|
committer | Yoann Lopes <yoann.lopes@nokia.com> | 2010-04-07 13:10:03 (GMT) |
commit | 4c23dd7e310c2af7dc7bf351eade0bd6d528561e (patch) | |
tree | cac9dcc4434e8fc881fb82d109d1b6b017e7cfd5 /tests | |
parent | 2883580a3e10df16789ba1c9ee67507e508b95c1 (diff) | |
download | Qt-4c23dd7e310c2af7dc7bf351eade0bd6d528561e.zip Qt-4c23dd7e310c2af7dc7bf351eade0bd6d528561e.tar.gz Qt-4c23dd7e310c2af7dc7bf351eade0bd6d528561e.tar.bz2 |
Fixes CursorChange and TooltipChange events delivery for QGraphicsWidget
As the documentation mentions, these two events are delivered
respectively after the cursor has changed and after the tooltip has
changed. These two events were previously delivered just before.
This patch is needed for fixing QTBUG-5349 even if it is not directly
related.
Auto-test included.
Reviewed-by: bnilsen
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 4a874be..1930a6f 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -165,6 +165,7 @@ private slots: void polishEvent2(); void initialShow(); void initialShow2(); + void itemChangeEvents(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2886,6 +2887,91 @@ void tst_QGraphicsWidget::initialShow2() QTRY_COMPARE(widget->repaints, expectedRepaintCount); } +void tst_QGraphicsWidget::itemChangeEvents() +{ + class TestGraphicsWidget : public QGraphicsWidget + { public: + TestGraphicsWidget() : QGraphicsWidget() {} + QHash<QEvent::Type, QVariant> valueDuringEvents; + bool event(QEvent *event) { + Q_UNUSED(event); + switch (event->type()) { + case QEvent::EnabledChange: { + valueDuringEvents.insert(QEvent::EnabledChange, isEnabled()); + break; + } + case QEvent::ParentAboutToChange: { + valueDuringEvents.insert(QEvent::ParentAboutToChange, qVariantFromValue(parentItem())); + break; + } + case QEvent::ParentChange: { + valueDuringEvents.insert(QEvent::ParentChange, qVariantFromValue(parentItem())); + break; + } + case QEvent::CursorChange: { + valueDuringEvents.insert(QEvent::CursorChange, int(cursor().shape())); + break; + } + case QEvent::ToolTipChange: { + valueDuringEvents.insert(QEvent::ToolTipChange, toolTip()); + break; + } + default: { + break; + } + } + return true; + } + void showEvent(QShowEvent *event) { + Q_UNUSED(event); + valueDuringEvents.insert(QEvent::Show, isVisible()); + } + void hideEvent(QHideEvent *event) { + Q_UNUSED(event); + valueDuringEvents.insert(QEvent::Hide, isVisible()); + } + }; + + QGraphicsScene scene; + QGraphicsView view(&scene); + QGraphicsWidget *parent = new QGraphicsWidget; + scene.addItem(parent); + view.show(); + QTest::qWaitForWindowShown(&view); + + TestGraphicsWidget *item = new TestGraphicsWidget; + item->setParentItem(parent); + // ParentAboutToChange should be triggered before the parent has changed + QTRY_COMPARE(qVariantValue<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentAboutToChange)), + static_cast<QGraphicsItem *>(0)); + // ParentChange should be triggered after the parent has changed + QTRY_COMPARE(qVariantValue<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentChange)), + static_cast<QGraphicsItem *>(parent)); + + // ShowEvent should be triggered before the item is shown + QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Show).toBool()); + + // HideEvent should be triggered after the item is hidden + QVERIFY(item->isVisible()); + item->setVisible(false); + QVERIFY(!item->isVisible()); + QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Hide).toBool()); + + // CursorChange should be triggered after the cursor has changed + item->setCursor(Qt::PointingHandCursor); + QTRY_COMPARE(item->valueDuringEvents.value(QEvent::CursorChange).toInt(), int(item->cursor().shape())); + + // ToolTipChange should be triggered after the tooltip has changed + item->setToolTip("tooltipText"); + QTRY_COMPARE(item->valueDuringEvents.value(QEvent::ToolTipChange).toString(), item->toolTip()); + + // EnabledChange should be triggered after the enabled state has changed + QVERIFY(item->isEnabled()); + item->setEnabled(false); + QVERIFY(!item->isEnabled()); + QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::EnabledChange).toBool()); +} + void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() { QGraphicsScene scene; |