Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QGraphicsScenePrivate Class Reference

#include <qgraphicsscene_p.h>

Inheritance diagram for QGraphicsScenePrivate:
QObjectPrivate QObjectData

Public Functions

void _q_emitUpdated ()
 
void _q_polishItems ()
 
void _q_processDirtyItems ()
 
void _q_updateLater ()
 
void _q_updateScenePosDescendants ()
 
void addPopup (QGraphicsWidget *widget)
 
void addView (QGraphicsView *view)
 
void cancelGesturesForChildren (QGesture *original)
 
void clearKeyboardGrabber ()
 
void clearMouseGrabber ()
 
void cloneDragDropEvent (QGraphicsSceneDragDropEvent *dest, QGraphicsSceneDragDropEvent *source)
 
bool dispatchHoverEvent (QGraphicsSceneHoverEvent *hoverEvent)
 This event handler, for event hoverEvent, can be reimplemented in a subclass to receive hover enter events. More...
 
void draw (QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const, QRegion *, QWidget *, qreal, const QTransform *const, bool, bool)
 
void drawItemHelper (QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget, bool painterStateProtection)
 Draws items directly, or using cache. More...
 
void drawItems (QPainter *painter, const QTransform *const viewTransform, QRegion *exposedRegion, QWidget *widget)
 
void drawSubtreeRecursive (QGraphicsItem *item, QPainter *painter, const QTransform *const, QRegion *exposedRegion, QWidget *widget, qreal parentOpacity=qreal(1.0), const QTransform *const effectTransform=0)
 
void enableMouseTrackingOnViews ()
 
void enableTouchEventsOnViews ()
 
void ensureSequentialTopLevelSiblingIndexes ()
 Ensures that the list of toplevels is sorted by insertion order, and that the siblingIndexes are packed (no gaps), and start at 0. More...
 
void ensureSortedTopLevelItems ()
 
void enterModal (QGraphicsItem *item, QGraphicsItem::PanelModality panelModality=QGraphicsItem::NonModal)
 
bool filterDescendantEvent (QGraphicsItem *item, QEvent *event)
 
bool filterEvent (QGraphicsItem *item, QEvent *event)
 
int findClosestTouchPointId (const QPointF &scenePos)
 
void gestureEventHandler (QGestureEvent *event)
 
void gestureTargetsAtHotSpots (const QSet< QGesture *> &gestures, Qt::GestureFlag flag, QHash< QGraphicsObject *, QSet< QGesture *> > *targets, QSet< QGraphicsObject *> *itemsSet=0, QSet< QGesture *> *normal=0, QSet< QGesture *> *conflicts=0)
 
void grabGesture (QGraphicsItem *, Qt::GestureType gesture)
 
void grabKeyboard (QGraphicsItem *item)
 
void grabMouse (QGraphicsItem *item, bool implicit=false)
 
void init ()
 
void installSceneEventFilter (QGraphicsItem *watched, QGraphicsItem *filter)
 
bool itemAcceptsHoverEvents_helper (const QGraphicsItem *item) const
 
QList< QGraphicsItem * > itemsAtPosition (const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
 Returns all items for the screen position in event. More...
 
void leaveModal (QGraphicsItem *item)
 
void leaveScene (QWidget *viewport)
 Handles all actions necessary to clean up the scene when the mouse leaves the view. More...
 
void markDirty (QGraphicsItem *item, const QRectF &rect=QRectF(), bool invalidateChildren=false, bool force=false, bool ignoreOpacity=false, bool removingItemFromScene=false, bool updateBoundingRect=false)
 
void mousePressEventHandler (QGraphicsSceneMouseEvent *mouseEvent)
 
void processDirtyItemsRecursive (QGraphicsItem *item, bool dirtyAncestorContainsChildren=false, qreal parentOpacity=qreal(1.0))
 
 QGraphicsScenePrivate ()
 
void registerScenePosItem (QGraphicsItem *item)
 
void registerTopLevelItem (QGraphicsItem *item)
 
void removeItemHelper (QGraphicsItem *item)
 Schedules an item for removal. More...
 
void removePopup (QGraphicsWidget *widget, bool itemIsDying=false)
 Remove widget from the popup list. More...
 
void removeSceneEventFilter (QGraphicsItem *watched, QGraphicsItem *filter)
 
void removeView (QGraphicsView *view)
 
void resetDirtyItem (QGraphicsItem *item, bool recursive=false)
 
void resolveFont ()
 Resolve the scene's font against the application font, and propagate the changes too all items in the scene. More...
 
void resolvePalette ()
 Resolve the scene's palette against the application palette, and propagate the changes too all items in the scene. More...
 
void sendDragDropEvent (QGraphicsItem *item, QGraphicsSceneDragDropEvent *dragDropEvent)
 
bool sendEvent (QGraphicsItem *item, QEvent *event)
 This is the final dispatch point for any events from the scene to the item. More...
 
void sendHoverEvent (QEvent::Type type, QGraphicsItem *item, QGraphicsSceneHoverEvent *hoverEvent)
 
void sendMouseEvent (QGraphicsSceneMouseEvent *mouseEvent)
 
bool sendTouchBeginEvent (QGraphicsItem *item, QTouchEvent *touchEvent)
 
void setActivePanelHelper (QGraphicsItem *item, bool duringActivationEvent)
 
void setFocusItemHelper (QGraphicsItem *item, Qt::FocusReason focusReason)
 
void setFont_helper (const QFont &font)
 Set the font and propagate the changes if the font is different from the current font. More...
 
void setPalette_helper (const QPalette &palette)
 Set the palette and propagate the changes if the palette is different from the current palette. More...
 
void setScenePosItemEnabled (QGraphicsItem *item, bool enabled)
 
void storeMouseButtonsForMouseGrabber (QGraphicsSceneMouseEvent *event)
 
void touchEventHandler (QTouchEvent *touchEvent)
 
void ungrabGesture (QGraphicsItem *, Qt::GestureType gesture)
 
void ungrabKeyboard (QGraphicsItem *item, bool itemIsDying=false)
 
void ungrabMouse (QGraphicsItem *item, bool itemIsDying=false)
 
void unregisterScenePosItem (QGraphicsItem *item)
 
void unregisterTopLevelItem (QGraphicsItem *item)
 
void updateFont (const QFont &font)
 Update the font, and whether or not it has changed, reresolve all fonts in the scene. More...
 
void updateInputMethodSensitivityInViews ()
 
void updatePalette (const QPalette &palette)
 Update the palette, and whether or not it has changed, reresolve all palettes in the scene. More...
 
QGraphicsWidgetwindowForItem (const QGraphicsItem *item) const
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static QGraphicsScenePrivateget (QGraphicsScene *q)
 
static void updateTouchPointsForItem (QGraphicsItem *item, QTouchEvent *touchEvent)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

int activationRefCount
 
QGraphicsItemactivePanel
 
quint32 allItemsIgnoreHoverEvents: 1
 
quint32 allItemsIgnoreTouchEvents: 1
 
quint32 allItemsUseDefaultCursor: 1
 
QBrush backgroundBrush
 
QHash< QGraphicsObject *, QSet< QGesture * > > cachedAlreadyDeliveredGestures
 
QHash< QGraphicsObject *, QSet< QGesture * > > cachedItemGestures
 
QList< QGraphicsItem * > cachedItemsUnderMouse
 
QList< QGraphicsObject * > cachedTargetItems
 
quint32 calledEmitUpdated: 1
 
int changedSignalIndex
 
int childExplicitActivation
 
quint32 dirtyGrowingItemsBoundingRect: 1
 
QGraphicsItemdragDropItem
 
QGraphicsWidgetenterWidget
 
QGraphicsItemfocusItem
 
QFont font
 
QBrush foregroundBrush
 
QHash< QGesture *, QGraphicsObject * > gestureTargets
 
QHash< Qt::GestureType, int > grabbedGestures
 
QRectF growingItemsBoundingRect
 
quint32 hasFocus: 1
 
quint32 hasSceneRect: 1
 
quint32 holesInTopLevelSiblingIndex: 1
 
QList< QGraphicsItem * > hoverItems
 
QGraphicsSceneIndexindex
 
QGraphicsScene::ItemIndexMethod indexMethod
 
QMap< int, QGraphicsItem * > itemForTouchPointId
 
QList< QGraphicsItem * > keyboardGrabberItems
 
QGraphicsItemlastActivePanel
 
Qt::DropAction lastDropAction
 
QGraphicsItemlastFocusItem
 
int lastItemCount
 
QGraphicsItemlastMouseGrabberItem
 
quint32 lastMouseGrabberItemHasImplicitMouseGrab: 1
 
QPointF lastSceneMousePos
 
QList< QGraphicsItem * > modalPanels
 
QMap< Qt::MouseButton, QPointFmouseGrabberButtonDownPos
 
QMap< Qt::MouseButton, QPointFmouseGrabberButtonDownScenePos
 
QMap< Qt::MouseButton, QPointmouseGrabberButtonDownScreenPos
 
QList< QGraphicsItem * > mouseGrabberItems
 
QMap< QGraphicsItem *, QPointFmovingItemsInitialPositions
 
quint32 needSortTopLevelItems: 1
 
quint32 padding: 15
 
quint32 painterStateProtection: 1
 
QPalette palette
 
QGraphicsItempassiveFocusItem
 
int polishItemsIndex
 
QList< QGraphicsWidget * > popupWidgets
 
quint32 processDirtyItemsEmitted: 1
 
int processDirtyItemsIndex
 
quint32 rectAdjust
 
QMap< int, QTouchEvent::TouchPointsceneCurrentTouchPoints
 
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters
 
quint32 scenePosDescendantsUpdatePending: 1
 
QSet< QGraphicsItem * > scenePosItems
 
QRectF sceneRect
 
QSet< QGraphicsItem * > selectedItems
 
QPainterPath selectionArea
 
int selectionChanging
 
quint32 sortCacheEnabled: 1
 
quint32 stickyFocus: 1
 
QStylestyle
 
QStyleOptionGraphicsItem styleOptionTmp
 
QGraphicsWidgettabFocusFirst
 
QList< QGraphicsItem * > topLevelItems
 
quint32 topLevelSequentialOrdering: 1
 
QVector< QGraphicsItem * > unpolishedItems
 
quint32 updateAll: 1
 
QList< QRectFupdatedRects
 
QList< QGraphicsView * > views
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 81 of file qgraphicsscene_p.h.

Constructors and Destructors

◆ QGraphicsScenePrivate()

QGraphicsScenePrivate::QGraphicsScenePrivate ( )
Warning
This function is not part of the public interface.

Definition at line 296 of file qgraphicsscene.cpp.

298  index(0),
299  lastItemCount(0),
300  hasSceneRect(false),
302  updateAll(false),
303  calledEmitUpdated(false),
305  needSortTopLevelItems(true),
309  stickyFocus(false),
310  hasFocus(false),
315  sortCacheEnabled(false),
318  rectAdjust(2),
319  focusItem(0),
320  lastFocusItem(0),
321  passiveFocusItem(0),
322  tabFocusFirst(0),
323  activePanel(0),
324  lastActivePanel(0),
328  dragDropItem(0),
329  enterWidget(0),
331  style(0)
332 {
333 }
QGraphicsItem * focusItem
QGraphicsSceneIndex * index
QGraphicsItem * passiveFocusItem
QGraphicsItem * dragDropItem
QGraphicsWidget * enterWidget
Qt::DropAction lastDropAction
QGraphicsItem * lastActivePanel
QGraphicsWidget * tabFocusFirst
quint32 scenePosDescendantsUpdatePending
QGraphicsItem * lastMouseGrabberItem
QGraphicsItem * lastFocusItem
QGraphicsItem * activePanel
QGraphicsScene::ItemIndexMethod indexMethod
quint32 lastMouseGrabberItemHasImplicitMouseGrab

Functions

◆ _q_emitUpdated()

void QGraphicsScenePrivate::_q_emitUpdated ( )

Definition at line 361 of file qgraphicsscene.cpp.

Referenced by _q_processDirtyItems().

362 {
364  calledEmitUpdated = false;
365 
367  if (!hasSceneRect) {
368  const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect;
369  growingItemsBoundingRect |= q->itemsBoundingRect();
370  if (oldGrowingItemsBoundingRect != growingItemsBoundingRect)
371  emit q->sceneRectChanged(growingItemsBoundingRect);
372  }
374  }
375 
376  // Ensure all views are connected if anything is connected. This disables
377  // the optimization that items send updates directly to the views, but it
378  // needs to happen in order to keep compatibility with the behavior from
379  // Qt 4.4 and backward.
381  for (int i = 0; i < views.size(); ++i) {
382  QGraphicsView *view = views.at(i);
383  if (!view->d_func()->connectedToScene) {
384  view->d_func()->connectedToScene = true;
385  q->connect(q, SIGNAL(changed(QList<QRectF>)),
386  views.at(i), SLOT(updateScene(QList<QRectF>)));
387  }
388  }
389  } else {
390  if (views.isEmpty()) {
391  updateAll = false;
392  return;
393  }
394  for (int i = 0; i < views.size(); ++i)
395  views.at(i)->d_func()->processPendingUpdates();
396  // It's important that we update all views before we dispatch, hence two for-loops.
397  for (int i = 0; i < views.size(); ++i)
398  views.at(i)->d_func()->dispatchPendingUpdateRequests();
399  return;
400  }
401 
402  // Notify the changes to anybody interested.
403  QList<QRectF> oldUpdatedRects;
404  oldUpdatedRects = updateAll ? (QList<QRectF>() << q->sceneRect()) : updatedRects;
405  updateAll = false;
407  emit q->changed(oldUpdatedRects);
408 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
#define SLOT(a)
Definition: qobjectdefs.h:226
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QGraphicsView * > views
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void clear()
Removes all items from the list.
Definition: qlist.h:764
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QList< QRectF > updatedRects

◆ _q_polishItems()

void QGraphicsScenePrivate::_q_polishItems ( )
Warning
This function is not part of the public interface.

Definition at line 447 of file qgraphicsscene.cpp.

448 {
449  if (unpolishedItems.isEmpty())
450  return;
451 
452  const QVariant booleanTrueVariant(true);
453  QGraphicsItem *item = 0;
454  QGraphicsItemPrivate *itemd = 0;
455  const int oldUnpolishedCount = unpolishedItems.count();
456 
457  for (int i = 0; i < oldUnpolishedCount; ++i) {
458  item = unpolishedItems.at(i);
459  if (!item)
460  continue;
461  itemd = item->d_ptr.data();
462  itemd->pendingPolish = false;
463  if (!itemd->explicitlyHidden) {
464  item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant);
465  item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant);
466  }
467  if (itemd->isWidget) {
470  }
471  }
472 
473  if (unpolishedItems.count() == oldUnpolishedCount) {
474  // No new items were added to the vector.
476  } else {
477  // New items were appended; keep them and remove the old ones.
478  unpolishedItems.remove(0, oldUnpolishedCount);
481  }
482 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void squeeze()
Releases any memory not required to store the items.
Definition: qvector.h:145
EventRef event
QScopedPointer< QGraphicsItemPrivate > d_ptr
void remove(int i)
Removes the element at index position i.
Definition: qvector.h:374
T * data() const
Returns the value of the pointer referenced by this object.
QObject * q_ptr
Definition: qobject.h:91
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item&#39;s ...
QVector< QGraphicsItem * > unpolishedItems
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ _q_processDirtyItems()

void QGraphicsScenePrivate::_q_processDirtyItems ( )

Definition at line 484 of file qgraphicsscene.cpp.

485 {
486  processDirtyItemsEmitted = false;
487 
488  if (updateAll) {
490  // No need for further processing (except resetting the dirty states).
491  // The growingItemsBoundingRect is updated in _q_emitUpdated.
492  for (int i = 0; i < topLevelItems.size(); ++i)
493  resetDirtyItem(topLevelItems.at(i), /*recursive=*/true);
494  return;
495  }
496 
497  const bool wasPendingSceneUpdate = calledEmitUpdated;
498  const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect;
499 
500  // Process items recursively.
501  for (int i = 0; i < topLevelItems.size(); ++i)
503 
505  if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect)
506  emit q_func()->sceneRectChanged(growingItemsBoundingRect);
507 
508  if (wasPendingSceneUpdate)
509  return;
510 
511  for (int i = 0; i < views.size(); ++i)
512  views.at(i)->d_func()->processPendingUpdates();
513 
514  if (calledEmitUpdated) {
515  // We did a compatibility QGraphicsScene::update in processDirtyItemsRecursive
516  // and we cannot wait for the control to reach the eventloop before the
517  // changed signal is emitted, so we emit it now.
518  _q_emitUpdated();
519  }
520 
521  // Immediately dispatch all pending update requests on the views.
522  for (int i = 0; i < views.size(); ++i)
523  views.at(i)->d_func()->dispatchPendingUpdateRequests();
524 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QGraphicsView * > views
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren=false, qreal parentOpacity=qreal(1.0))
QList< QGraphicsItem * > topLevelItems
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void resetDirtyItem(QGraphicsItem *item, bool recursive=false)

◆ _q_updateLater()

void QGraphicsScenePrivate::_q_updateLater ( )

◆ _q_updateScenePosDescendants()

void QGraphicsScenePrivate::_q_updateScenePosDescendants ( )
Warning
This function is not part of the public interface.

Definition at line 563 of file qgraphicsscene.cpp.

564 {
565  foreach (QGraphicsItem *item, scenePosItems) {
566  QGraphicsItem *p = item->d_ptr->parent;
567  while (p) {
568  p->d_ptr->scenePosDescendants = 1;
569  p = p->d_ptr->parent;
570  }
571  }
573 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QSet< QGraphicsItem * > scenePosItems
quint32 scenePosDescendantsUpdatePending

◆ addPopup()

void QGraphicsScenePrivate::addPopup ( QGraphicsWidget widget)
Warning
This function is not part of the public interface.

Definition at line 872 of file qgraphicsscene.cpp.

873 {
874  Q_ASSERT(widget);
875  Q_ASSERT(!popupWidgets.contains(widget));
876  popupWidgets << widget;
877  if (QGraphicsWidget *focusWidget = widget->focusWidget()) {
878  focusWidget->setFocus(Qt::PopupFocusReason);
879  } else {
880  grabKeyboard((QGraphicsItem *)widget);
881  if (focusItem && popupWidgets.size() == 1) {
884  }
885  }
886  grabMouse((QGraphicsItem *)widget);
887 }
QGraphicsWidget * focusWidget() const
If this widget, a child or descendant of this widget currently has input focus, this function will re...
EventRef event
QPointer< QWidget > widget
QGraphicsItem * focusItem
void grabKeyboard(QGraphicsItem *item)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
void grabMouse(QGraphicsItem *item, bool implicit=false)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
QList< QGraphicsWidget * > popupWidgets
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ addView()

void QGraphicsScenePrivate::addView ( QGraphicsView view)

Definition at line 5938 of file qgraphicsscene.cpp.

5939 {
5940  views << view;
5941 #ifndef QT_NO_GESTURES
5942  foreach (Qt::GestureType gesture, grabbedGestures.keys())
5943  view->viewport()->grabGesture(gesture);
5944 #endif
5945 }
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
Definition: qwidget.cpp:12964
QList< QGraphicsView * > views
QWidget * viewport() const
Returns the viewport widget.
QHash< Qt::GestureType, int > grabbedGestures
GestureType
Definition: qnamespace.h:1759
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648

◆ cancelGesturesForChildren()

void QGraphicsScenePrivate::cancelGesturesForChildren ( QGesture original)

Definition at line 6570 of file qgraphicsscene.cpp.

6571 {
6572  Q_ASSERT(original);
6573  QGraphicsItem *originalItem = gestureTargets.value(original);
6574  if (originalItem == 0) // we only act on accepted gestures, which implies it has a target.
6575  return;
6576 
6577  // iterate over all active gestures and for each find the owner
6578  // if the owner is part of our sub-hierarchy, cancel it.
6579 
6580  QSet<QGesture *> canceledGestures;
6582  while (iter != gestureTargets.end()) {
6583  QGraphicsObject *item = iter.value();
6584  // note that we don't touch the gestures for our originalItem
6585  if (item != originalItem && originalItem->isAncestorOf(item)) {
6586  G_DEBUG() << " found a gesture to cancel" << iter.key();
6587  iter.key()->d_func()->state = Qt::GestureCanceled;
6588  canceledGestures << iter.key();
6589  }
6590  ++iter;
6591  }
6592 
6593  // sort them per target item by cherry picking from almostCanceledGestures and delivering
6594  QSet<QGesture *> almostCanceledGestures = canceledGestures;
6596  while (!almostCanceledGestures.isEmpty()) {
6597  QGraphicsObject *target = 0;
6598  QSet<QGesture*> gestures;
6599  setIter = almostCanceledGestures.begin();
6600  // sort per target item
6601  while (setIter != almostCanceledGestures.end()) {
6602  QGraphicsObject *item = gestureTargets.value(*setIter);
6603  if (target == 0)
6604  target = item;
6605  if (target == item) {
6606  gestures << *setIter;
6607  setIter = almostCanceledGestures.erase(setIter);
6608  } else {
6609  ++setIter;
6610  }
6611  }
6612  Q_ASSERT(target);
6613 
6614  QList<QGesture *> list = gestures.toList();
6615  QGestureEvent ev(list);
6616  sendEvent(target, &ev);
6617 
6618  foreach (QGesture *g, list) {
6619  if (ev.isAccepted() || ev.isAccepted(g))
6620  gestures.remove(g);
6621  }
6622 
6623  foreach (QGesture *g, gestures) {
6624  if (!g->hasHotSpot())
6625  continue;
6626 
6627  QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, 0);
6628  for (int j = 0; j < items.size(); ++j) {
6629  QGraphicsObject *item = items.at(j)->toGraphicsObject();
6630  if (!item)
6631  continue;
6632  QGraphicsItemPrivate *d = item->QGraphicsItem::d_func();
6633  if (d->gestureContext.contains(g->gestureType())) {
6634  QList<QGesture *> list;
6635  list << g;
6636  QGestureEvent ev(list);
6637  sendEvent(item, &ev);
6638  if (ev.isAccepted() || ev.isAccepted(g))
6639  break; // successfully delivered
6640  }
6641  }
6642  }
6643  }
6644 
6646  Q_ASSERT(gestureManager); // it would be very odd if we got called without a manager.
6647  for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) {
6648  gestureManager->recycle(*setIter);
6649  gestureTargets.remove(*setIter);
6650  }
6651 }
double d
Definition: qnumeric_p.h:62
void recycle(QGesture *gesture)
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QList< QGraphicsItem * > itemsAtPosition(const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
Returns all items for the screen position in event.
bool remove(const T &value)
Definition: qset.h:89
bool isEmpty() const
Definition: qset.h:77
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
static QApplicationPrivate * instance()
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator begin()
Definition: qset.h:166
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
The QGestureEvent class provides the description of triggered gestures.
Definition: qevent.h:841
QList< T > toList() const
Definition: qset.h:296
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
iterator end()
Definition: qset.h:169
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qhash.h:347
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:64
QHash< QGesture *, QGraphicsObject * > gestureTargets
Qt::GestureType gestureType
the type of the gesture
Definition: qgesture.h:70
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
#define G_DEBUG
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
iterator erase(iterator i)
Definition: qset.h:172
The QGraphicsObject class provides a base class for all graphics items that require signals...
QGestureManager * gestureManager
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
bool hasHotSpot
whether the gesture has a hot-spot
Definition: qgesture.h:73
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ clearKeyboardGrabber()

void QGraphicsScenePrivate::clearKeyboardGrabber ( )
Warning
This function is not part of the public interface.

Definition at line 1086 of file qgraphicsscene.cpp.

1087 {
1090 }
QList< QGraphicsItem * > keyboardGrabberItems
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying=false)

