source: trunk/src/gui/graphicsview/qgraphicssceneindex_p.h@ 856

Last change on this file since 856 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGRAPHICSSCENEINDEX_H
43#define QGRAPHICSSCENEINDEX_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists for the convenience
50// of other Qt classes. This header file may change from version to
51// version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include "qgraphicsscene_p.h"
57#include "qgraphicsscene.h"
58#include <private/qobject_p.h>
59
60#include <QtCore/qnamespace.h>
61#include <QtCore/qobject.h>
62#include <QtGui/qtransform.h>
63
64QT_BEGIN_HEADER
65
66QT_BEGIN_NAMESPACE
67
68QT_MODULE(Gui)
69
70#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
71
72class QGraphicsSceneIndexIntersector;
73class QGraphicsSceneIndexPointIntersector;
74class QGraphicsSceneIndexRectIntersector;
75class QGraphicsSceneIndexPathIntersector;
76class QGraphicsSceneIndexPrivate;
77class QPointF;
78class QRectF;
79template<typename T> class QList;
80
81class Q_AUTOTEST_EXPORT QGraphicsSceneIndex : public QObject
82{
83 Q_OBJECT
84
85public:
86 QGraphicsSceneIndex(QGraphicsScene *scene = 0);
87 virtual ~QGraphicsSceneIndex();
88
89 QGraphicsScene *scene() const;
90
91 virtual QList<QGraphicsItem *> items(Qt::SortOrder order = Qt::DescendingOrder) const = 0;
92 virtual QList<QGraphicsItem *> items(const QPointF &pos, Qt::ItemSelectionMode mode,
93 Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
94 virtual QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode,
95 Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
96 virtual QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode,
97 Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
98 virtual QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode,
99 Qt::SortOrder order, const QTransform &deviceTransform = QTransform()) const;
100 virtual QList<QGraphicsItem *> estimateItems(const QPointF &point, Qt::SortOrder order) const;
101 virtual QList<QGraphicsItem *> estimateItems(const QRectF &rect, Qt::SortOrder order) const = 0;
102 virtual QList<QGraphicsItem *> estimateTopLevelItems(const QRectF &, Qt::SortOrder order) const;
103
104protected Q_SLOTS:
105 virtual void updateSceneRect(const QRectF &rect);
106
107protected:
108 virtual void clear();
109 virtual void addItem(QGraphicsItem *item) = 0;
110 virtual void removeItem(QGraphicsItem *item) = 0;
111 virtual void deleteItem(QGraphicsItem *item);
112
113 virtual void itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange, const void *const value);
114 virtual void prepareBoundingRectChange(const QGraphicsItem *item);
115
116 QGraphicsSceneIndex(QGraphicsSceneIndexPrivate &dd, QGraphicsScene *scene);
117
118 friend class QGraphicsScene;
119 friend class QGraphicsScenePrivate;
120 friend class QGraphicsItem;
121 friend class QGraphicsItemPrivate;
122 friend class QGraphicsSceneBspTreeIndex;
123private:
124 Q_DISABLE_COPY(QGraphicsSceneIndex)
125 Q_DECLARE_PRIVATE(QGraphicsSceneIndex)
126};
127
128class QGraphicsSceneIndexPrivate : public QObjectPrivate
129{
130 Q_DECLARE_PUBLIC(QGraphicsSceneIndex)
131public:
132 QGraphicsSceneIndexPrivate(QGraphicsScene *scene);
133 ~QGraphicsSceneIndexPrivate();
134
135 void init();
136 static bool itemCollidesWithPath(const QGraphicsItem *item, const QPainterPath &path, Qt::ItemSelectionMode mode);
137
138 void recursive_items_helper(QGraphicsItem *item, QRectF exposeRect,
139 QGraphicsSceneIndexIntersector *intersector, QList<QGraphicsItem *> *items,
140 const QTransform &viewTransform,
141 Qt::ItemSelectionMode mode, qreal parentOpacity = 1.0) const;
142 inline void items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector *intersector,
143 QList<QGraphicsItem *> *items, const QTransform &viewTransform,
144 Qt::ItemSelectionMode mode, Qt::SortOrder order) const;
145
146 QGraphicsScene *scene;
147 QGraphicsSceneIndexPointIntersector *pointIntersector;
148 QGraphicsSceneIndexRectIntersector *rectIntersector;
149 QGraphicsSceneIndexPathIntersector *pathIntersector;
150};
151
152inline void QGraphicsSceneIndexPrivate::items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector *intersector,
153 QList<QGraphicsItem *> *items, const QTransform &viewTransform,
154 Qt::ItemSelectionMode mode, Qt::SortOrder order) const
155{
156 Q_Q(const QGraphicsSceneIndex);
157 const QList<QGraphicsItem *> tli = q->estimateTopLevelItems(rect, Qt::AscendingOrder);
158 for (int i = 0; i < tli.size(); ++i)
159 recursive_items_helper(tli.at(i), rect, intersector, items, viewTransform, mode);
160 if (order == Qt::DescendingOrder) {
161 const int n = items->size();
162 for (int i = 0; i < n / 2; ++i)
163 items->swap(i, n - i - 1);
164 }
165}
166
167class QGraphicsSceneIndexIntersector
168{
169public:
170 QGraphicsSceneIndexIntersector() { }
171 virtual ~QGraphicsSceneIndexIntersector() { }
172 virtual bool intersect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode,
173 const QTransform &deviceTransform) const = 0;
174};
175
176#endif // QT_NO_GRAPHICSVIEW
177
178QT_END_NAMESPACE
179
180QT_END_HEADER
181
182#endif // QGRAPHICSSCENEINDEX_H
Note: See TracBrowser for help on using the repository browser.