summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-01-22 11:46:32 (GMT)
committerPrasanth Ullattil <prasanth.ullattil@nokia.com>2010-01-27 15:30:25 (GMT)
commit4bcc8a24129b69efa1217dd033f0af949df0bcb9 (patch)
tree9a4f5c348dd669be2024e87759ffa0534a3c8608
parentef427d48fa684578ecb69e4e1ce2072f12362682 (diff)
downloadQt-4bcc8a24129b69efa1217dd033f0af949df0bcb9.zip
Qt-4bcc8a24129b69efa1217dd033f0af949df0bcb9.tar.gz
Qt-4bcc8a24129b69efa1217dd033f0af949df0bcb9.tar.bz2
QGraphicsWidget is painted twice on the inital show.
Problem occured when doing something in the polishEvent() which eventually ended up as an update(). The problem was that in QGraphicsScene::addItem we scheduled a polish event after scheduling an update, resulting in update requests being processed before polish requests. Auto-test included. Task-number: QTBUG-6956 Reviewed-by: alexis
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp22
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h2
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp25
4 files changed, 43 insertions, 8 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index ac10aa7..bdd8863 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -178,6 +178,7 @@ public:
sequentialOrdering(1),
updateDueToGraphicsEffect(0),
scenePosDescendants(0),
+ pendingPolish(0),
globalStackingOrder(-1),
q_ptr(0)
{
@@ -486,6 +487,7 @@ public:
quint32 sequentialOrdering : 1;
quint32 updateDueToGraphicsEffect : 1;
quint32 scenePosDescendants : 1;
+ quint32 pendingPolish : 1;
// Optional stacking order
int globalStackingOrder;
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 088a6b9..7e182d0 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -429,12 +429,13 @@ void QGraphicsScenePrivate::unregisterTopLevelItem(QGraphicsItem *item)
*/
void QGraphicsScenePrivate::_q_polishItems()
{
- QSet<QGraphicsItem *>::Iterator it = unpolishedItems.begin();
+ QVector<QGraphicsItem *>::Iterator it = unpolishedItems.begin();
const QVariant booleanTrueVariant(true);
while (!unpolishedItems.isEmpty()) {
QGraphicsItem *item = *it;
it = unpolishedItems.erase(it);
unpolishedItemsModified = false;
+ item->d_ptr->pendingPolish = false;
if (!item->d_ptr->explicitlyHidden) {
item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant);
item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant);
@@ -638,8 +639,14 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
selectedItems.remove(item);
hoverItems.removeAll(item);
cachedItemsUnderMouse.removeAll(item);
- unpolishedItems.remove(item);
- unpolishedItemsModified = true;
+ if (item->d_ptr->pendingPolish) {
+ const int unpolishedIndex = unpolishedItems.indexOf(item);
+ if (unpolishedIndex != -1) {
+ unpolishedItems.remove(unpolishedIndex);
+ unpolishedItemsModified = true;
+ }
+ item->d_ptr->pendingPolish = false;
+ }
resetDirtyItem(item);
//We remove all references of item from the sceneEventFilter arrays
@@ -2501,6 +2508,11 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
return;
}
+ if (d->unpolishedItems.isEmpty())
+ QMetaObject::invokeMethod(this, "_q_polishItems", Qt::QueuedConnection);
+ d->unpolishedItems.append(item);
+ item->d_ptr->pendingPolish = true;
+
// Detach this item from its parent if the parent's scene is different
// from this scene.
if (QGraphicsItem *itemParent = item->d_ptr->parent) {
@@ -2583,10 +2595,6 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
item->d_ptr->resolveFont(d->font.resolve());
item->d_ptr->resolvePalette(d->palette.resolve());
- if (d->unpolishedItems.isEmpty())
- QMetaObject::invokeMethod(this, "_q_polishItems", Qt::QueuedConnection);
- d->unpolishedItems.insert(item);
- d->unpolishedItemsModified = true;
// Reenable selectionChanged() for individual items
--d->selectionChanging;
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index d10811c..a3e36d0 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -108,7 +108,7 @@ public:
QPainterPath selectionArea;
int selectionChanging;
QSet<QGraphicsItem *> selectedItems;
- QSet<QGraphicsItem *> unpolishedItems;
+ QVector<QGraphicsItem *> unpolishedItems;
QList<QGraphicsItem *> topLevelItems;
bool needSortTopLevelItems;
bool unpolishedItemsModified;
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 909ea54..d3132fe 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -163,6 +163,7 @@ private slots:
void addChildInpolishEvent();
void polishEvent();
void polishEvent2();
+ void initialShow();
// Task fixes
void task236127_bspTreeIndexFails();
@@ -2856,6 +2857,30 @@ void tst_QGraphicsWidget::polishEvent2()
QVERIFY(widget->events.contains(QEvent::Polish));
}
+void tst_QGraphicsWidget::initialShow()
+{
+ class MyGraphicsWidget : public QGraphicsWidget
+ { public:
+ MyGraphicsWidget() : repaints(0) {}
+ int repaints;
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; }
+ void polishEvent() { update(); }
+ };
+
+ QGraphicsScene scene;
+ MyGraphicsWidget *widget = new MyGraphicsWidget;
+
+ QGraphicsView view(&scene);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ QTest::qWait(100);
+ scene.addItem(widget);
+ QTest::qWait(100);
+
+ QCOMPARE(widget->repaints, 1);
+}
+
void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()
{
QGraphicsScene scene;