◆ clearMouseGrabber()

void QGraphicsScenePrivate::clearMouseGrabber ( )
Warning
This function is not part of the public interface.

Definition at line 1015 of file qgraphicsscene.cpp.

Referenced by sendMouseEvent().

1016 {
1017  if (!mouseGrabberItems.isEmpty())
1020 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QGraphicsItem * > mouseGrabberItems
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QGraphicsItem * lastMouseGrabberItem
void ungrabMouse()
Releases the mouse grab.

◆ cloneDragDropEvent()

void QGraphicsScenePrivate::cloneDragDropEvent ( QGraphicsSceneDragDropEvent dest,
QGraphicsSceneDragDropEvent source 
)
Warning
This function is not part of the public interface.

Definition at line 1244 of file qgraphicsscene.cpp.

1246 {
1247  dest->setWidget(source->widget());
1248  dest->setPos(source->pos());
1249  dest->setScenePos(source->scenePos());
1250  dest->setScreenPos(source->screenPos());
1251  dest->setButtons(source->buttons());
1252  dest->setModifiers(source->modifiers());
1253  dest->setPossibleActions(source->possibleActions());
1254  dest->setProposedAction(source->proposedAction());
1255  dest->setDropAction(source->dropAction());
1256  dest->setSource(source->source());
1257  dest->setMimeData(source->mimeData());
1258 }
Qt::DropAction dropAction() const
Returns the action that was performed in this drag and drop.
const QMimeData * mimeData() const
This function returns the MIME data of the event.
void setSource(QWidget *source)
This function set the source widget, i.
void setScenePos(const QPointF &pos)
Sets the scene position of the mouse to pos.
void setMimeData(const QMimeData *data)
This function sets the MIME data for the event.
Qt::MouseButtons buttons() const
Returns a Qt::MouseButtons value indicating which buttons were pressed on the mouse when this mouse e...
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers that were pressed when the drag and drop event was created...
void setWidget(QWidget *widget)
Sets the widget related to this event.
QWidget * source() const
This function returns the QGraphicsView that created the QGraphicsSceneDragDropEvent.
void setPossibleActions(Qt::DropActions actions)
Sets the possible drop actions that the drag can result in to actions.
void setDropAction(Qt::DropAction action)
This function lets the receiver of the drop set the drop action that was performed to action...
void setPos(const QPointF &pos)
Sets the position of the mouse to pos; this should be relative to the widget that generated the event...
QPoint screenPos() const
Returns the position of the mouse relative to the screen.
Qt::DropAction proposedAction() const
Returns the drop action that is proposed, i.e., preferred.
Qt::DropActions possibleActions() const
Returns the possible drop actions that the drag and drop can result in.
void setModifiers(Qt::KeyboardModifiers modifiers)
Sets the keyboard modifiers that were pressed when the event was created to modifiers.
void setButtons(Qt::MouseButtons buttons)
Sets the mouse buttons that were pressed when the event was created to buttons.
void setProposedAction(Qt::DropAction action)
Sets the proposed action to action.
QPointF scenePos() const
Returns the position of the mouse in scene coordinates.
void setScreenPos(const QPoint &pos)
Sets the mouse position relative to the screen to pos.
QPointF pos() const
Returns the mouse position of the event relative to the view that sent the event. ...

◆ dispatchHoverEvent()

bool QGraphicsScenePrivate::dispatchHoverEvent ( QGraphicsSceneHoverEvent hoverEvent)

This event handler, for event hoverEvent, can be reimplemented in a subclass to receive hover enter events.

The default implementation forwards the event to the topmost item that accepts hover events at the scene position from the event.

See also
QGraphicsItem::hoverEvent(), QGraphicsItem::setAcceptHoverEvents()

Definition at line 3999 of file qgraphicsscene.cpp.

4000 {
4002  return false;
4003 
4004  // Find the first item that accepts hover events, reusing earlier
4005  // calculated data is possible.
4008  hoverEvent->scenePos(),
4009  hoverEvent->widget());
4010  }
4011 
4012  QGraphicsItem *item = 0;
4013  for (int i = 0; i < cachedItemsUnderMouse.size(); ++i) {
4015  if (itemAcceptsHoverEvents_helper(tmp)) {
4016  item = tmp;
4017  break;
4018  }
4019  }
4020 
4021  // Find the common ancestor item for the new topmost hoverItem and the
4022  // last item in the hoverItem list.
4023  QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.last()) : 0;
4024  while (commonAncestorItem && !itemAcceptsHoverEvents_helper(commonAncestorItem))
4025  commonAncestorItem = commonAncestorItem->parentItem();
4026  if (commonAncestorItem && commonAncestorItem->panel() != item->panel()) {
4027  // The common ancestor isn't in the same panel as the two hovered
4028  // items.
4029  commonAncestorItem = 0;
4030  }
4031 
4032  // Check if the common ancestor item is known.
4033  int index = commonAncestorItem ? hoverItems.indexOf(commonAncestorItem) : -1;
4034  // Send hover leaves to any existing hovered children of the common
4035  // ancestor item.
4036  for (int i = hoverItems.size() - 1; i > index; --i) {
4037  QGraphicsItem *lastItem = hoverItems.takeLast();
4038  if (itemAcceptsHoverEvents_helper(lastItem))
4039  sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, hoverEvent);
4040  }
4041 
4042  // Item is a child of a known item. Generate enter events for the
4043  // missing links.
4044  QList<QGraphicsItem *> parents;
4045  QGraphicsItem *parent = item;
4046  while (parent && parent != commonAncestorItem) {
4047  parents.prepend(parent);
4048  if (parent->isPanel()) {
4049  // Stop at the panel - we don't deliver beyond this point.
4050  break;
4051  }
4052  parent = parent->parentItem();
4053  }
4054  for (int i = 0; i < parents.size(); ++i) {
4055  parent = parents.at(i);
4056  hoverItems << parent;
4057  if (itemAcceptsHoverEvents_helper(parent))
4058  sendHoverEvent(QEvent::GraphicsSceneHoverEnter, parent, hoverEvent);
4059  }
4060 
4061  // Generate a move event for the item itself
4062  if (item
4063  && !hoverItems.isEmpty()
4064  && item == hoverItems.last()) {
4066  return true;
4067  }
4068  return false;
4069 }
bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const
QGraphicsItem * commonAncestorItem(const QGraphicsItem *other) const
Returns the closest common ancestor item of this item and other, or 0 if either other is 0...
QList< QGraphicsItem * > itemsAtPosition(const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
Returns all items for the screen position in event.
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the hover event was sent...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > cachedItemsUnderMouse
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
QGraphicsSceneIndex * index
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void sendHoverEvent(QEvent::Type type, QGraphicsItem *item, QGraphicsSceneHoverEvent *hoverEvent)
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
QList< QGraphicsItem * > hoverItems
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QPointF scenePos() const
Returns the position of the mouse cursor in scene coordinates at the moment the hover event was sent...
QObject * parent
Definition: qobject.h:92
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ draw()

void QGraphicsScenePrivate::draw ( QGraphicsItem item,
QPainter painter,
const QTransform * const  viewTransform,
const QTransform * const  transformPtr,
QRegion exposedRegion,
QWidget widget,
qreal  opacity,
const QTransform * const  effectTransform,
bool  wasDirtyParentSceneTransform,
bool  drawItem 
)

Definition at line 5007 of file qgraphicsscene.cpp.

Referenced by QGraphicsItemEffectSourcePrivate::draw(), and QGraphicsItemEffectSourcePrivate::pixmap().

5011 {
5012  const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity);
5013  const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
5014  const bool itemHasChildren = !item->d_ptr->children.isEmpty();
5015  bool setChildClip = itemClipsChildrenToShape;
5016  bool itemHasChildrenStackedBehind = false;
5017 
5018  int i = 0;
5019  if (itemHasChildren) {
5020  if (itemClipsChildrenToShape)
5021  setWorldTransform(painter, transformPtr, effectTransform);
5022 
5023  item->d_ptr->ensureSortedChildren();
5024  // Items with the 'ItemStacksBehindParent' flag are put in front of the list
5025  // so all we have to do is to check the first item.
5026  itemHasChildrenStackedBehind = (item->d_ptr->children.at(0)->d_ptr->flags
5028 
5029  if (itemHasChildrenStackedBehind) {
5030  if (itemClipsChildrenToShape) {
5031  setClip(painter, item);
5032  setChildClip = false;
5033  }
5034 
5035  // Draw children behind
5036  for (i = 0; i < item->d_ptr->children.size(); ++i) {
5037  QGraphicsItem *child = item->d_ptr->children.at(i);
5038  if (wasDirtyParentSceneTransform)
5039  child->d_ptr->dirtySceneTransform = 1;
5041  break;
5042  if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
5043  continue;
5044  drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform);
5045  }
5046  }
5047  }
5048 
5049  // Draw item
5050  if (drawItem) {
5051  Q_ASSERT(!itemIsFullyTransparent);
5053  Q_ASSERT(transformPtr);
5054  item->d_ptr->initStyleOption(&styleOptionTmp, *transformPtr, exposedRegion
5055  ? *exposedRegion : QRegion(), exposedRegion == 0);
5056 
5057  const bool itemClipsToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsToShape;
5058  bool restorePainterClip = false;
5059 
5060  if (!itemHasChildren || !itemClipsChildrenToShape) {
5061  // Item does not have children or clip children to shape.
5062  setWorldTransform(painter, transformPtr, effectTransform);
5063  if ((restorePainterClip = itemClipsToShape))
5064  setClip(painter, item);
5065  } else if (itemHasChildrenStackedBehind){
5066  // Item clips children to shape and has children stacked behind, which means
5067  // the painter is already clipped to the item's shape.
5068  if (itemClipsToShape) {
5069  // The clip is already correct. Ensure correct world transform.
5070  setWorldTransform(painter, transformPtr, effectTransform);
5071  } else {
5072  // Remove clip (this also ensures correct world transform).
5073  painter->restore();
5074  setChildClip = true;
5075  }
5076  } else if (itemClipsToShape) {
5077  // Item clips children and itself to shape. It does not have hildren stacked
5078  // behind, which means the clip has not yet been set. We set it now and re-use it
5079  // for the children.
5080  setClip(painter, item);
5081  setChildClip = false;
5082  }
5083 
5084  if (painterStateProtection && !restorePainterClip)
5085  painter->save();
5086 
5087  painter->setOpacity(opacity);
5088  if (!item->d_ptr->cacheMode && !item->d_ptr->isWidget)
5089  item->paint(painter, &styleOptionTmp, widget);
5090  else
5091  drawItemHelper(item, painter, &styleOptionTmp, widget, painterStateProtection);
5092 
5093  if (painterStateProtection || restorePainterClip)
5094  painter->restore();
5095 
5096  static int drawRect = qgetenv("QT_DRAW_SCENE_ITEM_RECTS").toInt();
5097  if (drawRect) {
5098  QPen oldPen = painter->pen();
5099  QBrush oldBrush = painter->brush();
5100  quintptr ptr = reinterpret_cast<quintptr>(item);
5101  const QColor color = QColor::fromHsv(ptr % 255, 255, 255);
5102  painter->setPen(color);
5103  painter->setBrush(Qt::NoBrush);
5104  painter->drawRect(adjustedItemBoundingRect(item));
5105  painter->setPen(oldPen);
5106  painter->setBrush(oldBrush);
5107  }
5108  }
5109 
5110  // Draw children in front
5111  if (itemHasChildren) {
5112  if (setChildClip)
5113  setClip(painter, item);
5114 
5115  for (; i < item->d_ptr->children.size(); ++i) {
5116  QGraphicsItem *child = item->d_ptr->children.at(i);
5117  if (wasDirtyParentSceneTransform)
5118  child->d_ptr->dirtySceneTransform = 1;
5119  if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
5120  continue;
5121  drawSubtreeRecursive(child, painter, viewTransform, exposedRegion, widget, opacity, effectTransform);
5122  }
5123 
5124  // Restore child clip
5125  if (itemClipsChildrenToShape)
5126  painter->restore();
5127  }
5128 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
static QRectF adjustedItemBoundingRect(const QGraphicsItem *item)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static void setWorldTransform(QPainter *painter, const QTransform *const transformPtr, const QTransform *effectTransform)
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
QScopedPointer< QGraphicsItemPrivate > d_ptr
static QColor fromHsv(int h, int s, int v, int a=255)
Static convenience function that returns a QColor constructed from the HSV color values, h (hue), s (saturation), v (value), and a (alpha-channel, i.e.
Definition: qcolor.cpp:2048
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
bool isOpacityNull() const
QStyleOptionGraphicsItem styleOptionTmp
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static void setClip(QPainter *painter, QGraphicsItem *item)
void drawItemHelper(QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget, bool painterStateProtection)
Draws items directly, or using cache.
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, const QRegion &exposedRegion, bool allItems=false) const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const, QRegion *exposedRegion, QWidget *widget, qreal parentOpacity=qreal(1.0), const QTransform *const effectTransform=0)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
const T * ptr(const T &t)
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
QList< QGraphicsItem * > children

◆ drawItemHelper()

void QGraphicsScenePrivate::drawItemHelper ( QGraphicsItem item,
QPainter painter,
const QStyleOptionGraphicsItem option,
QWidget widget,
bool  painterStateProtection 
)

Draws items directly, or using cache.

Warning
This function is not part of the public interface.

Definition at line 4543 of file qgraphicsscene.cpp.

