summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-01 15:30:46 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-07-01 15:42:44 (GMT)
commit2b9294a2b47c4a193ef83be60a07a3e61b8531b4 (patch)
treed7f81c4ec5abc221462ee8bdafa09c24ce8e7359
parentf4a95e6d6e4c046ac4857cbd54f9488d3b67ce5a (diff)
downloadQt-2b9294a2b47c4a193ef83be60a07a3e61b8531b4.zip
Qt-2b9294a2b47c4a193ef83be60a07a3e61b8531b4.tar.gz
Qt-2b9294a2b47c4a193ef83be60a07a3e61b8531b4.tar.bz2
Fixes broken BSP lookup in QGraphicsSceneBspTreeIndex.
The chip demo was unbelievable slow, so I investigated and found out the bsp always returned almost all items in the tree (40 000 in this particular case). It did so because the tree was initialized with an empty sceneRect. The sceneRect was empty due to a lacking signal-slot connection, resulting in QGraphicsSceneBspTreeIndex::updateSceneRect never being invoked. Auto-test included.
-rw-r--r--src/gui/graphicsview/qgraphicssceneindex.cpp17
-rw-r--r--src/gui/graphicsview/qgraphicssceneindex_p.h3
-rw-r--r--tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp13
3 files changed, 27 insertions, 6 deletions
diff --git a/src/gui/graphicsview/qgraphicssceneindex.cpp b/src/gui/graphicsview/qgraphicssceneindex.cpp
index 2f2f05e..b317e8e 100644
--- a/src/gui/graphicsview/qgraphicssceneindex.cpp
+++ b/src/gui/graphicsview/qgraphicssceneindex.cpp
@@ -303,24 +303,31 @@ void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRe
}
}
+void QGraphicsSceneIndexPrivate::init()
+{
+ if (!scene)
+ return;
+
+ QObject::connect(scene, SIGNAL(sceneRectChanged(const QRectF&)),
+ q_func(), SLOT(updateSceneRect(const QRectF&)));
+}
+
/*!
Constructs an abstract scene index for a given \a scene.
*/
QGraphicsSceneIndex::QGraphicsSceneIndex(QGraphicsScene *scene)
: QObject(*new QGraphicsSceneIndexPrivate(scene), scene)
{
- if (scene) {
- connect(scene, SIGNAL(sceneRectChanged(const QRectF&)),
- this, SLOT(updateSceneRect(const QRectF&)));
- }
+ d_func()->init();
}
/*!
\internal
*/
-QGraphicsSceneIndex::QGraphicsSceneIndex(QObjectPrivate &dd, QGraphicsScene *scene)
+QGraphicsSceneIndex::QGraphicsSceneIndex(QGraphicsSceneIndexPrivate &dd, QGraphicsScene *scene)
: QObject(dd, scene)
{
+ d_func()->init();
}
/*!
diff --git a/src/gui/graphicsview/qgraphicssceneindex_p.h b/src/gui/graphicsview/qgraphicssceneindex_p.h
index 122d7ae..aabfa79 100644
--- a/src/gui/graphicsview/qgraphicssceneindex_p.h
+++ b/src/gui/graphicsview/qgraphicssceneindex_p.h
@@ -114,7 +114,7 @@ protected:
virtual void itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange, const QVariant &value);
virtual void prepareBoundingRectChange(const QGraphicsItem *item);
- QGraphicsSceneIndex(QObjectPrivate &dd, QGraphicsScene *scene);
+ QGraphicsSceneIndex(QGraphicsSceneIndexPrivate &dd, QGraphicsScene *scene);
friend class QGraphicsScene;
friend class QGraphicsScenePrivate;
@@ -133,6 +133,7 @@ public:
QGraphicsSceneIndexPrivate(QGraphicsScene *scene);
~QGraphicsSceneIndexPrivate();
+ void init();
static bool itemCollidesWithPath(const QGraphicsItem *item, const QPainterPath &path, Qt::ItemSelectionMode mode);
void recursive_items_helper(QGraphicsItem *item, QRectF exposeRect,
diff --git a/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp b/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
index ac21e20..9d0675d 100644
--- a/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
+++ b/tests/auto/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
@@ -64,6 +64,7 @@ private slots:
void overlappedItems();
void movingItems_data();
void movingItems();
+ void connectedToSceneRectChanged();
private:
void common_data();
@@ -214,6 +215,18 @@ void tst_QGraphicsSceneIndex::movingItems()
QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 11);
}
+void tst_QGraphicsSceneIndex::connectedToSceneRectChanged()
+{
+
+ class MyScene : public QGraphicsScene
+ { public: using QGraphicsScene::receivers; };
+
+ MyScene scene; // Uses QGraphicsSceneBspTreeIndex by default.
+ QCOMPARE(scene.receivers(SIGNAL(sceneRectChanged(const QRectF&))), 1);
+
+ scene.setItemIndexMethod(QGraphicsScene::NoIndex); // QGraphicsSceneLinearIndex
+ QCOMPARE(scene.receivers(SIGNAL(sceneRectChanged(const QRectF&))), 1);
+}
QTEST_MAIN(tst_QGraphicsSceneIndex)
#include "tst_qgraphicssceneindex.moc"