src/gui/graphicsview/qgraphicssceneindex_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtCore module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    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 
       
    64 QT_BEGIN_HEADER
       
    65 
       
    66 QT_BEGIN_NAMESPACE
       
    67 
       
    68 QT_MODULE(Gui)
       
    69 
       
    70 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
       
    71 
       
    72 class QGraphicsSceneIndexIntersector;
       
    73 class QGraphicsSceneIndexPointIntersector;
       
    74 class QGraphicsSceneIndexRectIntersector;
       
    75 class QGraphicsSceneIndexPathIntersector;
       
    76 class QGraphicsSceneIndexPrivate;
       
    77 class QPointF;
       
    78 class QRectF;
       
    79 template<typename T> class QList;
       
    80 
       
    81 class Q_AUTOTEST_EXPORT QGraphicsSceneIndex : public QObject
       
    82 {
       
    83     Q_OBJECT
       
    84 
       
    85 public:
       
    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 
       
   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 QVariant &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;
       
   123 private:
       
   124     Q_DISABLE_COPY(QGraphicsSceneIndex)
       
   125     Q_DECLARE_PRIVATE(QGraphicsSceneIndex)
       
   126 };
       
   127 
       
   128 class QGraphicsSceneIndexPrivate : public QObjectPrivate
       
   129 {
       
   130     Q_DECLARE_PUBLIC(QGraphicsSceneIndex)
       
   131 public:
       
   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 
       
   152 inline 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 
       
   167 class QGraphicsSceneIndexIntersector
       
   168 {
       
   169 public:
       
   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 
       
   178 QT_END_NAMESPACE
       
   179 
       
   180 QT_END_HEADER
       
   181 
       
   182 #endif // QGRAPHICSSCENEINDEX_H