diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-05-27 11:39:19 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-05-27 11:39:19 (GMT) |
commit | e54341b9677d2708c2db286ad6548069d7af6e57 (patch) | |
tree | 218fea560ec7064698536aa60aeec7188f540803 | |
parent | 3489f282278d6c667d13bef150f08490316a0c80 (diff) | |
parent | 575e832fd053df98e60aefebbc5843a4864f2523 (diff) | |
download | Qt-e54341b9677d2708c2db286ad6548069d7af6e57.zip Qt-e54341b9677d2708c2db286ad6548069d7af6e57.tar.gz Qt-e54341b9677d2708c2db286ad6548069d7af6e57.tar.bz2 |
Merge branch '4.7' of git://scm.dev.nokia.troll.no/qt/qt-water-team
* '4.7' of git://scm.dev.nokia.troll.no/qt/qt-water-team:
Fixed move a QGraphicsWidget and invalidate its layout at the same time
-rw-r--r-- | src/gui/graphicsview/qgraphicswidget.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp | 73 |
2 files changed, 74 insertions, 2 deletions
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 804394a..7048fcc 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -347,11 +347,10 @@ void QGraphicsWidget::setGeometry(const QRectF &rect) { QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func(); QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr.data(); - QRectF newGeom; + QRectF newGeom = rect; QPointF oldPos = d->geom.topLeft(); if (!wd->inSetPos) { setAttribute(Qt::WA_Resized); - newGeom = rect; newGeom.setSize(rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize)) .boundedTo(effectiveSizeHint(Qt::MaximumSize))); diff --git a/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp index d5d56fc..9411f97 100644 --- a/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp +++ b/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp @@ -63,6 +63,8 @@ private slots: void automaticReparenting(); void verifyActivate(); void invalidate(); + void invalidateAndMove_data(); + void invalidateAndMove(); void constructors(); void alternativeLayoutItems(); void ownership(); @@ -556,6 +558,77 @@ void tst_QGraphicsLayout::invalidate() QGraphicsLayout::setInstantInvalidatePropagation(false); } +void tst_QGraphicsLayout::invalidateAndMove_data() +{ + QTest::addColumn<bool>("instantInvalidatePropagation"); + QTest::newRow("Without instantInvalidatePropagation") << false; + QTest::newRow("With instantInvalidatePropagation") << true; + +} +void tst_QGraphicsLayout::invalidateAndMove() +{ + // Check that if we set the position of an item and invalidate its layout at the same + // time, the widget keeps its correct size + QFETCH(bool, instantInvalidatePropagation); + QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation); + QGraphicsScene scene; + + QGraphicsWidget *widget = new QGraphicsWidget; + new QGraphicsLinearLayout(widget); + + widget->setMinimumSize(1,1); + widget->setPreferredSize(34,34); + widget->setMaximumSize(100,100); + widget->resize(widget->preferredSize()); + + scene.addItem(widget); + + qApp->processEvents(); + + /* Invalidate and reactivate. The size should not have changed */ + widget->layout()->invalidate(); + widget->layout()->activate(); + + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + qApp->processEvents(); + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + + widget->layout()->invalidate(); + widget->setX(1); //Change just the position using setX + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + qApp->processEvents(); + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + + widget->layout()->invalidate(); + widget->setGeometry(1,1,34,34); //Change just the position using setGeometry + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + qApp->processEvents(); + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + + widget->layout()->invalidate(); + widget->setGeometry(1,1,60,60); //Change just the size using setGeometry + QCOMPARE(widget->geometry().size(), QSizeF(60,60)); + QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); + qApp->processEvents(); + QCOMPARE(widget->geometry().size(), QSizeF(60,60)); + QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60)); + + widget->layout()->invalidate(); + widget->setGeometry(0,0,34,34); //Change the size and position using setGeometry + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + qApp->processEvents(); + QCOMPARE(widget->geometry().size(), widget->preferredSize()); + QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize()); + + QGraphicsLayout::setInstantInvalidatePropagation(false); +} class Layout : public QGraphicsLayout { public: |