4546 {
4547  QGraphicsItemPrivate *itemd = item->d_ptr.data();
4549 
4550  // Render directly, using no cache.
4551  if (cacheMode == QGraphicsItem::NoCache
4552 #ifdef Q_WS_X11
4553  || !X11->use_xrender
4554 #endif
4555  ) {
4556  _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, true, painterStateProtection);
4557  return;
4558  }
4559 
4560  const qreal oldPainterOpacity = painter->opacity();
4561  qreal newPainterOpacity = oldPainterOpacity;
4562  QGraphicsProxyWidget *proxy = item->isWidget() ? qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(item)) : 0;
4563  if (proxy && proxy->widget()) {
4564  const qreal windowOpacity = proxy->widget()->windowOpacity();
4565  if (windowOpacity < 1.0)
4566  newPainterOpacity *= windowOpacity;
4567  }
4568 
4569  // Item's (local) bounding rect
4570  QRectF brect = item->boundingRect();
4571  QRectF adjustedBrect(brect);
4572  _q_adjustRect(&adjustedBrect);
4573  if (adjustedBrect.isEmpty())
4574  return;
4575 
4576  // Fetch the off-screen transparent buffer and exposed area info.
4577  QPixmapCache::Key pixmapKey;
4578  QPixmap pix;
4579  bool pixmapFound;
4580  QGraphicsItemCache *itemCache = itemd->extraItemCache();
4581  if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
4582  pixmapKey = itemCache->key;
4583  } else {
4584  pixmapKey = itemCache->deviceData.value(widget).key;
4585  }
4586 
4587  // Find pixmap in cache.
4588  pixmapFound = QPixmapCache::find(pixmapKey, &pix);
4589 
4590  // Render using item coordinate cache mode.
4591  if (cacheMode == QGraphicsItem::ItemCoordinateCache) {
4592  QSize pixmapSize;
4593  bool fixedCacheSize = false;
4594  QRect br = brect.toAlignedRect();
4595  if ((fixedCacheSize = itemCache->fixedSize.isValid())) {
4596  pixmapSize = itemCache->fixedSize;
4597  } else {
4598  pixmapSize = br.size();
4599  }
4600 
4601  // Create or recreate the pixmap.
4602  int adjust = itemCache->fixedSize.isValid() ? 0 : 2;
4603  QSize adjustSize(adjust*2, adjust*2);
4604  br.adjust(-adjust, -adjust, adjust, adjust);
4605  if (pix.isNull() || (!fixedCacheSize && (pixmapSize + adjustSize) != pix.size())) {
4606  pix = QPixmap(pixmapSize + adjustSize);
4607  itemCache->boundingRect = br;
4608  itemCache->exposed.clear();
4609  itemCache->allExposed = true;
4610  } else if (itemCache->boundingRect != br) {
4611  itemCache->boundingRect = br;
4612  itemCache->exposed.clear();
4613  itemCache->allExposed = true;
4614  }
4615 
4616  // Redraw any newly exposed areas.
4617  if (itemCache->allExposed || !itemCache->exposed.isEmpty()) {
4618 
4619  //We know that we will modify the pixmap, removing it from the cache
4620  //will detach the one we have and avoid a deep copy
4621  if (pixmapFound)
4622  QPixmapCache::remove(pixmapKey);
4623 
4624  // Fit the item's bounding rect into the pixmap's coordinates.
4625  QTransform itemToPixmap;
4626  if (fixedCacheSize) {
4627  const QPointF scale(pixmapSize.width() / brect.width(), pixmapSize.height() / brect.height());
4628  itemToPixmap.scale(scale.x(), scale.y());
4629  }
4630  itemToPixmap.translate(-br.x(), -br.y());
4631 
4632  // Generate the item's exposedRect and map its list of expose
4633  // rects to device coordinates.
4634  styleOptionTmp = *option;
4635  QRegion pixmapExposed;
4636  QRectF exposedRect;
4637  if (!itemCache->allExposed) {
4638  for (int i = 0; i < itemCache->exposed.size(); ++i) {
4639  QRectF r = itemCache->exposed.at(i);
4640  exposedRect |= r;
4641  pixmapExposed += itemToPixmap.mapRect(r).toAlignedRect();
4642  }
4643  } else {
4644  exposedRect = brect;
4645  }
4646  styleOptionTmp.exposedRect = exposedRect;
4647 
4648  // Render.
4649  _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(),
4651 
4652  // insert this pixmap into the cache.
4653  itemCache->key = QPixmapCache::insert(pix);
4654 
4655  // Reset expose data.
4656  itemCache->allExposed = false;
4657  itemCache->exposed.clear();
4658  }
4659 
4660  // Redraw the exposed area using the transformed painter. Depending on
4661  // the hardware, this may be a server-side operation, or an expensive
4662  // qpixmap-image-transform-pixmap roundtrip.
4663  if (newPainterOpacity != oldPainterOpacity) {
4664  painter->setOpacity(newPainterOpacity);
4665  painter->drawPixmap(br.topLeft(), pix);
4666  painter->setOpacity(oldPainterOpacity);
4667  } else {
4668  painter->drawPixmap(br.topLeft(), pix);
4669  }
4670  return;
4671  }
4672 
4673  // Render using device coordinate cache mode.
4674  if (cacheMode == QGraphicsItem::DeviceCoordinateCache) {
4675  // Find the item's bounds in device coordinates.
4676  QRectF deviceBounds = painter->worldTransform().mapRect(brect);
4677  QRect deviceRect = deviceBounds.toRect().adjusted(-1, -1, 1, 1);
4678  if (deviceRect.isEmpty())
4679  return;
4680  QRect viewRect = widget ? widget->rect() : QRect();
4681  if (widget && !viewRect.intersects(deviceRect))
4682  return;
4683 
4684  // Resort to direct rendering if the device rect exceeds the
4685  // (optional) maximum bounds. (QGraphicsSvgItem uses this).
4686  QSize maximumCacheSize =
4688  if (!maximumCacheSize.isEmpty()
4689  && (deviceRect.width() > maximumCacheSize.width()
4690  || deviceRect.height() > maximumCacheSize.height())) {
4691  _q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget,
4692  oldPainterOpacity != newPainterOpacity, painterStateProtection);
4693  return;
4694  }
4695 
4696  // Create or reuse offscreen pixmap, possibly scroll/blit from the old one.
4697  // If the world transform is rotated we always recreate the cache to avoid
4698  // wrong blending.
4699  bool pixModified = false;
4700  QGraphicsItemCache::DeviceData *deviceData = &itemCache->deviceData[widget];
4701  bool invertable = true;
4702  QTransform diff = deviceData->lastTransform.inverted(&invertable);
4703  if (invertable)
4704  diff *= painter->worldTransform();
4705  deviceData->lastTransform = painter->worldTransform();
4706  bool allowPartialCacheExposure = false;
4707  bool simpleTransform = invertable && diff.type() <= QTransform::TxTranslate
4708  && transformIsSimple(painter->worldTransform());
4709  if (!simpleTransform) {
4710  pixModified = true;
4711  itemCache->allExposed = true;
4712  itemCache->exposed.clear();
4713  deviceData->cacheIndent = QPoint();
4714  pix = QPixmap();
4715  } else if (!viewRect.isNull()) {
4716  allowPartialCacheExposure = deviceData->cacheIndent != QPoint();
4717  }
4718 
4719  // Allow partial cache exposure if the device rect isn't fully contained and
4720  // deviceRect is 20% taller or wider than the viewRect.
4721  if (!allowPartialCacheExposure && !viewRect.isNull() && !viewRect.contains(deviceRect)) {
4722  allowPartialCacheExposure = (viewRect.width() * 1.2 < deviceRect.width())
4723  || (viewRect.height() * 1.2 < deviceRect.height());
4724  }
4725 
4726  QRegion scrollExposure;
4727  if (allowPartialCacheExposure) {
4728  // Part of pixmap is drawn. Either device contains viewrect (big
4729  // item covers whole screen) or parts of device are outside the
4730  // viewport. In either case the device rect must be the intersect
4731  // between the two.
4732  int dx = deviceRect.left() < viewRect.left() ? viewRect.left() - deviceRect.left() : 0;
4733  int dy = deviceRect.top() < viewRect.top() ? viewRect.top() - deviceRect.top() : 0;
4734  QPoint newCacheIndent(dx, dy);
4735  deviceRect &= viewRect;
4736 
4737  if (pix.isNull()) {
4738  deviceData->cacheIndent = QPoint();
4739  itemCache->allExposed = true;
4740  itemCache->exposed.clear();
4741  pixModified = true;
4742  }
4743 
4744  // Copy / "scroll" the old pixmap onto the new ole and calculate
4745  // scrolled exposure.
4746  if (newCacheIndent != deviceData->cacheIndent || deviceRect.size() != pix.size()) {
4747  QPoint diff = newCacheIndent - deviceData->cacheIndent;
4748  QPixmap newPix(deviceRect.size());
4749  // ### Investigate removing this fill (test with Plasma and
4750  // graphicssystem raster).
4751  newPix.fill(Qt::transparent);
4752  if (!pix.isNull()) {
4753  QPainter newPixPainter(&newPix);
4754  newPixPainter.drawPixmap(-diff, pix);
4755  newPixPainter.end();
4756  }
4757  QRegion exposed;
4758  exposed += newPix.rect();
4759  if (!pix.isNull())
4760  exposed -= QRect(-diff, pix.size());
4761  scrollExposure = exposed;
4762 
4763  pix = newPix;
4764  pixModified = true;
4765  }
4766  deviceData->cacheIndent = newCacheIndent;
4767  } else {
4768  // Full pixmap is drawn.
4769  deviceData->cacheIndent = QPoint();
4770 
4771  // Auto-adjust the pixmap size.
4772  if (deviceRect.size() != pix.size()) {
4773  // exposed needs to cover the whole pixmap
4774  pix = QPixmap(deviceRect.size());
4775  pixModified = true;
4776  itemCache->allExposed = true;
4777  itemCache->exposed.clear();
4778  }
4779  }
4780 
4781  // Check for newly invalidated areas.
4782  if (itemCache->allExposed || !itemCache->exposed.isEmpty() || !scrollExposure.isEmpty()) {
4783  //We know that we will modify the pixmap, removing it from the cache
4784  //will detach the one we have and avoid a deep copy
4785  if (pixmapFound)
4786  QPixmapCache::remove(pixmapKey);
4787 
4788  // Construct an item-to-pixmap transform.
4789  QPointF p = deviceRect.topLeft();
4790  QTransform itemToPixmap = painter->worldTransform();
4791  if (!p.isNull())
4792  itemToPixmap *= QTransform::fromTranslate(-p.x(), -p.y());
4793 
4794  // Map the item's logical expose to pixmap coordinates.
4795  QRegion pixmapExposed = scrollExposure;
4796  if (!itemCache->allExposed) {
4797  const QVector<QRectF> &exposed = itemCache->exposed;
4798  for (int i = 0; i < exposed.size(); ++i)
4799  pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1);
4800  }
4801 
4802  // Calculate the style option's exposedRect.
4803  QRectF br;
4804  if (itemCache->allExposed) {
4805  br = item->boundingRect();
4806  } else {
4807  const QVector<QRectF> &exposed = itemCache->exposed;
4808  for (int i = 0; i < exposed.size(); ++i)
4809  br |= exposed.at(i);
4810  QTransform pixmapToItem = itemToPixmap.inverted();
4811  foreach (QRect r, scrollExposure.rects())
4812  br |= pixmapToItem.mapRect(r);
4813  }
4814  styleOptionTmp = *option;
4815  styleOptionTmp.exposedRect = br.adjusted(-1, -1, 1, 1);
4816 
4817  // Render the exposed areas.
4818  _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(),
4820 
4821  // Reset expose data.
4822  pixModified = true;
4823  itemCache->allExposed = false;
4824  itemCache->exposed.clear();
4825  }
4826 
4827  if (pixModified) {
4828  // Insert this pixmap into the cache.
4829  deviceData->key = QPixmapCache::insert(pix);
4830  }
4831 
4832  // Redraw the exposed area using an untransformed painter. This
4833  // effectively becomes a bitblit that does not transform the cache.
4834  QTransform restoreTransform = painter->worldTransform();
4835  painter->setWorldTransform(QTransform());
4836  if (newPainterOpacity != oldPainterOpacity) {
4837  painter->setOpacity(newPainterOpacity);
4838  painter->drawPixmap(deviceRect.topLeft(), pix);
4839  painter->setOpacity(oldPainterOpacity);
4840  } else {
4841  painter->drawPixmap(deviceRect.topLeft(), pix);
4842  }
4843  painter->setWorldTransform(restoreTransform);
4844  return;
4845  }
4846 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
QMap< QPaintDevice *, DeviceData > deviceData
static void _q_paintItem(QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget, bool useWindowOpacity, bool painterStateProtection)
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
double windowOpacity
The level of opacity for the window.
Definition: qwidget.h:201
double qreal
Definition: qglobal.h:1193
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
QPointer< QWidget > widget
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
static bool transformIsSimple(const QTransform &transform)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QStyleOptionGraphicsItem styleOptionTmp
TransformationType type() const
Returns the transformation type of this matrix.
#define X11
Definition: qt_x11_p.h:724
static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion &pixmapExposed, const QTransform &itemToPixmap, QPainter::RenderHints renderHints, const QStyleOptionGraphicsItem *option, bool painterStateProtection)
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
static QPixmap * find(const QString &key)
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
int width() const
Returns the width.
Definition: qsize.h:126
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
static void _q_adjustRect(QRect *rect)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
static Bigint * diff(Bigint *a, Bigint *b)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
QVariant extra(Extra type) const
QSize toSize() const
Returns the variant as a QSize if the variant has type() Size ; otherwise returns an invalid QSize...
Definition: qvariant.cpp:2432
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
CacheMode
This enum describes QGraphicsItem&#39;s cache modes.
The QPixmapCache::Key class can be used for efficient access to the QPixmapCache. ...
Definition: qpixmapcache.h:61
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QPixmapCache::Key key
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
bool isWidget() const
Returns true if this item is a widget (i.
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
QVector< QRectF > exposed
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
static void remove(const QString &key)
Removes the pixmap associated with key from the cache.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
QGraphicsItemCache * extraItemCache() const
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QRectF exposedRect
the exposed rectangle, in item coordinates
Definition: qstyleoption.h:873
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QWidget * widget() const
Returns a pointer to the embedded widget.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ drawItems()

void QGraphicsScenePrivate::drawItems ( QPainter painter,
const QTransform *const  viewTransform,
QRegion exposedRegion,
QWidget widget 
)

Definition at line 4848 of file qgraphicsscene.cpp.

4850 {
4851  // Make sure we don't have unpolished items before we draw.
4852  if (!unpolishedItems.isEmpty())
4853  _q_polishItems();
4854 
4855  updateAll = false;
4856  QRectF exposedSceneRect;
4857  if (exposedRegion && indexMethod != QGraphicsScene::NoIndex) {
4858  exposedSceneRect = exposedRegion->boundingRect().adjusted(-1, -1, 1, 1);
4859  if (viewTransform)
4860  exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect);
4861  }
4862  const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder);
4863  for (int i = 0; i < tli.size(); ++i)
4864  drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget);
4865 }
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
QPointer< QWidget > widget
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
QVector< QGraphicsItem * > unpolishedItems
QGraphicsSceneIndex * index
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform *const, QRegion *exposedRegion, QWidget *widget, qreal parentOpacity=qreal(1.0), const QTransform *const effectTransform=0)
virtual QList< QGraphicsItem * > estimateTopLevelItems(const QRectF &, Qt::SortOrder order) const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QGraphicsScene::ItemIndexMethod indexMethod
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ drawSubtreeRecursive()

void QGraphicsScenePrivate::drawSubtreeRecursive ( QGraphicsItem item,
QPainter painter,
const QTransform * const  viewTransform,
QRegion exposedRegion,
QWidget widget,
qreal  parentOpacity = qreal(1.0),
const QTransform *const  effectTransform = 0 
)

Definition at line 4867 of file qgraphicsscene.cpp.

4871 {
4872  Q_ASSERT(item);
4873 
4874  if (!item->d_ptr->visible)
4875  return;
4876 
4877  const bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents);
4878  const bool itemHasChildren = !item->d_ptr->children.isEmpty();
4879  if (!itemHasContents && !itemHasChildren)
4880  return; // Item has neither contents nor children!(?)
4881 
4882  const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity);
4883  const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity);
4884  if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity()))
4885  return;
4886 
4887  QTransform transform(Qt::Uninitialized);
4888  QTransform *transformPtr = 0;
4889  bool translateOnlyTransform = false;
4890 #define ENSURE_TRANSFORM_PTR \
4891  if (!transformPtr) { \
4892  Q_ASSERT(!itemIsUntransformable); \
4893  if (viewTransform) { \
4894  transform = item->d_ptr->sceneTransform; \
4895  transform *= *viewTransform; \
4896  transformPtr = &transform; \
4897  } else { \
4898  transformPtr = &item->d_ptr->sceneTransform; \
4899  translateOnlyTransform = item->d_ptr->sceneTransformTranslateOnly; \
4900  } \
4901  }
4902 
4903  // Update the item's scene transform if the item is transformable;
4904  // otherwise calculate the full transform,
4905  bool wasDirtyParentSceneTransform = false;
4906  const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable();
4907  if (itemIsUntransformable) {
4908  transform = item->deviceTransform(viewTransform ? *viewTransform : QTransform());
4909  transformPtr = &transform;
4910  } else if (item->d_ptr->dirtySceneTransform) {
4913  wasDirtyParentSceneTransform = true;
4914  }
4915 
4916  const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
4917  bool drawItem = itemHasContents && !itemIsFullyTransparent;
4918  if (drawItem) {
4919  const QRectF brect = adjustedItemEffectiveBoundingRect(item);
4921  QRect viewBoundingRect = translateOnlyTransform ? brect.translated(transformPtr->dx(), transformPtr->dy()).toAlignedRect()
4922  : transformPtr->mapRect(brect).toAlignedRect();
4923  viewBoundingRect.adjust(-int(rectAdjust), -int(rectAdjust), rectAdjust, rectAdjust);
4924  if (widget)
4925  item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect);
4926  drawItem = exposedRegion ? exposedRegion->intersects(viewBoundingRect)
4927  : !viewBoundingRect.normalized().isEmpty();
4928  if (!drawItem) {
4929  if (!itemHasChildren)
4930  return;
4931  if (itemClipsChildrenToShape) {
4932  if (wasDirtyParentSceneTransform)
4934  return;
4935  }
4936  }
4937  } // else we know for sure this item has children we must process.
4938 
4939  if (itemHasChildren && itemClipsChildrenToShape)
4941 
4942 #ifndef QT_NO_GRAPHICSEFFECT
4943  if (item->d_ptr->graphicsEffect && item->d_ptr->graphicsEffect->isEnabled()) {
4945  QGraphicsItemPaintInfo info(viewTransform, transformPtr, effectTransform, exposedRegion, widget, &styleOptionTmp,
4946  painter, opacity, wasDirtyParentSceneTransform, itemHasContents && !itemIsFullyTransparent);
4947  QGraphicsEffectSource *source = item->d_ptr->graphicsEffect->d_func()->source;
4949  (source->d_func());
4950  sourced->info = &info;
4951  const QTransform restoreTransform = painter->worldTransform();
4952  if (effectTransform)
4953  painter->setWorldTransform(*transformPtr * *effectTransform);
4954  else
4955  painter->setWorldTransform(*transformPtr);
4956  painter->setOpacity(opacity);
4957 
4959  && sourced->lastEffectTransform != painter->worldTransform())
4960  {
4962  && painter->worldTransform().type() <= QTransform::TxTranslate)
4963  {
4964  QRectF sourceRect = sourced->boundingRect(Qt::DeviceCoordinates);
4965  QRect effectRect = sourced->paddedEffectRect(Qt::DeviceCoordinates, sourced->currentCachedMode(), sourceRect);
4966 
4967  sourced->setCachedOffset(effectRect.topLeft());
4968  } else {
4970  }
4971 
4972  sourced->lastEffectTransform = painter->worldTransform();
4973  }
4974 
4975  item->d_ptr->graphicsEffect->draw(painter);
4976  painter->setWorldTransform(restoreTransform);
4977  sourced->info = 0;
4978  } else
4979 #endif //QT_NO_GRAPHICSEFFECT
4980  {
4981  draw(item, painter, viewTransform, transformPtr, exposedRegion, widget, opacity,
4982  effectTransform, wasDirtyParentSceneTransform, drawItem);
4983  }
4984 }
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
qreal combineOpacityFromParent(qreal parentOpacity) const
double qreal
Definition: qglobal.h:1193
static mach_timebase_info_data_t info
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool isEnabled() const
virtual void updateSceneTransformFromParent()
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on...
bool isOpacityNull() const
QStyleOptionGraphicsItem styleOptionTmp
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
TransformationType type() const
Returns the transformation type of this matrix.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Qt::CoordinateSystem currentCachedSystem() const
void invalidateCache(InvalidateReason reason=SourceChanged) const
QRectF boundingRect(Qt::CoordinateSystem system) const
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void invalidateChildrenSceneTransform()
bool itemIsUntransformable() const
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
QGraphicsEffect * graphicsEffect
#define ENSURE_TRANSFORM_PTR
QTransform deviceTransform(const QTransform &viewportTransform) const
Returns this item&#39;s device transformation matrix, using viewportTransform to map from scene to device...
void setCachedOffset(const QPoint &offset)
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QRect paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode, const QRectF &sourceRect, bool *unpadded=0) const
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
bool intersects(const QRegion &r) const
Returns true if this region intersects with region, otherwise returns false.
Definition: qregion.cpp:766
QGraphicsItemPaintInfo * info
QGraphicsEffect::PixmapPadMode currentCachedMode() const
QMap< QWidget *, QRect > paintedViewBoundingRects
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
QList< QGraphicsItem * > children
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const, QRegion *, QWidget *, qreal, const QTransform *const, bool, bool)
QGraphicsEffectSource * source() const
Returns a pointer to the source, which provides extra context information that can be useful for the ...
bool childrenCombineOpacity() const
virtual void draw(QPainter *painter)=0
This pure virtual function draws the effect and is called whenever the source needs to be drawn...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ enableMouseTrackingOnViews()

void QGraphicsScenePrivate::enableMouseTrackingOnViews ( )

Definition at line 1092 of file qgraphicsscene.cpp.

1093 {
1094  foreach (QGraphicsView *view, views)
1095  view->viewport()->setMouseTracking(true);
1096 }
QList< QGraphicsView * > views
QWidget * viewport() const
Returns the viewport widget.
void setMouseTracking(bool enable)
Definition: qwidget.h:990
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ enableTouchEventsOnViews()

void QGraphicsScenePrivate::enableTouchEventsOnViews ( )

Definition at line 6176 of file qgraphicsscene.cpp.

6177 {
6178  foreach (QGraphicsView *view, views)
6180 }
QList< QGraphicsView * > views
QWidget * viewport() const
Returns the viewport widget.
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ ensureSequentialTopLevelSiblingIndexes()

void QGraphicsScenePrivate::ensureSequentialTopLevelSiblingIndexes ( )

Ensures that the list of toplevels is sorted by insertion order, and that the siblingIndexes are packed (no gaps), and start at 0.

Warning
This function is not part of the public interface.

This function is almost identical to

QGraphicsItemPrivate::ensureSequentialSiblingIndex().

Definition at line 1490 of file qgraphicsscene.cpp.

1491 {
1496  }
1499  for (int i = 0; i < topLevelItems.size(); ++i)
1500  topLevelItems[i]->d_ptr->siblingIndex = i;
1501  }
1502 }
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
static bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b)
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QList< QGraphicsItem * > topLevelItems
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ ensureSortedTopLevelItems()

void QGraphicsScenePrivate::ensureSortedTopLevelItems ( )
inline

Definition at line 271 of file qgraphicsscene_p.h.

Referenced by QGraphicsSceneIndex::estimateTopLevelItems().

272  {
273  if (needSortTopLevelItems) {
276  needSortTopLevelItems = false;
277  }
278  }
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
bool qt_notclosestLeaf(const QGraphicsItem *item1, const QGraphicsItem *item2)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QList< QGraphicsItem * > topLevelItems

◆ enterModal()

void QGraphicsScenePrivate::enterModal ( QGraphicsItem item,
QGraphicsItem::PanelModality  panelModality = QGraphicsItem::NonModal 
)

Definition at line 6188 of file qgraphicsscene.cpp.

6189 {
6191  Q_ASSERT(panel && panel->isPanel());
6192 
6193  QGraphicsItem::PanelModality panelModality = panel->d_ptr->panelModality;
6194  if (previousModality != QGraphicsItem::NonModal) {
6195  // the panel is changing from one modality type to another... temporarily set it back so
6196  // that blockedPanels is populated correctly
6197  panel->d_ptr->panelModality = previousModality;
6198  }
6199 
6200  QSet<QGraphicsItem *> blockedPanels;
6201  QList<QGraphicsItem *> items = q->items(); // ### store panels separately
6202  for (int i = 0; i < items.count(); ++i) {
6203  QGraphicsItem *item = items.at(i);
6204  if (item->isPanel() && item->isBlockedByModalPanel())
6205  blockedPanels.insert(item);
6206  }
6207  // blockedPanels contains all currently blocked panels
6208 
6209  if (previousModality != QGraphicsItem::NonModal) {
6210  // reset the modality to the proper value, since we changed it above
6211  panel->d_ptr->panelModality = panelModality;
6212  // remove this panel so that it will be reinserted at the front of the stack
6213  modalPanels.removeAll(panel);
6214  }
6215 
6216  modalPanels.prepend(panel);
6217 
6218  if (!hoverItems.isEmpty()) {
6219  // send GraphicsSceneHoverLeave events to newly blocked hoverItems
6220  QGraphicsSceneHoverEvent hoverEvent;
6221  hoverEvent.setScenePos(lastSceneMousePos);
6222  dispatchHoverEvent(&hoverEvent);
6223  }
6224 
6227  if (item->isBlockedByModalPanel())
6228  ungrabMouse(item, /*itemIsDying =*/ false);
6229  }
6230 
6231  QEvent windowBlockedEvent(QEvent::WindowBlocked);
6232  QEvent windowUnblockedEvent(QEvent::WindowUnblocked);
6233  for (int i = 0; i < items.count(); ++i) {
6234  QGraphicsItem *item = items.at(i);
6235  if (item->isPanel()) {
6236  if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) {
6237  // send QEvent::WindowBlocked to newly blocked panels
6238  sendEvent(item, &windowBlockedEvent);
6239  } else if (blockedPanels.contains(item) && !item->isBlockedByModalPanel()) {
6240  // send QEvent::WindowUnblocked to unblocked panels when downgrading
6241  // a panel from SceneModal to PanelModal
6242  sendEvent(item, &windowUnblockedEvent);
6243  }
6244  }
6245  }
6246 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent)
This event handler, for event hoverEvent, can be reimplemented in a subclass to receive hover enter e...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > modalPanels
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
void ungrabMouse(QGraphicsItem *item, bool itemIsDying=false)
QList< QGraphicsItem * > mouseGrabberItems
bool contains(const T &value) const
Definition: qset.h:91
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator insert(const T &value)
Definition: qset.h:179
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
QList< QGraphicsItem * > hoverItems
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
PanelModality
This enum specifies the behavior of a modal panel.
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
void setScenePos(const QPointF &pos)
Sets the position associated with the hover event to the given point in scene coordinates.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
quint32 lastMouseGrabberItemHasImplicitMouseGrab

◆ filterDescendantEvent()

bool QGraphicsScenePrivate::filterDescendantEvent ( QGraphicsItem item,
QEvent event 
)
Warning
This function is not part of the public interface.

Definition at line 1168 of file qgraphicsscene.cpp.

Referenced by sendEvent().

1169 {
1171  QGraphicsItem *parent = item->parentItem();
1172  while (parent) {
1173  if (parent->d_ptr->filtersDescendantEvents && parent->sceneEventFilter(item, event))
1174  return true;
1176  return false;
1177  parent = parent->parentItem();
1178  }
1179  }
1180  return false;
1181 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
QObject * parent
Definition: qobject.h:92
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
Filters events for the item watched.

