summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@trolltech.com>2009-04-15 12:14:27 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2009-04-15 22:01:57 (GMT)
commit4f32aaebc26709daf449b460f3be68592bd29d12 (patch)
tree546e8a9263070ecb5593ae9013717833a979c922
parent5595bb2f99d5d6a3c8bb20d3f150915cddc560de (diff)
downloadQt-4f32aaebc26709daf449b460f3be68592bd29d12.zip
Qt-4f32aaebc26709daf449b460f3be68592bd29d12.tar.gz
Qt-4f32aaebc26709daf449b460f3be68592bd29d12.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 (cherry picked from commit 36b16a126e24cb8d8e5c34cfd807bc7c51ea49cf)
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp1
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp34
2 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 801ba99..de4332c 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -8489,6 +8489,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 29b6cdd..ef84f50 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -222,6 +222,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();
@@ -5272,6 +5273,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