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
qgraphicsscene_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 QGRAPHICSSCENE_P_H
5#define QGRAPHICSSCENE_P_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#include "qgraphicsscene.h"
20
21#include "qgraphicssceneevent.h"
22#include "qgraphicsview.h"
23#include "qgraphicsview_p.h"
24#include "qgraphicsitem_p.h"
25
26#include <private/qobject_p.h>
27#include <QtCore/qbitarray.h>
28#include <QtCore/qlist.h>
29#include <QtCore/qmap.h>
30#include <QtCore/qset.h>
31#include <QtGui/qfont.h>
32#include <QtGui/qpalette.h>
33#include <QtWidgets/qstyle.h>
34#include <QtWidgets/qstyleoption.h>
35
36#include <set>
37#include <tuple>
38
39QT_REQUIRE_CONFIG(graphicsview);
40
42
44class QGraphicsView;
45class QGraphicsWidget;
46
48{
49 Q_DECLARE_PUBLIC(QGraphicsScene)
50public:
52 void init();
53
55
59
62
64
66
82 quint32 sortCacheEnabled : 1; // for compatibility
86
88
90
91 void _q_emitUpdated();
92
94 {
95 bool operator() (const QRectF &a, const QRectF &b) const noexcept
96 {
97 return std::make_tuple(a.y(), a.x(), a.height(), a.width())
98 < std::make_tuple(b.y(), b.x(), b.height(), b.width());
99 }
100 };
101
102 // std::set was used here instead of std::unordered_set due to requiring only a comparator and
103 // showing equivalent performance in empirical measurements within the ranges of interest...
104 std::set<QRectF, UpdatedRectsCmp> updatedRects;
105
108 QSet<QGraphicsItem *> selectedItems;
109 QList<QGraphicsItem *> unpolishedItems;
110 QList<QGraphicsItem *> topLevelItems;
111
112 QHash<QGraphicsItem *, QPointF> movingItemsInitialPositions;
113 void registerTopLevelItem(QGraphicsItem *item);
114 void unregisterTopLevelItem(QGraphicsItem *item);
116 void _q_polishItems();
117
118 void _q_processDirtyItems();
119
120 QSet<QGraphicsItem *> scenePosItems;
121 void setScenePosItemEnabled(QGraphicsItem *item, bool enabled);
122 void registerScenePosItem(QGraphicsItem *item);
123 void unregisterScenePosItem(QGraphicsItem *item);
124 void _q_updateScenePosDescendants();
125
126 void removeItemHelper(QGraphicsItem *item);
127
130
140 void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent);
141 void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason,
142 bool emitFocusChanged = true);
143
144 QList<QGraphicsWidget *> popupWidgets;
145 void addPopup(QGraphicsWidget *widget);
146 void removePopup(QGraphicsWidget *widget, bool itemIsDying = false);
147
149 QList<QGraphicsItem *> mouseGrabberItems;
150 void grabMouse(QGraphicsItem *item, bool implicit = false);
151 void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false);
152 void clearMouseGrabber();
153
154 QList<QGraphicsItem *> keyboardGrabberItems;
155 void grabKeyboard(QGraphicsItem *item);
156 void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
157 void clearKeyboardGrabber();
158
162 QList<QGraphicsItem *> cachedItemsUnderMouse;
163 QList<QGraphicsItem *> hoverItems;
165 void enableMouseTrackingOnViews();
166 QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownPos;
167 QMap<Qt::MouseButton, QPointF> mouseGrabberButtonDownScenePos;
168 QMap<Qt::MouseButton, QPoint> mouseGrabberButtonDownScreenPos;
169 QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
170 const QPointF &scenePos,
171 QWidget *widget) const;
172 void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
173
174 QList<QGraphicsView *> views;
175 void addView(QGraphicsView *view);
176 void removeView(QGraphicsView *view);
177
178 QMultiMap<QGraphicsItem *, QGraphicsItem *> sceneEventFilters;
180 void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
181 bool filterDescendantEvent(QGraphicsItem *item, QEvent *event);
182 bool filterEvent(QGraphicsItem *item, QEvent *event);
183 bool sendEvent(QGraphicsItem *item, QEvent *event);
184
185 bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
186 bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
187 void leaveScene(QWidget *viewport);
188
189 void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
191 void sendDragDropEvent(QGraphicsItem *item,
192 QGraphicsSceneDragDropEvent *dragDropEvent);
193 void sendHoverEvent(QEvent::Type type, QGraphicsItem *item,
194 QGraphicsSceneHoverEvent *hoverEvent);
195 void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent);
196 void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent);
198
199 void drawItemHelper(QGraphicsItem *item, QPainter *painter,
201 bool painterStateProtection);
202
203 void drawItems(QPainter *painter, const QTransform *const viewTransform,
204 QRegion *exposedRegion, QWidget *widget);
205
206 void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const,
207 QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0),
208 const QTransform *const effectTransform = nullptr);
209 void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const,
210 QRegion *, QWidget *, qreal, const QTransform *const, bool, bool);
211
212 void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
213 bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false,
214 bool updateBoundingRect = false);
215 void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
216 qreal parentOpacity = qreal(1.0));
217
218 inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
219 {
220 Q_ASSERT(item);
221 item->d_ptr->dirty = 0;
224 if (!item->d_ptr->dirtyChildren)
225 recursive = false;
232#if QT_CONFIG(graphicseffect)
233 QGraphicsEffect::ChangeFlags flags;
237 }
241 }
242#endif // QT_CONFIG(graphicseffect)
243 if (recursive) {
244 for (int i = 0; i < item->d_ptr->children.size(); ++i)
245 resetDirtyItem(item->d_ptr->children.at(i), recursive);
246 }
247#if QT_CONFIG(graphicseffect)
250#endif // QT_CONFIG(graphicseffect)
251 }
252
254 {
255 if (needSortTopLevelItems) {
256 std::sort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
257 topLevelSequentialOrdering = false;
258 needSortTopLevelItems = false;
259 }
260 }
261
262 void ensureSequentialTopLevelSiblingIndexes();
263
266 void setFont_helper(const QFont &font);
267 void resolveFont();
268 void updateFont(const QFont &font);
270 void setPalette_helper(const QPalette &palette);
271 void resolvePalette();
272 void updatePalette(const QPalette &palette);
273
275
276 QMap<int, QEventPoint> sceneCurrentTouchPoints;
277 QMap<int, QGraphicsItem *> itemForTouchPointId;
278 static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
279 int findClosestTouchPointId(const QPointF &scenePos);
280 void touchEventHandler(QTouchEvent *touchEvent);
281 bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
282 void enableTouchEventsOnViews();
283
284 QList<QGraphicsObject *> cachedTargetItems;
285#ifndef QT_NO_GESTURES
286 QHash<QGraphicsObject *, QSet<QGesture *> > cachedItemGestures;
287 QHash<QGraphicsObject *, QSet<QGesture *> > cachedAlreadyDeliveredGestures;
288 QHash<QGesture *, QGraphicsObject *> gestureTargets;
289 QHash<Qt::GestureType, int> grabbedGestures;
290 void gestureEventHandler(QGestureEvent *event);
291 void gestureTargetsAtHotSpots(const QSet<QGesture *> &gestures,
292 Qt::GestureFlag flag,
293 QHash<QGraphicsObject *, QSet<QGesture *> > *targets,
294 QSet<QGraphicsObject *> *itemsSet = nullptr,
295 QSet<QGesture *> *normal = nullptr,
296 QSet<QGesture *> *conflicts = nullptr);
297 void cancelGesturesForChildren(QGesture *original);
298 void grabGesture(QGraphicsItem *, Qt::GestureType gesture);
299 void ungrabGesture(QGraphicsItem *, Qt::GestureType gesture);
300#endif // QT_NO_GESTURES
301
302 void updateInputMethodSensitivityInViews();
303
304 QList<QGraphicsItem *> modalPanels;
305 void enterModal(QGraphicsItem *item,
307 void leaveModal(QGraphicsItem *item);
308};
309
310// QRectF::intersects() returns false always if either the source or target
311// rectangle's width or height are 0. This works around that problem.
312static inline void _q_adjustRect(QRectF *rect)
313{
314 Q_ASSERT(rect);
315 if (!rect->width())
316 rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
317 if (!rect->height())
318 rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
319}
320
328
336
338
339#endif
\inmodule QtGui
Definition qbrush.h:30
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
\reentrant
Definition qfont.h:22
The QGestureEvent class provides the description of triggered gestures.
Definition qgesture.h:244
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition qgesture.h:29
virtual void sourceChanged(ChangeFlags flags)
This virtual function is called by QGraphicsEffect to notify the effect that the source has changed.
QGraphicsEffect * graphicsEffect
QList< QGraphicsItem * > children
quint32 paintedViewBoundingRectsNeedRepaint
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
QScopedPointer< QGraphicsItemPrivate > d_ptr
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QGraphicsObject class provides a base class for all graphics items that require signals,...
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsSceneIndex class provides a base class to implement a custom indexing algorithm for disc...
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
QList< QGraphicsItem * > cachedItemsUnderMouse
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters
QList< QGraphicsView * > views
QHash< QGraphicsObject *, QSet< QGesture * > > cachedItemGestures
void resetDirtyItem(QGraphicsItem *item, bool recursive=false)
QHash< QGesture *, QGraphicsObject * > gestureTargets
QList< QGraphicsItem * > modalPanels
QList< QGraphicsItem * > mouseGrabberItems
QHash< QGraphicsObject *, QSet< QGesture * > > cachedAlreadyDeliveredGestures
QSet< QGraphicsItem * > scenePosItems
QGraphicsItem * lastFocusItem
QList< QGraphicsWidget * > popupWidgets
QStyleOptionGraphicsItem styleOptionTmp
QMap< int, QEventPoint > sceneCurrentTouchPoints
QList< QGraphicsItem * > unpolishedItems
Qt::DropAction lastDropAction
QMap< Qt::MouseButton, QPoint > mouseGrabberButtonDownScreenPos
QGraphicsWidget * tabFocusFirst
QHash< Qt::GestureType, int > grabbedGestures
QSet< QGraphicsItem * > selectedItems
QGraphicsItem * passiveFocusItem
QList< QGraphicsObject * > cachedTargetItems
QGraphicsItem * activePanel
QList< QGraphicsItem * > hoverItems
QGraphicsItem * focusItem
QHash< QGraphicsItem *, QPointF > movingItemsInitialPositions
std::set< QRectF, UpdatedRectsCmp > updatedRects
QGraphicsItem * lastMouseGrabberItem
QGraphicsScene::ItemIndexMethod indexMethod
quint32 scenePosDescendantsUpdatePending
QGraphicsItem * lastActivePanel
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownScenePos
QGraphicsSceneIndex * index
QGraphicsItem * dragDropItem
QMap< int, QGraphicsItem * > itemForTouchPointId
QList< QGraphicsItem * > keyboardGrabberItems
QGraphicsWidget * enterWidget
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownPos
quint32 lastMouseGrabberItemHasImplicitMouseGrab
QList< QGraphicsItem * > topLevelItems
QGraphicsWidget * windowForItem(const QGraphicsItem *item) const
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
ItemIndexMethod
This enum describes the indexing algorithms QGraphicsScene provides for managing positional informati...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
\inmodule QtCore
Definition qhash.h:820
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:484
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
rect
[4]
Combined button and popup list for selecting options.
DropAction
GestureType
GestureFlag
FocusReason
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
static QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
static void _q_adjustRect(QRectF *rect)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLbitfield flags
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint GLenum option
static const QRectF boundingRect(const QPointF *points, int pointCount)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_AUTOTEST_EXPORT
#define QT_REQUIRE_CONFIG(feature)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned int quint32
Definition qtypes.h:50
double qreal
Definition qtypes.h:187
line installSceneEventFilter(ellipse)
QGraphicsItem * item
view viewport() -> scroll(dx, dy, deviceRect)
myFilter draw(painter, QPoint(0, 0), originalPixmap)
QPainter painter(this)
[7]
QQuickView * view
[0]