Qt 4.8
qgraphicssceneindex_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
65 
67 
68 QT_MODULE(Gui)
69 
70 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
71 
77 class QPointF;
78 class QRectF;
79 template<typename T> class QList;
80 
82 {
83  Q_OBJECT
84 
85 public:
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 
104 protected Q_SLOTS:
105  virtual void updateSceneRect(const QRectF &rect);
106 
107 protected:
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 
117 
118  friend class QGraphicsScene;
119  friend class QGraphicsScenePrivate;
120  friend class QGraphicsItem;
121  friend class QGraphicsItemPrivate;
123 private:
126 };
127 
129 {
131 public:
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,
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 
150 };
151 
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 
168 {
169 public:
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 
179 
181 
182 #endif // QGRAPHICSSCENEINDEX_H
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
QGraphicsSceneIndexPointIntersector * pointIntersector
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
ItemSelectionMode
Definition: qnamespace.h:1503
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QGraphicsSceneIndexPathIntersector * pathIntersector
#define Q_Q(Class)
Definition: qglobal.h:2483
SortOrder
Definition: qnamespace.h:189
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool init
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
The QGraphicsSceneIndex class provides a base class to implement a custom indexing algorithm for disc...
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
#define QT_END_HEADER
Definition: qglobal.h:137
QGraphicsSceneIndexRectIntersector * rectIntersector
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void items_helper(const QRectF &rect, QGraphicsSceneIndexIntersector *intersector, QList< QGraphicsItem *> *items, const QTransform &viewTransform, Qt::ItemSelectionMode mode, Qt::SortOrder order) const