◆ filterEvent()

bool QGraphicsScenePrivate::filterEvent ( QGraphicsItem item,
QEvent event 
)
Warning
This function is not part of the public interface.

Definition at line 1186 of file qgraphicsscene.cpp.

Referenced by sendEvent().

1187 {
1188  if (item && !sceneEventFilters.contains(item))
1189  return false;
1190 
1193  while (it != end) {
1194  // ### The filterer and filteree might both be deleted.
1195  if (it.value()->sceneEventFilter(it.key(), event))
1196  return true;
1197  ++it;
1198  }
1199  return false;
1200 }
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qmap.h:250
EventRef event
#define it(className, varName)
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
bool contains(const Key &key, const T &value) const
Returns true if the map contains an item with key key and value value; otherwise returns false...
Definition: qmap.h:1048
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
iterator upperBound(const Key &key)
Returns an iterator pointing to the item that immediately follows the last item with key key in the m...
Definition: qmap.h:918
iterator lowerBound(const Key &key)
Returns an iterator pointing to the first item with key key in the map.
Definition: qmap.h:899
static const KeyPair *const end
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters

◆ findClosestTouchPointId()

int QGraphicsScenePrivate::findClosestTouchPointId ( const QPointF scenePos)

Definition at line 5964 of file qgraphicsscene.cpp.

5965 {
5966  int closestTouchPointId = -1;
5967  qreal closestDistance = qreal(0.);
5968  foreach (const QTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) {
5969  qreal distance = QLineF(scenePos, touchPoint.scenePos()).length();
5970  if (closestTouchPointId == -1|| distance < closestDistance) {
5971  closestTouchPointId = touchPoint.id();
5972  closestDistance = distance;
5973  }
5974  }
5975  return closestTouchPointId;
5976 }
int id() const
Returns the id number of this touch point.
Definition: qevent.cpp:4445
double qreal
Definition: qglobal.h:1193
QPointF scenePos() const
Returns the scene position of this touch point.
Definition: qevent.cpp:4488
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
QMap< int, QTouchEvent::TouchPoint > sceneCurrentTouchPoints
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744

◆ gestureEventHandler()

void QGraphicsScenePrivate::gestureEventHandler ( QGestureEvent event)

Definition at line 6324 of file qgraphicsscene.cpp.

6325 {
6326  QWidget *viewport = event->widget();
6327  if (!viewport)
6328  return;
6329  QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(viewport->parent());
6330  if (!graphicsView)
6331  return;
6332 
6333  QList<QGesture *> allGestures = event->gestures();
6334  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6335  << "Gestures:" << allGestures;
6336 
6337  QSet<QGesture *> startedGestures;
6338  QPoint delta = viewport->mapFromGlobal(QPoint());
6339  QTransform toScene = QTransform::fromTranslate(delta.x(), delta.y())
6340  * graphicsView->viewportTransform().inverted();
6341  foreach (QGesture *gesture, allGestures) {
6342  // cache scene coordinates of the hot spot
6343  if (gesture->hasHotSpot()) {
6344  gesture->d_func()->sceneHotSpot = toScene.map(gesture->hotSpot());
6345  } else {
6346  gesture->d_func()->sceneHotSpot = QPointF();
6347  }
6348 
6349  QGraphicsObject *target = gestureTargets.value(gesture, 0);
6350  if (!target) {
6351  // when we are not in started mode but don't have a target
6352  // then the only one interested in gesture is the view/scene
6353  if (gesture->state() == Qt::GestureStarted)
6354  startedGestures.insert(gesture);
6355  }
6356  }
6357 
6358  if (!startedGestures.isEmpty()) {
6359  QSet<QGesture *> normalGestures; // that have just one target
6360  QSet<QGesture *> conflictedGestures; // that have multiple possible targets
6362  &normalGestures, &conflictedGestures);
6365  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6366  << "Normal gestures:" << normalGestures
6367  << "Conflicting gestures:" << conflictedGestures;
6368 
6369  // deliver conflicted gestures as override events AND remember
6370  // initial gesture targets
6371  if (!conflictedGestures.isEmpty()) {
6372  for (int i = 0; i < cachedTargetItems.size(); ++i) {
6374 
6375  // get gestures to deliver to the current item
6376  QSet<QGesture *> gestures = conflictedGestures & cachedItemGestures.value(item.data());
6377  if (gestures.isEmpty())
6378  continue;
6379 
6380  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6381  << "delivering override to"
6382  << item.data() << gestures;
6383  // send gesture override
6384  QGestureEvent ev(gestures.toList());
6386  ev.setWidget(event->widget());
6387  // mark event and individual gestures as ignored
6388  ev.ignore();
6389  foreach(QGesture *g, gestures)
6390  ev.setAccepted(g, false);
6391  sendEvent(item.data(), &ev);
6392  // mark all accepted gestures to deliver them as normal gesture events
6393  foreach (QGesture *g, gestures) {
6394  if (ev.isAccepted() || ev.isAccepted(g)) {
6395  conflictedGestures.remove(g);
6396  // mark the item as a gesture target
6397  if (item) {
6398  gestureTargets.insert(g, item.data());
6400  it = cachedItemGestures.begin();
6401  e = cachedItemGestures.end();
6402  for(; it != e; ++it)
6403  it.value().remove(g);
6404  cachedItemGestures[item.data()].insert(g);
6405  }
6406  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6407  << "override was accepted:"
6408  << g << item.data();
6409  }
6410  // remember the first item that received the override event
6411  // as it most likely become a target if no one else accepts
6412  // the override event
6413  if (!gestureTargets.contains(g) && item)
6414  gestureTargets.insert(g, item.data());
6415 
6416  }
6417  if (conflictedGestures.isEmpty())
6418  break;
6419  }
6420  }
6421  // remember the initial target item for each gesture that was not in
6422  // the conflicted state.
6423  if (!normalGestures.isEmpty()) {
6424  for (int i = 0; i < cachedTargetItems.size() && !normalGestures.isEmpty(); ++i) {
6426 
6427  // get gestures to deliver to the current item
6428  foreach (QGesture *g, cachedItemGestures.value(item)) {
6429  if (!gestureTargets.contains(g)) {
6430  gestureTargets.insert(g, item);
6431  normalGestures.remove(g);
6432  }
6433  }
6434  }
6435  }
6436  }
6437 
6438 
6439  // deliver all gesture events
6440  QSet<QGesture *> undeliveredGestures;
6441  QSet<QGesture *> parentPropagatedGestures;
6442  foreach (QGesture *gesture, allGestures) {
6443  if (QGraphicsObject *target = gestureTargets.value(gesture, 0)) {
6444  cachedItemGestures[target].insert(gesture);
6445  cachedTargetItems.append(target);
6446  undeliveredGestures.insert(gesture);
6447  QGraphicsItemPrivate *d = target->QGraphicsItem::d_func();
6448  const Qt::GestureFlags flags = d->gestureContext.value(gesture->gestureType());
6450  parentPropagatedGestures.insert(gesture);
6451  } else {
6452  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6453  << "no target for" << gesture << "at"
6454  << gesture->hotSpot() << gesture->d_func()->sceneHotSpot;
6455  }
6456  }
6458  for (int i = 0; i < cachedTargetItems.size(); ++i) {
6460  QSet<QGesture *> gestures =
6461  undeliveredGestures & cachedItemGestures.value(receiver.data());
6462  gestures -= cachedAlreadyDeliveredGestures.value(receiver.data());
6463 
6464  if (gestures.isEmpty())
6465  continue;
6466 
6467  cachedAlreadyDeliveredGestures[receiver.data()] += gestures;
6468  const bool isPanel = receiver.data()->isPanel();
6469 
6470  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6471  << "delivering to"
6472  << receiver.data() << gestures;
6473  QGestureEvent ev(gestures.toList());
6474  ev.setWidget(event->widget());
6475  sendEvent(receiver.data(), &ev);
6476  QSet<QGesture *> ignoredGestures;
6477  foreach (QGesture *g, gestures) {
6478  if (!ev.isAccepted() && !ev.isAccepted(g)) {
6479  // if the gesture was ignored by its target, we will update the
6480  // targetItems list with a possible target items (items that
6481  // want to receive partial gestures).
6482  // ### wont' work if the target was destroyed in the event
6483  // we will just stop delivering it.
6484  if (receiver && receiver.data() == gestureTargets.value(g, 0))
6485  ignoredGestures.insert(g);
6486  } else {
6487  if (receiver && g->state() == Qt::GestureStarted) {
6488  // someone accepted the propagated initial GestureStarted
6489  // event, let it be the new target for all following events.
6490  gestureTargets[g] = receiver.data();
6491  }
6492  undeliveredGestures.remove(g);
6493  }
6494  }
6495  if (undeliveredGestures.isEmpty())
6496  break;
6497 
6498  // ignoredGestures list is only filled when delivering to the gesture
6499  // target item, so it is safe to assume item == target.
6500  if (!ignoredGestures.isEmpty() && !isPanel) {
6501  // look for new potential targets for gestures that were ignored
6502  // and should be propagated.
6503 
6505 
6506  if (receiver) {
6507  // first if the gesture should be propagated to parents only
6508  for (QSet<QGesture *>::iterator it = ignoredGestures.begin();
6509  it != ignoredGestures.end();) {
6510  if (parentPropagatedGestures.contains(*it)) {
6511  QGesture *gesture = *it;
6512  const Qt::GestureType gestureType = gesture->gestureType();
6513  QGraphicsItem *item = receiver.data();
6514  while (item) {
6515  if (QGraphicsObject *obj = item->toGraphicsObject()) {
6516  if (item->d_func()->gestureContext.contains(gestureType)) {
6517  targetsSet.insert(obj);
6518  cachedItemGestures[obj].insert(gesture);
6519  }
6520  }
6521  if (item->isPanel())
6522  break;
6523  item = item->parentItem();
6524  }
6525 
6526  it = ignoredGestures.erase(it);
6527  continue;
6528  }
6529  ++it;
6530  }
6531  }
6532 
6534  &cachedItemGestures, &targetsSet, 0, 0);
6535 
6536  cachedTargetItems = targetsSet.toList();
6538  G_DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
6539  << "new targets:" << cachedTargetItems;
6540  i = -1; // start delivery again
6541  continue;
6542  }
6543  }
6544 
6545  foreach (QGesture *g, startedGestures) {
6547  G_DEBUG() << "lets try to cancel some";
6548  // find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them
6550  }
6551  }
6552 
6553  // forget about targets for gestures that have ended
6554  foreach (QGesture *g, allGestures) {
6555  switch (g->state()) {
6556  case Qt::GestureFinished:
6557  case Qt::GestureCanceled:
6559  break;
6560  default:
6561  break;
6562  }
6563  }
6564 
6568 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
double d
Definition: qnumeric_p.h:62
QSet< T > toSet() const
Returns a QSet object with the data contained in this QList.
Definition: qset.h:309
ushort t
Definition: qcoreevent.h:316
void clear()
Removes all items from the hash.
Definition: qhash.h:574
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
#define it(className, varName)
bool remove(const T &value)
Definition: qset.h:89
bool isEmpty() const
Definition: qset.h:77
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QGesture::GestureCancelPolicy gestureCancelPolicy
the policy for deciding what happens on accepting a gesture
Definition: qgesture.h:71
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
T * data() const
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem *item2)
Returns true if item1 is on top of item2.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QGestureEvent class provides the description of triggered gestures.
Definition: qevent.h:841
bool contains(const T &value) const
Definition: qset.h:91
QList< T > toList() const
Definition: qset.h:296
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
GestureFlag
Definition: qnamespace.h:1772
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
const_iterator insert(const T &value)
Definition: qset.h:179
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QGraphicsObject * > cachedTargetItems
GestureType
Definition: qnamespace.h:1759
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
QWidget * widget() const
Returns the widget on which the event occurred.
Definition: qevent.cpp:5047
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void cancelGesturesForChildren(QGesture *original)
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:64
QHash< QGesture *, QGraphicsObject * > gestureTargets
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
QPointF hotSpot
The point that is used to find the receiver for the gesture event.
Definition: qgesture.h:72
Qt::GestureType gestureType
the type of the gesture
Definition: qgesture.h:70
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
#define G_DEBUG
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setWidget(QWidget *widget)
Sets the widget for this event to the widget specified.
Definition: qevent.cpp:5039
QHash< QGraphicsObject *, QSet< QGesture * > > cachedItemGestures
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
Qt::GestureState state
the current state of the gesture
Definition: qgesture.h:69
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
void gestureTargetsAtHotSpots(const QSet< QGesture *> &gestures, Qt::GestureFlag flag, QHash< QGraphicsObject *, QSet< QGesture *> > *targets, QSet< QGraphicsObject *> *itemsSet=0, QSet< QGesture *> *normal=0, QSet< QGesture *> *conflicts=0)
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QGraphicsObject class provides a base class for all graphics items that require signals...
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
bool hasHotSpot
whether the gesture has a hot-spot
Definition: qgesture.h:73
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
QHash< QGraphicsObject *, QSet< QGesture * > > cachedAlreadyDeliveredGestures
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ gestureTargetsAtHotSpots()

void QGraphicsScenePrivate::gestureTargetsAtHotSpots ( const QSet< QGesture *> &  gestures,
Qt::GestureFlag  flag,
QHash< QGraphicsObject *, QSet< QGesture *> > *  targets,
QSet< QGraphicsObject *> *  itemsSet = 0,
QSet< QGesture *> *  normal = 0,
QSet< QGesture *> *  conflicts = 0 
)

Definition at line 6277 of file qgraphicsscene.cpp.

