summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@trolltech.com>2009-03-04 16:35:08 +0100
committerAlexis Menard <alexis.menard@trolltech.com>2009-04-07 19:51:14 +0200
commit33a0ebfc5c9b18850d4d09900fe9dea8abfd1fd2 (patch)
tree0d17bb07765f5b8f55f1186a92eeaa6a7cd60195
parent37c72476fc444d3089075473cb4e9aa42ed64694 (diff)
Fixes: Initial work on an API to allow a custom/indexing on the QGraphicsScene
-rw-r--r--src/gui/graphicsview/graphicsview.pri2
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp51
-rw-r--r--src/gui/graphicsview/qgraphicsscene.h4
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h3
-rw-r--r--src/gui/graphicsview/qgraphicssceneindex.cpp61
-rw-r--r--src/gui/graphicsview/qgraphicssceneindex.h83
6 files changed, 198 insertions, 6 deletions
diff --git a/src/gui/graphicsview/graphicsview.pri b/src/gui/graphicsview/graphicsview.pri
index 02d9bb1a94..f0bdddc598 100644
--- a/src/gui/graphicsview/graphicsview.pri
+++ b/src/gui/graphicsview/graphicsview.pri
@@ -7,6 +7,7 @@ HEADERS += \
graphicsview/qgraphicsscene.h \
graphicsview/qgraphicsscene_p.h \
graphicsview/qgraphicsscene_bsp_p.h \
+ graphicsview/qgraphicssceneindex.h \
graphicsview/qgraphicssceneevent.h \
graphicsview/qgraphicsview_p.h \
graphicsview/qgraphicsview.h
@@ -16,6 +17,7 @@ SOURCES += \
graphicsview/qgraphicsitemanimation.cpp \
graphicsview/qgraphicsscene.cpp \
graphicsview/qgraphicsscene_bsp.cpp \
+ graphicsview/qgraphicssceneindex.cpp \
graphicsview/qgraphicssceneevent.cpp \
graphicsview/qgraphicsview.cpp
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index e88523892e..e74ae3ae62 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -219,6 +219,7 @@ static const int QGRAPHICSSCENE_INDEXTIMER_TIMEOUT = 2000;
#include "qgraphicsview_p.h"
#include "qgraphicswidget.h"
#include "qgraphicswidget_p.h"
+#include "qgraphicssceneindex.h"
#include <QtCore/qdebug.h>
#include <QtCore/qlist.h>
@@ -330,6 +331,7 @@ QGraphicsScenePrivate::QGraphicsScenePrivate()
indexMethod(QGraphicsScene::BspTreeIndex),
bspTreeDepth(0),
lastItemCount(0),
+ customIndex(0),
hasSceneRect(false),
updateAll(false),
calledEmitUpdated(false),
@@ -381,12 +383,18 @@ QList<QGraphicsItem *> QGraphicsScenePrivate::estimateItemsInRect(const QRectF &
const_cast<QGraphicsScenePrivate *>(this)->purgeRemovedItems();
const_cast<QGraphicsScenePrivate *>(this)->_q_updateSortCache();
- if (indexMethod == QGraphicsScene::BspTreeIndex) {
+ if (indexMethod != QGraphicsScene::NoIndex) {
// ### Only do this once in a while.
QGraphicsScenePrivate *that = const_cast<QGraphicsScenePrivate *>(this);
- // Get items from BSP tree
- QList<QGraphicsItem *> items = that->bspTree.items(rect);
+ QList<QGraphicsItem *> items;
+ if (indexMethod == QGraphicsScene::BspTreeIndex) {
+ // Get items from BSP tree
+ items = that->bspTree.items(rect);
+ } else {
+ //ask to the custom indexing
+ items = that->customIndex->items(rect);
+ }
// Fill in with any unindexed items
for (int i = 0; i < unindexedItems.size(); ++i) {
@@ -444,6 +452,12 @@ void QGraphicsScenePrivate::addToIndex(QGraphicsItem *item)
// size.
startIndexTimer();
}
+ } else if (indexMethod == QGraphicsScene::CustomIndex) {
+ if (item->d_func()->index != -1) {
+ customIndex->insertItem(item, item->sceneBoundingRect());
+ foreach (QGraphicsItem *child, item->children())
+ child->addToIndex();
+ }
}
}
@@ -452,10 +466,13 @@ void QGraphicsScenePrivate::addToIndex(QGraphicsItem *item)
*/
void QGraphicsScenePrivate::removeFromIndex(QGraphicsItem *item)
{
- if (indexMethod == QGraphicsScene::BspTreeIndex) {
+ if (indexMethod != QGraphicsScene::NoIndex) {
int index = item->d_func()->index;
if (index != -1) {
- bspTree.removeItem(item, item->sceneBoundingRect());
+ if (indexMethod == QGraphicsScene::CustomIndex)
+ customIndex->removeItem(item, item->sceneBoundingRect());
+ else
+ bspTree.removeItem(item, item->sceneBoundingRect());
freeItemIndexes << index;
indexedItems[index] = 0;
item->d_func()->index = -1;
@@ -464,7 +481,6 @@ void QGraphicsScenePrivate::removeFromIndex(QGraphicsItem *item)
foreach (QGraphicsItem *child, item->children())
child->removeFromIndex();
}
-
startIndexTimer();
}
}
@@ -564,6 +580,8 @@ void QGraphicsScenePrivate::_q_updateIndex()
continue;
if (indexMethod == QGraphicsScene::BspTreeIndex)
bspTree.insertItem(item, rect);
+ if (indexMethod == QGraphicsScene::CustomIndex)
+ customIndex->insertItem(item,rect);
// If the item ignores view transformations, update our
// largest-item-counter to ensure that the view can accurately
@@ -2359,10 +2377,31 @@ QGraphicsScene::ItemIndexMethod QGraphicsScene::itemIndexMethod() const
void QGraphicsScene::setItemIndexMethod(ItemIndexMethod method)
{
Q_D(QGraphicsScene);
+ if (method == CustomIndex) {
+ qWarning("QGraphicsScene: Invalid index type %d", CustomIndex);
+ return;
+ }
d->resetIndex();
d->indexMethod = method;
}
+void QGraphicsScene::setSceneIndex(QGraphicsSceneIndex *index)
+{
+ Q_D(QGraphicsScene);
+ if (!index) {
+ qWarning("QGraphicsScene::setSceneIndex: Attempt to insert a null indexer");
+ } else {
+ d->indexMethod = CustomIndex;
+ d->customIndex = index;
+ }
+}
+
+QGraphicsSceneIndex* QGraphicsScene::sceneIndex()
+{
+ Q_D(QGraphicsScene);
+ return d->customIndex;
+}
+
/*!
\property QGraphicsScene::bspTreeDepth
\brief the depth of QGraphicsScene's BSP index tree
diff --git a/src/gui/graphicsview/qgraphicsscene.h b/src/gui/graphicsview/qgraphicsscene.h
index 9802f8755b..7e1e040360 100644
--- a/src/gui/graphicsview/qgraphicsscene.h
+++ b/src/gui/graphicsview/qgraphicsscene.h
@@ -83,6 +83,7 @@ class QGraphicsSimpleTextItem;
class QGraphicsTextItem;
class QGraphicsView;
class QGraphicsWidget;
+class QGraphicsSceneIndex;
class QHelpEvent;
class QInputMethodEvent;
class QKeyEvent;
@@ -113,6 +114,7 @@ class Q_GUI_EXPORT QGraphicsScene : public QObject
public:
enum ItemIndexMethod {
BspTreeIndex,
+ CustomIndex,
NoIndex = -1
};
@@ -142,6 +144,8 @@ public:
ItemIndexMethod itemIndexMethod() const;
void setItemIndexMethod(ItemIndexMethod method);
+ void setSceneIndex(QGraphicsSceneIndex *index);
+ QGraphicsSceneIndex* sceneIndex();
bool isSortCacheEnabled() const;
void setSortCacheEnabled(bool enabled);
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index 9ace7252b3..fe36fbdb83 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -58,6 +58,7 @@
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
#include "qgraphicsscene_bsp_p.h"
+#include "qgraphicssceneindex.h"
#include "qgraphicsitem_p.h"
#include <private/qobject_p.h>
@@ -95,6 +96,8 @@ public:
void _q_updateIndex();
int lastItemCount;
+ QGraphicsSceneIndex *customIndex;
+
QRectF sceneRect;
bool hasSceneRect;
QRectF growingItemsBoundingRect;
diff --git a/src/gui/graphicsview/qgraphicssceneindex.cpp b/src/gui/graphicsview/qgraphicssceneindex.cpp
new file mode 100644
index 0000000000..00c63a31db
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicssceneindex.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgraphicssceneindex.h"
+
+#ifndef QT_NO_GRAPHICSVIEW
+
+QT_BEGIN_NAMESPACE
+
+QGraphicsSceneIndex::QGraphicsSceneIndex()
+{
+}
+
+QGraphicsSceneIndex::~QGraphicsSceneIndex()
+{
+
+}
+
+QT_END_NAMESPACE
+
+//#include "moc_qgraphicssceneindex.cpp"
+
+#endif // QT_NO_GRAPHICSVIEW
diff --git a/src/gui/graphicsview/qgraphicssceneindex.h b/src/gui/graphicsview/qgraphicssceneindex.h
new file mode 100644
index 0000000000..2b1cc6e349
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicssceneindex.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGRAPHICSSCENEINDEX_H
+#define QGRAPHICSSCENEINDEX_H
+
+#include <QtCore/qnamespace.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
+
+class QGraphicsItem;
+class QRectF;
+class QPointF;
+template<typename T> class QList;
+template<typename T> class QSet;
+
+class Q_GUI_EXPORT QGraphicsSceneIndex
+{
+public:
+ QGraphicsSceneIndex();
+ virtual ~QGraphicsSceneIndex();
+
+ virtual void clear() = 0;
+
+ virtual void insertItem(QGraphicsItem *item, const QRectF &rect) = 0;
+ virtual void removeItem(QGraphicsItem *item, const QRectF &rect) = 0;
+ virtual void removeItems(const QSet<QGraphicsItem *> &items) = 0;
+
+ virtual QList<QGraphicsItem *> items(const QRectF &rect) = 0;
+ virtual QList<QGraphicsItem *> items(const QPointF &pos) = 0;
+};
+
+#endif // QT_NO_GRAPHICSVIEW
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QGRAPHICSSCENEINDEX_H