--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp Mon Mar 15 12:43:09 2010 +0200
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp Thu Apr 08 14:19:33 2010 +0300
@@ -111,6 +111,8 @@
void fontPropagationSceneChange();
void geometry_data();
void geometry();
+ void width();
+ void height();
void getContentsMargins_data();
void getContentsMargins();
void initStyleOption_data();
@@ -164,6 +166,7 @@
void polishEvent();
void polishEvent2();
void initialShow();
+ void initialShow2();
// Task fixes
void task236127_bspTreeIndexFails();
@@ -460,7 +463,7 @@
QFETCH(int, childWithFocus);
SubQGraphicsWidget *widget = children[childWithFocus];
widget->setFocus();
- QVERIFY(widget->hasFocus());
+ QTRY_VERIFY(widget->hasFocus());
QCOMPARE(parent->focusWidget(), static_cast<QGraphicsWidget*>(widget));
}
}
@@ -477,23 +480,23 @@
scene.addItem(widget);
- QVERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!widget->hasFocus());
widget->setFocusPolicy(Qt::StrongFocus);
- QVERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!widget->hasFocus());
QGraphicsWidget *subWidget = new QGraphicsWidget(widget);
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
scene.setFocus();
- QVERIFY(!widget->hasFocus());
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!widget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
widget->setFocus();
- QVERIFY(widget->hasFocus());
- QCOMPARE(focusInSpy.count(), 1);
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(widget->hasFocus());
+ QTRY_COMPARE(focusInSpy.count(), 1);
+ QTRY_VERIFY(!subWidget->hasFocus());
QGraphicsWidget *otherSubWidget = new QGraphicsWidget;
EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn);
@@ -502,18 +505,18 @@
otherSubWidget->setFocusPolicy(Qt::StrongFocus);
otherSubWidget->setParentItem(widget);
- QVERIFY(widget->hasFocus());
+ QTRY_VERIFY(widget->hasFocus());
QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget);
- QVERIFY(!subWidget->hasFocus());
- QVERIFY(!otherSubWidget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!otherSubWidget->hasFocus());
widget->hide();
- QVERIFY(!widget->hasFocus()); // lose but still has subfocus
+ QTRY_VERIFY(!widget->hasFocus()); // lose but still has subfocus
QCOMPARE(focusInSpy.count(), 1);
QCOMPARE(focusOutSpy.count(), 1);
widget->show();
- QVERIFY(!widget->hasFocus()); // no regain
+ QTRY_VERIFY(!widget->hasFocus()); // no regain
QCOMPARE(focusInSpy.count(), 1);
QCOMPARE(focusOutSpy.count(), 1);
@@ -521,24 +524,24 @@
// try to setup subFocus on item that can't take focus
subWidget->setFocus();
- QVERIFY(!subWidget->hasFocus());
+ QTRY_VERIFY(!subWidget->hasFocus());
QVERIFY(!scene.focusItem()); // but isn't the scene's focus item
// try to setup subFocus on item that can take focus
otherSubWidget->setFocus();
- QVERIFY(!otherSubWidget->hasFocus());
+ QTRY_VERIFY(!otherSubWidget->hasFocus());
QCOMPARE(widget->focusWidget(), otherSubWidget);
QVERIFY(!scene.focusItem()); // but isn't the scene's focus item
widget->show();
- QCOMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item
+ QTRY_COMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item
QCOMPARE(otherFocusInSpy.count(), 1);
QCOMPARE(otherFocusOutSpy.count(), 0);
delete otherSubWidget;
- QCOMPARE(otherFocusOutSpy.count(), 1);
+ QTRY_COMPARE(otherFocusOutSpy.count(), 1);
QVERIFY(!scene.focusItem());
QVERIFY(!widget->focusWidget());
}
@@ -577,16 +580,16 @@
SubQGraphicsWidget *widget = new SubQGraphicsWidget;
scene.addItem(widget);
- QCOMPARE(Qt::NoFocus, widget->focusPolicy());
+ QTRY_COMPARE(Qt::NoFocus, widget->focusPolicy());
QFETCH(Qt::FocusPolicy, focusPolicy1);
widget->setFocusPolicy(focusPolicy1);
- QCOMPARE(widget->focusPolicy(), focusPolicy1);
+ QTRY_COMPARE(widget->focusPolicy(), focusPolicy1);
bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable;
bool wasFocusable = isFocusable;
- QVERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus));
+ QTRY_VERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus));
widget->setFocus();
- QCOMPARE(widget->hasFocus(), isFocusable);
+ QTRY_COMPARE(widget->hasFocus(), isFocusable);
QFETCH(Qt::FocusPolicy, focusPolicy2);
widget->setFocusPolicy(focusPolicy2);
@@ -689,25 +692,21 @@
EventSpy rootSpyFont(root, QEvent::FontChange);
EventSpy rootSpyPolish(root, QEvent::Polish);
- QCOMPARE(rootSpyFont.count(), 0);
- QApplication::processEvents(); //The polish event is sent
- QCOMPARE(rootSpyPolish.count(), 1);
- QApplication::processEvents(); //Process events to see if we get the font change event
+ QTRY_COMPARE(rootSpyFont.count(), 0);
+ QTRY_COMPARE(rootSpyPolish.count(), 1);
//The font is still the same so no fontChangeEvent
- QCOMPARE(rootSpyFont.count(), 0);
+ QTRY_COMPARE(rootSpyFont.count(), 0);
QFont font;
font.setPointSize(43);
root->setFont(font);
- QApplication::processEvents(); //Process events to get the font change event
//The font changed
- QCOMPARE(rootSpyFont.count(), 1);
+ QTRY_COMPARE(rootSpyFont.count(), 1);
//then roll back to the default one.
root->setFont(appFont);
- QApplication::processEvents(); //Process events to get the font change event
//The font changed
- QCOMPARE(rootSpyFont.count(), 2);
+ QTRY_COMPARE(rootSpyFont.count(), 2);
}
void tst_QGraphicsWidget::fontPropagationWidgetItemWidget()
@@ -768,14 +767,42 @@
{
SubQGraphicsWidget widget;
QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size()));
-
+ QSignalSpy spy(&widget, SIGNAL(geometryChanged()));
QFETCH(QPointF, pos);
QFETCH(QSizeF, size);
widget.setPos(pos);
widget.resize(size);
+ if (!size.isNull())
+ QCOMPARE(spy.count(), 1);
QCOMPARE(widget.geometry(), QRectF(pos, size));
}
+void tst_QGraphicsWidget::width()
+{
+ QGraphicsWidget w;
+ QCOMPARE(w.property("width").toReal(), qreal(0));
+ QSignalSpy spy(&w, SIGNAL(widthChanged()));
+ w.setProperty("width", qreal(50));
+ QCOMPARE(w.property("width").toReal(), qreal(50));
+ QCOMPARE(spy.count(), 1);
+ //calling old school setGeometry should work too
+ w.setGeometry(0, 0, 200, 200);
+ QCOMPARE(spy.count(), 2);
+}
+
+void tst_QGraphicsWidget::height()
+{
+ QGraphicsWidget w;
+ QCOMPARE(w.property("height").toReal(), qreal(0));
+ QSignalSpy spy(&w, SIGNAL(heightChanged()));
+ w.setProperty("height", qreal(50));
+ QCOMPARE(w.property("height").toReal(), qreal(50));
+ QCOMPARE(spy.count(), 1);
+ //calling old school setGeometry should work too
+ w.setGeometry(0, 0, 200, 200);
+ QCOMPARE(spy.count(), 2);
+}
+
void tst_QGraphicsWidget::getContentsMargins_data()
{
QTest::addColumn<qreal>("left");
@@ -841,7 +868,6 @@
qt_x11_wait_for_window_manager(&view);
#endif
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
@@ -866,7 +892,6 @@
view.resize(300, 300);
view.show();
QTest::qWaitForWindowShown(&view);
- QTest::qWait(20);
sendMouseMove(view.viewport(), view.mapFromScene(widget->mapToScene(widget->boundingRect().center())));
}
@@ -919,9 +944,7 @@
}
widget.setLayout(layout);
- QTest::qWait(25);
-
- QCOMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
+ QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
for (int i = 0; i < children.count(); ++i) {
SubQGraphicsWidget *item = children[i];
QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget);
@@ -961,10 +984,9 @@
view->show();
QTest::qWaitForWindowShown(view);
for (int i = 0; i < children.count(); ++i) {
- QCOMPARE(children[i]->layoutDirection(), layoutDirection);
- QCOMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false);
+ QTRY_COMPARE(children[i]->layoutDirection(), layoutDirection);
+ QTRY_COMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false);
view->repaint();
- QApplication::processEvents();
QTRY_COMPARE(children[i]->m_painterLayoutDirection, layoutDirection);
}
delete view;
@@ -1177,7 +1199,6 @@
qt_x11_wait_for_window_manager(&view);
#endif
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
QGraphicsWidget *lastItem = 0;
@@ -1198,7 +1219,6 @@
if (!children.isEmpty()) {
QGraphicsWidget *first = children.first();
view.viewport()->setFocus();
- QApplication::processEvents();
QTRY_VERIFY(view.viewport()->hasFocus());
first->setFocus();
QVERIFY(first->hasFocus());
@@ -1459,18 +1479,14 @@
QTest::qWaitForWindowShown(window);
lineEdit->setFocus();
- QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_1->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_2->hasFocus());
// remove the tabFocusFirst and insert new item
delete w1_1; // calls _q_removeItemLater
- QTest::qWait(25);
SubQGraphicsWidget *w1_3 = new SubQGraphicsWidget;
w1_3->setFocusPolicy(Qt::StrongFocus);
w1_3->setData(0, "w1_3");
@@ -1478,14 +1494,11 @@
scene.addItem(w1_3);
QTRY_VERIFY(w1_2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
// tabFocusFirst should now point to w1_2
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_2->hasFocus());
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_3->hasFocus());
scene.removeItem(w1_2); // does not call _q_removeItemLater
delete w1_2; // calls _q_removeItemLater
@@ -1496,16 +1509,12 @@
w1_4->setGeometry(75,0,25, 25);
scene.addItem(w1_4);
QTRY_VERIFY(w1_3->hasFocus());
- QTest::qWait(25);
QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4));
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
- QTest::qWait(25);
QTRY_VERIFY(lineEdit->hasFocus());
// tabFocusFirst should now point to w1_3
QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
- QTest::qWait(25);
QTRY_VERIFY(w1_3->hasFocus());
- QTest::qWait(25);
QTRY_VERIFY(compareFocusChain(view, QList<QGraphicsItem*>() << w1_3 << w1_4));
delete window;
}
@@ -1520,7 +1529,6 @@
qt_x11_wait_for_window_manager(&view);
#endif
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
// delete item in focus chain with no focus and verify chain
@@ -1754,31 +1762,29 @@
widget->setPreferredSize(pref);
widget->setMaximumSize(max);
- QApplication::processEvents();
-
for (i = 0; i < compareInstructions.count(); ++i) {
Inst input = compareInstructions.at(i);
switch (input.first) {
case MinimumSize:
- QCOMPARE(widget->minimumSize(), input.second.toSizeF());
+ QTRY_COMPARE(widget->minimumSize(), input.second.toSizeF());
break;
case PreferredSize:
- QCOMPARE(widget->preferredSize(), input.second.toSizeF());
+ QTRY_COMPARE(widget->preferredSize(), input.second.toSizeF());
break;
case MaximumSize:
- QCOMPARE(widget->maximumSize(), input.second.toSizeF());
+ QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF());
break;
case Size:
- QCOMPARE(widget->size(), input.second.toSizeF());
+ QTRY_COMPARE(widget->size(), input.second.toSizeF());
break;
case MinimumWidth:
- QCOMPARE(widget->minimumWidth(), qreal(input.second.toDouble()));
+ QTRY_COMPARE(widget->minimumWidth(), qreal(input.second.toDouble()));
break;
case PreferredWidth:
- QCOMPARE(widget->preferredWidth(), qreal(input.second.toDouble()));
+ QTRY_COMPARE(widget->preferredWidth(), qreal(input.second.toDouble()));
break;
case MaximumWidth:
- QCOMPARE(widget->maximumWidth(), qreal(input.second.toDouble()));
+ QTRY_COMPARE(widget->maximumWidth(), qreal(input.second.toDouble()));
break;
default:
qWarning("instruction not implemented");
@@ -1833,14 +1839,13 @@
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&view);
#endif
- QTest::qWait(100);
-
- QVERIFY(!scene.itemAt(25, 25));
+
+ QTRY_VERIFY(!scene.itemAt(25, 25));
widget->setGeometry(0, 112, 360, 528);
- QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
+ QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
widget2->setGeometry(0, 573, 360, 67);
- QCOMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
- QCOMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2);
+ QTRY_COMPARE(scene.itemAt(15, 120), (QGraphicsItem *)widget);
+ QTRY_COMPARE(scene.itemAt(50, 585), (QGraphicsItem *)widget2);
}
void tst_QGraphicsWidget::defaultSize()
@@ -1855,7 +1860,6 @@
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&view);
#endif
- QTest::qWait(50);
QSizeF initialSize = widget->size();
widget->resize(initialSize);
@@ -1865,9 +1869,8 @@
widget->setPreferredSize(60, 60);
widget->setMaximumSize(110, 110);
widget->setVisible(true);
- QTest::qWait(50);
// should still have its size set to initialsize
- QCOMPARE(widget->geometry().size(), initialSize);
+ QTRY_COMPARE(widget->geometry().size(), initialSize);
}
@@ -2389,7 +2392,6 @@
scene.addItem(widget);
view.show();
QTest::qWaitForWindowShown(&view);
- QTest::qWait(500);
}
class ProxyStyle : public QCommonStyle
@@ -2478,7 +2480,6 @@
view.setScene(&scene);
view.show();
QApplication::setActiveWindow(&view);
- QTest::qWait(25);
QTRY_COMPARE(QApplication::activeWindow(), &view);
@@ -2733,9 +2734,7 @@
QTest::qWaitForWindowShown(view);
{ // here we go - simulate a interactive resize of the window
- QTest::qWait(100);
QTest::mouseMove(view, view->mapFromScene(71, 71)); // bottom right corner
- QTest::qWait(100);
QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200);
view->grabMouse();
@@ -2749,10 +2748,9 @@
QApplication::sendEvent(view->viewport(), &e);
view->releaseMouse();
}
- QTest::qWait(100);
const QSizeF winSize = window->size();
qreal minHFW = window->effectiveSizeHint(Qt::MinimumSize, QSizeF(winSize.width(), -1)).height();
- QVERIFY(qAbs(minHFW - winSize.height()) < 1);
+ QTRY_VERIFY(qAbs(minHFW - winSize.height()) < 1);
#endif
}
@@ -2804,7 +2802,7 @@
view.resize(200, 200);
view.show();
QTest::qWaitForWindowShown(&view);
- QCOMPARE(PolishWidget::numberOfPolish, 2);
+ QTRY_COMPARE(PolishWidget::numberOfPolish, 2);
}
void tst_QGraphicsWidget::polishEvent()
@@ -2851,10 +2849,8 @@
widget->events.clear();
- QApplication::processEvents();
-
// Make sure the item got polish event.
- QVERIFY(widget->events.contains(QEvent::Polish));
+ QTRY_VERIFY(widget->events.contains(QEvent::Polish));
}
void tst_QGraphicsWidget::initialShow()
@@ -2874,11 +2870,50 @@
view.show();
QTest::qWaitForWindowShown(&view);
- QTest::qWait(100);
scene.addItem(widget);
- QTest::qWait(100);
-
- QCOMPARE(widget->repaints, 1);
+
+ QTRY_COMPARE(widget->repaints, 1);
+}
+
+void tst_QGraphicsWidget::initialShow2()
+{
+ class MyGraphicsWidget : public QGraphicsWidget
+ { public:
+ MyGraphicsWidget() : repaints(0) {}
+ int repaints;
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; }
+ void polishEvent() { update(); }
+ };
+
+ // Don't let paint events triggered by the windowing system
+ // influence our test case. We're only interested in knowing
+ // whether a QGraphicsWidget generates an additional repaint
+ // on the inital show. Hence create a dummy scenario to find out
+ // how many repaints we should expect.
+ QGraphicsScene dummyScene(0, 0, 200, 200);
+ dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100));
+
+ QGraphicsView *dummyView = new QGraphicsView(&dummyScene);
+ dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint);
+ EventSpy paintSpy(dummyView->viewport(), QEvent::Paint);
+ dummyView->show();
+ QTest::qWaitForWindowShown(dummyView);
+ const int expectedRepaintCount = paintSpy.count();
+ delete dummyView;
+ dummyView = 0;
+
+ MyGraphicsWidget *widget = new MyGraphicsWidget;
+ widget->resize(100, 100);
+
+ QGraphicsScene scene(0, 0, 200, 200);
+ scene.addItem(widget);
+
+ QGraphicsView view(&scene);
+ view.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ QTRY_COMPARE(widget->repaints, expectedRepaintCount);
}
void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()