6283 {
6284  QSet<QGesture *> normalGestures; // that are not in conflicted state.
6285  foreach (QGesture *gesture, gestures) {
6286  if (!gesture->hasHotSpot())
6287  continue;
6288  const Qt::GestureType gestureType = gesture->gestureType();
6289  QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, 0);
6290  for (int j = 0; j < items.size(); ++j) {
6291  QGraphicsItem *item = items.at(j);
6292 
6293  // Check if the item is blocked by a modal panel and use it as
6294  // a target instead of this item.
6295  (void) item->isBlockedByModalPanel(&item);
6296 
6297  if (QGraphicsObject *itemobj = item->toGraphicsObject()) {
6298  QGraphicsItemPrivate *d = item->QGraphicsItem::d_func();
6300  d->gestureContext.find(gestureType);
6301  if (it != d->gestureContext.end() && (!flag || (it.value() & flag))) {
6302  if (normalGestures.contains(gesture)) {
6303  normalGestures.remove(gesture);
6304  if (conflicts)
6305  conflicts->insert(gesture);
6306  } else {
6307  normalGestures.insert(gesture);
6308  }
6309  if (targets)
6310  (*targets)[itemobj].insert(gesture);
6311  if (itemsSet)
6312  (*itemsSet).insert(itemobj);
6313  }
6314  }
6315  // Don't propagate through panels.
6316  if (item->isPanel())
6317  break;
6318  }
6319  }
6320  if (normal)
6321  *normal = normalGestures;
6322 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
QList< QGraphicsItem * > itemsAtPosition(const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
Returns all items for the screen position in event.
bool remove(const T &value)
Definition: qset.h:89
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
bool contains(const T &value) const
Definition: qset.h:91
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const_iterator insert(const T &value)
Definition: qset.h:179
GestureType
Definition: qnamespace.h:1759
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:64
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
Qt::GestureType gestureType
the type of the gesture
Definition: qgesture.h:70
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QGraphicsObject class provides a base class for all graphics items that require signals...
bool hasHotSpot
whether the gesture has a hot-spot
Definition: qgesture.h:73
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ get()

QGraphicsScenePrivate * QGraphicsScenePrivate::get ( QGraphicsScene q)
static
Warning
This function is not part of the public interface.

Definition at line 356 of file qgraphicsscene.cpp.

357 {
358  return q->d_func();
359 }

◆ grabGesture()

void QGraphicsScenePrivate::grabGesture ( QGraphicsItem ,
Qt::GestureType  gesture 
)

Definition at line 6653 of file qgraphicsscene.cpp.

6654 {
6655  (void)QGestureManager::instance(); // create a gesture manager
6656  if (!grabbedGestures[gesture]++) {
6657  foreach (QGraphicsView *view, views)
6658  view->viewport()->grabGesture(gesture);
6659  }
6660 }
static QGestureManager * instance()
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
Definition: qwidget.cpp:12964
QList< QGraphicsView * > views
QWidget * viewport() const
Returns the viewport widget.
QHash< Qt::GestureType, int > grabbedGestures
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64

◆ grabKeyboard()

void QGraphicsScenePrivate::grabKeyboard ( QGraphicsItem item)
Warning
This function is not part of the public interface.

Definition at line 1025 of file qgraphicsscene.cpp.

Referenced by addPopup().

1026 {
1027  if (keyboardGrabberItems.contains(item)) {
1028  if (keyboardGrabberItems.last() == item)
1029  qWarning("QGraphicsItem::grabKeyboard: already a keyboard grabber");
1030  else
1031  qWarning("QGraphicsItem::grabKeyboard: already blocked by keyboard grabber: %p",
1033  return;
1034  }
1035 
1036  // Send ungrab event to the last grabber.
1037  if (!keyboardGrabberItems.isEmpty()) {
1038  // Just send ungrab event to current grabber.
1039  QEvent ungrabEvent(QEvent::UngrabKeyboard);
1040  sendEvent(keyboardGrabberItems.last(), &ungrabEvent);
1041  }
1042 
1043  keyboardGrabberItems << item;
1044 
1045  // Send grab event to current grabber.
1046  QEvent grabEvent(QEvent::GrabKeyboard);
1047  sendEvent(item, &grabEvent);
1048 }
QList< QGraphicsItem * > keyboardGrabberItems
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
Q_CORE_EXPORT void qWarning(const char *,...)
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ grabMouse()

void QGraphicsScenePrivate::grabMouse ( QGraphicsItem item,
bool  implicit = false 
)
Warning
This function is not part of the public interface.

Definition at line 925 of file qgraphicsscene.cpp.

Referenced by addPopup().

926 {
927  // Append to list of mouse grabber items, and send a mouse grab event.
928  if (mouseGrabberItems.contains(item)) {
929  if (mouseGrabberItems.last() == item) {
930  Q_ASSERT(!implicit);
932  qWarning("QGraphicsItem::grabMouse: already a mouse grabber");
933  } else {
934  // Upgrade to an explicit mouse grab
936  }
937  } else {
938  qWarning("QGraphicsItem::grabMouse: already blocked by mouse grabber: %p",
940  }
941  return;
942  }
943 
944  // Send ungrab event to the last grabber.
945  if (!mouseGrabberItems.isEmpty()) {
948  // Implicit mouse grab is immediately lost.
949  last->ungrabMouse();
950  } else {
951  // Just send ungrab event to current grabber.
952  QEvent ungrabEvent(QEvent::UngrabMouse);
953  sendEvent(last, &ungrabEvent);
954  }
955  }
956 
957  mouseGrabberItems << item;
959 
960  // Send grab event to current grabber.
961  QEvent grabEvent(QEvent::GrabMouse);
962  sendEvent(item, &grabEvent);
963 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QList< QGraphicsItem * > mouseGrabberItems
Q_CORE_EXPORT void qWarning(const char *,...)
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
void ungrabMouse()
Releases the mouse grab.
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
quint32 lastMouseGrabberItemHasImplicitMouseGrab

◆ init()

void QGraphicsScenePrivate::init ( )
Warning
This function is not part of the public interface.

Definition at line 338 of file qgraphicsscene.cpp.

339 {
341 
343 
344  // Keep this index so we can check for connected slots later on.
345  changedSignalIndex = signalIndex("changed(QList<QRectF>)");
346  processDirtyItemsIndex = q->metaObject()->indexOfSlot("_q_processDirtyItems()");
347  polishItemsIndex = q->metaObject()->indexOfSlot("_q_polishItems()");
348 
349  qApp->d_func()->scene_list.append(q);
350  q->update();
351 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
The QGraphicsSceneBspTreeIndex class provides an implementation of a BSP indexing algorithm for disco...
QGraphicsSceneIndex * index
#define Q_Q(Class)
Definition: qglobal.h:2483
#define qApp
int signalIndex(const char *signalName) const
Returns the signal index used in the internal connectionLists vector.
Definition: qobject.cpp:3719

◆ installSceneEventFilter()

void QGraphicsScenePrivate::installSceneEventFilter ( QGraphicsItem watched,
QGraphicsItem filter 
)
Warning
This function is not part of the public interface.

Definition at line 1142 of file qgraphicsscene.cpp.

1143 {
1144  sceneEventFilters.insert(watched, filter);
1145 }
QMap< Key, T >::iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:982
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters

◆ itemAcceptsHoverEvents_helper()

bool QGraphicsScenePrivate::itemAcceptsHoverEvents_helper ( const QGraphicsItem item) const

Definition at line 3983 of file qgraphicsscene.cpp.

3984 {
3985  return (item->d_ptr->acceptsHover
3986  || (item->d_ptr->isWidget
3987  && static_cast<const QGraphicsWidget *>(item)->d_func()->hasDecoration()))
3988  && !item->isBlockedByModalPanel();
3989 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.

◆ itemsAtPosition()

QList< QGraphicsItem * > QGraphicsScenePrivate::itemsAtPosition ( const QPoint screenPos,
const QPointF scenePos,
QWidget widget 
) const

Returns all items for the screen position in event.

Definition at line 1101 of file qgraphicsscene.cpp.

Referenced by mousePressEventHandler().

1104 {
1105  Q_Q(const QGraphicsScene);
1106  QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
1107  if (!view)
1109 
1110  const QRectF pointRect(QPointF(widget->mapFromGlobal(screenPos)), QSizeF(1, 1));
1111  if (!view->isTransformed())
1112  return q->items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder);
1113 
1114  const QTransform viewTransform = view->viewportTransform();
1115  if (viewTransform.type() <= QTransform::TxScale) {
1116  return q->items(viewTransform.inverted().mapRect(pointRect), Qt::IntersectsItemShape,
1117  Qt::DescendingOrder, viewTransform);
1118  }
1119  return q->items(viewTransform.inverted().map(pointRect), Qt::IntersectsItemShape,
1120  Qt::DescendingOrder, viewTransform);
1121 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool isTransformed() const
Returns true if the view is transformed (i.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
TransformationType type() const
Returns the transformation type of this matrix.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
#define Q_Q(Class)
Definition: qglobal.h:2483
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ leaveModal()

void QGraphicsScenePrivate::leaveModal ( QGraphicsItem item)

Definition at line 6248 of file qgraphicsscene.cpp.

Referenced by removeItemHelper().

6249 {
6251  Q_ASSERT(panel && panel->isPanel());
6252 
6253  QSet<QGraphicsItem *> blockedPanels;
6254  QList<QGraphicsItem *> items = q->items(); // ### same as above
6255  for (int i = 0; i < items.count(); ++i) {
6256  QGraphicsItem *item = items.at(i);
6257  if (item->isPanel() && item->isBlockedByModalPanel())
6258  blockedPanels.insert(item);
6259  }
6260 
6261  modalPanels.removeAll(panel);
6262 
6264  for (int i = 0; i < items.count(); ++i) {
6265  QGraphicsItem *item = items.at(i);
6266  if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
6267  sendEvent(item, &e);
6268  }
6269 
6270  // send GraphicsSceneHoverEnter events to newly unblocked items
6271  QGraphicsSceneHoverEvent hoverEvent;
6272  hoverEvent.setScenePos(lastSceneMousePos);
6273  dispatchHoverEvent(&hoverEvent);
6274 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEvent)
This event handler, for event hoverEvent, can be reimplemented in a subclass to receive hover enter e...
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > modalPanels
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_Q(Class)
Definition: qglobal.h:2483
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
void setScenePos(const QPointF &pos)
Sets the position associated with the hover event to the given point in scene coordinates.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ leaveScene()

void QGraphicsScenePrivate::leaveScene ( QWidget viewport)

Handles all actions necessary to clean up the scene when the mouse leaves the view.

Warning
This function is not part of the public interface.

Definition at line 4080 of file qgraphicsscene.cpp.

4081 {
4082 #ifndef QT_NO_TOOLTIP
4084 #endif
4085  QGraphicsView *view = qobject_cast<QGraphicsView *>(viewport->parent());
4086  // Send HoverLeave events to all existing hover items, topmost first.
4087  QGraphicsSceneHoverEvent hoverEvent;
4088  hoverEvent.setWidget(viewport);
4089 
4090  if (view) {
4091  QPoint cursorPos = QCursor::pos();
4092  hoverEvent.setScenePos(view->mapToScene(viewport->mapFromGlobal(cursorPos)));
4093  hoverEvent.setLastScenePos(hoverEvent.scenePos());
4094  hoverEvent.setScreenPos(cursorPos);
4095  hoverEvent.setLastScreenPos(hoverEvent.screenPos());
4096  }
4097 
4098  while (!hoverItems.isEmpty()) {
4099  QGraphicsItem *lastItem = hoverItems.takeLast();
4100  if (itemAcceptsHoverEvents_helper(lastItem))
4101  sendHoverEvent(QEvent::GraphicsSceneHoverLeave, lastItem, &hoverEvent);
4102  }
4103 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
bool itemAcceptsHoverEvents_helper(const QGraphicsItem *item) const
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
void setWidget(QWidget *widget)
Sets the widget related to this event.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void sendHoverEvent(QEvent::Type type, QGraphicsItem *item, QGraphicsSceneHoverEvent *hoverEvent)
static void hideText()
Hides the tool tip.
Definition: qtooltip.h:61
QList< QGraphicsItem * > hoverItems
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.

◆ markDirty()

void QGraphicsScenePrivate::markDirty ( QGraphicsItem item,
const QRectF rect = QRectF(),
bool  invalidateChildren = false,
bool  force = false,
bool  ignoreOpacity = false,
bool  removingItemFromScene = false,
bool  updateBoundingRect = false 
)

Definition at line 5130 of file qgraphicsscene.cpp.

Referenced by QGraphicsItem::prepareGeometryChange(), and removeItemHelper().

5133 {
5134  Q_ASSERT(item);
5135  if (updateAll)
5136  return;
5137 
5138  if (removingItemFromScene && !ignoreOpacity && !item->d_ptr->ignoreOpacity) {
5139  // If any of the item's ancestors ignore opacity, it means that the opacity
5140  // was set to 0 (and the update request has not yet been processed). That
5141  // also means that we have to ignore the opacity for the item itself; otherwise
5142  // things like: parent->setOpacity(0); scene->removeItem(child) won't work.
5143  // Note that we only do this when removing items from the scene. In all other
5144  // cases the ignoreOpacity bit propagates properly in processDirtyItems, but
5145  // since the item is removed immediately it won't be processed there.
5146  QGraphicsItem *p = item->d_ptr->parent;
5147  while (p) {
5148  if (p->d_ptr->ignoreOpacity) {
5149  item->d_ptr->ignoreOpacity = true;
5150  break;
5151  }
5152  p = p->d_ptr->parent;
5153  }
5154  }
5155 
5156  if (item->d_ptr->discardUpdateRequest(/*ignoreVisibleBit=*/force,
5157  /*ignoreDirtyBit=*/removingItemFromScene || invalidateChildren,
5158  /*ignoreOpacity=*/ignoreOpacity)) {
5159  if (item->d_ptr->dirty) {
5160  // The item is already marked as dirty and will be processed later. However,
5161  // we have to make sure ignoreVisible and ignoreOpacity are set properly;
5162  // otherwise things like: item->update(); item->hide() (force is now true)
5163  // won't work as expected.
5164  if (force)
5165  item->d_ptr->ignoreVisible = 1;
5166  if (ignoreOpacity)
5167  item->d_ptr->ignoreOpacity = 1;
5168  }
5169  return;
5170  }
5171 
5172  const bool fullItemUpdate = rect.isNull();
5173  if (!fullItemUpdate && rect.isEmpty())
5174  return;
5175 
5176  if (!processDirtyItemsEmitted) {
5179 // QMetaObject::invokeMethod(q_ptr, "_q_processDirtyItems", Qt::QueuedConnection);
5180  processDirtyItemsEmitted = true;
5181  }
5182 
5183  if (removingItemFromScene) {
5184  // Note that this function can be called from the item's destructor, so
5185  // do NOT call any virtual functions on it within this block.
5187  // This block of code is kept for compatibility. Since 4.5, by default
5188  // QGraphicsView does not connect the signal and we use the below
5189  // method of delivering updates.
5190  q_func()->update();
5191  return;
5192  }
5193 
5194  for (int i = 0; i < views.size(); ++i) {
5195  QGraphicsViewPrivate *viewPrivate = views.at(i)->d_func();
5196  QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport);
5197  rect.translate(viewPrivate->dirtyScrollOffset);
5198  viewPrivate->updateRect(rect);
5199  }
5200  return;
5201  }
5202 
5203  bool hasNoContents = item->d_ptr->flags & QGraphicsItem::ItemHasNoContents;
5204  if (!hasNoContents) {
5205  item->d_ptr->dirty = 1;
5206  if (fullItemUpdate)
5207  item->d_ptr->fullUpdatePending = 1;
5208  else if (!item->d_ptr->fullUpdatePending)
5209  item->d_ptr->needsRepaint |= rect;
5210  } else if (item->d_ptr->graphicsEffect) {
5211  invalidateChildren = true;
5212  }
5213 
5214  if (invalidateChildren) {
5215  item->d_ptr->allChildrenDirty = 1;
5216  item->d_ptr->dirtyChildren = 1;
5217  }
5218 
5219  if (force)
5220  item->d_ptr->ignoreVisible = 1;
5221  if (ignoreOpacity)
5222  item->d_ptr->ignoreOpacity = 1;
5223 
5224  if (!updateBoundingRect)
5225  item->d_ptr->markParentDirty();
5226 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
QObject * q_ptr
Definition: qobject.h:91
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QGraphicsView * > views
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsEffect * graphicsEffect
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
bool updateRect(const QRect &rect)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
QMap< QWidget *, QRect > paintedViewBoundingRects
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.
void markParentDirty(bool updateBoundingRect=false)
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool discardUpdateRequest(bool ignoreVisibleBit=false, bool ignoreDirtyBit=false, bool ignoreOpacity=false) const
Returns true if we can discard an update request; otherwise false.

◆ mousePressEventHandler()

void QGraphicsScenePrivate::mousePressEventHandler ( QGraphicsSceneMouseEvent mouseEvent)
Warning
This function is not part of the public interface.

Definition at line 1318 of file qgraphicsscene.cpp.

1319 {
1321 
1322  // Ignore by default, unless we find a mouse grabber that accepts it.
1323  mouseEvent->ignore();
1324 
1325  // Deliver to any existing mouse grabber.
1326  if (!mouseGrabberItems.isEmpty()) {
1328  return;
1329  // The event is ignored by default, but we disregard the event's
1330  // accepted state after delivery; the mouse is grabbed, after all.
1331  sendMouseEvent(mouseEvent);
1332  return;
1333  }
1334 
1335  // Start by determining the number of items at the current position.
1336  // Reuse value from earlier calculations if possible.
1339  mouseEvent->scenePos(),
1340  mouseEvent->widget());
1341  }
1342 
1343  // Update window activation.
1345  QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : 0;
1346  if (newActiveWindow && newActiveWindow->isBlockedByModalPanel(&topItem)) {
1347  // pass activation to the blocking modal window
1348  newActiveWindow = topItem ? topItem->window() : 0;
1349  }
1350 
1351  if (newActiveWindow != q->activeWindow())
1352  q->setActiveWindow(newActiveWindow);
1353 
1354  // Set focus on the topmost enabled item that can take focus.
1355  bool setFocus = false;
1356 
1357  foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
1358  if (item->isBlockedByModalPanel()
1360  // Make sure we don't clear focus.
1361  setFocus = true;
1362  break;
1363  }
1364  if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable))) {
1365  if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
1366  setFocus = true;
1367  if (item != q->focusItem() && item->d_ptr->mouseSetsFocus)
1368  q->setFocusItem(item, Qt::MouseFocusReason);
1369  break;
1370  }
1371  }
1372  if (item->isPanel())
1373  break;
1375  break;
1376  }
1377 
1378  // Check for scene modality.
1379  bool sceneModality = false;
1380  for (int i = 0; i < modalPanels.size(); ++i) {
1382  sceneModality = true;
1383  break;
1384  }
1385  }
1386 
1387  // If nobody could take focus, clear it.
1388  if (!stickyFocus && !setFocus && !sceneModality)
1389  q->setFocusItem(0, Qt::MouseFocusReason);
1390 
1391  // Any item will do.
1392  if (sceneModality && cachedItemsUnderMouse.isEmpty())
1394 
1395  // Find a mouse grabber by sending mouse press events to all mouse grabber
1396  // candidates one at a time, until the event is accepted. It's accepted by
1397  // default, so the receiver has to explicitly ignore it for it to pass
1398  // through.
1399  foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
1400  if (!(item->acceptedMouseButtons() & mouseEvent->button())) {
1401  // Skip items that don't accept the event's mouse button.
1402  continue;
1403  }
1404 
1405  // Check if this item is blocked by a modal panel and deliver the mouse event to the
1406  // blocking panel instead of this item if blocked.
1407  (void) item->isBlockedByModalPanel(&item);
1408 
1409  grabMouse(item, /* implicit = */ true);
1410  mouseEvent->accept();
1411 
1412  // check if the item we are sending to are disabled (before we send the event)
1413  bool disabled = !item->isEnabled();
1414  bool isPanel = item->isPanel();
1415  if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick
1417  // If this item is different from the item that received the last
1418  // mouse event, and mouseEvent is a doubleclick event, then the
1419  // event is converted to a press. Known limitation:
1420  // Triple-clicking will not generate a doubleclick, though.
1422  mousePress.spont = mouseEvent->spont;
1423  mousePress.accept();
1424  mousePress.setButton(mouseEvent->button());
1425  mousePress.setButtons(mouseEvent->buttons());
1426  mousePress.setScreenPos(mouseEvent->screenPos());
1427  mousePress.setScenePos(mouseEvent->scenePos());
1428  mousePress.setModifiers(mouseEvent->modifiers());
1429  mousePress.setWidget(mouseEvent->widget());
1430  mousePress.setButtonDownPos(mouseEvent->button(),
1431  mouseEvent->buttonDownPos(mouseEvent->button()));
1432  mousePress.setButtonDownScenePos(mouseEvent->button(),
1433  mouseEvent->buttonDownScenePos(mouseEvent->button()));
1434  mousePress.setButtonDownScreenPos(mouseEvent->button(),
1435  mouseEvent->buttonDownScreenPos(mouseEvent->button()));
1437  mouseEvent->setAccepted(mousePress.isAccepted());
1438  } else {
1439  sendMouseEvent(mouseEvent);
1440  }
1441 
1442  bool dontSendUngrabEvents = mouseGrabberItems.isEmpty() || mouseGrabberItems.last() != item;
1443  if (disabled) {
1444  ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents);
1445  break;
1446  }
1447  if (mouseEvent->isAccepted()) {
1448  if (!mouseGrabberItems.isEmpty())
1450  lastMouseGrabberItem = item;
1451  return;
1452  }
1453  ungrabMouse(item, /* itemIsDying = */ dontSendUngrabEvents);
1454 
1455  // Don't propagate through panels.
1456  if (isPanel)
1457  break;
1458  }
1459 
1460  // Is the event still ignored? Then the mouse press goes to the scene.
1461  // Reset the mouse grabber, clear the selection, clear focus, and leave
1462  // the event ignored so that it can propagate through the originating
1463  // view.
1464  if (!mouseEvent->isAccepted()) {
1466 
1467  QGraphicsView *view = mouseEvent->widget() ? qobject_cast<QGraphicsView *>(mouseEvent->widget()->parentWidget()) : 0;
1468  bool dontClearSelection = view && view->dragMode() == QGraphicsView::ScrollHandDrag;
1469  if (!dontClearSelection) {
1470  // Clear the selection if the originating view isn't in scroll
1471  // hand drag mode. The view will clear the selection if no drag
1472  // happened.
1473  q->clearSelection();
1474  }
1475  }
1476 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
#define disabled
QGraphicsItem * focusItem() const
If this item, a child or descendant of this item currently has input focus, this function will return...
QScopedPointer< QGraphicsItemPrivate > d_ptr
QList< QGraphicsItem * > itemsAtPosition(const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
Returns all items for the screen position in event.
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
QList< QGraphicsItem * > modalPanels
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
QList< QGraphicsItem * > cachedItemsUnderMouse
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
PanelModality panelModality() const
Returns the modality for this item.
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
void storeMouseButtonsForMouseGrabber(QGraphicsSceneMouseEvent *event)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void sendMouseEvent(QGraphicsSceneMouseEvent *mouseEvent)
#define Q_Q(Class)
Definition: qglobal.h:2483
QPointF buttonDownScenePos(Qt::MouseButton button) const
Returns the mouse cursor position in scene coordinates where the specified button was clicked...
void ungrabMouse(QGraphicsItem *item, bool itemIsDying=false)
void mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=0, QPoint pos=QPoint(), int delay=-1)
Simulates pressing a mouse button with an optional modifier on a widget.
Definition: qtestmouse.h:129
bool isAccepted() const
Definition: qcoreevent.h:307
QList< QGraphicsItem * > mouseGrabberItems
DragMode dragMode
the behavior for dragging the mouse over the scene while the left mouse button is pressed...
Definition: qgraphicsview.h:75
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void grabMouse(QGraphicsItem *item, bool implicit=false)
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QGraphicsWidget * window() const
Returns the item&#39;s window, or 0 if this item does not have a window.
bool isWidget() const
Returns true if this item is a widget (i.
QPoint buttonDownScreenPos(Qt::MouseButton button) const
Returns the mouse cursor position in screen coordinates where the specified button was clicked...
QGraphicsItem * lastMouseGrabberItem
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QPointF buttonDownPos(Qt::MouseButton button) const
Returns the mouse cursor position in item coordinates where the specified button was clicked...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers in use at the time the event was sent.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
Qt::MouseButtons acceptedMouseButtons() const
Returns the mouse buttons that this item accepts mouse events for.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ processDirtyItemsRecursive()

void QGraphicsScenePrivate::processDirtyItemsRecursive ( QGraphicsItem item,
bool  dirtyAncestorContainsChildren = false,
qreal  parentOpacity = qreal(1.0) 
)

Definition at line 5265 of file qgraphicsscene.cpp.

Referenced by _q_processDirtyItems().

5267 {
5269  Q_ASSERT(item);
5270  Q_ASSERT(!updateAll);
5271 
5272  if (!item->d_ptr->dirty && !item->d_ptr->dirtyChildren) {
5273  resetDirtyItem(item);
5274  return;
5275  }
5276 
5277  const bool itemIsHidden = !item->d_ptr->ignoreVisible && !item->d_ptr->visible;
5278  if (itemIsHidden) {
5279  resetDirtyItem(item, /*recursive=*/true);
5280  return;
5281  }
5282 
5283  bool itemHasContents = !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents);
5284  const bool itemHasChildren = !item->d_ptr->children.isEmpty();
5285  if (!itemHasContents) {
5286  if (!itemHasChildren) {
5287  resetDirtyItem(item);
5288  return; // Item has neither contents nor children!(?)
5289  }
5290  if (item->d_ptr->graphicsEffect)
5291  itemHasContents = true;
5292  }
5293 
5294  const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity);
5295  const bool itemIsFullyTransparent = !item->d_ptr->ignoreOpacity
5297  if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity())) {
5298  resetDirtyItem(item, /*recursive=*/itemHasChildren);
5299  return;
5300  }
5301 
5302  bool wasDirtyParentSceneTransform = item->d_ptr->dirtySceneTransform;
5303  const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable();
5304  if (wasDirtyParentSceneTransform && !itemIsUntransformable) {
5307  }
5308 
5309  const bool wasDirtyParentViewBoundingRects = item->d_ptr->paintedViewBoundingRectsNeedRepaint;
5310  if (itemIsFullyTransparent || !itemHasContents || dirtyAncestorContainsChildren) {
5311  // Make sure we don't process invisible items or items with no content.
5312  item->d_ptr->dirty = 0;
5313  item->d_ptr->fullUpdatePending = 0;
5314  // Might have a dirty view bounding rect otherwise.
5315  if (itemIsFullyTransparent || !itemHasContents)
5317  }
5318 
5319  if (!hasSceneRect && item->d_ptr->geometryChanged && item->d_ptr->visible) {
5320  // Update growingItemsBoundingRect.
5321  if (item->d_ptr->sceneTransformTranslateOnly) {
5323  item->d_ptr->sceneTransform.dy());
5324  } else {
5326  }
5327  }
5328 
5329  // Process item.
5330  if (item->d_ptr->dirty || item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
5331  const bool useCompatUpdate = views.isEmpty() || isSignalConnected(changedSignalIndex);
5332  const QRectF itemBoundingRect = adjustedItemEffectiveBoundingRect(item);
5333 
5334  if (useCompatUpdate && !itemIsUntransformable && qFuzzyIsNull(item->boundingRegionGranularity())) {
5335  // This block of code is kept for compatibility. Since 4.5, by default
5336  // QGraphicsView does not connect the signal and we use the below
5337  // method of delivering updates.
5338  if (item->d_ptr->sceneTransformTranslateOnly) {
5339  q->update(itemBoundingRect.translated(item->d_ptr->sceneTransform.dx(),
5340  item->d_ptr->sceneTransform.dy()));
5341  } else {
5342  QRectF rect = item->d_ptr->sceneTransform.mapRect(itemBoundingRect);
5343  if (!rect.isEmpty())
5344  q->update(rect);
5345  }
5346  } else {
5347  QRectF dirtyRect;
5348  bool uninitializedDirtyRect = true;
5349 
5350  for (int j = 0; j < views.size(); ++j) {
5351  QGraphicsView *view = views.at(j);
5352  QGraphicsViewPrivate *viewPrivate = view->d_func();
5353  QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport];
5354  if (viewPrivate->fullUpdatePending
5356  // Okay, if we have a full update pending or no viewport update, this item's
5357  // paintedViewBoundingRect will be updated correctly in the next paintEvent if
5358  // it is inside the viewport, but for now we can pretend that it is outside.
5359  paintedViewBoundingRect = QRect(-1, -1, -1, -1);
5360  continue;
5361  }
5362 
5364  paintedViewBoundingRect.translate(viewPrivate->dirtyScrollOffset);
5365  if (!viewPrivate->updateRect(paintedViewBoundingRect))
5366  paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport.
5367  }
5368 
5369  if (!item->d_ptr->dirty)
5370  continue;
5371 
5373  && paintedViewBoundingRect.x() == -1 && paintedViewBoundingRect.y() == -1
5374  && paintedViewBoundingRect.width() == -1 && paintedViewBoundingRect.height() == -1) {
5375  continue; // Outside viewport.
5376  }
5377 
5378  if (uninitializedDirtyRect) {
5379  dirtyRect = itemBoundingRect;
5380  if (!item->d_ptr->fullUpdatePending) {
5381  _q_adjustRect(&item->d_ptr->needsRepaint);
5382  dirtyRect &= item->d_ptr->needsRepaint;
5383  }
5384  uninitializedDirtyRect = false;
5385  }
5386 
5387  if (dirtyRect.isEmpty())
5388  continue; // Discard updates outside the bounding rect.
5389 
5390  if (!updateHelper(viewPrivate, item->d_ptr.data(), dirtyRect, itemIsUntransformable)
5392  paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport.
5393  }
5394  }
5395  }
5396  }
5397 
5398  // Process children.
5399  if (itemHasChildren && item->d_ptr->dirtyChildren) {
5400  const bool itemClipsChildrenToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape;
5401  // Items with no content are threated as 'dummy' items which means they are never drawn and
5402  // 'processed', so the painted view bounding rect is never up-to-date. This means that whenever
5403  // such an item changes geometry, its children have to take care of the update regardless
5404  // of whether the item clips children to shape or not.
5405  const bool bypassUpdateClip = !itemHasContents && wasDirtyParentViewBoundingRects;
5406  if (itemClipsChildrenToShape && !bypassUpdateClip) {
5407  // Make sure child updates are clipped to the item's bounding rect.
5408  for (int i = 0; i < views.size(); ++i)
5409  views.at(i)->d_func()->setUpdateClip(item);
5410  }
5411  if (!dirtyAncestorContainsChildren) {
5412  dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending
5413  && itemClipsChildrenToShape;
5414  }
5415  const bool allChildrenDirty = item->d_ptr->allChildrenDirty;
5416  const bool parentIgnoresVisible = item->d_ptr->ignoreVisible;
5417  const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity;
5418  for (int i = 0; i < item->d_ptr->children.size(); ++i) {
5419  QGraphicsItem *child = item->d_ptr->children.at(i);
5420  if (wasDirtyParentSceneTransform)
5421  child->d_ptr->dirtySceneTransform = 1;
5422  if (wasDirtyParentViewBoundingRects)
5424  if (parentIgnoresVisible)
5425  child->d_ptr->ignoreVisible = 1;
5426  if (parentIgnoresOpacity)
5427  child->d_ptr->ignoreOpacity = 1;
5428  if (allChildrenDirty) {
5429  child->d_ptr->dirty = 1;
5430  child->d_ptr->fullUpdatePending = 1;
5431  child->d_ptr->dirtyChildren = 1;
5432  child->d_ptr->allChildrenDirty = 1;
5433  }
5434  processDirtyItemsRecursive(child, dirtyAncestorContainsChildren, opacity);
5435  }
5436 
5437  if (itemClipsChildrenToShape) {
5438  // Reset updateClip.
5439  for (int i = 0; i < views.size(); ++i)
5440  views.at(i)->d_func()->setUpdateClip(0);
5441  }
5442  } else if (wasDirtyParentSceneTransform) {
5444  }
5445 
5446  resetDirtyItem(item);
5447 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
qreal combineOpacityFromParent(qreal parentOpacity) const
double qreal
Definition: qglobal.h:1193
static QRectF adjustedItemEffectiveBoundingRect(const QGraphicsItem *item)
QScopedPointer< QGraphicsItemPrivate > d_ptr
T * data() const
Returns the value of the pointer referenced by this object.
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
virtual void updateSceneTransformFromParent()
static bool updateHelper(QGraphicsViewPrivate *view, QGraphicsItemPrivate *item, const QRectF &rect, bool itemIsUntransformable)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool isOpacityNull() const
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QGraphicsView * > views
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
static void _q_adjustRect(QRect *rect)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QGraphicsView::ViewportUpdateMode viewportUpdateMode
void invalidateChildrenSceneTransform()
bool itemIsUntransformable() const
quint32 sceneTransformTranslateOnly
quint32 paintedViewBoundingRectsNeedRepaint
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsEffect * graphicsEffect
qreal boundingRegionGranularity() const
Returns the item&#39;s bounding region granularity; a value between and including 0 and 1...
void processDirtyItemsRecursive(QGraphicsItem *item, bool dirtyAncestorContainsChildren=false, qreal parentOpacity=qreal(1.0))
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
bool updateRect(const QRect &rect)
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
QMap< QWidget *, QRect > paintedViewBoundingRects
QList< QGraphicsItem * > children
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
void resetDirtyItem(QGraphicsItem *item, bool recursive=false)
bool childrenCombineOpacity() const

