diff options
author | Alexis Menard <alexis.menard@trolltech.com> | 2009-04-15 12:14:27 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-04-15 16:14:19 (GMT) |
commit | a0c67f25dfa722af7a321cf1814bdbba6d7fa947 (patch) | |
tree | 8c4e005d2916a5b8e3131bd6d16d3e3fca47d3a2 | |
parent | 305b64b551a5c1b708434033e56e7c6a0efb54dc (diff) | |
download | Qt-a0c67f25dfa722af7a321cf1814bdbba6d7fa947.zip Qt-a0c67f25dfa722af7a321cf1814bdbba6d7fa947.tar.gz Qt-a0c67f25dfa722af7a321cf1814bdbba6d7fa947.tar.bz2 |
Update the item if the text has changed but the boundingRect is the
same.
updateBoudingRect update the item only if the boundingRect change
but if we have 123 as an initial text and then we set 321 as the new
text, then nothing happen because the rect is the same.
In case the boundingRect change then we call update 2 times but
the item is already dirty so the second call will just return.
BT:yes
Reviewed-by: Andreas
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 7aba576..3aa74f3 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -8617,6 +8617,7 @@ void QGraphicsSimpleTextItem::setText(const QString &text) return; d->text = text; d->updateBoundingRect(); + update(); } /*! diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 439dc2b..09b209d 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -223,6 +223,7 @@ private slots: // task specific tests below me void task141694_textItemEnsureVisible(); void task128696_textItemEnsureMovable(); + void ensureUpdateOnTextItem(); void task177918_lineItemUndetected(); void task240400_clickOnTextItem_data(); void task240400_clickOnTextItem(); @@ -5294,6 +5295,39 @@ void tst_QGraphicsItem::task240400_clickOnTextItem() QCOMPARE(item->textCursor().columnNumber(), 0); } +class TextItem : public QGraphicsSimpleTextItem +{ +public: + TextItem(const QString& text) : QGraphicsSimpleTextItem(text) + { + updates = 0; + } + + void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) + { + updates++; + QGraphicsSimpleTextItem::paint(painter, option, widget); + } + + int updates; +}; + +void tst_QGraphicsItem::ensureUpdateOnTextItem() +{ + QGraphicsScene scene; + TextItem *text1 = new TextItem(QLatin1String("123")); + scene.addItem(text1); + QGraphicsView view(&scene); + view.show(); + QTest::qWait(250); + QCOMPARE(text1->updates,1); + + //same bouding rect but we have to update + text1->setText(QLatin1String("321")); + QTest::qWait(250); + QCOMPARE(text1->updates,2); +} + void tst_QGraphicsItem::task243707_addChildBeforeParent() { // Task reports that adding the child before the parent leads to an |