summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview/qgraphicsscene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsscene.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp847
1 files changed, 370 insertions, 477 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index 3dce958b08..c022af6fc0 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
/*!
\class QGraphicsScene
@@ -114,7 +78,7 @@
Another responsibility that QGraphicsScene has, is to propagate events
from QGraphicsView. To send an event to a scene, you construct an event
that inherits QEvent, and then send it using, for example,
- QApplication::sendEvent(). event() is responsible for dispatching
+ QCoreApplication::sendEvent(). event() is responsible for dispatching
the event to the individual items. Some common events are handled by
convenience event handlers. For example, key press events are handled by
keyPressEvent(), and mouse press events are handled by mousePressEvent().
@@ -226,22 +190,25 @@
#include <QtCore/qvarlengtharray.h>
#include <QtCore/QMetaMethod>
#include <QtWidgets/qapplication.h>
-#include <QtWidgets/qdesktopwidget.h>
#include <QtGui/qevent.h>
#include <QtWidgets/qgraphicslayout.h>
#include <QtWidgets/qgraphicsproxywidget.h>
#include <QtWidgets/qgraphicswidget.h>
-#include <QtGui/qmatrix.h>
#include <QtGui/qpaintengine.h>
#include <QtGui/qpainter.h>
+#include <QtGui/qpainterpath.h>
#include <QtGui/qpixmapcache.h>
#include <QtGui/qpolygon.h>
-#include <QtGui/qtouchdevice.h>
+#include <QtGui/qpointingdevice.h>
#include <QtWidgets/qstyleoption.h>
+#if QT_CONFIG(tooltip)
#include <QtWidgets/qtooltip.h>
+#endif
#include <QtGui/qtransform.h>
#include <QtGui/qinputmethod.h>
#include <private/qapplication_p.h>
+#include <private/qevent_p.h>
+#include <QtGui/private/qeventpoint_p.h>
#include <private/qobject_p.h>
#if QT_CONFIG(graphicseffect)
#include <private/qgraphicseffect_p.h>
@@ -249,6 +216,8 @@
#include <private/qgesturemanager_p.h>
#include <private/qpathclipper_p.h>
+#include <QtCore/qpointer.h>
+
// #define GESTURE_DEBUG
#ifndef GESTURE_DEBUG
# define DEBUG if (0) qDebug
@@ -278,7 +247,7 @@ static void _q_hoverFromMouseEvent(QGraphicsSceneHoverEvent *hover, const QGraph
*/
QGraphicsScenePrivate::QGraphicsScenePrivate()
: indexMethod(QGraphicsScene::BspTreeIndex),
- index(0),
+ index(nullptr),
lastItemCount(0),
hasSceneRect(false),
dirtyGrowingItemsBoundingRect(true),
@@ -301,19 +270,19 @@ QGraphicsScenePrivate::QGraphicsScenePrivate()
minimumRenderSize(0.0),
selectionChanging(0),
rectAdjust(2),
- focusItem(0),
- lastFocusItem(0),
- passiveFocusItem(0),
- tabFocusFirst(0),
- activePanel(0),
- lastActivePanel(0),
+ focusItem(nullptr),
+ lastFocusItem(nullptr),
+ passiveFocusItem(nullptr),
+ tabFocusFirst(nullptr),
+ activePanel(nullptr),
+ lastActivePanel(nullptr),
activationRefCount(0),
childExplicitActivation(0),
- lastMouseGrabberItem(0),
- dragDropItem(0),
- enterWidget(0),
+ lastMouseGrabberItem(nullptr),
+ dragDropItem(nullptr),
+ enterWidget(nullptr),
lastDropAction(Qt::IgnoreAction),
- style(0)
+ style(nullptr)
{
}
@@ -363,12 +332,11 @@ void QGraphicsScenePrivate::_q_emitUpdated()
// needs to happen in order to keep compatibility with the behavior from
// Qt 4.4 and backward.
if (isSignalConnected(changedSignalIndex)) {
- for (int i = 0; i < views.size(); ++i) {
- QGraphicsView *view = views.at(i);
+ for (auto view : std::as_const(views)) {
if (!view->d_func()->connectedToScene) {
view->d_func()->connectedToScene = true;
q->connect(q, SIGNAL(changed(QList<QRectF>)),
- views.at(i), SLOT(updateScene(QList<QRectF>)));
+ view, SLOT(updateScene(QList<QRectF>)));
}
}
} else {
@@ -376,17 +344,25 @@ void QGraphicsScenePrivate::_q_emitUpdated()
updateAll = false;
return;
}
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->processPendingUpdates();
+ for (auto view : std::as_const(views))
+ view->d_func()->processPendingUpdates();
// It's important that we update all views before we dispatch, hence two for-loops.
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->dispatchPendingUpdateRequests();
+ for (auto view : std::as_const(views))
+ view->d_func()->dispatchPendingUpdateRequests();
return;
}
// Notify the changes to anybody interested.
QList<QRectF> oldUpdatedRects;
- oldUpdatedRects = updateAll ? (QList<QRectF>() << q->sceneRect()) : updatedRects;
+ if (updateAll) {
+ oldUpdatedRects << q->sceneRect();
+ } else {
+ // Switch to a ranged constructor in Qt 6...
+ oldUpdatedRects.reserve(int(updatedRects.size()));
+ std::copy(updatedRects.cbegin(), updatedRects.cend(),
+ std::back_inserter(oldUpdatedRects));
+ }
+
updateAll = false;
updatedRects.clear();
emit q->changed(oldUpdatedRects);
@@ -435,9 +411,9 @@ void QGraphicsScenePrivate::_q_polishItems()
return;
const QVariant booleanTrueVariant(true);
- QGraphicsItem *item = 0;
- QGraphicsItemPrivate *itemd = 0;
- const int oldUnpolishedCount = unpolishedItems.count();
+ QGraphicsItem *item = nullptr;
+ QGraphicsItemPrivate *itemd = nullptr;
+ const int oldUnpolishedCount = unpolishedItems.size();
for (int i = 0; i < oldUnpolishedCount; ++i) {
item = unpolishedItems.at(i);
@@ -451,11 +427,11 @@ void QGraphicsScenePrivate::_q_polishItems()
}
if (itemd->isWidget) {
QEvent event(QEvent::Polish);
- QApplication::sendEvent((QGraphicsWidget *)item, &event);
+ QCoreApplication::sendEvent((QGraphicsWidget *)item, &event);
}
}
- if (unpolishedItems.count() == oldUnpolishedCount) {
+ if (unpolishedItems.size() == oldUnpolishedCount) {
// No new items were added to the vector.
unpolishedItems.clear();
} else {
@@ -474,8 +450,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
Q_ASSERT(calledEmitUpdated);
// No need for further processing (except resetting the dirty states).
// The growingItemsBoundingRect is updated in _q_emitUpdated.
- for (int i = 0; i < topLevelItems.size(); ++i)
- resetDirtyItem(topLevelItems.at(i), /*recursive=*/true);
+ for (auto topLevelItem : std::as_const(topLevelItems))
+ resetDirtyItem(topLevelItem, /*recursive=*/true);
return;
}
@@ -483,8 +459,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect;
// Process items recursively.
- for (int i = 0; i < topLevelItems.size(); ++i)
- processDirtyItemsRecursive(topLevelItems.at(i));
+ for (auto topLevelItem : std::as_const(topLevelItems))
+ processDirtyItemsRecursive(topLevelItem);
dirtyGrowingItemsBoundingRect = false;
if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect)
@@ -493,8 +469,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
if (wasPendingSceneUpdate)
return;
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->processPendingUpdates();
+ for (auto view : std::as_const(views))
+ view->d_func()->processPendingUpdates();
if (calledEmitUpdated) {
// We did a compatibility QGraphicsScene::update in processDirtyItemsRecursive
@@ -504,8 +480,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
}
// Immediately dispatch all pending update requests on the views.
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->dispatchPendingUpdateRequests();
+ for (auto view : std::as_const(views))
+ view->d_func()->dispatchPendingUpdateRequests();
}
/*!
@@ -547,7 +523,7 @@ void QGraphicsScenePrivate::unregisterScenePosItem(QGraphicsItem *item)
*/
void QGraphicsScenePrivate::_q_updateScenePosDescendants()
{
- foreach (QGraphicsItem *item, scenePosItems) {
+ for (QGraphicsItem *item : std::as_const(scenePosItems)) {
QGraphicsItem *p = item->d_ptr->parent;
while (p) {
p->d_ptr->scenePosDescendants = 1;
@@ -594,19 +570,19 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
unregisterScenePosItem(item);
QGraphicsScene *oldScene = item->d_func()->scene;
- item->d_func()->scene = 0;
+ item->d_func()->scene = nullptr;
//We need to remove all children first because they might use their parent
//attributes (e.g. sceneTransform).
if (!item->d_ptr->inDestructor) {
// Remove all children recursively
- for (int i = 0; i < item->d_ptr->children.size(); ++i)
- q->removeItem(item->d_ptr->children.at(i));
+ for (auto child : std::as_const(item->d_ptr->children))
+ q->removeItem(child);
}
if (!item->d_ptr->inDestructor && !item->parentItem() && item->isWidget()) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
- widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0);
+ widget->d_func()->fixFocusChainBeforeReparenting(nullptr, oldScene, nullptr);
}
// Unregister focus proxy.
@@ -617,7 +593,7 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
if (parentItem->scene()) {
Q_ASSERT_X(parentItem->scene() == q, "QGraphicsScene::removeItem",
"Parent item's scene is different from this item's scene");
- item->setParentItem(0);
+ item->setParentItem(nullptr);
}
} else {
unregisterTopLevelItem(item);
@@ -625,17 +601,17 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
// Reset the mouse grabber and focus item data.
if (item == focusItem)
- focusItem = 0;
+ focusItem = nullptr;
if (item == lastFocusItem)
- lastFocusItem = 0;
+ lastFocusItem = nullptr;
if (item == passiveFocusItem)
- passiveFocusItem = 0;
+ passiveFocusItem = nullptr;
if (item == activePanel) {
// ### deactivate...
- activePanel = 0;
+ activePanel = nullptr;
}
if (item == lastActivePanel)
- lastActivePanel = 0;
+ lastActivePanel = nullptr;
// Change tabFocusFirst to the next widget in focus chain if removing the current one.
if (item == tabFocusFirst) {
@@ -643,7 +619,7 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
if (wd->focusNext && wd->focusNext != tabFocusFirst && wd->focusNext->scene() == q)
tabFocusFirst = wd->focusNext;
else
- tabFocusFirst = 0;
+ tabFocusFirst = nullptr;
}
// Cancel active touches
@@ -697,20 +673,19 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
// Reset the last mouse grabber item
if (item == lastMouseGrabberItem)
- lastMouseGrabberItem = 0;
+ lastMouseGrabberItem = nullptr;
// Reset the current drop item
if (item == dragDropItem)
- dragDropItem = 0;
+ dragDropItem = nullptr;
- // Reenable selectionChanged() for individual items
+ // Re-enable selectionChanged() for individual items
--selectionChanging;
if (!selectionChanging && selectedItems.size() != oldSelectedItemsSize)
emit q->selectionChanged();
#ifndef QT_NO_GESTURES
- QHash<QGesture *, QGraphicsObject *>::iterator it;
- for (it = gestureTargets.begin(); it != gestureTargets.end();) {
+ for (auto it = gestureTargets.begin(); it != gestureTargets.end();) {
if (it.value() == item)
it = gestureTargets.erase(it);
else
@@ -723,8 +698,9 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
cachedAlreadyDeliveredGestures.remove(dummy);
}
- foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys())
- ungrabGesture(item, gesture);
+ for (auto it = item->d_ptr->gestureContext.constBegin();
+ it != item->d_ptr->gestureContext.constEnd(); ++it)
+ ungrabGesture(item, it.key());
#endif // QT_NO_GESTURES
}
@@ -744,8 +720,8 @@ void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool durin
q->setFocus(Qt::ActiveWindowFocusReason);
// Find the item's panel.
- QGraphicsItem *panel = item ? item->panel() : 0;
- lastActivePanel = panel ? activePanel : 0;
+ QGraphicsItem *panel = item ? item->panel() : nullptr;
+ lastActivePanel = panel ? activePanel : nullptr;
if (panel == activePanel || (!q->isActive() && !duringActivationEvent))
return;
@@ -756,7 +732,7 @@ void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool durin
if (QGraphicsItem *fi = activePanel->focusItem()) {
// Remove focus from the current focus item.
if (fi == q->focusItem())
- setFocusItemHelper(0, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false);
+ setFocusItemHelper(nullptr, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false);
}
QEvent event(QEvent::WindowDeactivate);
@@ -774,7 +750,7 @@ void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool durin
// Update activate state.
activePanel = panel;
QEvent event(QEvent::ActivationChange);
- QApplication::sendEvent(q, &event);
+ QCoreApplication::sendEvent(q, &event);
// Activate
if (panel) {
@@ -833,7 +809,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
// accept input focus.
if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable)
|| !item->isVisible() || !item->isEnabled())) {
- item = 0;
+ item = nullptr;
}
// Set focus on the scene if an item requests focus.
@@ -841,7 +817,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
q->setFocus(focusReason);
if (item == focusItem) {
if (emitFocusChanged)
- emit q->focusItemChanged(focusItem, (QGraphicsItem *)0, focusReason);
+ emit q->focusItemChanged(focusItem, (QGraphicsItem *)nullptr, focusReason);
return;
}
}
@@ -861,7 +837,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
}
#endif //QT_NO_IM
- focusItem = 0;
+ focusItem = nullptr;
QFocusEvent event(QEvent::FocusOut, focusReason);
sendEvent(lastFocusItem, &event);
}
@@ -869,7 +845,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
// This handles the case that the item has been removed from the
// scene in response to the FocusOut event.
if (item && item->scene() != q)
- item = 0;
+ item = nullptr;
if (item)
focusItem = item;
@@ -1030,8 +1006,8 @@ void QGraphicsScenePrivate::ungrabMouse(QGraphicsItem *item, bool itemIsDying)
void QGraphicsScenePrivate::clearMouseGrabber()
{
if (!mouseGrabberItems.isEmpty())
- mouseGrabberItems.first()->ungrabMouse();
- lastMouseGrabberItem = 0;
+ mouseGrabberItems.constFirst()->ungrabMouse();
+ lastMouseGrabberItem = nullptr;
}
/*!
@@ -1106,7 +1082,7 @@ void QGraphicsScenePrivate::clearKeyboardGrabber()
void QGraphicsScenePrivate::enableMouseTrackingOnViews()
{
- foreach (QGraphicsView *view, views)
+ for (QGraphicsView *view : std::as_const(views))
view->viewport()->setMouseTracking(true);
}
@@ -1243,9 +1219,9 @@ bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event)
return false;
if (QGraphicsObject *o = item->toGraphicsObject()) {
bool spont = event->spontaneous();
- if (spont ? qt_sendSpontaneousEvent(o, event) : QApplication::sendEvent(o, event))
+ if (spont ? qt_sendSpontaneousEvent(o, event) : QCoreApplication::sendEvent(o, event))
return true;
- event->spont = spont;
+ event->m_spont = spont;
}
return item->sceneEvent(event);
}
@@ -1357,10 +1333,10 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// Update window activation.
QGraphicsItem *topItem = cachedItemsUnderMouse.value(0);
- QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : 0;
+ QGraphicsWidget *newActiveWindow = topItem ? topItem->window() : nullptr;
if (newActiveWindow && newActiveWindow->isBlockedByModalPanel(&topItem)) {
// pass activation to the blocking modal window
- newActiveWindow = topItem ? topItem->window() : 0;
+ newActiveWindow = topItem ? topItem->window() : nullptr;
}
if (newActiveWindow != q->activeWindow())
@@ -1369,7 +1345,7 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// Set focus on the topmost enabled item that can take focus.
bool setFocus = false;
- foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
+ for (QGraphicsItem *item : std::as_const(cachedItemsUnderMouse)) {
if (item->isBlockedByModalPanel()
|| (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling)) {
// Make sure we don't clear focus.
@@ -1392,8 +1368,8 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// Check for scene modality.
bool sceneModality = false;
- for (int i = 0; i < modalPanels.size(); ++i) {
- if (modalPanels.at(i)->panelModality() == QGraphicsItem::SceneModal) {
+ for (auto modalPanel : std::as_const(modalPanels)) {
+ if (modalPanel->panelModality() == QGraphicsItem::SceneModal) {
sceneModality = true;
break;
}
@@ -1401,7 +1377,7 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// If nobody could take focus, clear it.
if (!stickyFocus && !setFocus && !sceneModality)
- q->setFocusItem(0, Qt::MouseFocusReason);
+ q->setFocusItem(nullptr, Qt::MouseFocusReason);
// Any item will do.
if (sceneModality && cachedItemsUnderMouse.isEmpty())
@@ -1411,7 +1387,7 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
// candidates one at a time, until the event is accepted. It's accepted by
// default, so the receiver has to explicitly ignore it for it to pass
// through.
- foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
+ for (QGraphicsItem *item : std::as_const(cachedItemsUnderMouse)) {
if (!(item->acceptedMouseButtons() & mouseEvent->button())) {
// Skip items that don't accept the event's mouse button.
continue;
@@ -1430,11 +1406,11 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
if (mouseEvent->type() == QEvent::GraphicsSceneMouseDoubleClick
&& item != lastMouseGrabberItem && lastMouseGrabberItem) {
// If this item is different from the item that received the last
- // mouse event, and mouseEvent is a doubleclick event, then the
+ // mouse event, and mouseEvent is a double-click event, then the
// event is converted to a press. Known limitation:
- // Triple-clicking will not generate a doubleclick, though.
+ // Triple-clicking will not generate a double-click, though.
QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
- mousePress.spont = mouseEvent->spont;
+ mousePress.m_spont = mouseEvent->spontaneous();
mousePress.accept();
mousePress.setButton(mouseEvent->button());
mousePress.setButtons(mouseEvent->buttons());
@@ -1523,7 +1499,7 @@ void QGraphicsScenePrivate::ensureSequentialTopLevelSiblingIndexes()
*/
void QGraphicsScenePrivate::setFont_helper(const QFont &font)
{
- if (this->font == font && this->font.resolve() == font.resolve())
+ if (this->font == font && this->font.resolveMask() == font.resolveMask())
return;
updateFont(font);
}
@@ -1537,7 +1513,7 @@ void QGraphicsScenePrivate::setFont_helper(const QFont &font)
void QGraphicsScenePrivate::resolveFont()
{
QFont naturalFont = QApplication::font();
- naturalFont.resolve(0);
+ naturalFont.setResolveMask(0);
QFont resolvedFont = font.resolve(naturalFont);
updateFont(resolvedFont);
}
@@ -1563,13 +1539,13 @@ void QGraphicsScenePrivate::updateFont(const QFont &font)
// Resolvefont for an item is a noop operation, but
// every item can be a widget, or can have a widget
// childre.
- item->d_ptr->resolveFont(font.resolve());
+ item->d_ptr->resolveFont(font.resolveMask());
}
}
// Send the scene a FontChange event.
QEvent event(QEvent::FontChange);
- QApplication::sendEvent(q, &event);
+ QCoreApplication::sendEvent(q, &event);
}
/*!
@@ -1580,7 +1556,7 @@ void QGraphicsScenePrivate::updateFont(const QFont &font)
*/
void QGraphicsScenePrivate::setPalette_helper(const QPalette &palette)
{
- if (this->palette == palette && this->palette.resolve() == palette.resolve())
+ if (this->palette == palette && this->palette.resolveMask() == palette.resolveMask())
return;
updatePalette(palette);
}
@@ -1593,8 +1569,8 @@ void QGraphicsScenePrivate::setPalette_helper(const QPalette &palette)
*/
void QGraphicsScenePrivate::resolvePalette()
{
- QPalette naturalPalette = QApplication::palette();
- naturalPalette.resolve(0);
+ QPalette naturalPalette = QGuiApplication::palette();
+ naturalPalette.setResolveMask(0);
QPalette resolvedPalette = palette.resolve(naturalPalette);
updatePalette(resolvedPalette);
}
@@ -1620,13 +1596,13 @@ void QGraphicsScenePrivate::updatePalette(const QPalette &palette)
// ResolvePalette for an item is a noop operation, but
// every item can be a widget, or can have a widget
// children.
- item->d_ptr->resolvePalette(palette.resolve());
+ item->d_ptr->resolvePalette(palette.resolveMask());
}
}
// Send the scene a PaletteChange event.
QEvent event(QEvent::PaletteChange);
- QApplication::sendEvent(q, &event);
+ QCoreApplication::sendEvent(q, &event);
}
/*!
@@ -1685,8 +1661,10 @@ QGraphicsScene::~QGraphicsScene()
clear();
// Remove this scene from all associated views.
- for (int j = 0; j < d->views.size(); ++j)
- d->views.at(j)->setScene(0);
+ // Note: d->views is modified by QGraphicsView::setScene, so must make a copy
+ const auto views = d->views;
+ for (auto view : std::as_const(views))
+ view->setScene(nullptr);
}
/*!
@@ -1804,8 +1782,8 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect
// in reverse order).
QList<QGraphicsItem *> itemList = items(sourceRect, Qt::IntersectsItemBoundingRect);
QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
- int numItems = itemList.size();
- for (int i = 0; i < numItems; ++i)
+ const qsizetype numItems = itemList.size();
+ for (qsizetype i = 0; i < numItems; ++i)
itemArray[numItems - i - 1] = itemList.at(i);
itemList.clear();
@@ -1822,7 +1800,7 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect
// Generate the style options
QStyleOptionGraphicsItem *styleOptionArray = new QStyleOptionGraphicsItem[numItems];
- for (int i = 0; i < numItems; ++i)
+ for (qsizetype i = 0; i < numItems; ++i)
itemArray[i]->d_ptr->initStyleOption(&styleOptionArray[i], painterTransform, targetRect.toRect());
// Render the scene.
@@ -1844,7 +1822,7 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect
item discovery functions like items() and itemAt(). Indexing is most
efficient for static scenes (i.e., where items don't move around). For
dynamic scenes, or scenes with many animated items, the index bookkeeping
- can outweight the fast lookup speeds.
+ can outweigh the fast lookup speeds.
For the common case, the default index method BspTreeIndex works fine. If
your scene uses many animations and you are experiencing slowness, you can
@@ -1923,34 +1901,13 @@ void QGraphicsScene::setBspTreeDepth(int depth)
QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index);
if (!bspTree) {
- qWarning("QGraphicsScene::setBspTreeDepth: can not apply if indexing method is not BSP");
+ qWarning("QGraphicsScene::setBspTreeDepth: cannot apply if indexing method is not BSP");
return;
}
bspTree->setBspTreeDepth(depth);
}
/*!
- \property QGraphicsScene::sortCacheEnabled
- \brief whether sort caching is enabled
- \since 4.5
- \obsolete
-
- Since Qt 4.6, this property has no effect.
-*/
-bool QGraphicsScene::isSortCacheEnabled() const
-{
- Q_D(const QGraphicsScene);
- return d->sortCacheEnabled;
-}
-void QGraphicsScene::setSortCacheEnabled(bool enabled)
-{
- Q_D(QGraphicsScene);
- if (d->sortCacheEnabled == enabled)
- return;
- d->sortCacheEnabled = enabled;
-}
-
-/*!
Calculates and returns the bounding rect of all items on the scene. This
function works by iterating over all items, and because of this, it can
be slow for large scenes.
@@ -1980,18 +1937,6 @@ QList<QGraphicsItem *> QGraphicsScene::items(Qt::SortOrder order) const
}
/*!
- \fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode) const
- \obsolete
- \since 4.3
-
- This convenience function is equivalent to calling items(QRectF(\a x, \a y, \a w, \a h), \a mode).
-
- This function is deprecated and returns incorrect results if the scene
- contains items that ignore transformations. Use the overload that takes
- a QTransform instead.
-*/
-
-/*!
\fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const
\overload
\since 4.6
@@ -2140,26 +2085,9 @@ QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item,
}
/*!
- \fn QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position) const
- \overload
- \obsolete
-
- Returns the topmost visible item at the specified \a position, or 0 if
- there are no items at this position.
-
- This function is deprecated and returns incorrect results if the scene
- contains items that ignore transformations. Use the overload that takes
- a QTransform instead.
-
- Note: See items() for a definition of which items are considered visible by this function.
-
- \sa items(), collidingItems(), {QGraphicsItem#Sorting}{Sorting}
-*/
-
-/*!
\since 4.6
- Returns the topmost visible item at the specified \a position, or 0
+ Returns the topmost visible item at the specified \a position, or \nullptr
if there are no items at this position.
\a deviceTransform is the transformation that applies to the view, and needs to
@@ -2173,7 +2101,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
{
const QList<QGraphicsItem *> itemsAtPoint = items(position, Qt::IntersectsItemShape,
Qt::DescendingOrder, deviceTransform);
- return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first();
+ return itemsAtPoint.isEmpty() ? nullptr : itemsAtPoint.first();
}
/*!
@@ -2182,7 +2110,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
\since 4.6
Returns the topmost visible item at the position specified by (\a x, \a
- y), or 0 if there are no items at this position.
+ y), or \nullptr if there are no items at this position.
\a deviceTransform is the transformation that applies to the view, and needs to
be provided if the scene contains items that ignore transformations.
@@ -2194,24 +2122,6 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
*/
/*!
- \fn QGraphicsScene::itemAt(qreal x, qreal y) const
- \overload
- \obsolete
-
- Returns the topmost visible item at the position specified by (\a x, \a
- y), or 0 if there are no items at this position.
-
- This convenience function is equivalent to calling \c
- {itemAt(QPointF(x, y))}.
-
- This function is deprecated and returns incorrect results if the scene
- contains items that ignore transformations. Use the overload that takes
- a QTransform instead.
-
- Note: See items() for a definition of which items are considered visible by this function.
-*/
-
-/*!
Returns a list of all currently selected items. The items are
returned in no particular order.
@@ -2224,7 +2134,7 @@ QList<QGraphicsItem *> QGraphicsScene::selectedItems() const
// Optimization: Lazily removes items that are not selected.
QGraphicsScene *that = const_cast<QGraphicsScene *>(this);
QSet<QGraphicsItem *> actuallySelectedSet;
- foreach (QGraphicsItem *item, that->d_func()->selectedItems) {
+ for (QGraphicsItem *item : std::as_const(that->d_func()->selectedItems)) {
if (item->isSelected())
actuallySelectedSet << item;
}
@@ -2264,25 +2174,7 @@ QPainterPath QGraphicsScene::selectionArea() const
*/
void QGraphicsScene::setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform)
{
- setSelectionArea(path, Qt::IntersectsItemShape, deviceTransform);
-}
-
-/*!
- \overload
- \since 4.6
-
- Sets the selection area to \a path using \a mode to determine if items are
- included in the selection area.
-
- \a deviceTransform is the transformation that applies to the view, and needs to
- be provided if the scene contains items that ignore transformations.
-
- \sa clearSelection(), selectionArea()
-*/
-void QGraphicsScene::setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode,
- const QTransform &deviceTransform)
-{
- setSelectionArea(path, Qt::ReplaceSelection, mode, deviceTransform);
+ setSelectionArea(path, Qt::ReplaceSelection, Qt::IntersectsItemShape, deviceTransform);
}
/*!
@@ -2332,7 +2224,7 @@ void QGraphicsScene::setSelectionArea(const QPainterPath &path,
switch (selectionOperation) {
case Qt::ReplaceSelection:
// Deselect all items outside path.
- foreach (QGraphicsItem *item, unselectItems) {
+ for (QGraphicsItem *item : std::as_const(unselectItems)) {
item->setSelected(false);
changed = true;
}
@@ -2341,7 +2233,7 @@ void QGraphicsScene::setSelectionArea(const QPainterPath &path,
break;
}
- // Reenable emitting selectionChanged() for individual items.
+ // Re-enable emitting selectionChanged() for individual items.
--d->selectionChanging;
if (!d->selectionChanging && changed)
@@ -2359,13 +2251,20 @@ void QGraphicsScene::clearSelection()
// Disable emitting selectionChanged
++d->selectionChanging;
- bool changed = !d->selectedItems.isEmpty();
+ // iterate over a copy, as clearing selection might invalidate selectedItems
+ const auto selectedItems = d->selectedItems;
+ QSet<QGraphicsItem *> stillSelectedSet;
- foreach (QGraphicsItem *item, d->selectedItems)
+ for (QGraphicsItem *item : selectedItems) {
item->setSelected(false);
- d->selectedItems.clear();
+ // items might override itemChange to prevent deselection
+ if (item->isSelected())
+ stillSelectedSet << item;
+ }
+ const bool changed = stillSelectedSet != selectedItems;
+ d->selectedItems = stillSelectedSet;
- // Reenable emitting selectionChanged() for individual items.
+ // Re-enable emitting selectionChanged() for individual items.
--d->selectionChanging;
if (!d->selectionChanging && changed)
@@ -2422,7 +2321,7 @@ QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *>
}
// Find the common ancestor for all items
- QGraphicsItem *commonAncestor = 0;
+ QGraphicsItem *commonAncestor = nullptr;
if (!ancestors.isEmpty()) {
while (n < items.size()) {
int commonIndex = -1;
@@ -2436,7 +2335,7 @@ QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *>
} while ((parent = parent->parentItem()));
if (commonIndex == -1) {
- commonAncestor = 0;
+ commonAncestor = nullptr;
break;
}
@@ -2470,7 +2369,7 @@ void QGraphicsScene::destroyItemGroup(QGraphicsItemGroup *group)
}
/*!
- Adds or moves the \a item and all its childen to this scene.
+ Adds or moves the \a item and all its children to this scene.
This scene takes ownership of the \a item.
If the item is visible (i.e., QGraphicsItem::isVisible() returns
@@ -2520,22 +2419,18 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
return;
}
- // QDeclarativeItems do not rely on initial itemChanged message, as the componentComplete
- // function allows far more opportunity for delayed-construction optimization.
- if (!item->d_ptr->isDeclarativeItem) {
- if (d->unpolishedItems.isEmpty()) {
- QMetaMethod method = metaObject()->method(d->polishItemsIndex);
- method.invoke(this, Qt::QueuedConnection);
- }
- d->unpolishedItems.append(item);
- item->d_ptr->pendingPolish = true;
+ if (d->unpolishedItems.isEmpty()) {
+ QMetaMethod method = metaObject()->method(d->polishItemsIndex);
+ method.invoke(this, Qt::QueuedConnection);
}
+ d->unpolishedItems.append(item);
+ item->d_ptr->pendingPolish = true;
// Detach this item from its parent if the parent's scene is different
// from this scene.
if (QGraphicsItem *itemParent = item->d_ptr->parent) {
if (itemParent->d_ptr->scene != this)
- item->setParentItem(0);
+ item->setParentItem(nullptr);
}
// Add the item to this scene
@@ -2558,8 +2453,16 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
++d->selectionChanging;
int oldSelectedItemSize = d->selectedItems.size();
- // Enable mouse tracking if the item accepts hover events or has a cursor set.
- if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) {
+ // Enable mouse tracking if we haven't already done so, and the item needs it.
+ // We cannot use itemAcceptsHoverEvents_helper() here, since we need to enable
+ // mouse tracking also if this item is temporarily blocked by a modal panel.
+
+ auto needsMouseTracking = [](const QGraphicsItemPrivate *item) {
+ return item->acceptsHover
+ || (item->isWidget && static_cast<const QGraphicsWidgetPrivate *>(item)->hasDecoration());
+ };
+
+ if (d->allItemsIgnoreHoverEvents && needsMouseTracking(item->d_ptr.data())) {
d->allItemsIgnoreHoverEvents = false;
d->enableMouseTrackingOnViews();
}
@@ -2578,9 +2481,9 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
}
#ifndef QT_NO_GESTURES
- const auto gestures = item->d_ptr->gestureContext.keys(); // FIXME: iterate over hash directly?
- for (Qt::GestureType gesture : gestures)
- d->grabGesture(item, gesture);
+ for (auto it = item->d_ptr->gestureContext.constBegin();
+ it != item->d_ptr->gestureContext.constEnd(); ++it)
+ d->grabGesture(item, it.key());
#endif
// Update selection lists
@@ -2611,15 +2514,15 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
// Add all children recursively
item->d_ptr->ensureSortedChildren();
- for (int i = 0; i < item->d_ptr->children.size(); ++i)
- addItem(item->d_ptr->children.at(i));
+ for (auto child : std::as_const(item->d_ptr->children))
+ addItem(child);
// Resolve font and palette.
- item->d_ptr->resolveFont(d->font.resolve());
- item->d_ptr->resolvePalette(d->palette.resolve());
+ item->d_ptr->resolveFont(d->font.resolveMask());
+ item->d_ptr->resolvePalette(d->palette.resolveMask());
- // Reenable selectionChanged() for individual items
+ // Re-enable selectionChanged() for individual items
--d->selectionChanging;
if (!d->selectionChanging && d->selectedItems.size() != oldSelectedItemSize)
emit selectionChanged();
@@ -2803,7 +2706,7 @@ QGraphicsPolygonItem *QGraphicsScene::addPolygon(const QPolygonF &polygon,
Note that the item's geometry is provided in item coordinates, and its
position is initialized to (0, 0). For example, if a QRect(50, 50, 100,
100) is added, its top-left corner will be at (50, 50) relative to the
- origin in the items coordinate system.
+ origin in the item's coordinate system.
If the item is visible (i.e., QGraphicsItem::isVisible() returns \c true),
QGraphicsScene will emit changed() once control goes back to the event
@@ -2886,14 +2789,14 @@ QGraphicsSimpleTextItem *QGraphicsScene::addSimpleText(const QString &text, cons
Note that widgets with the Qt::WA_PaintOnScreen widget attribute
set and widgets that wrap an external application or controller
- are not supported. Examples are QGLWidget and QAxWidget.
+ are not supported. Examples are QOpenGLWidget and QAxWidget.
\sa addEllipse(), addLine(), addPixmap(), addPixmap(), addRect(),
addText(), addSimpleText(), addItem()
*/
QGraphicsProxyWidget *QGraphicsScene::addWidget(QWidget *widget, Qt::WindowFlags wFlags)
{
- QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, wFlags);
+ QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(nullptr, wFlags);
proxy->setWidget(widget);
addItem(proxy);
return proxy;
@@ -2926,7 +2829,7 @@ void QGraphicsScene::removeItem(QGraphicsItem *item)
const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange,
QVariant::fromValue<QGraphicsScene *>(0)));
QGraphicsScene *targetScene = qvariant_cast<QGraphicsScene *>(newSceneVariant);
- if (targetScene != 0 && targetScene != this) {
+ if (targetScene != nullptr && targetScene != this) {
targetScene->addItem(item);
return;
}
@@ -2941,9 +2844,9 @@ void QGraphicsScene::removeItem(QGraphicsItem *item)
/*!
When the scene is active, this functions returns the scene's current focus
- item, or 0 if no item currently has focus. When the scene is inactive, this
- functions returns the item that will gain input focus when the scene becomes
- active.
+ item, or \nullptr if no item currently has focus. When the scene is inactive,
+ this functions returns the item that will gain input focus when the scene
+ becomes active.
The focus item receives keyboard input when the scene receives a
key event.
@@ -2961,12 +2864,12 @@ QGraphicsItem *QGraphicsScene::focusItem() const
focusReason, after removing focus from any previous item that may have had
focus.
- If \a item is 0, or if it either does not accept focus (i.e., it does not
+ If \a item is \nullptr, or if it either does not accept focus (i.e., it does not
have the QGraphicsItem::ItemIsFocusable flag enabled), or is not visible
or not enabled, this function only removes focus from any previous
focusitem.
- If item is not 0, and the scene does not currently have focus (i.e.,
+ If item is not \nullptr, and the scene does not currently have focus (i.e.,
hasFocus() returns \c false), this function will call setFocus()
automatically.
@@ -2983,7 +2886,7 @@ void QGraphicsScene::setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReas
/*!
Returns \c true if the scene has focus; otherwise returns \c false. If the scene
- has focus, it will will forward key events from QKeyEvent to any item that
+ has focus, it will forward key events from QKeyEvent to any item that
has focus.
\sa setFocus(), setFocusItem()
@@ -3028,7 +2931,7 @@ void QGraphicsScene::clearFocus()
if (d->hasFocus) {
d->hasFocus = false;
d->passiveFocusItem = d->focusItem;
- setFocusItem(0, Qt::OtherFocusReason);
+ setFocusItem(nullptr, Qt::OtherFocusReason);
}
}
@@ -3062,9 +2965,9 @@ bool QGraphicsScene::stickyFocus() const
}
/*!
- Returns the current mouse grabber item, or 0 if no item is currently
- grabbing the mouse. The mouse grabber item is the item that receives all
- mouse events sent to the scene.
+ Returns the current mouse grabber item, or \nullptr if no item is
+ currently grabbing the mouse. The mouse grabber item is the item
+ that receives all mouse events sent to the scene.
An item becomes a mouse grabber when it receives and accepts a
mouse press event, and it stays the mouse grabber until either of
@@ -3114,7 +3017,7 @@ void QGraphicsScene::setBackgroundBrush(const QBrush &brush)
{
Q_D(QGraphicsScene);
d->backgroundBrush = brush;
- foreach (QGraphicsView *view, d->views) {
+ for (QGraphicsView *view : std::as_const(d->views)) {
view->resetCachedContent();
view->viewport()->update();
}
@@ -3172,13 +3075,13 @@ QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const
return QVariant();
const QTransform matrix = d->focusItem->sceneTransform();
QVariant value = d->focusItem->inputMethodQuery(query);
- if (value.type() == QVariant::RectF)
+ if (value.userType() == QMetaType::QRectF)
value = matrix.mapRect(value.toRectF());
- else if (value.type() == QVariant::PointF)
+ else if (value.userType() == QMetaType::QPointF)
value = matrix.map(value.toPointF());
- else if (value.type() == QVariant::Rect)
+ else if (value.userType() == QMetaType::QRect)
value = matrix.mapRect(value.toRect());
- else if (value.type() == QVariant::Point)
+ else if (value.userType() == QMetaType::QPoint)
value = matrix.map(value.toPoint());
return value;
}
@@ -3203,22 +3106,20 @@ void QGraphicsScene::update(const QRectF &rect)
d->updatedRects.clear();
if (directUpdates) {
// Update all views.
- for (int i = 0; i < d->views.size(); ++i)
- d->views.at(i)->d_func()->fullUpdatePending = true;
+ for (auto view : std::as_const(d->views))
+ view->d_func()->fullUpdatePending = true;
}
} else {
if (directUpdates) {
// Update all views.
- for (int i = 0; i < d->views.size(); ++i) {
- QGraphicsView *view = d->views.at(i);
+ for (auto view : std::as_const(d->views)) {
if (view->isTransformed())
view->d_func()->updateRectF(view->viewportTransform().mapRect(rect));
else
view->d_func()->updateRectF(rect);
}
} else {
- if (!d->updatedRects.contains(rect))
- d->updatedRects << rect;
+ d->updatedRects.insert(rect);
}
}
@@ -3322,6 +3223,9 @@ void QGraphicsScene::advance()
\l{QWidget::}{enterEvent()} and \l{QWidget::}{leaveEvent()}. Use this
function to obtain those events instead.
+ Returns \c true if \a event has been recognized and processed; otherwise,
+ returns \c false.
+
\sa contextMenuEvent(), keyPressEvent(), keyReleaseEvent(),
mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(),
mouseDoubleClickEvent(), focusInEvent(), focusOutEvent()
@@ -3349,6 +3253,7 @@ bool QGraphicsScene::event(QEvent *event)
// ### this should only be cleared if we received a new mouse move event,
// which relies on us fixing the replay mechanism in QGraphicsView.
d->cachedItemsUnderMouse.clear();
+ break;
default:
break;
}
@@ -3437,9 +3342,15 @@ bool QGraphicsScene::event(QEvent *event)
break;
}
case QEvent::Leave:
- // hackieshly unpacking the viewport pointer from the leave event.
- d->leaveScene(reinterpret_cast<QWidget *>(event->d));
+ Q_ASSERT_X(false, "QGraphicsScene::event",
+ "QGraphicsScene must not receive QEvent::Leave, use GraphicsSceneLeave");
break;
+ case QEvent::GraphicsSceneLeave:
+ {
+ auto *leaveEvent = static_cast<QGraphicsSceneEvent*>(event);
+ d->leaveScene(leaveEvent->widget());
+ break;
+ }
case QEvent::GraphicsSceneHelp:
helpEvent(static_cast<QGraphicsSceneHelpEvent *>(event));
break;
@@ -3472,7 +3383,7 @@ bool QGraphicsScene::event(QEvent *event)
// Deactivate the active panel (but keep it so we can
// reactivate it later).
QGraphicsItem *lastActivePanel = d->activePanel;
- d->setActivePanelHelper(0, true);
+ d->setActivePanelHelper(nullptr, true);
d->lastActivePanel = lastActivePanel;
} else {
// Activate all toplevel items.
@@ -3543,10 +3454,10 @@ bool QGraphicsScene::eventFilter(QObject *watched, QEvent *event)
switch (event->type()) {
case QEvent::ApplicationPaletteChange:
- QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange));
+ QCoreApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange));
break;
case QEvent::ApplicationFontChange:
- QApplication::postEvent(this, new QEvent(QEvent::ApplicationFontChange));
+ QCoreApplication::postEvent(this, new QEvent(QEvent::ApplicationFontChange));
break;
default:
break;
@@ -3601,7 +3512,7 @@ void QGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMen
void QGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
Q_D(QGraphicsScene);
- d->dragDropItem = 0;
+ d->dragDropItem = nullptr;
d->lastDropAction = Qt::IgnoreAction;
event->accept();
}
@@ -3685,7 +3596,7 @@ void QGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
QGraphicsSceneDragDropEvent dragLeave(QEvent::GraphicsSceneDragLeave);
d->cloneDragDropEvent(&dragLeave, event);
d->sendDragDropEvent(d->dragDropItem, &dragLeave);
- d->dragDropItem = 0;
+ d->dragDropItem = nullptr;
}
// Propagate
event->setDropAction(Qt::IgnoreAction);
@@ -3705,7 +3616,7 @@ void QGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
if (d->dragDropItem) {
// Leave the last drag drop item
d->sendDragDropEvent(d->dragDropItem, event);
- d->dragDropItem = 0;
+ d->dragDropItem = nullptr;
}
}
@@ -3723,7 +3634,7 @@ void QGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event)
if (d->dragDropItem) {
// Drop on the last drag drop item
d->sendDragDropEvent(d->dragDropItem, event);
- d->dragDropItem = 0;
+ d->dragDropItem = nullptr;
}
}
@@ -3773,7 +3684,7 @@ void QGraphicsScene::focusOutEvent(QFocusEvent *focusEvent)
Q_D(QGraphicsScene);
d->hasFocus = false;
d->passiveFocusItem = d->focusItem;
- setFocusItem(0, focusEvent->reason());
+ setFocusItem(nullptr, focusEvent->reason());
// Remove all popups when the scene loses focus.
if (!d->popupWidgets.isEmpty())
@@ -3797,25 +3708,24 @@ void QGraphicsScene::focusOutEvent(QFocusEvent *focusEvent)
*/
void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent)
{
-#ifdef QT_NO_TOOLTIP
+#if !QT_CONFIG(tooltip)
Q_UNUSED(helpEvent);
#else
// Find the first item that does tooltips
Q_D(QGraphicsScene);
- QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(),
- helpEvent->scenePos(),
- helpEvent->widget());
- QGraphicsItem *toolTipItem = 0;
- for (int i = 0; i < itemsAtPos.size(); ++i) {
- QGraphicsItem *tmp = itemsAtPos.at(i);
- if (tmp->d_func()->isProxyWidget()) {
+ const QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(),
+ helpEvent->scenePos(),
+ helpEvent->widget());
+ QGraphicsItem *toolTipItem = nullptr;
+ for (auto item : itemsAtPos) {
+ if (item->d_func()->isProxyWidget()) {
// if the item is a proxy widget, the event is forwarded to it
- sendEvent(tmp, helpEvent);
+ sendEvent(item, helpEvent);
if (helpEvent->isAccepted())
return;
}
- if (!tmp->toolTip().isEmpty()) {
- toolTipItem = tmp;
+ if (!item->toolTip().isEmpty()) {
+ toolTipItem = item;
break;
}
}
@@ -3863,9 +3773,8 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
hoverEvent->widget());
}
- QGraphicsItem *item = 0;
- for (int i = 0; i < cachedItemsUnderMouse.size(); ++i) {
- QGraphicsItem *tmp = cachedItemsUnderMouse.at(i);
+ QGraphicsItem *item = nullptr;
+ for (auto tmp : std::as_const(cachedItemsUnderMouse)) {
if (itemAcceptsHoverEvents_helper(tmp)) {
item = tmp;
break;
@@ -3874,13 +3783,13 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
// Find the common ancestor item for the new topmost hoverItem and the
// last item in the hoverItem list.
- QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.constLast()) : 0;
+ QGraphicsItem *commonAncestorItem = (item && !hoverItems.isEmpty()) ? item->commonAncestorItem(hoverItems.constLast()) : nullptr;
while (commonAncestorItem && !itemAcceptsHoverEvents_helper(commonAncestorItem))
commonAncestorItem = commonAncestorItem->parentItem();
if (commonAncestorItem && commonAncestorItem->panel() != item->panel()) {
// The common ancestor isn't in the same panel as the two hovered
// items.
- commonAncestorItem = 0;
+ commonAncestorItem = nullptr;
}
// Check if the common ancestor item is known.
@@ -3930,7 +3839,7 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
*/
void QGraphicsScenePrivate::leaveScene(QWidget *viewport)
{
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
QToolTip::hideText();
#endif
QGraphicsView *view = qobject_cast<QGraphicsView *>(viewport->parent());
@@ -4110,7 +4019,7 @@ void QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
if (d->lastMouseGrabberItemHasImplicitMouseGrab)
d->mouseGrabberItems.constLast()->ungrabMouse();
} else {
- d->lastMouseGrabberItem = 0;
+ d->lastMouseGrabberItem = nullptr;
}
// Generate a hoverevent
@@ -4122,15 +4031,15 @@ void QGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
/*!
This event handler, for event \a mouseEvent, can be reimplemented
- in a subclass to receive mouse doubleclick events for the scene.
+ in a subclass to receive mouse double-click events for the scene.
If someone doubleclicks on the scene, the scene will first receive
a mouse press event, followed by a release event (i.e., a click),
- then a doubleclick event, and finally a release event. If the
- doubleclick event is delivered to a different item than the one
+ then a double-click event, and finally a release event. If the
+ double-click event is delivered to a different item than the one
that received the first press and release, it will be delivered as
a press event. However, tripleclick events are not delivered as
- doubleclick events in this case.
+ double-click events in this case.
The default implementation is similar to mousePressEvent().
@@ -4165,24 +4074,16 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
wheelEvent->scenePos(),
wheelEvent->widget());
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
- // On Mac, ignore the event if the first item under the mouse is not the last opened
- // popup (or one of its descendant)
- if (!d->popupWidgets.isEmpty() && !wheelCandidates.isEmpty() && wheelCandidates.first() != d->popupWidgets.back() && !d->popupWidgets.back()->isAncestorOf(wheelCandidates.first())) {
- wheelEvent->accept();
- return;
- }
-#else
// Find the first popup under the mouse (including the popup's descendants) starting from the last.
// Remove all popups after the one found, or all or them if no popup is under the mouse.
// Then continue with the event.
QList<QGraphicsWidget *>::const_iterator iter = d->popupWidgets.constEnd();
- while (--iter >= d->popupWidgets.constBegin() && !wheelCandidates.isEmpty()) {
+ while (iter > d->popupWidgets.constBegin() && !wheelCandidates.isEmpty()) {
+ --iter;
if (wheelCandidates.first() == *iter || (*iter)->isAncestorOf(wheelCandidates.first()))
break;
d->removePopup(*iter);
}
-#endif
bool hasSetFocus = false;
for (QGraphicsItem *item : wheelCandidates) {
@@ -4219,8 +4120,12 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
void QGraphicsScene::inputMethodEvent(QInputMethodEvent *event)
{
Q_D(QGraphicsScene);
- if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
+ if (d->focusItem && (d->focusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
d->sendEvent(d->focusItem, event);
+ return;
+ }
+ if (d->lastFocusItem && d->lastFocusItem != d->focusItem && (d->lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod))
+ d->sendEvent(d->lastFocusItem, event);
}
/*!
@@ -4351,7 +4256,7 @@ static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion &
pixmapPainter.setWorldTransform(itemToPixmap, true);
// Render.
- _q_paintItem(item, &pixmapPainter, option, 0, false, painterStateProtection);
+ _q_paintItem(item, &pixmapPainter, option, nullptr, false, painterStateProtection);
pixmapPainter.end();
if (!subPix.isNull()) {
@@ -4404,11 +4309,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
QGraphicsItem::CacheMode cacheMode = QGraphicsItem::CacheMode(itemd->cacheMode);
// Render directly, using no cache.
- if (cacheMode == QGraphicsItem::NoCache
-#if 0 // Used to be included in Qt4 for Q_WS_X11
- || !X11->use_xrender
-#endif
- ) {
+ if (cacheMode == QGraphicsItem::NoCache) {
_q_paintItem(static_cast<QGraphicsWidget *>(item), painter, option, widget, true, painterStateProtection);
return;
}
@@ -4496,10 +4397,9 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
QRegion pixmapExposed;
QRectF exposedRect;
if (!itemCache->allExposed) {
- for (int i = 0; i < itemCache->exposed.size(); ++i) {
- QRectF r = itemCache->exposed.at(i);
- exposedRect |= r;
- pixmapExposed += itemToPixmap.mapRect(r).toAlignedRect();
+ for (const auto &rect : std::as_const(itemCache->exposed)) {
+ exposedRect |= rect;
+ pixmapExposed += itemToPixmap.mapRect(rect).toAlignedRect();
}
} else {
exposedRect = brect;
@@ -4657,9 +4557,8 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
// Map the item's logical expose to pixmap coordinates.
QRegion pixmapExposed = scrollExposure;
if (!itemCache->allExposed) {
- const QVector<QRectF> &exposed = itemCache->exposed;
- for (int i = 0; i < exposed.size(); ++i)
- pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1);
+ for (const auto &rect : std::as_const(itemCache->exposed))
+ pixmapExposed += itemToPixmap.mapRect(rect).toRect().adjusted(-1, -1, 1, 1);
}
// Calculate the style option's exposedRect.
@@ -4667,11 +4566,10 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
if (itemCache->allExposed) {
br = item->boundingRect();
} else {
- const QVector<QRectF> &exposed = itemCache->exposed;
- for (int i = 0; i < exposed.size(); ++i)
- br |= exposed.at(i);
+ for (const auto &rect : std::as_const(itemCache->exposed))
+ br |= rect;
QTransform pixmapToItem = itemToPixmap.inverted();
- for (const QRect &r : scrollExposure)
+ for (const QRect &r : std::as_const(scrollExposure))
br |= pixmapToItem.mapRect(r);
}
styleOptionTmp = *option;
@@ -4724,8 +4622,8 @@ void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const
exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect);
}
const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder);
- for (int i = 0; i < tli.size(); ++i)
- drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget);
+ for (const auto subTree : tli)
+ drawSubtreeRecursive(subTree, painter, viewTransform, exposedRegion, widget);
}
void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter,
@@ -4749,7 +4647,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
return;
QTransform transform(Qt::Uninitialized);
- QTransform *transformPtr = 0;
+ QTransform *transformPtr = nullptr;
bool translateOnlyTransform = false;
#define ENSURE_TRANSFORM_PTR \
if (!transformPtr) { \
@@ -4807,7 +4705,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
if (itemIsTooSmallToRender || itemIsOutsideVisibleRect) {
// We cannot simply use !drawItem here. If we did it is possible
- // to enter the outter if statement with drawItem == false and minimumRenderSize > 0
+ // to enter the outer if statement with drawItem == false and minimumRenderSize > 0
// and finally end up inside this inner if, even though none of the above two
// conditions are met. In that case we should not return from this function
// but call draw() instead.
@@ -4859,7 +4757,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
item->d_ptr->graphicsEffect->draw(painter);
painter->setWorldTransform(restoreTransform);
- sourced->info = 0;
+ sourced->info = nullptr;
} else
#endif // QT_CONFIG(graphicseffect)
{
@@ -4894,9 +4792,11 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
qreal opacity, const QTransform *effectTransform,
bool wasDirtyParentSceneTransform, bool drawItem)
{
+ const auto &children = item->d_ptr->children;
+
const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity);
const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
- const bool itemHasChildren = !item->d_ptr->children.isEmpty();
+ const bool itemHasChildren = !children.isEmpty();
bool setChildClip = itemClipsChildrenToShape;
bool itemHasChildrenStackedBehind = false;
@@ -4908,7 +4808,7 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
item->d_ptr->ensureSortedChildren();
// Items with the 'ItemStacksBehindParent' flag are put in front of the list
// so all we have to do is to check the first item.
- itemHasChildrenStackedBehind = (item->d_ptr->children.at(0)->d_ptr->flags
+ itemHasChildrenStackedBehind = (children.at(0)->d_ptr->flags
& QGraphicsItem::ItemStacksBehindParent);
if (itemHasChildrenStackedBehind) {
@@ -4918,8 +4818,8 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
}
// Draw children behind
- for (i = 0; i < item->d_ptr->children.size(); ++i) {
- QGraphicsItem *child = item->d_ptr->children.at(i);
+ for (i = 0; i < children.size(); ++i) {
+ QGraphicsItem *child = children.at(i);
if (wasDirtyParentSceneTransform)
child->d_ptr->dirtySceneTransform = 1;
if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent))
@@ -4937,7 +4837,7 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
Q_ASSERT(!(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents));
Q_ASSERT(transformPtr);
item->d_ptr->initStyleOption(&styleOptionTmp, *transformPtr, exposedRegion
- ? *exposedRegion : QRegion(), exposedRegion == 0);
+ ? *exposedRegion : QRegion(), exposedRegion == nullptr);
const bool itemClipsToShape = item->d_ptr->flags & QGraphicsItem::ItemClipsToShape;
bool restorePainterClip = false;
@@ -4997,8 +4897,8 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
if (setChildClip)
setClip(painter, item);
- for (; i < item->d_ptr->children.size(); ++i) {
- QGraphicsItem *child = item->d_ptr->children.at(i);
+ for (; i < children.size(); ++i) {
+ QGraphicsItem *child = children.at(i);
if (wasDirtyParentSceneTransform)
child->d_ptr->dirtySceneTransform = 1;
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
@@ -5076,8 +4976,8 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b
return;
}
- for (int i = 0; i < views.size(); ++i) {
- QGraphicsViewPrivate *viewPrivate = views.at(i)->d_func();
+ for (auto view : std::as_const(views)) {
+ QGraphicsViewPrivate *viewPrivate = view->d_func();
QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport);
rect.translate(viewPrivate->dirtyScrollOffset);
viewPrivate->updateRect(rect);
@@ -5232,8 +5132,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
QRectF dirtyRect;
bool uninitializedDirtyRect = true;
- for (int j = 0; j < views.size(); ++j) {
- QGraphicsView *view = views.at(j);
+ for (auto view : std::as_const(views)) {
QGraphicsViewPrivate *viewPrivate = view->d_func();
QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport];
if (viewPrivate->fullUpdatePending
@@ -5291,8 +5190,8 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
const bool bypassUpdateClip = !itemHasContents && wasDirtyParentViewBoundingRects;
if (itemClipsChildrenToShape && !bypassUpdateClip) {
// Make sure child updates are clipped to the item's bounding rect.
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->setUpdateClip(item);
+ for (auto view : std::as_const(views))
+ view->d_func()->setUpdateClip(item);
}
if (!dirtyAncestorContainsChildren) {
dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending
@@ -5301,8 +5200,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
const bool allChildrenDirty = item->d_ptr->allChildrenDirty;
const bool parentIgnoresVisible = item->d_ptr->ignoreVisible;
const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity;
- for (int i = 0; i < item->d_ptr->children.size(); ++i) {
- QGraphicsItem *child = item->d_ptr->children.at(i);
+ for (auto child : std::as_const(item->d_ptr->children)) {
if (wasDirtyParentSceneTransform)
child->d_ptr->dirtySceneTransform = 1;
if (wasDirtyParentViewBoundingRects)
@@ -5322,8 +5220,8 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
if (itemClipsChildrenToShape) {
// Reset updateClip.
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->setUpdateClip(0);
+ for (auto view : std::as_const(views))
+ view->d_func()->setUpdateClip(nullptr);
}
} else if (wasDirtyParentSceneTransform) {
item->d_ptr->invalidateChildrenSceneTransform();
@@ -5333,7 +5231,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
}
/*!
- \obsolete
+ \deprecated
Paints the given \a items using the provided \a painter, after the
background has been drawn, and before the foreground has been
@@ -5355,7 +5253,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
Example:
- \snippet graphicssceneadditemsnippet.cpp 0
+ \snippet graphicssceneadditem/graphicssceneadditemsnippet.cpp 0
Since Qt 4.6, this function is not called anymore unless
the QGraphicsView::IndirectPainting flag is given as an Optimization
@@ -5379,7 +5277,7 @@ void QGraphicsScene::drawItems(QPainter *painter,
// Determine view, expose and flags.
QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
- QRegion *expose = 0;
+ QRegion *expose = nullptr;
const quint32 oldRectAdjust = d->rectAdjust;
if (view) {
d->updateAll = false;
@@ -5403,8 +5301,8 @@ void QGraphicsScene::drawItems(QPainter *painter,
d->rectAdjust = oldRectAdjust;
// Reset discovery bits.
- for (int i = 0; i < topLevelItems.size(); ++i)
- topLevelItems.at(i)->d_ptr->itemDiscovered = 0;
+ for (auto topLevelItem : std::as_const(topLevelItems))
+ topLevelItem->d_ptr->itemDiscovered = 0;
painter->setWorldTransform(viewTransform);
painter->setOpacity(opacity);
@@ -5463,7 +5361,7 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
}
// The item must be a widget.
- QGraphicsWidget *widget = 0;
+ QGraphicsWidget *widget = nullptr;
if (!item) {
widget = next ? d->tabFocusFirst : d->tabFocusFirst->d_func()->focusPrev;
} else {
@@ -5479,7 +5377,7 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
// Run around the focus chain until we find a widget that can take tab focus.
do {
if (widget->flags() & QGraphicsItem::ItemIsFocusable
- && widget->isEnabled() && widget->isVisibleTo(0)
+ && widget->isEnabled() && widget->isVisibleTo(nullptr)
&& (widget->focusPolicy() & Qt::TabFocus)
&& (!item || !item->isPanel() || item->isAncestorOf(widget))
) {
@@ -5547,11 +5445,11 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
\a oldFocusItem is a pointer to the item that previously had focus, or
0 if no item had focus before the signal was emitted. \a newFocusItem
- is a pointer to the item that gained input focus, or 0 if focus was lost.
+ is a pointer to the item that gained input focus, or \nullptr if focus was lost.
\a reason is the reason for the focus change (e.g., if the scene was
deactivated while an input field had focus, \a oldFocusItem would point
- to the input field item, \a newFocusItem would be 0, and \a reason would be
- Qt::ActiveWindowFocusReason.
+ to the input field item, \a newFocusItem would be \nullptr, and \a reason
+ would be Qt::ActiveWindowFocusReason.
*/
/*!
@@ -5582,7 +5480,7 @@ QStyle *QGraphicsScene::style() const
the style for all widgets in the scene that do not have a style explicitly
assigned to them.
- If \a style is 0, QGraphicsScene will revert to QApplication::style().
+ If \a style is \nullptr, QGraphicsScene will revert to QApplication::style().
\sa style()
*/
@@ -5600,7 +5498,7 @@ void QGraphicsScene::setStyle(QStyle *style)
// Notify the scene.
QEvent event(QEvent::StyleChange);
- QApplication::sendEvent(this, &event);
+ QCoreApplication::sendEvent(this, &event);
// Notify all widgets that don't have a style explicitly set.
const auto items_ = items();
@@ -5608,7 +5506,7 @@ void QGraphicsScene::setStyle(QStyle *style)
if (item->isWidget()) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
if (!widget->testAttribute(Qt::WA_SetStyle))
- QApplication::sendEvent(widget, &event);
+ QCoreApplication::sendEvent(widget, &event);
}
}
}
@@ -5645,7 +5543,7 @@ void QGraphicsScene::setFont(const QFont &font)
{
Q_D(QGraphicsScene);
QFont naturalFont = QApplication::font();
- naturalFont.resolve(0);
+ naturalFont.setResolveMask(0);
QFont resolvedFont = font.resolve(naturalFont);
d->setFont_helper(resolvedFont);
}
@@ -5681,8 +5579,8 @@ QPalette QGraphicsScene::palette() const
void QGraphicsScene::setPalette(const QPalette &palette)
{
Q_D(QGraphicsScene);
- QPalette naturalPalette = QApplication::palette();
- naturalPalette.resolve(0);
+ QPalette naturalPalette = QGuiApplication::palette();
+ naturalPalette.setResolveMask(0);
QPalette resolvedPalette = palette.resolve(naturalPalette);
d->setPalette_helper(resolvedPalette);
}
@@ -5703,7 +5601,8 @@ bool QGraphicsScene::isActive() const
/*!
\since 4.6
- Returns the current active panel, or 0 if no panel is currently active.
+ Returns the current active panel, or \nullptr if no panel is
+ currently active.
\sa QGraphicsScene::setActivePanel()
*/
@@ -5720,7 +5619,7 @@ QGraphicsItem *QGraphicsScene::activePanel() const
deactivate any currently active panel.
If the scene is currently inactive, \a item remains inactive until the
- scene becomes active (or, ir \a item is 0, no item will be activated).
+ scene becomes active (or, ir \a item is \nullptr, no item will be activated).
\sa activePanel(), isActive(), QGraphicsItem::isActive()
*/
@@ -5733,8 +5632,8 @@ void QGraphicsScene::setActivePanel(QGraphicsItem *item)
/*!
\since 4.4
- Returns the current active window, or 0 if no window is currently
- active.
+ Returns the current active window, or \nullptr if no window is
+ currently active.
\sa QGraphicsScene::setActiveWindow()
*/
@@ -5743,7 +5642,7 @@ QGraphicsWidget *QGraphicsScene::activeWindow() const
Q_D(const QGraphicsScene);
if (d->activePanel && d->activePanel->isWindow())
return static_cast<QGraphicsWidget *>(d->activePanel);
- return 0;
+ return nullptr;
}
/*!
@@ -5763,7 +5662,7 @@ void QGraphicsScene::setActiveWindow(QGraphicsWidget *widget)
}
// Activate the widget's panel (all windows are panels).
- QGraphicsItem *panel = widget ? widget->panel() : 0;
+ QGraphicsItem *panel = widget ? widget->panel() : nullptr;
setActivePanel(panel);
// Raise
@@ -5895,9 +5794,9 @@ void QGraphicsScenePrivate::addView(QGraphicsView *view)
{
views << view;
#ifndef QT_NO_GESTURES
- const auto gestures = grabbedGestures.keys();
- for (Qt::GestureType gesture : gestures)
- view->viewport()->grabGesture(gesture);
+ for (auto it = grabbedGestures.constBegin();
+ it != grabbedGestures.constEnd(); ++it)
+ view->viewport()->grabGesture(it.key());
#endif
}
@@ -5911,14 +5810,9 @@ void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouch
const QTransform mapFromScene =
item->d_ptr->genericMapFromSceneTransform(static_cast<const QWidget *>(touchEvent->target()));
- for (auto &touchPoint : touchEvent->_touchPoints) {
- // Deprecated TouchPoint::setRect clobbers ellipseDiameters, restore
- const QSizeF ellipseDiameters = touchPoint.ellipseDiameters();
- touchPoint.setRect(mapFromScene.map(touchPoint.sceneRect()).boundingRect());
- touchPoint.setEllipseDiameters(ellipseDiameters);
- touchPoint.setPos(mapFromScene.map(touchPoint.scenePos()));
- touchPoint.setStartPos(mapFromScene.map(touchPoint.startScenePos()));
- touchPoint.setLastPos(mapFromScene.map(touchPoint.lastScenePos()));
+ for (int i = 0; i < touchEvent->pointCount(); ++i) {
+ auto &pt = touchEvent->point(i);
+ QMutableEventPoint::setPosition(pt, mapFromScene.map(pt.scenePosition()));
}
}
@@ -5926,8 +5820,8 @@ int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos)
{
int closestTouchPointId = -1;
qreal closestDistance = qreal(0.);
- foreach (const QTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) {
- qreal distance = QLineF(scenePos, touchPoint.scenePos()).length();
+ for (const QEventPoint &touchPoint : std::as_const(sceneCurrentTouchPoints)) {
+ qreal distance = QLineF(scenePos, touchPoint.scenePosition()).length();
if (closestTouchPointId == -1|| distance < closestDistance) {
closestTouchPointId = touchPoint.id();
closestDistance = distance;
@@ -5938,16 +5832,15 @@ int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos)
void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
{
- typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
+ typedef QPair<QEventPoint::States, QList<QEventPoint> > StatesAndTouchPoints;
QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents;
- for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) {
- const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i);
-
+ const auto &touchPoints = sceneTouchEvent->points();
+ for (const auto &touchPoint : touchPoints) {
// update state
- QGraphicsItem *item = 0;
- if (touchPoint.state() == Qt::TouchPointPressed) {
- if (sceneTouchEvent->device()->type() == QTouchDevice::TouchPad) {
+ QGraphicsItem *item = nullptr;
+ if (touchPoint.state() == QEventPoint::State::Pressed) {
+ if (sceneTouchEvent->pointingDevice()->type() == QInputDevice::DeviceType::TouchPad) {
// on touch-pad devices, send all touch points to the same item
item = itemForTouchPointId.isEmpty()
? 0
@@ -5956,15 +5849,15 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
if (!item) {
// determine which item this touch point will go to
- cachedItemsUnderMouse = itemsAtPosition(touchPoint.screenPos().toPoint(),
- touchPoint.scenePos(),
+ cachedItemsUnderMouse = itemsAtPosition(touchPoint.globalPosition().toPoint(),
+ touchPoint.scenePosition(),
static_cast<QWidget *>(sceneTouchEvent->target()));
item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.constFirst();
}
- if (sceneTouchEvent->device()->type() == QTouchDevice::TouchScreen) {
+ if (sceneTouchEvent->pointingDevice()->type() == QInputDevice::DeviceType::TouchScreen) {
// on touch-screens, combine this touch point with the closest one we find
- int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos());
+ int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePosition());
QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId);
if (!item || (closestItem && cachedItemsUnderMouse.contains(closestItem)))
item = closestItem;
@@ -5974,7 +5867,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
itemForTouchPointId.insert(touchPoint.id(), item);
sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
- } else if (touchPoint.state() == Qt::TouchPointReleased) {
+ } else if (touchPoint.state() == QEventPoint::State::Released) {
item = itemForTouchPointId.take(touchPoint.id());
if (!item)
continue;
@@ -5989,7 +5882,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
}
StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item];
- statesAndTouchPoints.first |= touchPoint.state();
+ statesAndTouchPoints.first = QEventPoint::States(statesAndTouchPoints.first | touchPoint.state());
statesAndTouchPoints.second.append(touchPoint);
}
@@ -6009,15 +5902,15 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
// determine event type from the state mask
QEvent::Type eventType;
switch (it.value().first) {
- case Qt::TouchPointPressed:
+ case QEventPoint::State::Pressed:
// all touch points have pressed state
eventType = QEvent::TouchBegin;
break;
- case Qt::TouchPointReleased:
+ case QEventPoint::State::Released:
// all touch points have released state
eventType = QEvent::TouchEnd;
break;
- case Qt::TouchPointStationary:
+ case QEventPoint::State::Stationary:
// don't send the event if nothing changed
continue;
default:
@@ -6026,13 +5919,9 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
break;
}
- QTouchEvent touchEvent(eventType);
- touchEvent.setWindow(sceneTouchEvent->window());
+ QMutableTouchEvent touchEvent(eventType, sceneTouchEvent->pointingDevice(), sceneTouchEvent->modifiers(), it.value().second);
touchEvent.setTarget(sceneTouchEvent->target());
- touchEvent.setDevice(sceneTouchEvent->device());
touchEvent.setModifiers(sceneTouchEvent->modifiers());
- touchEvent.setTouchPointStates(it.value().first);
- touchEvent.setTouchPoints(it.value().second);
touchEvent.setTimestamp(sceneTouchEvent->timestamp());
switch (touchEvent.type()) {
@@ -6041,12 +5930,11 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
// if the TouchBegin handler recurses, we assume that means the event
// has been implicitly accepted and continue to send touch events
item->d_ptr->acceptedTouchBeginEvent = true;
- bool res = sendTouchBeginEvent(item, &touchEvent)
- && touchEvent.isAccepted();
+ bool res = sendTouchBeginEvent(item, &touchEvent) && touchEvent.isAccepted();
if (!res) {
// forget about these touch points, we didn't handle them
- for (int i = 0; i < touchEvent.touchPoints().count(); ++i) {
- const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i);
+ const auto &unhandledTouchPoints = touchEvent.points();
+ for (const auto &touchPoint : unhandledTouchPoints) {
itemForTouchPointId.remove(touchPoint.id());
sceneCurrentTouchPoints.remove(touchPoint.id());
}
@@ -6063,7 +5951,8 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
break;
}
}
- sceneTouchEvent->setAccepted(ignoreSceneTouchEvent);
+ // don't override the acceptance state of the individual points
+ sceneTouchEvent->QInputEvent::setAccepted(ignoreSceneTouchEvent);
}
bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEvent *touchEvent)
@@ -6072,16 +5961,16 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
if (focusOnTouch) {
if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.constFirst() != origin) {
- const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first();
- cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(),
- firstTouchPoint.scenePos(),
+ const QEventPoint &firstTouchPoint = touchEvent->points().first();
+ cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.globalPosition().toPoint(),
+ firstTouchPoint.scenePosition(),
static_cast<QWidget *>(touchEvent->target()));
}
// Set focus on the topmost enabled item that can take focus.
bool setFocus = false;
- foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
+ for (QGraphicsItem *item : std::as_const(cachedItemsUnderMouse)) {
if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
setFocus = true;
@@ -6103,51 +5992,51 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
// If nobody could take focus, clear it.
if (!stickyFocus && !setFocus)
- q->setFocusItem(0, Qt::MouseFocusReason);
+ q->setFocusItem(nullptr, Qt::MouseFocusReason);
}
bool res = false;
bool eventAccepted = touchEvent->isAccepted();
- foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
+ for (QGraphicsItem *item : std::as_const(cachedItemsUnderMouse)) {
// first, try to deliver the touch event
updateTouchPointsForItem(item, touchEvent);
bool acceptTouchEvents = item->acceptTouchEvents();
touchEvent->setAccepted(acceptTouchEvents);
res = acceptTouchEvents && sendEvent(item, touchEvent);
eventAccepted = touchEvent->isAccepted();
- if (itemForTouchPointId.value(touchEvent->touchPoints().first().id()) == 0) {
+ if (itemForTouchPointId.value(touchEvent->points().first().id()) == 0) {
// item was deleted
- item = 0;
+ item = nullptr;
} else {
item->d_ptr->acceptedTouchBeginEvent = (res && eventAccepted);
}
- touchEvent->spont = false;
+ touchEvent->m_spont = false;
if (res && eventAccepted) {
// the first item to accept the TouchBegin gets an implicit grab.
- for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
- const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i);
+ const auto &touchPoints = touchEvent->points();
+ for (const auto &touchPoint : touchPoints)
itemForTouchPointId[touchPoint.id()] = item; // can be zero
- }
break;
}
if (item && item->isPanel())
break;
}
- touchEvent->setAccepted(eventAccepted);
+ // don't override the acceptance state of the touch points
+ touchEvent->QInputEvent::setAccepted(eventAccepted);
return res;
}
void QGraphicsScenePrivate::enableTouchEventsOnViews()
{
- foreach (QGraphicsView *view, views)
+ for (QGraphicsView *view : std::as_const(views))
view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
}
void QGraphicsScenePrivate::updateInputMethodSensitivityInViews()
{
- for (int i = 0; i < views.size(); ++i)
- views.at(i)->d_func()->updateInputMethodSensitivity();
+ for (auto view : std::as_const(views))
+ view->d_func()->updateInputMethodSensitivity();
}
void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::PanelModality previousModality)
@@ -6163,11 +6052,12 @@ void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::Pane
}
QSet<QGraphicsItem *> blockedPanels;
- QList<QGraphicsItem *> items = q->items(); // ### store panels separately
- for (int i = 0; i < items.count(); ++i) {
- QGraphicsItem *item = items.at(i);
- if (item->isPanel() && item->isBlockedByModalPanel())
- blockedPanels.insert(item);
+ {
+ const auto items_ = q->items();
+ for (const auto &item : items_) {
+ if (item->isPanel() && item->isBlockedByModalPanel())
+ blockedPanels.insert(item);
+ }
}
// blockedPanels contains all currently blocked panels
@@ -6195,8 +6085,8 @@ void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::Pane
QEvent windowBlockedEvent(QEvent::WindowBlocked);
QEvent windowUnblockedEvent(QEvent::WindowUnblocked);
- for (int i = 0; i < items.count(); ++i) {
- QGraphicsItem *item = items.at(i);
+ const auto items_ = q->items();
+ for (const auto &item : items_) {
if (item->isPanel()) {
if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) {
// send QEvent::WindowBlocked to newly blocked panels
@@ -6216,20 +6106,23 @@ void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel)
Q_ASSERT(panel && panel->isPanel());
QSet<QGraphicsItem *> blockedPanels;
- QList<QGraphicsItem *> items = q->items(); // ### same as above
- for (int i = 0; i < items.count(); ++i) {
- QGraphicsItem *item = items.at(i);
- if (item->isPanel() && item->isBlockedByModalPanel())
- blockedPanels.insert(item);
+ {
+ const auto items_ = q->items();
+ for (const auto &item : items_) {
+ if (item->isPanel() && item->isBlockedByModalPanel())
+ blockedPanels.insert(item);
+ }
}
modalPanels.removeAll(panel);
- QEvent e(QEvent::WindowUnblocked);
- for (int i = 0; i < items.count(); ++i) {
- QGraphicsItem *item = items.at(i);
- if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
- sendEvent(item, &e);
+ {
+ QEvent e(QEvent::WindowUnblocked);
+ const auto items_ = q->items();
+ for (const auto &item : items_) {
+ if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
+ sendEvent(item, &e);
+ }
}
// send GraphicsSceneHoverEnter events to newly unblocked items
@@ -6251,7 +6144,7 @@ void QGraphicsScenePrivate::gestureTargetsAtHotSpots(const QSet<QGesture *> &ges
if (!gesture->hasHotSpot())
continue;
const Qt::GestureType gestureType = gesture->gestureType();
- QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, 0);
+ const QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, nullptr);
for (int j = 0; j < items.size(); ++j) {
QGraphicsItem *item = items.at(j);
@@ -6323,7 +6216,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
if (!startedGestures.isEmpty()) {
QSet<QGesture *> normalGestures; // that have just one target
QSet<QGesture *> conflictedGestures; // that have multiple possible targets
- gestureTargetsAtHotSpots(startedGestures, Qt::GestureFlag(0), &cachedItemGestures, 0,
+ gestureTargetsAtHotSpots(startedGestures, Qt::GestureFlag(0), &cachedItemGestures, nullptr,
&normalGestures, &conflictedGestures);
cachedTargetItems = cachedItemGestures.keys();
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
@@ -6346,7 +6239,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
<< "delivering override to"
<< item.data() << gestures;
// send gesture override
- QGestureEvent ev(gestures.toList());
+ QGestureEvent ev(gestures.values());
ev.t = QEvent::GestureOverride;
ev.setWidget(event->widget());
// mark event and individual gestures as ignored
@@ -6423,9 +6316,9 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
for (int i = 0; i < cachedTargetItems.size(); ++i) {
QPointer<QGraphicsObject> receiver = cachedTargetItems.at(i);
- QSet<QGesture *> gestures =
- undeliveredGestures & cachedItemGestures.value(receiver.data());
- gestures -= cachedAlreadyDeliveredGestures.value(receiver.data());
+ const QSet<QGesture *> gestures = (undeliveredGestures
+ & cachedItemGestures.value(receiver.data()))
+ - cachedAlreadyDeliveredGestures.value(receiver.data());
if (gestures.isEmpty())
continue;
@@ -6436,11 +6329,11 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "delivering to"
<< receiver.data() << gestures;
- QGestureEvent ev(gestures.toList());
+ QGestureEvent ev(gestures.values());
ev.setWidget(event->widget());
sendEvent(receiver.data(), &ev);
QSet<QGesture *> ignoredGestures;
- for (QGesture *g : qAsConst(gestures)) {
+ for (QGesture *g : gestures) {
if (!ev.isAccepted() && !ev.isAccepted(g)) {
// if the gesture was ignored by its target, we will update the
// targetItems list with a possible target items (items that
@@ -6467,7 +6360,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
// look for new potential targets for gestures that were ignored
// and should be propagated.
- QSet<QGraphicsObject *> targetsSet = cachedTargetItems.toSet();
+ QSet<QGraphicsObject *> targetsSet(cachedTargetItems.constBegin(), cachedTargetItems.constEnd());
if (receiver) {
// first if the gesture should be propagated to parents only
@@ -6497,9 +6390,9 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
}
gestureTargetsAtHotSpots(ignoredGestures, Qt::ReceivePartialGestures,
- &cachedItemGestures, &targetsSet, 0, 0);
+ &cachedItemGestures, &targetsSet, nullptr, nullptr);
- cachedTargetItems = targetsSet.toList();
+ cachedTargetItems = targetsSet.values();
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "new targets:" << cachedTargetItems;
@@ -6508,7 +6401,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
}
}
- foreach (QGesture *g, startedGestures) {
+ for (QGesture *g : std::as_const(startedGestures)) {
if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) {
DEBUG() << "lets try to cancel some";
// find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them
@@ -6537,7 +6430,7 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
{
Q_ASSERT(original);
QGraphicsItem *originalItem = gestureTargets.value(original);
- if (originalItem == 0) // we only act on accepted gestures, which implies it has a target.
+ if (originalItem == nullptr) // we only act on accepted gestures, which implies it has a target.
return;
// iterate over all active gestures and for each find the owner
@@ -6560,13 +6453,13 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
QSet<QGesture *> almostCanceledGestures = canceledGestures;
QSet<QGesture *>::Iterator setIter;
while (!almostCanceledGestures.isEmpty()) {
- QGraphicsObject *target = 0;
+ QGraphicsObject *target = nullptr;
QSet<QGesture*> gestures;
setIter = almostCanceledGestures.begin();
// sort per target item
while (setIter != almostCanceledGestures.end()) {
QGraphicsObject *item = gestureTargets.value(*setIter);
- if (target == 0)
+ if (target == nullptr)
target = item;
if (target == item) {
gestures << *setIter;
@@ -6577,7 +6470,7 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
}
Q_ASSERT(target);
- const QList<QGesture *> list = gestures.toList();
+ const QList<QGesture *> list = gestures.values();
QGestureEvent ev(list);
sendEvent(target, &ev);
@@ -6590,17 +6483,17 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
if (!g->hasHotSpot())
continue;
- QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, 0);
- for (int j = 0; j < items.size(); ++j) {
- QGraphicsObject *item = items.at(j)->toGraphicsObject();
- if (!item)
+ const QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, nullptr);
+ for (const auto &item : items) {
+ QGraphicsObject *object = item->toGraphicsObject();
+ if (!object)
continue;
- QGraphicsItemPrivate *d = item->QGraphicsItem::d_func();
+ QGraphicsItemPrivate *d = object->QGraphicsItem::d_func();
if (d->gestureContext.contains(g->gestureType())) {
QList<QGesture *> list;
list << g;
QGestureEvent ev(list);
- sendEvent(item, &ev);
+ sendEvent(object, &ev);
if (ev.isAccepted() || ev.isAccepted(g))
break; // successfully delivered
}
@@ -6621,7 +6514,7 @@ void QGraphicsScenePrivate::grabGesture(QGraphicsItem *, Qt::GestureType gesture
{
(void)QGestureManager::instance(); // create a gesture manager
if (!grabbedGestures[gesture]++) {
- foreach (QGraphicsView *view, views)
+ for (QGraphicsView *view : std::as_const(views))
view->viewport()->grabGesture(gesture);
}
}
@@ -6633,7 +6526,7 @@ void QGraphicsScenePrivate::ungrabGesture(QGraphicsItem *item, Qt::GestureType g
QGraphicsObject *obj = static_cast<QGraphicsObject *>(item);
QGestureManager::instance()->cleanupCachedGestures(obj, gesture);
if (!--grabbedGestures[gesture]) {
- foreach (QGraphicsView *view, views)
+ for (QGraphicsView *view : std::as_const(views))
view->viewport()->ungrabGesture(gesture);
}
}