Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgraphicsscenelinearindex_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QGRAPHICSSCENELINEARINDEX_H
6#define QGRAPHICSSCENELINEARINDEX_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20
21#include <QtCore/qrect.h>
22#include <QtCore/qlist.h>
23#include <QtWidgets/qgraphicsitem.h>
24#include <private/qgraphicssceneindex_p.h>
25
27
29
30class Q_AUTOTEST_EXPORT QGraphicsSceneLinearIndex : public QGraphicsSceneIndex
31{
32 Q_OBJECT
33
34public:
35 QGraphicsSceneLinearIndex(QGraphicsScene *scene = nullptr) : QGraphicsSceneIndex(scene), m_numSortedElements(0)
36 { }
37
38 QList<QGraphicsItem *> items(Qt::SortOrder order = Qt::DescendingOrder) const override
39 { Q_UNUSED(order); return m_items; }
40
41 virtual QList<QGraphicsItem *> estimateItems(const QRectF &rect, Qt::SortOrder order) const override
42 {
43 Q_UNUSED(rect);
44 Q_UNUSED(order);
45 return m_items;
46 }
47
48protected :
49 virtual void clear() override
50 {
51 m_items.clear();
52 m_numSortedElements = 0;
53 }
54
55 virtual void addItem(QGraphicsItem *item) override
56 { m_items << item; }
57
58 virtual void removeItem(QGraphicsItem *item) override
59 {
60 // Sort m_items if needed
61 if (m_numSortedElements < m_items.size())
62 {
63 std::sort(m_items.begin() + m_numSortedElements, m_items.end() );
64 std::inplace_merge(m_items.begin(), m_items.begin() + m_numSortedElements, m_items.end());
65 m_numSortedElements = m_items.size();
66 }
67
68 QList<QGraphicsItem*>::iterator element = std::lower_bound(m_items.begin(), m_items.end(), item);
69 if (element != m_items.end() && *element == item)
70 {
71 m_items.erase(element);
72 --m_numSortedElements;
73 }
74 }
75
76private:
77 QList<QGraphicsItem*> m_items;
78 int m_numSortedElements;
79};
80
81QT_END_NAMESPACE
82
83#endif // QGRAPHICSSCENELINEARINDEX_H
The QGraphicsSceneLinearIndex class provides an implementation of a linear indexing algorithm for dis...
friend class QPainter
friend class QWidget
Definition qpainter.h:431
QT_REQUIRE_CONFIG(animation)
QT_REQUIRE_CONFIG(graphicsview)
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
static void setClip(QPainter *painter, QGraphicsItem *item)
static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraphicsSceneMouseEvent *mouseEvent)
static void setWorldTransform(QPainter *painter, const QTransform *const transformPtr, const QTransform *effectTransform)
static bool transformIsSimple(const QTransform &transform)
#define ENSURE_TRANSFORM_PTR
static void _q_paintItem(QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget, bool useWindowOpacity, bool painterStateProtection)
static bool updateHelper(QGraphicsViewPrivate *view, QGraphicsItemPrivate *item, const QRectF &rect, bool itemIsUntransformable)
static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion &pixmapExposed, const QTransform &itemToPixmap, QPainter::RenderHints renderHints, const QStyleOptionGraphicsItem *option, bool painterStateProtection)