summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@trolltech.com>2009-04-07 18:06:38 (GMT)
committerAlexis Menard <alexis.menard@trolltech.com>2009-04-07 18:06:38 (GMT)
commite2e30d5c0ca99a47cc142465436d5e0a3f616b82 (patch)
treeb9fe22cfc7fa816ff9128a2ea264ca6de020056c
parent9e5293822b849ed37742054cf1f4c0bb1b1e7156 (diff)
downloadQt-e2e30d5c0ca99a47cc142465436d5e0a3f616b82.zip
Qt-e2e30d5c0ca99a47cc142465436d5e0a3f616b82.tar.gz
Qt-e2e30d5c0ca99a47cc142465436d5e0a3f616b82.tar.bz2
Fixes: Make the bsp tree inherits from the new API
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp6
-rw-r--r--src/gui/graphicsview/qgraphicsscene_bsp.cpp31
-rw-r--r--src/gui/graphicsview/qgraphicsscene_bsp_p.h16
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicssceneindex.h4
5 files changed, 41 insertions, 18 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index a41f931..8660853 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -443,7 +443,7 @@ void QGraphicsScenePrivate::addToIndex(QGraphicsItem *item)
{
if (indexMethod == QGraphicsScene::BspTreeIndex) {
if (item->d_func()->index != -1) {
- bspTree.insertItem(item, item->sceneBoundingRect());
+ bspTree.insertItem(item);
foreach (QGraphicsItem *child, item->children())
child->addToIndex();
} else {
@@ -472,7 +472,7 @@ void QGraphicsScenePrivate::removeFromIndex(QGraphicsItem *item)
if (indexMethod == QGraphicsScene::CustomIndex)
customIndex->removeItem(item);
else
- bspTree.removeItem(item, item->sceneBoundingRect());
+ bspTree.removeItem(item);
freeItemIndexes << index;
indexedItems[index] = 0;
item->d_func()->index = -1;
@@ -579,7 +579,7 @@ void QGraphicsScenePrivate::_q_updateIndex()
if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
continue;
if (indexMethod == QGraphicsScene::BspTreeIndex)
- bspTree.insertItem(item, rect);
+ bspTree.insertItem(item);
if (indexMethod == QGraphicsScene::CustomIndex)
customIndex->insertItem(item);
diff --git a/src/gui/graphicsview/qgraphicsscene_bsp.cpp b/src/gui/graphicsview/qgraphicsscene_bsp.cpp
index f8fa450..c295cb3 100644
--- a/src/gui/graphicsview/qgraphicsscene_bsp.cpp
+++ b/src/gui/graphicsview/qgraphicsscene_bsp.cpp
@@ -100,7 +100,7 @@ QGraphicsSceneBspTree::~QGraphicsSceneBspTree()
void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth)
{
- this->rect = rect;
+ sceneRect = rect;
leafCnt = 0;
nodes.resize((1 << (depth + 1)) - 1);
nodes.fill(Node());
@@ -117,19 +117,36 @@ void QGraphicsSceneBspTree::clear()
leaves.clear();
}
-void QGraphicsSceneBspTree::insertItem(QGraphicsItem *item, const QRectF &rect)
+QRectF QGraphicsSceneBspTree::rect() const
+{
+ return sceneRect;
+}
+
+void QGraphicsSceneBspTree::setRect(const QRectF &rect)
+{
+ sceneRect = rect;
+}
+
+void QGraphicsSceneBspTree::insertItem(QGraphicsItem *item)
{
insertVisitor->item = item;
- climbTree(insertVisitor, rect);
+ climbTree(insertVisitor, item->sceneBoundingRect());
+}
+
+void QGraphicsSceneBspTree::insertItems(const QList<QGraphicsItem *> &items)
+{
+ foreach(QGraphicsItem *item, items) {
+ insertItem(item);
+ }
}
-void QGraphicsSceneBspTree::removeItem(QGraphicsItem *item, const QRectF &rect)
+void QGraphicsSceneBspTree::removeItem(QGraphicsItem *item)
{
removeVisitor->item = item;
- climbTree(removeVisitor, rect);
+ climbTree(removeVisitor, item->sceneBoundingRect());
}
-void QGraphicsSceneBspTree::removeItems(const QSet<QGraphicsItem *> &items)
+void QGraphicsSceneBspTree::removeItems(const QList<QGraphicsItem *> &items)
{
for (int i = 0; i < leaves.size(); ++i) {
QList<QGraphicsItem *> newItemList;
@@ -302,7 +319,7 @@ void QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor *visitor, con
QRectF QGraphicsSceneBspTree::rectForIndex(int index) const
{
if (index <= 0)
- return rect;
+ return sceneRect;
int parentIdx = parentIndex(index);
QRectF rect = rectForIndex(parentIdx);
diff --git a/src/gui/graphicsview/qgraphicsscene_bsp_p.h b/src/gui/graphicsview/qgraphicsscene_bsp_p.h
index e6ceb78..4114b3b 100644
--- a/src/gui/graphicsview/qgraphicsscene_bsp_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_bsp_p.h
@@ -60,6 +60,7 @@
#include <QtCore/qrect.h>
#include <QtCore/qset.h>
#include <QtCore/qvector.h>
+#include <QtGui/qgraphicssceneindex.h>
QT_BEGIN_NAMESPACE
@@ -69,7 +70,7 @@ class QGraphicsSceneInsertItemBspTreeVisitor;
class QGraphicsSceneRemoveItemBspTreeVisitor;
class QGraphicsSceneFindItemBspTreeVisitor;
-class QGraphicsSceneBspTree
+class QGraphicsSceneBspTree : public QGraphicsSceneIndex
{
public:
struct Node
@@ -87,10 +88,13 @@ public:
void initialize(const QRectF &rect, int depth);
void clear();
+ QRectF rect() const;
+ void setRect(const QRectF &rect);
- void insertItem(QGraphicsItem *item, const QRectF &rect);
- void removeItem(QGraphicsItem *item, const QRectF &rect);
- void removeItems(const QSet<QGraphicsItem *> &items);
+ void insertItem(QGraphicsItem *item);
+ void insertItems(const QList<QGraphicsItem *> &items);
+ void removeItem(QGraphicsItem *item);
+ void removeItems(const QList<QGraphicsItem *> &items);
QList<QGraphicsItem *> items(const QRectF &rect);
QList<QGraphicsItem *> items(const QPointF &pos);
@@ -116,7 +120,7 @@ private:
QVector<Node> nodes;
QVector<QList<QGraphicsItem *> > leaves;
int leafCnt;
- QRectF rect;
+ QRectF sceneRect;
QGraphicsSceneInsertItemBspTreeVisitor *insertVisitor;
QGraphicsSceneRemoveItemBspTreeVisitor *removeVisitor;
@@ -130,6 +134,8 @@ public:
virtual void visit(QList<QGraphicsItem *> *items) = 0;
};
+Q_DECLARE_TYPEINFO(QGraphicsSceneBspTree::Node, Q_PRIMITIVE_TYPE);
+
QT_END_NAMESPACE
#endif // QT_NO_GRAPHICSVIEW
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index fe36fbd..aacbc40 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -132,7 +132,7 @@ public:
bool purgePending;
void _q_removeItemLater(QGraphicsItem *item);
- QSet<QGraphicsItem *> removedItems;
+ QList<QGraphicsItem *> removedItems;
void purgeRemovedItems();
QBrush backgroundBrush;
diff --git a/src/gui/graphicsview/qgraphicssceneindex.h b/src/gui/graphicsview/qgraphicssceneindex.h
index 5e825ba..bda6f5e 100644
--- a/src/gui/graphicsview/qgraphicssceneindex.h
+++ b/src/gui/graphicsview/qgraphicssceneindex.h
@@ -69,9 +69,9 @@ public:
virtual void clear() = 0;
virtual void insertItem(QGraphicsItem *item) = 0;
- virtual void insertItems(QList<QGraphicsItem *> items) = 0;
+ virtual void insertItems(const QList<QGraphicsItem *> &items) = 0;
virtual void removeItem(QGraphicsItem *item) = 0;
- virtual void removeItems(QList<QGraphicsItem *> items) = 0;
+ virtual void removeItems(const QList<QGraphicsItem *> &items) = 0;
virtual QList<QGraphicsItem *> items(const QRectF &rect) = 0;