QtBase  v6.3.1
qgraphicsscene_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QGRAPHICSSCENE_P_H
41 #define QGRAPHICSSCENE_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists for the convenience
48 // of other Qt classes. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtWidgets/private/qtwidgetsglobal_p.h>
55 #include "qgraphicsscene.h"
56 
57 #include "qgraphicssceneevent.h"
58 #include "qgraphicsview.h"
59 #include "qgraphicsview_p.h"
60 #include "qgraphicsitem_p.h"
61 
62 #include <private/qobject_p.h>
63 #include <QtCore/qbitarray.h>
64 #include <QtCore/qlist.h>
65 #include <QtCore/qmap.h>
66 #include <QtCore/qset.h>
67 #include <QtGui/qfont.h>
68 #include <QtGui/qpalette.h>
69 #include <QtWidgets/qstyle.h>
70 #include <QtWidgets/qstyleoption.h>
71 
72 #include <set>
73 #include <tuple>
74 
75 QT_REQUIRE_CONFIG(graphicsview);
76 
78 
80 class QGraphicsView;
81 class QGraphicsWidget;
82 
84 {
85  Q_DECLARE_PUBLIC(QGraphicsScene)
86 public:
88  void init();
89 
91 
95 
98 
100 
102 
118  quint32 sortCacheEnabled : 1; // for compatibility
122 
124 
126 
127  void _q_emitUpdated();
128 
130  {
131  bool operator() (const QRectF &a, const QRectF &b) const noexcept
132  {
133  return std::make_tuple(a.y(), a.x(), a.height(), a.width())
134  < std::make_tuple(b.y(), b.x(), b.height(), b.width());
135  }
136  };
137 
138  // std::set was used here instead of std::unordered_set due to requiring only a comparator and
139  // showing equivalent performance in empirical measurements within the ranges of interest...
140  std::set<QRectF, UpdatedRectsCmp> updatedRects;
141 
147 
149  void registerTopLevelItem(QGraphicsItem *item);
150  void unregisterTopLevelItem(QGraphicsItem *item);
152  void _q_polishItems();
153 
154  void _q_processDirtyItems();
155 
157  void setScenePosItemEnabled(QGraphicsItem *item, bool enabled);
158  void registerScenePosItem(QGraphicsItem *item);
159  void unregisterScenePosItem(QGraphicsItem *item);
160  void _q_updateScenePosDescendants();
161 
162  void removeItemHelper(QGraphicsItem *item);
163 
166 
176  void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent);
177  void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason,
178  bool emitFocusChanged = true);
179 
181  void addPopup(QGraphicsWidget *widget);
182  void removePopup(QGraphicsWidget *widget, bool itemIsDying = false);
183 
186  void grabMouse(QGraphicsItem *item, bool implicit = false);
187  void ungrabMouse(QGraphicsItem *item, bool itemIsDying = false);
188  void clearMouseGrabber();
189 
191  void grabKeyboard(QGraphicsItem *item);
192  void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying = false);
193  void clearKeyboardGrabber();
194 
201  void enableMouseTrackingOnViews();
205  QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
206  const QPointF &scenePos,
207  QWidget *widget) const;
208  void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event);
209 
211  void addView(QGraphicsView *view);
212  void removeView(QGraphicsView *view);
213 
216  void removeSceneEventFilter(QGraphicsItem *watched, QGraphicsItem *filter);
217  bool filterDescendantEvent(QGraphicsItem *item, QEvent *event);
218  bool filterEvent(QGraphicsItem *item, QEvent *event);
219  bool sendEvent(QGraphicsItem *item, QEvent *event);
220 
221  bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent);
222  bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const;
223  void leaveScene(QWidget *viewport);
224 
225  void cloneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
227  void sendDragDropEvent(QGraphicsItem *item,
228  QGraphicsSceneDragDropEvent *dragDropEvent);
229  void sendHoverEvent(QEvent::Type type, QGraphicsItem *item,
230  QGraphicsSceneHoverEvent *hoverEvent);
231  void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent);
232  void mousePressEventHandler(QGraphicsSceneMouseEvent *mouseEvent);
234 
235  void drawItemHelper(QGraphicsItem *item, QPainter *painter,
237  bool painterStateProtection);
238 
239  void drawItems(QPainter *painter, const QTransform *const viewTransform,
240  QRegion *exposedRegion, QWidget *widget);
241 
242  void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const,
243  QRegion *exposedRegion, QWidget *widget, qreal parentOpacity = qreal(1.0),
244  const QTransform *const effectTransform = nullptr);
245  void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const,
246  QRegion *, QWidget *, qreal, const QTransform *const, bool, bool);
247 
248  void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
249  bool force = false, bool ignoreOpacity = false, bool removingItemFromScene = false,
250  bool updateBoundingRect = false);
251  void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren = false,
252  qreal parentOpacity = qreal(1.0));
253 
254  inline void resetDirtyItem(QGraphicsItem *item, bool recursive = false)
255  {
256  Q_ASSERT(item);
257  item->d_ptr->dirty = 0;
259  item->d_ptr->geometryChanged = 0;
260  if (!item->d_ptr->dirtyChildren)
261  recursive = false;
262  item->d_ptr->dirtyChildren = 0;
266  item->d_ptr->ignoreVisible = 0;
267  item->d_ptr->ignoreOpacity = 0;
268 #if QT_CONFIG(graphicseffect)
269  QGraphicsEffect::ChangeFlags flags;
273  }
274  if (item->d_ptr->notifyInvalidated) {
277  }
278 #endif // QT_CONFIG(graphicseffect)
279  if (recursive) {
280  for (int i = 0; i < item->d_ptr->children.size(); ++i)
281  resetDirtyItem(item->d_ptr->children.at(i), recursive);
282  }
283 #if QT_CONFIG(graphicseffect)
284  if (flags && item->d_ptr->graphicsEffect)
286 #endif // QT_CONFIG(graphicseffect)
287  }
288 
290  {
291  if (needSortTopLevelItems) {
292  std::sort(topLevelItems.begin(), topLevelItems.end(), qt_notclosestLeaf);
293  topLevelSequentialOrdering = false;
294  needSortTopLevelItems = false;
295  }
296  }
297 
298  void ensureSequentialTopLevelSiblingIndexes();
299 
302  void setFont_helper(const QFont &font);
303  void resolveFont();
304  void updateFont(const QFont &font);
306  void setPalette_helper(const QPalette &palette);
307  void resolvePalette();
308  void updatePalette(const QPalette &palette);
309 
311 
314  static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
315  int findClosestTouchPointId(const QPointF &scenePos);
316  void touchEventHandler(QTouchEvent *touchEvent);
317  bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent);
318  void enableTouchEventsOnViews();
319 
321 #ifndef QT_NO_GESTURES
326  void gestureEventHandler(QGestureEvent *event);
327  void gestureTargetsAtHotSpots(const QSet<QGesture *> &gestures,
328  Qt::GestureFlag flag,
329  QHash<QGraphicsObject *, QSet<QGesture *> > *targets,
330  QSet<QGraphicsObject *> *itemsSet = nullptr,
331  QSet<QGesture *> *normal = nullptr,
332  QSet<QGesture *> *conflicts = nullptr);
333  void cancelGesturesForChildren(QGesture *original);
334  void grabGesture(QGraphicsItem *, Qt::GestureType gesture);
335  void ungrabGesture(QGraphicsItem *, Qt::GestureType gesture);
336 #endif // QT_NO_GESTURES
337 
338  void updateInputMethodSensitivityInViews();
339 
341  void enterModal(QGraphicsItem *item,
343  void leaveModal(QGraphicsItem *item);
344 };
345 
346 // QRectF::intersects() returns false always if either the source or target
347 // rectangle's width or height are 0. This works around that problem.
348 static inline void _q_adjustRect(QRectF *rect)
349 {
350  Q_ASSERT(rect);
351  if (!rect->width())
352  rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
353  if (!rect->height())
354  rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001));
355 }
356 
357 static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
358 {
359  Q_ASSERT(item);
360  QRectF boundingRect(item->boundingRect());
361  _q_adjustRect(&boundingRect);
362  return boundingRect;
363 }
364 
365 static inline QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
366 {
367  Q_ASSERT(item);
368  QRectF boundingRect(QGraphicsItemPrivate::get(item)->effectiveBoundingRect());
369  _q_adjustRect(&boundingRect);
370  return boundingRect;
371 }
372 
374 
375 #endif
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QGestureEvent class provides the description of triggered gestures.
Definition: qgesture.h:276
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:62
virtual void sourceChanged(ChangeFlags flags)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
QScopedPointer< QGraphicsItemPrivate > d_ptr
virtual QRectF boundingRect() const =0
QGraphicsEffect * graphicsEffect
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
QList< QGraphicsItem * > children
quint32 paintedViewBoundingRectsNeedRepaint
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 QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
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
QGraphicsWidget * windowForItem(const QGraphicsItem *item) const
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
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
qsizetype size() const noexcept
Definition: qlist.h:414
iterator end()
Definition: qlist.h:624
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
iterator begin()
Definition: qlist.h:623
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:368
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:63
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
Definition: qstyleoption.h:684
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:1020
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QOpenGLWidget * widget
[1]
rect
[4]
palette
constexpr T & operator()(T &v) const
Definition: hb-algs.hh:2
QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit=true)
Definition: qtesttouch.h:78
DropAction
Definition: qnamespace.h:1484
GestureType
Definition: qnamespace.h:1641
GestureFlag
Definition: qnamespace.h:1654
FocusReason
Definition: qnamespace.h:1360
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
unsigned int quint32
Definition: qglobal.h:288
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:579
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
QT_REQUIRE_CONFIG(graphicsview)
GLenum type
Definition: qopengl.h:270
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbitfield flags
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei GLsizei GLchar * source
struct _cl_event * event
Definition: qopenglext.h:2998
GLdouble GLdouble GLdouble GLdouble q
Definition: qopenglext.h:259
GLuint GLenum option
Definition: qopenglext.h:5929
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
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]