Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QGRAPHICSSCENELINEARINDEX_H
5#define QGRAPHICSSCENELINEARINDEX_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19
20#include <QtCore/qrect.h>
21#include <QtCore/qlist.h>
22#include <QtWidgets/qgraphicsitem.h>
23#include <private/qgraphicssceneindex_p.h>
24
25QT_REQUIRE_CONFIG(graphicsview);
26
28
30{
32
33public:
35 { }
36
37 QList<QGraphicsItem *> items(Qt::SortOrder order = Qt::DescendingOrder) const override
38 { Q_UNUSED(order); return m_items; }
39
40 virtual QList<QGraphicsItem *> estimateItems(const QRectF &rect, Qt::SortOrder order) const override
41 {
44 return m_items;
45 }
46
47protected :
48 virtual void clear() override
49 {
50 m_items.clear();
51 m_numSortedElements = 0;
52 }
53
54 virtual void addItem(QGraphicsItem *item) override
55 { m_items << item; }
56
57 virtual void removeItem(QGraphicsItem *item) override
58 {
59 // Sort m_items if needed
60 if (m_numSortedElements < m_items.size())
61 {
62 std::sort(m_items.begin() + m_numSortedElements, m_items.end() );
63 std::inplace_merge(m_items.begin(), m_items.begin() + m_numSortedElements, m_items.end());
64 m_numSortedElements = m_items.size();
65 }
66
67 QList<QGraphicsItem*>::iterator element = std::lower_bound(m_items.begin(), m_items.end(), item);
68 if (element != m_items.end() && *element == item)
69 {
70 m_items.erase(element);
71 --m_numSortedElements;
72 }
73 }
74
75private:
76 QList<QGraphicsItem*> m_items;
77 int m_numSortedElements;
78};
79
81
82#endif // QGRAPHICSSCENELINEARINDEX_H
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsSceneIndex class provides a base class to implement a custom indexing algorithm for disc...
The QGraphicsSceneLinearIndex class provides an implementation of a linear indexing algorithm for dis...
virtual void removeItem(QGraphicsItem *item) override
Add the item from the index.
QList< QGraphicsItem * > items(Qt::SortOrder order=Qt::DescendingOrder) const override
Return all items in the index and sort them using order.
virtual void addItem(QGraphicsItem *item) override
Add the item into the index.
QGraphicsSceneLinearIndex(QGraphicsScene *scene=nullptr)
Construct a linear index for the given scene.
virtual QList< QGraphicsItem * > estimateItems(const QRectF &rect, Qt::SortOrder order) const override
Returns an estimation visible items that are either inside or intersect with the specified rect and r...
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
\inmodule QtCore\reentrant
Definition qrect.h:484
rect
[4]
Combined button and popup list for selecting options.
SortOrder
Definition qnamespace.h:121
@ DescendingOrder
Definition qnamespace.h:123
GLfixed GLfixed GLint GLint order
#define Q_AUTOTEST_EXPORT
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define Q_UNUSED(x)
QGraphicsScene scene
[0]
QGraphicsItem * item