◆ registerScenePosItem()

void QGraphicsScenePrivate::registerScenePosItem ( QGraphicsItem item)
Warning
This function is not part of the public interface.

Definition at line 545 of file qgraphicsscene.cpp.

546 {
547  scenePosItems.insert(item);
548  setScenePosItemEnabled(item, true);
549 }
void setScenePosItemEnabled(QGraphicsItem *item, bool enabled)
QSet< QGraphicsItem * > scenePosItems
const_iterator insert(const T &value)
Definition: qset.h:179

◆ registerTopLevelItem()

void QGraphicsScenePrivate::registerTopLevelItem ( QGraphicsItem item)
Warning
This function is not part of the public interface.

This function is almost identical to QGraphicsItemPrivate::addChild().

Definition at line 415 of file qgraphicsscene.cpp.

416 {
418  needSortTopLevelItems = true; // ### maybe false
420  topLevelItems.append(item);
421 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void ensureSequentialSiblingIndex()
Ensures that the list of children is sorted by insertion order, and that the siblingIndexes are packe...
QList< QGraphicsItem * > topLevelItems
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ removeItemHelper()

void QGraphicsScenePrivate::removeItemHelper ( QGraphicsItem item)

Schedules an item for removal.

Warning
This function is not part of the public interface.

This function leaves some stale indexes around in the BSP tree if called from the item's destructor; these will be cleaned up the next time someone triggers purgeRemovedItems().

Note: This function might get called from QGraphicsItem's destructor. item is being destroyed, so we cannot call any pure virtual functions on it (such as boundingRect()). Also, it is unnecessary to update the item's own state in any way.

Definition at line 590 of file qgraphicsscene.cpp.

591 {
593 
594  // Clear focus on the item to remove any reference in the focusWidget chain.
595  item->clearFocus();
596 
597  markDirty(item, QRectF(), /*invalidateChildren=*/false, /*force=*/false,
598  /*ignoreOpacity=*/false, /*removingItemFromScene=*/true);
599 
600  if (item->d_ptr->inDestructor) {
601  // The item is actually in its destructor, we call the special method in the index.
602  index->deleteItem(item);
603  } else {
604  // Can potentially call item->boundingRect() (virtual function), that's why
605  // we only can call this function if the item is not in its destructor.
606  index->removeItem(item);
607  }
608 
609  item->d_ptr->clearSubFocus();
610 
613 
614  QGraphicsScene *oldScene = item->d_func()->scene;
615  item->d_func()->scene = 0;
616 
617  //We need to remove all children first because they might use their parent
618  //attributes (e.g. sceneTransform).
619  if (!item->d_ptr->inDestructor) {
620  // Remove all children recursively
621  for (int i = 0; i < item->d_ptr->children.size(); ++i)
622  q->removeItem(item->d_ptr->children.at(i));
623  }
624 
625  if (!item->d_ptr->inDestructor && item == tabFocusFirst) {
626  QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
627  widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0);
628  }
629 
630  // Unregister focus proxy.
631  item->d_ptr->resetFocusProxy();
632 
633  // Remove from parent, or unregister from toplevels.
634  if (QGraphicsItem *parentItem = item->parentItem()) {
635  if (parentItem->scene()) {
636  Q_ASSERT_X(parentItem->scene() == q, "QGraphicsScene::removeItem",
637  "Parent item's scene is different from this item's scene");
638  item->setParentItem(0);
639  }
640  } else {
642  }
643 
644  // Reset the mouse grabber and focus item data.
645  if (item == focusItem)
646  focusItem = 0;
647  if (item == lastFocusItem)
648  lastFocusItem = 0;
649  if (item == passiveFocusItem)
650  passiveFocusItem = 0;
651  if (item == activePanel) {
652  // ### deactivate...
653  activePanel = 0;
654  }
655  if (item == lastActivePanel)
656  lastActivePanel = 0;
657 
658  // Cancel active touches
659  {
661  while (it != itemForTouchPointId.end()) {
662  if (it.value() == item) {
664  it = itemForTouchPointId.erase(it);
665  } else {
666  ++it;
667  }
668  }
669  }
670 
671  // Disable selectionChanged() for individual items
673  int oldSelectedItemsSize = selectedItems.size();
674 
675  // Update selected & hovered item bookkeeping
676  selectedItems.remove(item);
677  hoverItems.removeAll(item);
679  if (item->d_ptr->pendingPolish) {
680  const int unpolishedIndex = unpolishedItems.indexOf(item);
681  if (unpolishedIndex != -1)
682  unpolishedItems[unpolishedIndex] = 0;
683  item->d_ptr->pendingPolish = false;
684  }
685  resetDirtyItem(item);
686 
687  //We remove all references of item from the sceneEventFilter arrays
689  while (iterator != sceneEventFilters.end()) {
690  if (iterator.value() == item || iterator.key() == item)
691  iterator = sceneEventFilters.erase(iterator);
692  else
693  ++iterator;
694  }
695 
696  if (item->isPanel() && item->isVisible() && item->panelModality() != QGraphicsItem::NonModal)
697  leaveModal(item);
698 
699  // Reset the mouse grabber and focus item data.
700  if (mouseGrabberItems.contains(item))
701  ungrabMouse(item, /* item is dying */ item->d_ptr->inDestructor);
702 
703  // Reset the keyboard grabber
704  if (keyboardGrabberItems.contains(item))
705  ungrabKeyboard(item, /* item is dying */ item->d_ptr->inDestructor);
706 
707  // Reset the last mouse grabber item
708  if (item == lastMouseGrabberItem)
710 
711  // Reset the current drop item
712  if (item == dragDropItem)
713  dragDropItem = 0;
714 
715  // Reenable selectionChanged() for individual items
717  if (!selectionChanging && selectedItems.size() != oldSelectedItemsSize)
718  emit q->selectionChanged();
719 
720 #ifndef QT_NO_GESTURES
722  for (it = gestureTargets.begin(); it != gestureTargets.end();) {
723  if (it.value() == item)
724  it = gestureTargets.erase(it);
725  else
726  ++it;
727  }
728 
729  QGraphicsObject *dummy = static_cast<QGraphicsObject *>(item);
731  cachedItemGestures.remove(dummy);
733 
734  foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys())
735  ungrabGesture(item, gesture);
736 #endif // QT_NO_GESTURES
737 }
void unregisterScenePosItem(QGraphicsItem *item)
QMap< int, QGraphicsItem * > itemForTouchPointId
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qmap.h:250
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QList< QGraphicsItem * > keyboardGrabberItems
QPointer< QWidget > widget
void resetFocusProxy()
Sets the focusProxy pointer to 0 for all items that have this item as their focusProxy.
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define it(className, varName)
bool remove(const T &value)
Definition: qset.h:89
void clearFocus()
Takes keyboard input focus from the item.
QGraphicsItem * focusItem
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QList< QGraphicsItem * > cachedItemsUnderMouse
QVector< QGraphicsItem * > unpolishedItems
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
QGraphicsSceneIndex * index
PanelModality panelModality() const
Returns the modality for this item.
QSet< QGraphicsItem * > selectedItems
#define Q_Q(Class)
Definition: qglobal.h:2483
int size() const
Definition: qset.h:75
virtual void removeItem(QGraphicsItem *item)=0
This pure virtual function removes an item to the scene index.
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
QGraphicsItem * passiveFocusItem
QGraphicsItem * dragDropItem
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
void ungrabMouse(QGraphicsItem *item, bool itemIsDying=false)
void ungrabGesture(QGraphicsItem *, Qt::GestureType gesture)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
void markDirty(QGraphicsItem *item, const QRectF &rect=QRectF(), bool invalidateChildren=false, bool force=false, bool ignoreOpacity=false, bool removingItemFromScene=false, bool updateBoundingRect=false)
QList< QGraphicsItem * > mouseGrabberItems
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
QList< QGraphicsObject * > cachedTargetItems
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the vector, searching forward from ind...
Definition: qvector.h:698
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
GestureType
Definition: qnamespace.h:1759
void clearSubFocus(QGraphicsItem *rootItem=0, QGraphicsItem *stopItem=0)
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
QGraphicsItem * lastActivePanel
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
QGraphicsWidget * tabFocusFirst
int remove(const Key &key)
Removes all the items that have the key key from the map.
Definition: qmap.h:662
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
void unregisterTopLevelItem(QGraphicsItem *item)
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void leaveModal(QGraphicsItem *item)
QHash< QGesture *, QGraphicsObject * > gestureTargets
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
QList< QGraphicsItem * > hoverItems
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QHash< QGraphicsObject *, QSet< QGesture * > > cachedItemGestures
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QGraphicsItem * lastMouseGrabberItem
QMap< int, QTouchEvent::TouchPoint > sceneCurrentTouchPoints
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
QGraphicsItem * lastFocusItem
QList< QGraphicsItem * > children
The QGraphicsObject class provides a base class for all graphics items that require signals...
void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying=false)
virtual void deleteItem(QGraphicsItem *item)
This method is called when an item has been deleted.
void resetDirtyItem(QGraphicsItem *item, bool recursive=false)
QGraphicsItem * activePanel
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
QHash< QGraphicsObject *, QSet< QGesture * > > cachedAlreadyDeliveredGestures
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ removePopup()

void QGraphicsScenePrivate::removePopup ( QGraphicsWidget widget,
bool  itemIsDying = false 
)

Remove widget from the popup list.

Warning
This function is not part of the public interface.

Important notes:

widget is guaranteed to be in the list of popups, but it might not be the last entry; you can hide any item in the pop list before the others, and this must cause all later mouse grabbers to lose the grab.

Definition at line 901 of file qgraphicsscene.cpp.

Referenced by ungrabMouse().

902 {
903  Q_ASSERT(widget);
904  int index = popupWidgets.indexOf(widget);
905  Q_ASSERT(index != -1);
906 
907  for (int i = popupWidgets.size() - 1; i >= index; --i) {
909  ungrabMouse(widget, itemIsDying);
910  if (focusItem && popupWidgets.isEmpty()) {
913  } else if (keyboardGrabberItems.contains(static_cast<QGraphicsItem *>(widget))) {
914  ungrabKeyboard(static_cast<QGraphicsItem *>(widget), itemIsDying);
915  }
916  if (!itemIsDying && widget->isVisible()) {
917  widget->QGraphicsItem::d_ptr->setVisibleHelper(false, /* explicit = */ false);
918  }
919  }
920 }
QList< QGraphicsItem * > keyboardGrabberItems
EventRef event
QGraphicsItem * focusItem
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QGraphicsSceneIndex * index
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void ungrabMouse(QGraphicsItem *item, bool itemIsDying=false)
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying=false)
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
QList< QGraphicsWidget * > popupWidgets
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ removeSceneEventFilter()

void QGraphicsScenePrivate::removeSceneEventFilter ( QGraphicsItem watched,
QGraphicsItem filter 
)
Warning
This function is not part of the public interface.

Definition at line 1150 of file qgraphicsscene.cpp.

1151 {
1152  if (!sceneEventFilters.contains(watched))
1153  return;
1154 
1157  do {
1158  if (it.value() == filter)
1159  it = sceneEventFilters.erase(it);
1160  else
1161  ++it;
1162  } while (it != end);
1163 }
#define it(className, varName)
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
bool contains(const Key &key, const T &value) const
Returns true if the map contains an item with key key and value value; otherwise returns false...
Definition: qmap.h:1048
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
iterator upperBound(const Key &key)
Returns an iterator pointing to the item that immediately follows the last item with key key in the m...
Definition: qmap.h:918
iterator lowerBound(const Key &key)
Returns an iterator pointing to the first item with key key in the map.
Definition: qmap.h:899
static const KeyPair *const end
QMultiMap< QGraphicsItem *, QGraphicsItem * > sceneEventFilters

◆ removeView()

void QGraphicsScenePrivate::removeView ( QGraphicsView view)

Definition at line 5947 of file qgraphicsscene.cpp.

5948 {
5949  views.removeAll(view);
5950 }
QList< QGraphicsView * > views
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ resetDirtyItem()

void QGraphicsScenePrivate::resetDirtyItem ( QGraphicsItem item,
bool  recursive = false 
)
inline

Definition at line 236 of file qgraphicsscene_p.h.

Referenced by _q_processDirtyItems(), and removeItemHelper().

237  {
238  Q_ASSERT(item);
239  item->d_ptr->dirty = 0;
241  item->d_ptr->geometryChanged = 0;
242  if (!item->d_ptr->dirtyChildren)
243  recursive = false;
244  item->d_ptr->dirtyChildren = 0;
245  item->d_ptr->needsRepaint = QRectF();
246  item->d_ptr->allChildrenDirty = 0;
247  item->d_ptr->fullUpdatePending = 0;
248  item->d_ptr->ignoreVisible = 0;
249  item->d_ptr->ignoreOpacity = 0;
250 #ifndef QT_NO_GRAPHICSEFFECT
251  QGraphicsEffect::ChangeFlags flags;
252  if (item->d_ptr->notifyBoundingRectChanged) {
254  item->d_ptr->notifyBoundingRectChanged = 0;
255  }
256  if (item->d_ptr->notifyInvalidated) {
258  item->d_ptr->notifyInvalidated = 0;
259  }
260 #endif //QT_NO_GRAPHICSEFFECT
261  if (recursive) {
262  for (int i = 0; i < item->d_ptr->children.size(); ++i)
263  resetDirtyItem(item->d_ptr->children.at(i), recursive);
264  }
265 #ifndef QT_NO_GRAPHICSEFFECT
266  if (flags && item->d_ptr->graphicsEffect)
267  item->d_ptr->graphicsEffect->sourceChanged(flags);
268 #endif //QT_NO_GRAPHICSEFFECT
269  }
virtual void sourceChanged(ChangeFlags flags)
This virtual function is called by QGraphicsEffect to notify the effect that the source has changed...
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
quint32 paintedViewBoundingRectsNeedRepaint
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGraphicsEffect * graphicsEffect
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QGraphicsItem * > children
void resetDirtyItem(QGraphicsItem *item, bool recursive=false)

◆ resolveFont()

void QGraphicsScenePrivate::resolveFont ( )

Resolve the scene's font against the application font, and propagate the changes too all items in the scene.

Warning
This function is not part of the public interface.

Definition at line 1529 of file qgraphicsscene.cpp.

1530 {
1531  QFont naturalFont = QApplication::font();
1532  naturalFont.resolve(0);
1533  QFont resolvedFont = font.resolve(naturalFont);
1534  updateFont(resolvedFont);
1535 }
static QFont font()
Returns the default application font.
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
void updateFont(const QFont &font)
Update the font, and whether or not it has changed, reresolve all fonts in the scene.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64

◆ resolvePalette()

void QGraphicsScenePrivate::resolvePalette ( )

Resolve the scene's palette against the application palette, and propagate the changes too all items in the scene.

Warning
This function is not part of the public interface.

Definition at line 1594 of file qgraphicsscene.cpp.

1595 {
1596  QPalette naturalPalette = QApplication::palette();
1597  naturalPalette.resolve(0);
1598  QPalette resolvedPalette = palette.resolve(naturalPalette);
1599  updatePalette(resolvedPalette);
1600 }
static QPalette palette()
Returns the application palette.
void updatePalette(const QPalette &palette)
Update the palette, and whether or not it has changed, reresolve all palettes in the scene...
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ sendDragDropEvent()

void QGraphicsScenePrivate::sendDragDropEvent ( QGraphicsItem item,
QGraphicsSceneDragDropEvent dragDropEvent 
)
Warning
This function is not part of the public interface.

Definition at line 1263 of file qgraphicsscene.cpp.

1265 {
1266  dragDropEvent->setPos(item->d_ptr->genericMapFromScene(dragDropEvent->scenePos(), dragDropEvent->widget()));
1267  sendEvent(item, dragDropEvent);
1268 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
void setPos(const QPointF &pos)
Sets the position of the mouse to pos; this should be relative to the widget that generated the event...
QPointF scenePos() const
Returns the position of the mouse in scene coordinates.
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.

◆ sendEvent()

bool QGraphicsScenePrivate::sendEvent ( QGraphicsItem item,
QEvent event 
)

This is the final dispatch point for any events from the scene to the item.

Warning
This function is not part of the public interface.

It filters the event first - if the filter returns true, the event is considered to have been eaten by the filter, and is therefore stopped (the default filter returns false). Then/otherwise, if the item is enabled, the event is sent; otherwise it is stopped.

Definition at line 1214 of file qgraphicsscene.cpp.

Referenced by addPopup(), grabKeyboard(), grabMouse(), removePopup(), sendDragDropEvent(), sendHoverEvent(), sendMouseEvent(), setFocusItemHelper(), ungrabKeyboard(), and ungrabMouse().

1215 {
1216  if (QGraphicsObject *object = item->toGraphicsObject()) {
1217 #ifndef QT_NO_GESTURES
1219  if (gestureManager) {
1220  if (gestureManager->filterEvent(object, event))
1221  return true;
1222  }
1223 #endif // QT_NO_GESTURES
1224  }
1225 
1226  if (filterEvent(item, event))
1227  return false;
1228  if (filterDescendantEvent(item, event))
1229  return false;
1230  if (!item || !item->isEnabled())
1231  return false;
1232  if (QGraphicsObject *o = item->toGraphicsObject()) {
1233  bool spont = event->spontaneous();
1234  if (spont ? qt_sendSpontaneousEvent(o, event) : QApplication::sendEvent(o, event))
1235  return true;
1236  event->spont = spont;
1237  }
1238  return item->sceneEvent(event);
1239 }
virtual bool sceneEvent(QEvent *event)
This virtual function receives events to this item.
bool filterEvent(QWidget *receiver, QEvent *event)
static QApplicationPrivate * instance()
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
bool filterDescendantEvent(QGraphicsItem *item, QEvent *event)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
The QGraphicsObject class provides a base class for all graphics items that require signals...
QGestureManager * gestureManager
bool filterEvent(QGraphicsItem *item, QEvent *event)

◆ sendHoverEvent()

void QGraphicsScenePrivate::sendHoverEvent ( QEvent::Type  type,
QGraphicsItem item,
QGraphicsSceneHoverEvent hoverEvent 
)
Warning
This function is not part of the public interface.

Definition at line 1273 of file qgraphicsscene.cpp.

1275 {
1277  event.setWidget(hoverEvent->widget());
1278  event.setPos(item->d_ptr->genericMapFromScene(hoverEvent->scenePos(), hoverEvent->widget()));
1279  event.setScenePos(hoverEvent->scenePos());
1280  event.setScreenPos(hoverEvent->screenPos());
1281  event.setLastPos(item->d_ptr->genericMapFromScene(hoverEvent->lastScenePos(), hoverEvent->widget()));
1282  event.setLastScenePos(hoverEvent->lastScenePos());
1283  event.setLastScreenPos(hoverEvent->lastScreenPos());
1284  event.setModifiers(hoverEvent->modifiers());
1285  sendEvent(item, &event);
1286 }
int type
Definition: qmetatype.cpp:239
EventRef event
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPoint screenPos() const
Returns the position of the mouse cursor in screen coordinates at the moment the hover event was sent...
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
QPointF lastScenePos() const
Returns the last recorded, the scene coordinates of the previous mouse or hover event received by the...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers at the moment the hover event was sent.
QPointF scenePos() const
Returns the position of the mouse cursor in scene coordinates at the moment the hover event was sent...
QPoint lastScreenPos() const
Returns the last recorded mouse cursor position in screen coordinates.
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.

◆ sendMouseEvent()

void QGraphicsScenePrivate::sendMouseEvent ( QGraphicsSceneMouseEvent mouseEvent)
Warning
This function is not part of the public interface.

Definition at line 1291 of file qgraphicsscene.cpp.

Referenced by mousePressEventHandler().

1292 {
1293  if (mouseEvent->button() == 0 && mouseEvent->buttons() == 0 && lastMouseGrabberItemHasImplicitMouseGrab) {
1294  // ### This is a temporary fix for until we get proper mouse
1295  // grab events.
1297  return;
1298  }
1299 
1301  if (item->isBlockedByModalPanel())
1302  return;
1303 
1304  for (int i = 0x1; i <= 0x10; i <<= 1) {
1305  Qt::MouseButton button = Qt::MouseButton(i);
1306  mouseEvent->setButtonDownPos(button, mouseGrabberButtonDownPos.value(button, item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget())));
1307  mouseEvent->setButtonDownScenePos(button, mouseGrabberButtonDownScenePos.value(button, mouseEvent->scenePos()));
1308  mouseEvent->setButtonDownScreenPos(button, mouseGrabberButtonDownScreenPos.value(button, mouseEvent->screenPos()));
1309  }
1310  mouseEvent->setPos(item->d_ptr->genericMapFromScene(mouseEvent->scenePos(), mouseEvent->widget()));
1311  mouseEvent->setLastPos(item->d_ptr->genericMapFromScene(mouseEvent->lastScenePos(), mouseEvent->widget()));
1312  sendEvent(item, mouseEvent);
1313 }
QMap< Qt::MouseButton, QPoint > mouseGrabberButtonDownScreenPos
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setLastPos(const QPointF &pos)
void setButtonDownScenePos(Qt::MouseButton button, const QPointF &pos)
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
void setButtonDownPos(Qt::MouseButton button, const QPointF &pos)
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownScenePos
QPointF lastScenePos() const
Returns the last recorded mouse cursor position in scene coordinates.
QList< QGraphicsItem * > mouseGrabberItems
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
void setPos(const QPointF &pos)
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownPos
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
void setButtonDownScreenPos(Qt::MouseButton button, const QPoint &pos)
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
MouseButton
Definition: qnamespace.h:150
quint32 lastMouseGrabberItemHasImplicitMouseGrab

◆ sendTouchBeginEvent()

bool QGraphicsScenePrivate::sendTouchBeginEvent ( QGraphicsItem item,
QTouchEvent touchEvent 
)

Definition at line 6106 of file qgraphicsscene.cpp.

6107 {
6109 
6111  const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first();
6113  firstTouchPoint.scenePos(),
6114  touchEvent->widget());
6115  }
6116 
6117  // Set focus on the topmost enabled item that can take focus.
6118  bool setFocus = false;
6119 
6120  foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
6121  if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
6122  if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
6123  setFocus = true;
6124  if (item != q->focusItem())
6125  q->setFocusItem(item, Qt::MouseFocusReason);
6126  break;
6127  }
6128  }
6129  if (item->isPanel())
6130  break;
6132  break;
6134  // Make sure we don't clear focus.
6135  setFocus = true;
6136  break;
6137  }
6138  }
6139 
6140  // If nobody could take focus, clear it.
6141  if (!stickyFocus && !setFocus)
6142  q->setFocusItem(0, Qt::MouseFocusReason);
6143 
6144  bool res = false;
6145  bool eventAccepted = touchEvent->isAccepted();
6146  foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
6147  // first, try to deliver the touch event
6148  updateTouchPointsForItem(item, touchEvent);
6149  bool acceptTouchEvents = item->acceptTouchEvents();
6150  touchEvent->setAccepted(acceptTouchEvents);
6151  res = acceptTouchEvents && sendEvent(item, touchEvent);
6152  eventAccepted = touchEvent->isAccepted();
6153  if (itemForTouchPointId.value(touchEvent->touchPoints().first().id()) == 0) {
6154  // item was deleted
6155  item = 0;
6156  } else {
6157  item->d_ptr->acceptedTouchBeginEvent = (res && eventAccepted);
6158  }
6159  touchEvent->spont = false;
6160  if (res && eventAccepted) {
6161  // the first item to accept the TouchBegin gets an implicit grab.
6162  for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
6163  const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i);
6164  itemForTouchPointId[touchPoint.id()] = item; // can be zero
6165  }
6166  break;
6167  }
6168  if (item && item->isPanel())
6169  break;
6170  }
6171 
6172  touchEvent->setAccepted(eventAccepted);
6173  return res;
6174 }
QMap< int, QGraphicsItem * > itemForTouchPointId
int id() const
Returns the id number of this touch point.
Definition: qevent.cpp:4445
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QGraphicsItem * focusItem() const
If this item, a child or descendant of this item currently has input focus, this function will return...
QScopedPointer< QGraphicsItemPrivate > d_ptr
QList< QGraphicsItem * > itemsAtPosition(const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
Returns all items for the screen position in event.
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QList< QGraphicsItem * > cachedItemsUnderMouse
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent)
QPointF scenePos() const
Returns the scene position of this touch point.
Definition: qevent.cpp:4488
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isAccepted() const
Definition: qcoreevent.h:307
QWidget * widget() const
Returns the widget on which the event occurred.
Definition: qevent.h:817
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool acceptTouchEvents() const
Returns true if an item accepts touch events; otherwise, returns false.
QPointF screenPos() const
Returns the screen position of this touch point.
Definition: qevent.cpp:4498
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
Definition: qevent.h:820
bool isWidget() const
Returns true if this item is a widget (i.
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.

◆ setActivePanelHelper()

void QGraphicsScenePrivate::setActivePanelHelper ( QGraphicsItem item,
bool  duringActivationEvent 
)
Warning
This function is not part of the public interface.

Definition at line 742 of file qgraphicsscene.cpp.

743 {
745  if (item && item->scene() != q) {
746  qWarning("QGraphicsScene::setActivePanel: item %p must be part of this scene",
747  item);
748  return;
749  }
750 
751  // Ensure the scene has focus when we change panel activation.
752  q->setFocus(Qt::ActiveWindowFocusReason);
753 
754  // Find the item's panel.
755  QGraphicsItem *panel = item ? item->panel() : 0;
756  lastActivePanel = panel ? activePanel : 0;
757  if (panel == activePanel || (!q->isActive() && !duringActivationEvent))
758  return;
759 
760  // Deactivate the last active panel.
761  if (activePanel) {
762  if (QGraphicsItem *fi = activePanel->focusItem()) {
763  // Remove focus from the current focus item.
764  if (fi == q->focusItem())
765  q->setFocusItem(0, Qt::ActiveWindowFocusReason);
766  }
767 
769  q->sendEvent(activePanel, &event);
770  } else if (panel && !duringActivationEvent) {
771  // Deactivate the scene if changing activation to a panel.
773  foreach (QGraphicsItem *item, q->items()) {
774  if (item->isVisible() && !item->isPanel() && !item->parentItem())
775  q->sendEvent(item, &event);
776  }
777  }
778 
779  // Update activate state.
780  activePanel = panel;
783 
784  // Activate
785  if (panel) {
787  q->sendEvent(panel, &event);
788 
789  // Set focus on the panel's focus item.
790  if (QGraphicsItem *focusItem = panel->focusItem())
792  } else if (q->isActive()) {
793  // Activate the scene
795  foreach (QGraphicsItem *item, q->items()) {
796  if (item->isVisible() && !item->isPanel() && !item->parentItem())
797  q->sendEvent(item, &event);
798  }
799  }
800 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QGraphicsItem * focusItem() const
If this item, a child or descendant of this item currently has input focus, this function will return...
EventRef event
QGraphicsItem * focusItem
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
#define Q_Q(Class)
Definition: qglobal.h:2483
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.
Q_CORE_EXPORT void qWarning(const char *,...)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QGraphicsItem * lastActivePanel
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QGraphicsItem * activePanel
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.

◆ setFocusItemHelper()

void QGraphicsScenePrivate::setFocusItemHelper ( QGraphicsItem item,
Qt::FocusReason  focusReason 
)
Warning
This function is not part of the public interface.

Definition at line 805 of file qgraphicsscene.cpp.

807 {
809  if (item == focusItem)
810  return;
811 
812  // Clear focus if asked to set focus on something that can't
813  // accept input focus.
814  if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable)
815  || !item->isVisible() || !item->isEnabled())) {
816  item = 0;
817  }
818 
819  // Set focus on the scene if an item requests focus.
820  if (item) {
821  q->setFocus(focusReason);
822  if (item == focusItem)
823  return;
824  }
825 
826  if (focusItem) {
828 
829 #ifndef QT_NO_IM
830  if (lastFocusItem
832  // Close any external input method panel. This happens
833  // automatically by removing WA_InputMethodEnabled on
834  // the views, but if we are changing focus, we have to
835  // do it ourselves.
836  for (int i = 0; i < views.size(); ++i)
837  if (views.at(i)->inputContext())
838  views.at(i)->inputContext()->reset();
839  }
840 
841  focusItem = 0;
842  QFocusEvent event(QEvent::FocusOut, focusReason);
844 #endif //QT_NO_IM
845  }
846 
847  // This handles the case that the item has been removed from the
848  // scene in response to the FocusOut event.
849  if (item && item->scene() != q)
850  item = 0;
851 
852  if (item)
853  focusItem = item;
855 
856 #ifndef QT_NO_ACCESSIBILITY
857  if (focusItem) {
858  if (QGraphicsObject *focusObj = focusItem->toGraphicsObject()) {
860  }
861  }
862 #endif
863  if (item) {
864  QFocusEvent event(QEvent::FocusIn, focusReason);
865  sendEvent(item, &event);
866  }
867 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
EventRef event
QGraphicsItem * focusItem
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
#define Q_Q(Class)
Definition: qglobal.h:2483
QList< QGraphicsView * > views
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
void updateInputMethodSensitivityInViews()
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
virtual void reset()=0
This function can be reimplemented in a subclass to reset the state of the input method.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
QGraphicsItem * lastFocusItem
The QGraphicsObject class provides a base class for all graphics items that require signals...
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.

◆ setFont_helper()

void QGraphicsScenePrivate::setFont_helper ( const QFont font)

Set the font and propagate the changes if the font is different from the current font.

Warning
This function is not part of the public interface.

Definition at line 1513 of file qgraphicsscene.cpp.

1514 {
1515  if (this->font == font && this->font.resolve() == font.resolve())
1516  return;
1517  updateFont(font);
1518 }
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
void updateFont(const QFont &font)
Update the font, and whether or not it has changed, reresolve all fonts in the scene.

◆ setPalette_helper()

void QGraphicsScenePrivate::setPalette_helper ( const QPalette palette)

Set the palette and propagate the changes if the palette is different from the current palette.

Warning
This function is not part of the public interface.

Definition at line 1578 of file qgraphicsscene.cpp.

1579 {
1580  if (this->palette == palette && this->palette.resolve() == palette.resolve())
1581  return;
1582  updatePalette(palette);
1583 }
void updatePalette(const QPalette &palette)
Update the palette, and whether or not it has changed, reresolve all palettes in the scene...
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101

◆ setScenePosItemEnabled()

void QGraphicsScenePrivate::setScenePosItemEnabled ( QGraphicsItem item,
bool  enabled 
)
Warning
This function is not part of the public interface.

Definition at line 529 of file qgraphicsscene.cpp.

Referenced by registerScenePosItem(), and unregisterScenePosItem().

530 {
531  QGraphicsItem *p = item->d_ptr->parent;
532  while (p) {
534  p = p->d_ptr->parent;
535  }
538  QMetaObject::invokeMethod(q_func(), "_q_updateScenePosDescendants", Qt::QueuedConnection);
539  }
540 }
QGraphicsItem * parent
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
quint32 scenePosDescendantsUpdatePending
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
#define enabled

◆ storeMouseButtonsForMouseGrabber()

void QGraphicsScenePrivate::storeMouseButtonsForMouseGrabber ( QGraphicsSceneMouseEvent event)
Warning
This function is not part of the public interface.

Definition at line 1126 of file qgraphicsscene.cpp.

1127 {
1128  for (int i = 0x1; i <= 0x10; i <<= 1) {
1129  if (event->buttons() & i) {
1132  event->widget()));
1135  }
1136  }
1137 }
QMap< Qt::MouseButton, QPoint > mouseGrabberButtonDownScreenPos
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownScenePos
QList< QGraphicsItem * > mouseGrabberItems
QMap< Qt::MouseButton, QPointF > mouseGrabberButtonDownPos
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
MouseButton
Definition: qnamespace.h:150

◆ touchEventHandler()

void QGraphicsScenePrivate::touchEventHandler ( QTouchEvent touchEvent)

Definition at line 5978 of file qgraphicsscene.cpp.

5979 {
5980  typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
5982 
5983  for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) {
5984  const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i);
5985 
5986  // update state
5987  QGraphicsItem *item = 0;
5988  if (touchPoint.state() == Qt::TouchPointPressed) {
5989  if (sceneTouchEvent->deviceType() == QTouchEvent::TouchPad) {
5990  // on touch-pad devices, send all touch points to the same item
5991  item = itemForTouchPointId.isEmpty()
5992  ? 0
5993  : itemForTouchPointId.constBegin().value();
5994  }
5995 
5996  if (!item) {
5997  // determine which item this touch point will go to
5999  touchPoint.scenePos(),
6000  sceneTouchEvent->widget());
6002  }
6003 
6004  if (sceneTouchEvent->deviceType() == QTouchEvent::TouchScreen) {
6005  // on touch-screens, combine this touch point with the closest one we find
6006  int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos());
6007  QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId);
6008  if (!item || (closestItem && cachedItemsUnderMouse.contains(closestItem)))
6009  item = closestItem;
6010  }
6011  if (!item)
6012  continue;
6013 
6014  itemForTouchPointId.insert(touchPoint.id(), item);
6015  sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
6016  } else if (touchPoint.state() == Qt::TouchPointReleased) {
6017  item = itemForTouchPointId.take(touchPoint.id());
6018  if (!item)
6019  continue;
6020 
6021  sceneCurrentTouchPoints.remove(touchPoint.id());
6022  } else {
6023  item = itemForTouchPointId.value(touchPoint.id());
6024  if (!item)
6025  continue;
6027  sceneCurrentTouchPoints[touchPoint.id()] = touchPoint;
6028  }
6029 
6030  StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item];
6031  statesAndTouchPoints.first |= touchPoint.state();
6032  statesAndTouchPoints.second.append(touchPoint);
6033  }
6034 
6035  if (itemsNeedingEvents.isEmpty()) {
6036  sceneTouchEvent->accept();
6037  return;
6038  }
6039 
6040  bool ignoreSceneTouchEvent = true;
6043  for (; it != end; ++it) {
6044  QGraphicsItem *item = it.key();
6045 
6046  (void) item->isBlockedByModalPanel(&item);
6047 
6048  // determine event type from the state mask
6049  QEvent::Type eventType;
6050  switch (it.value().first) {
6051  case Qt::TouchPointPressed:
6052  // all touch points have pressed state
6053  eventType = QEvent::TouchBegin;
6054  break;
6056  // all touch points have released state
6057  eventType = QEvent::TouchEnd;
6058  break;
6060  // don't send the event if nothing changed
6061  continue;
6062  default:
6063  // all other combinations
6064  eventType = QEvent::TouchUpdate;
6065  break;
6066  }
6067 
6068  QTouchEvent touchEvent(eventType);
6069  touchEvent.setWidget(sceneTouchEvent->widget());
6070  touchEvent.setDeviceType(sceneTouchEvent->deviceType());
6071  touchEvent.setModifiers(sceneTouchEvent->modifiers());
6072  touchEvent.setTouchPointStates(it.value().first);
6073  touchEvent.setTouchPoints(it.value().second);
6074 
6075  switch (touchEvent.type()) {
6076  case QEvent::TouchBegin:
6077  {
6078  // if the TouchBegin handler recurses, we assume that means the event
6079  // has been implicitly accepted and continue to send touch events
6080  item->d_ptr->acceptedTouchBeginEvent = true;
6081  bool res = sendTouchBeginEvent(item, &touchEvent)
6082  && touchEvent.isAccepted();
6083  if (!res) {
6084  // forget about these touch points, we didn't handle them
6085  for (int i = 0; i < touchEvent.touchPoints().count(); ++i) {
6086  const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i);
6087  itemForTouchPointId.remove(touchPoint.id());
6088  sceneCurrentTouchPoints.remove(touchPoint.id());
6089  }
6090  ignoreSceneTouchEvent = false;
6091  }
6092  break;
6093  }
6094  default:
6095  if (item->d_ptr->acceptedTouchBeginEvent) {
6096  updateTouchPointsForItem(item, &touchEvent);
6097  (void) sendEvent(item, &touchEvent);
6098  ignoreSceneTouchEvent = false;
6099  }
6100  break;
6101  }
6102  }
6103  sceneTouchEvent->setAccepted(ignoreSceneTouchEvent);
6104 }
QMap< int, QGraphicsItem * > itemForTouchPointId
int id() const
Returns the id number of this touch point.
Definition: qevent.cpp:4445
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
int findClosestTouchPointId(const QPointF &scenePos)
Qt::TouchPointState state() const
Returns the current state of this touch point.
Definition: qevent.cpp:4453
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define it(className, varName)
QList< QGraphicsItem * > itemsAtPosition(const QPoint &screenPos, const QPointF &scenePos, QWidget *widget) const
Returns all items for the screen position in event.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
QList< QGraphicsItem * > cachedItemsUnderMouse
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent)
QPointF scenePos() const
Returns the scene position of this touch point.
Definition: qevent.cpp:4488
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setTouchPointStates(Qt::TouchPointStates aTouchPointStates)
Sets a bitwise OR of all the touch point states for this event.
Definition: qevent.h:825
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const Key & key() const
Returns the current item&#39;s key.
Definition: qhash.h:419
bool isAccepted() const
Definition: qcoreevent.h:307
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
QPointF screenPos() const
Returns the screen position of this touch point.
Definition: qevent.cpp:4498
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
int remove(const Key &key)
Removes all the items that have the key key from the map.
Definition: qmap.h:662
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
void setDeviceType(DeviceType adeviceType)
Sets the device type to deviceType, which is of type QTouchEvent::DeviceType {DeviceType}.
Definition: qevent.h:824
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
Definition: qevent.h:820
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
QMap< int, QTouchEvent::TouchPoint > sceneCurrentTouchPoints
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:741
T take(const Key &key)
Removes the item with the key key from the map and returns the value associated with it...
Definition: qmap.h:692
void setWidget(QWidget *awidget)
Definition: qevent.h:823
QTouchEventSequence touchEvent(QWidget *widget=0, QTouchEvent::DeviceType deviceType=QTouchEvent::TouchScreen)
Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget...
Definition: qtesttouch.h:141
void setModifiers(Qt::KeyboardModifiers amodifiers)
Sets the keyboard modifiers flags for this event.
Definition: qevent.h:80
void setTouchPoints(const QList< QTouchEvent::TouchPoint > &atouchPoints)
Sets the list of touch points for this event.
Definition: qevent.h:826
static const KeyPair *const end
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
bool sendTouchBeginEvent(QGraphicsItem *item, QTouchEvent *touchEvent)

◆ ungrabGesture()

void QGraphicsScenePrivate::ungrabGesture ( QGraphicsItem item,
Qt::GestureType  gesture 
)

Definition at line 6662 of file qgraphicsscene.cpp.

Referenced by removeItemHelper().

6663 {
6664  // we know this can only be an object
6665  Q_ASSERT(item->d_ptr->isObject);
6666  QGraphicsObject *obj = static_cast<QGraphicsObject *>(item);
6668  if (!--grabbedGestures[gesture]) {
6669  foreach (QGraphicsView *view, views)
6670  view->viewport()->ungrabGesture(gesture);
6671  }
6672 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void cleanupCachedGestures(QObject *target, Qt::GestureType type)
static QGestureManager * instance()
QList< QGraphicsView * > views
QWidget * viewport() const
Returns the viewport widget.
QHash< Qt::GestureType, int > grabbedGestures
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
void ungrabGesture(Qt::GestureType type)
Unsubscribes the widget from a given gesture type.
Definition: qwidget.cpp:12977
The QGraphicsObject class provides a base class for all graphics items that require signals...

◆ ungrabKeyboard()

void QGraphicsScenePrivate::ungrabKeyboard ( QGraphicsItem item,
bool  itemIsDying = false 
)
Warning
This function is not part of the public interface.

Definition at line 1053 of file qgraphicsscene.cpp.

Referenced by clearKeyboardGrabber(), removeItemHelper(), and removePopup().

1054 {
1056  if (index == -1) {
1057  qWarning("QGraphicsItem::ungrabKeyboard: not a keyboard grabber");
1058  return;
1059  }
1060  if (item != keyboardGrabberItems.last()) {
1061  // Recursively ungrab the topmost keyboard grabber until we reach this
1062  // item to ensure state consistency.
1063  ungrabKeyboard(keyboardGrabberItems.at(index + 1), itemIsDying);
1064  }
1065 
1066  // Send notification about keyboard ungrab.
1067  if (!itemIsDying) {
1069  sendEvent(item, &event);
1070  }
1071 
1072  // Remove the item from the list of grabbers.
1074 
1075  // Send notification about mouse regrab.
1076  if (!itemIsDying && !keyboardGrabberItems.isEmpty()) {
1079  sendEvent(last, &event);
1080  }
1081 }
QList< QGraphicsItem * > keyboardGrabberItems
EventRef event
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsSceneIndex * index
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
int lastIndexOf(const T &t, int from=-1) const
Returns the index position of the last occurrence of value in the list, searching backward from index...
Definition: qlist.h:862
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
void ungrabKeyboard(QGraphicsItem *item, bool itemIsDying=false)
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ ungrabMouse()

void QGraphicsScenePrivate::ungrabMouse ( QGraphicsItem item,
bool  itemIsDying = false 
)
Warning
This function is not part of the public interface.

Definition at line 968 of file qgraphicsscene.cpp.

Referenced by removeItemHelper(), and removePopup().

969 {
970  int index = mouseGrabberItems.indexOf(item);
971  if (index == -1) {
972  qWarning("QGraphicsItem::ungrabMouse: not a mouse grabber");
973  return;
974  }
975 
976  if (item != mouseGrabberItems.last()) {
977  // Recursively ungrab the next mouse grabber until we reach this item
978  // to ensure state consistency.
979  ungrabMouse(mouseGrabberItems.at(index + 1), itemIsDying);
980  }
981  if (!popupWidgets.isEmpty() && item == popupWidgets.last()) {
982  // If the item is a popup, go via removePopup to ensure state
983  // consistency and that it gets hidden correctly - beware that
984  // removePopup() reenters this function to continue removing the grab.
985  removePopup((QGraphicsWidget *)item, itemIsDying);
986  return;
987  }
988 
989  // Send notification about mouse ungrab.
990  if (!itemIsDying) {
992  sendEvent(item, &event);
993  }
994 
995  // Remove the item from the list of grabbers. Whenever this happens, we
996  // reset the implicitGrab (there can be only ever be one implicit grabber
997  // in a scene, and it is always the latest grabber; if the implicit grab
998  // is lost, it is not automatically regained.
1001 
1002  // Send notification about mouse regrab. ### It's unfortunate that all the
1003  // items get a GrabMouse event, but this is a rare case with a simple
1004  // implementation and it does ensure a consistent state.
1005  if (!itemIsDying && !mouseGrabberItems.isEmpty()) {
1008  sendEvent(last, &event);
1009  }
1010 }
EventRef event
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
QGraphicsSceneIndex * index
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void ungrabMouse(QGraphicsItem *item, bool itemIsDying=false)
void removePopup(QGraphicsWidget *widget, bool itemIsDying=false)
Remove widget from the popup list.
QList< QGraphicsItem * > mouseGrabberItems
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
bool sendEvent(QGraphicsItem *item, QEvent *event)
This is the final dispatch point for any events from the scene to the item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QList< QGraphicsWidget * > popupWidgets
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
quint32 lastMouseGrabberItemHasImplicitMouseGrab

◆ unregisterScenePosItem()

void QGraphicsScenePrivate::unregisterScenePosItem ( QGraphicsItem item)
Warning
This function is not part of the public interface.

Definition at line 554 of file qgraphicsscene.cpp.

Referenced by removeItemHelper().

555 {
556  scenePosItems.remove(item);
557  setScenePosItemEnabled(item, false);
558 }
void setScenePosItemEnabled(QGraphicsItem *item, bool enabled)
bool remove(const T &value)
Definition: qset.h:89
QSet< QGraphicsItem * > scenePosItems

◆ unregisterTopLevelItem()

void QGraphicsScenePrivate::unregisterTopLevelItem ( QGraphicsItem item)
Warning
This function is not part of the public interface.

This function is almost identical to QGraphicsItemPrivate::removeChild().

Definition at line 428 of file qgraphicsscene.cpp.

Referenced by removeItemHelper().

429 {
434  else
435  topLevelItems.removeOne(item);
436  // NB! Do not use topLevelItems.removeAt(item->d_ptr->siblingIndex) because
437  // the item is not guaranteed to be at the index after the list is sorted
438  // (see ensureSortedTopLevelItems()).
439  item->d_ptr->siblingIndex = -1;
442 }
QScopedPointer< QGraphicsItemPrivate > d_ptr
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
QList< QGraphicsItem * > topLevelItems
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ updateFont()

void QGraphicsScenePrivate::updateFont ( const QFont font)

Update the font, and whether or not it has changed, reresolve all fonts in the scene.

Warning
This function is not part of the public interface.

Definition at line 1546 of file qgraphicsscene.cpp.

Referenced by resolveFont(), and setFont_helper().

1547 {
1549 
1550  // Update local font setting.
1551  this->font = font;
1552 
1553  // Resolve the fonts of all top-level widget items, or widget items
1554  // whose parent is not a widget.
1555  foreach (QGraphicsItem *item, q->items()) {
1556  if (!item->parentItem()) {
1557  // Resolvefont for an item is a noop operation, but
1558  // every item can be a widget, or can have a widget
1559  // childre.
1560  item->d_ptr->resolveFont(font.resolve());
1561  }
1562  }
1563 
1564  // Send the scene a FontChange event.
1567 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
EventRef event
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_Q(Class)
Definition: qglobal.h:2483
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
virtual void resolveFont(uint inheritedMask)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ updateInputMethodSensitivityInViews()

void QGraphicsScenePrivate::updateInputMethodSensitivityInViews ( )

Definition at line 6182 of file qgraphicsscene.cpp.

Referenced by setFocusItemHelper().

6183 {
6184  for (int i = 0; i < views.size(); ++i)
6185  views.at(i)->d_func()->updateInputMethodSensitivity();
6186 }
QList< QGraphicsView * > views
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ updatePalette()

void QGraphicsScenePrivate::updatePalette ( const QPalette palette)

Update the palette, and whether or not it has changed, reresolve all palettes in the scene.

Warning
This function is not part of the public interface.

Definition at line 1611 of file qgraphicsscene.cpp.

Referenced by resolvePalette(), and setPalette_helper().

1612 {
1614 
1615  // Update local palette setting.
1616  this->palette = palette;
1617 
1618  // Resolve the palettes of all top-level widget items, or widget items
1619  // whose parent is not a widget.
1620  foreach (QGraphicsItem *item, q->items()) {
1621  if (!item->parentItem()) {
1622  // Resolvefont for an item is a noop operation, but
1623  // every item can be a widget, or can have a widget
1624  // childre.
1625  item->d_ptr->resolvePalette(palette.resolve());
1626  }
1627  }
1628 
1629  // Send the scene a PaletteChange event.
1632 }
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
EventRef event
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_Q(Class)
Definition: qglobal.h:2483
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
virtual void resolvePalette(uint inheritedMask)
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101

◆ updateTouchPointsForItem()

void QGraphicsScenePrivate::updateTouchPointsForItem ( QGraphicsItem item,
QTouchEvent touchEvent 
)
static

Definition at line 5952 of file qgraphicsscene.cpp.

5953 {
5954  QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
5955  for (int i = 0; i < touchPoints.count(); ++i) {
5956  QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
5957  touchPoint.setRect(item->mapFromScene(touchPoint.sceneRect()).boundingRect());
5958  touchPoint.setStartPos(item->d_ptr->genericMapFromScene(touchPoint.startScenePos(), touchEvent->widget()));
5959  touchPoint.setLastPos(item->d_ptr->genericMapFromScene(touchPoint.lastScenePos(), touchEvent->widget()));
5960  }
5961  touchEvent->setTouchPoints(touchPoints);
5962 }
void setLastPos(const QPointF &lastPos)
Definition: qevent.cpp:4743
QPointF startScenePos() const
Returns the starting scene position of this touch point.
Definition: qevent.cpp:4537
QScopedPointer< QGraphicsItemPrivate > d_ptr
void setRect(const QRectF &rect)
Definition: qevent.cpp:4775
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
QPointF lastScenePos() const
Returns the scene position of this touch point from the previous touch event.
Definition: qevent.cpp:4587
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void setStartPos(const QPointF &startPos)
Definition: qevent.cpp:4711
QRectF sceneRect() const
Returns the rect for this touch point in scene coordinates.
Definition: qevent.cpp:4636
static const QRectF boundingRect(const QPointF *points, int pointCount)
QWidget * widget() const
Returns the widget on which the event occurred.
Definition: qevent.h:817
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
Definition: qevent.h:820
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744
void setTouchPoints(const QList< QTouchEvent::TouchPoint > &atouchPoints)
Sets the list of touch points for this event.
Definition: qevent.h:826

◆ windowForItem()

QGraphicsWidget* QGraphicsScenePrivate::windowForItem ( const QGraphicsItem item) const

Properties

◆ activationRefCount

int QGraphicsScenePrivate::activationRefCount

Definition at line 157 of file qgraphicsscene_p.h.

◆ activePanel

QGraphicsItem* QGraphicsScenePrivate::activePanel

Definition at line 155 of file qgraphicsscene_p.h.

Referenced by removeItemHelper(), and setActivePanelHelper().

◆ allItemsIgnoreHoverEvents

quint32 QGraphicsScenePrivate::allItemsIgnoreHoverEvents

Definition at line 113 of file qgraphicsscene_p.h.

◆ allItemsIgnoreTouchEvents

quint32 QGraphicsScenePrivate::allItemsIgnoreTouchEvents

Definition at line 117 of file qgraphicsscene_p.h.

◆ allItemsUseDefaultCursor

quint32 QGraphicsScenePrivate::allItemsUseDefaultCursor

Definition at line 114 of file qgraphicsscene_p.h.

◆ backgroundBrush

QBrush QGraphicsScenePrivate::backgroundBrush

Definition at line 147 of file qgraphicsscene_p.h.

◆ cachedAlreadyDeliveredGestures

QHash<QGraphicsObject *, QSet<QGesture *> > QGraphicsScenePrivate::cachedAlreadyDeliveredGestures

Definition at line 305 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ cachedItemGestures

QHash<QGraphicsObject *, QSet<QGesture *> > QGraphicsScenePrivate::cachedItemGestures

Definition at line 304 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ cachedItemsUnderMouse

QList<QGraphicsItem *> QGraphicsScenePrivate::cachedItemsUnderMouse

Definition at line 180 of file qgraphicsscene_p.h.

Referenced by mousePressEventHandler(), and removeItemHelper().

◆ cachedTargetItems

QList<QGraphicsObject *> QGraphicsScenePrivate::cachedTargetItems

Definition at line 302 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ calledEmitUpdated

quint32 QGraphicsScenePrivate::calledEmitUpdated

Definition at line 104 of file qgraphicsscene_p.h.

Referenced by _q_emitUpdated(), and _q_processDirtyItems().

◆ changedSignalIndex

int QGraphicsScenePrivate::changedSignalIndex

Definition at line 90 of file qgraphicsscene_p.h.

Referenced by _q_emitUpdated(), init(), and QGraphicsItem::prepareGeometryChange().

◆ childExplicitActivation

int QGraphicsScenePrivate::childExplicitActivation

Definition at line 158 of file qgraphicsscene_p.h.

◆ dirtyGrowingItemsBoundingRect

quint32 QGraphicsScenePrivate::dirtyGrowingItemsBoundingRect

◆ dragDropItem

QGraphicsItem* QGraphicsScenePrivate::dragDropItem

Definition at line 177 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ enterWidget

QGraphicsWidget* QGraphicsScenePrivate::enterWidget

Definition at line 178 of file qgraphicsscene_p.h.

◆ focusItem

QGraphicsItem* QGraphicsScenePrivate::focusItem

◆ font

QFont QGraphicsScenePrivate::font

Definition at line 283 of file qgraphicsscene_p.h.

Referenced by resolveFont(), and updateFont().

◆ foregroundBrush

QBrush QGraphicsScenePrivate::foregroundBrush

Definition at line 148 of file qgraphicsscene_p.h.

◆ gestureTargets

QHash<QGesture *, QGraphicsObject *> QGraphicsScenePrivate::gestureTargets

Definition at line 306 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ grabbedGestures

QHash<Qt::GestureType, int> QGraphicsScenePrivate::grabbedGestures

Definition at line 307 of file qgraphicsscene_p.h.

◆ growingItemsBoundingRect

QRectF QGraphicsScenePrivate::growingItemsBoundingRect

◆ hasFocus

quint32 QGraphicsScenePrivate::hasFocus

Definition at line 111 of file qgraphicsscene_p.h.

◆ hasSceneRect

quint32 QGraphicsScenePrivate::hasSceneRect

Definition at line 101 of file qgraphicsscene_p.h.

Referenced by _q_emitUpdated(), and _q_processDirtyItems().

◆ holesInTopLevelSiblingIndex

quint32 QGraphicsScenePrivate::holesInTopLevelSiblingIndex

◆ hoverItems

QList<QGraphicsItem *> QGraphicsScenePrivate::hoverItems

Definition at line 181 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ index

QGraphicsSceneIndex* QGraphicsScenePrivate::index

◆ indexMethod

QGraphicsScene::ItemIndexMethod QGraphicsScenePrivate::indexMethod

Definition at line 94 of file qgraphicsscene_p.h.

◆ itemForTouchPointId

QMap<int, QGraphicsItem *> QGraphicsScenePrivate::itemForTouchPointId

Definition at line 295 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ keyboardGrabberItems

QList<QGraphicsItem *> QGraphicsScenePrivate::keyboardGrabberItems

◆ lastActivePanel

QGraphicsItem* QGraphicsScenePrivate::lastActivePanel

Definition at line 156 of file qgraphicsscene_p.h.

Referenced by removeItemHelper(), and setActivePanelHelper().

◆ lastDropAction

Qt::DropAction QGraphicsScenePrivate::lastDropAction

Definition at line 179 of file qgraphicsscene_p.h.

◆ lastFocusItem

QGraphicsItem* QGraphicsScenePrivate::lastFocusItem

Definition at line 152 of file qgraphicsscene_p.h.

Referenced by removeItemHelper(), and setFocusItemHelper().

◆ lastItemCount

int QGraphicsScenePrivate::lastItemCount

Definition at line 97 of file qgraphicsscene_p.h.

◆ lastMouseGrabberItem

QGraphicsItem* QGraphicsScenePrivate::lastMouseGrabberItem

Definition at line 166 of file qgraphicsscene_p.h.

Referenced by clearMouseGrabber(), and removeItemHelper().

◆ lastMouseGrabberItemHasImplicitMouseGrab

quint32 QGraphicsScenePrivate::lastMouseGrabberItemHasImplicitMouseGrab

Definition at line 112 of file qgraphicsscene_p.h.

Referenced by grabMouse(), sendMouseEvent(), and ungrabMouse().

◆ lastSceneMousePos

QPointF QGraphicsScenePrivate::lastSceneMousePos

Definition at line 182 of file qgraphicsscene_p.h.

◆ modalPanels

QList<QGraphicsItem *> QGraphicsScenePrivate::modalPanels

◆ mouseGrabberButtonDownPos

QMap<Qt::MouseButton, QPointF> QGraphicsScenePrivate::mouseGrabberButtonDownPos

Definition at line 184 of file qgraphicsscene_p.h.

Referenced by sendMouseEvent(), and storeMouseButtonsForMouseGrabber().

◆ mouseGrabberButtonDownScenePos

QMap<Qt::MouseButton, QPointF> QGraphicsScenePrivate::mouseGrabberButtonDownScenePos

Definition at line 185 of file qgraphicsscene_p.h.

Referenced by sendMouseEvent(), and storeMouseButtonsForMouseGrabber().

◆ mouseGrabberButtonDownScreenPos

QMap<Qt::MouseButton, QPoint> QGraphicsScenePrivate::mouseGrabberButtonDownScreenPos

Definition at line 186 of file qgraphicsscene_p.h.

Referenced by sendMouseEvent(), and storeMouseButtonsForMouseGrabber().

◆ mouseGrabberItems

QList<QGraphicsItem *> QGraphicsScenePrivate::mouseGrabberItems

◆ movingItemsInitialPositions

QMap<QGraphicsItem *, QPointF> QGraphicsScenePrivate::movingItemsInitialPositions

Definition at line 131 of file qgraphicsscene_p.h.

◆ needSortTopLevelItems

quint32 QGraphicsScenePrivate::needSortTopLevelItems

◆ padding

quint32 QGraphicsScenePrivate::padding

Definition at line 118 of file qgraphicsscene_p.h.

◆ painterStateProtection

quint32 QGraphicsScenePrivate::painterStateProtection

Definition at line 115 of file qgraphicsscene_p.h.

◆ palette

QPalette QGraphicsScenePrivate::palette

Definition at line 287 of file qgraphicsscene_p.h.

Referenced by resolvePalette(), and updatePalette().

◆ passiveFocusItem

QGraphicsItem* QGraphicsScenePrivate::passiveFocusItem

Definition at line 153 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ polishItemsIndex

int QGraphicsScenePrivate::polishItemsIndex

Definition at line 92 of file qgraphicsscene_p.h.

Referenced by init().

◆ popupWidgets

QList<QGraphicsWidget *> QGraphicsScenePrivate::popupWidgets

◆ processDirtyItemsEmitted

quint32 QGraphicsScenePrivate::processDirtyItemsEmitted

Definition at line 105 of file qgraphicsscene_p.h.

Referenced by _q_processDirtyItems().

◆ processDirtyItemsIndex

int QGraphicsScenePrivate::processDirtyItemsIndex

Definition at line 91 of file qgraphicsscene_p.h.

Referenced by init().

◆ rectAdjust

quint32 QGraphicsScenePrivate::rectAdjust

Definition at line 150 of file qgraphicsscene_p.h.

◆ sceneCurrentTouchPoints

QMap<int, QTouchEvent::TouchPoint> QGraphicsScenePrivate::sceneCurrentTouchPoints

Definition at line 294 of file qgraphicsscene_p.h.

Referenced by removeItemHelper().

◆ sceneEventFilters

QMultiMap<QGraphicsItem *, QGraphicsItem *> QGraphicsScenePrivate::sceneEventFilters

◆ scenePosDescendantsUpdatePending

quint32 QGraphicsScenePrivate::scenePosDescendantsUpdatePending

Definition at line 109 of file qgraphicsscene_p.h.

Referenced by _q_updateScenePosDescendants(), and setScenePosItemEnabled().

◆ scenePosItems

QSet<QGraphicsItem *> QGraphicsScenePrivate::scenePosItems

◆ sceneRect

QRectF QGraphicsScenePrivate::sceneRect

Definition at line 99 of file qgraphicsscene_p.h.

◆ selectedItems

QSet<QGraphicsItem *> QGraphicsScenePrivate::selectedItems

Definition at line 127 of file qgraphicsscene_p.h.

Referenced by removeItemHelper(), and QGraphicsItem::setSelected().

◆ selectionArea

QPainterPath QGraphicsScenePrivate::selectionArea

Definition at line 125 of file qgraphicsscene_p.h.

◆ selectionChanging

int QGraphicsScenePrivate::selectionChanging

Definition at line 126 of file qgraphicsscene_p.h.

Referenced by removeItemHelper(), and QGraphicsItem::setSelected().

◆ sortCacheEnabled

quint32 QGraphicsScenePrivate::sortCacheEnabled

Definition at line 116 of file qgraphicsscene_p.h.

◆ stickyFocus

quint32 QGraphicsScenePrivate::stickyFocus

Definition at line 110 of file qgraphicsscene_p.h.

Referenced by mousePressEventHandler().

◆ style

QStyle* QGraphicsScenePrivate::style

Definition at line 282 of file qgraphicsscene_p.h.

◆ styleOptionTmp

QStyleOptionGraphicsItem QGraphicsScenePrivate::styleOptionTmp

Definition at line 292 of file qgraphicsscene_p.h.

◆ tabFocusFirst

QGraphicsWidget* QGraphicsScenePrivate::tabFocusFirst

◆ topLevelItems

QList<QGraphicsItem *> QGraphicsScenePrivate::topLevelItems

◆ topLevelSequentialOrdering

quint32 QGraphicsScenePrivate::topLevelSequentialOrdering

◆ unpolishedItems

QVector<QGraphicsItem *> QGraphicsScenePrivate::unpolishedItems

Definition at line 128 of file qgraphicsscene_p.h.

Referenced by _q_polishItems(), and removeItemHelper().

◆ updateAll

quint32 QGraphicsScenePrivate::updateAll

Definition at line 103 of file qgraphicsscene_p.h.

Referenced by _q_emitUpdated(), and _q_processDirtyItems().

◆ updatedRects

QList<QRectF> QGraphicsScenePrivate::updatedRects

Definition at line 123 of file qgraphicsscene_p.h.

Referenced by _q_emitUpdated().

◆ views

QList<QGraphicsView *> QGraphicsScenePrivate::views

The documentation for this class was generated from the following files: