QGraphicsView: consistently use ranged for and iterators
- replace random access with ranged for - replace foreach with ranged for - add qAsConst where possible - iterate directly over QMap, rather than the keys (address FIXME comment) - add some const to ensure that code has no side effects on containers or indices used in different places Change-Id: I6199fd6edd5e4426c6c7fee0ff64ec9421a64cd5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
6dab2577bf
commit
e349f787d5
@ -2633,7 +2633,7 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
|
|||||||
top += geom.top();
|
top += geom.top();
|
||||||
right = geom.right() - right;
|
right = geom.right() - right;
|
||||||
|
|
||||||
foreach (QGraphicsLayoutItem *item, items) {
|
for (QGraphicsLayoutItem *item : qAsConst(items)) {
|
||||||
QRectF newGeom;
|
QRectF newGeom;
|
||||||
QSizeF itemPreferredSize = item->effectiveSizeHint(Qt::PreferredSize);
|
QSizeF itemPreferredSize = item->effectiveSizeHint(Qt::PreferredSize);
|
||||||
if (m_floatItems[Horizontal].contains(item)) {
|
if (m_floatItems[Horizontal].contains(item)) {
|
||||||
|
@ -1075,7 +1075,7 @@ void QGraphicsItemPrivate::setIsMemberOfGroup(bool enabled)
|
|||||||
Q_Q(QGraphicsItem);
|
Q_Q(QGraphicsItem);
|
||||||
isMemberOfGroup = enabled;
|
isMemberOfGroup = enabled;
|
||||||
if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {
|
if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {
|
||||||
foreach (QGraphicsItem *child, children)
|
for (QGraphicsItem *child : qAsConst(children))
|
||||||
child->d_func()->setIsMemberOfGroup(enabled);
|
child->d_func()->setIsMemberOfGroup(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1591,9 +1591,8 @@ QGraphicsItem::~QGraphicsItem()
|
|||||||
if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
|
if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
|
||||||
QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
|
QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
|
||||||
if (QGestureManager *manager = QGestureManager::instance(QGestureManager::DontForceCreation)) {
|
if (QGestureManager *manager = QGestureManager::instance(QGestureManager::DontForceCreation)) {
|
||||||
const auto types = d_ptr->gestureContext.keys(); // FIXME: iterate over the map directly?
|
for (auto it = d_ptr->gestureContext.constBegin(); it != d_ptr->gestureContext.constEnd(); ++it)
|
||||||
for (Qt::GestureType type : types)
|
manager->cleanupCachedGestures(o, it.key());
|
||||||
manager->cleanupCachedGestures(o, type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2511,7 +2510,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly,
|
|||||||
const bool updateChildren = update && !((flags & QGraphicsItem::ItemClipsChildrenToShape
|
const bool updateChildren = update && !((flags & QGraphicsItem::ItemClipsChildrenToShape
|
||||||
|| flags & QGraphicsItem::ItemContainsChildrenInShape)
|
|| flags & QGraphicsItem::ItemContainsChildrenInShape)
|
||||||
&& !(flags & QGraphicsItem::ItemHasNoContents));
|
&& !(flags & QGraphicsItem::ItemHasNoContents));
|
||||||
foreach (QGraphicsItem *child, children) {
|
for (QGraphicsItem *child : qAsConst(children)) {
|
||||||
if (!newVisible || !child->d_ptr->explicitlyHidden)
|
if (!newVisible || !child->d_ptr->explicitlyHidden)
|
||||||
child->d_ptr->setVisibleHelper(newVisible, false, updateChildren, hiddenByPanel);
|
child->d_ptr->setVisibleHelper(newVisible, false, updateChildren, hiddenByPanel);
|
||||||
}
|
}
|
||||||
@ -2701,7 +2700,7 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
|
|||||||
if (update)
|
if (update)
|
||||||
q_ptr->update();
|
q_ptr->update();
|
||||||
|
|
||||||
foreach (QGraphicsItem *child, children) {
|
for (QGraphicsItem *child : qAsConst(children)) {
|
||||||
if (!newEnabled || !child->d_ptr->explicitlyDisabled)
|
if (!newEnabled || !child->d_ptr->explicitlyDisabled)
|
||||||
child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false);
|
child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false);
|
||||||
}
|
}
|
||||||
@ -3981,7 +3980,7 @@ void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
|
|||||||
sceneRect = sceneTransform().mapRect(rect);
|
sceneRect = sceneTransform().mapRect(rect);
|
||||||
else
|
else
|
||||||
sceneRect = sceneBoundingRect();
|
sceneRect = sceneBoundingRect();
|
||||||
foreach (QGraphicsView *view, d_ptr->scene->d_func()->views)
|
for (QGraphicsView *view : qAsConst(d_ptr->scene->d_func()->views))
|
||||||
view->ensureVisible(sceneRect, xmargin, ymargin);
|
view->ensureVisible(sceneRect, xmargin, ymargin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4765,7 +4764,7 @@ inline void QGraphicsItemPrivate::sendScenePosChange()
|
|||||||
if (flags & QGraphicsItem::ItemSendsScenePositionChanges)
|
if (flags & QGraphicsItem::ItemSendsScenePositionChanges)
|
||||||
q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos());
|
q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos());
|
||||||
if (scenePosDescendants) {
|
if (scenePosDescendants) {
|
||||||
foreach (QGraphicsItem *item, scene->d_func()->scenePosItems) {
|
for (QGraphicsItem *item : qAsConst(scene->d_func()->scenePosItems)) {
|
||||||
if (q->isAncestorOf(item))
|
if (q->isAncestorOf(item))
|
||||||
item->itemChange(QGraphicsItem::ItemScenePositionHasChanged, item->scenePos());
|
item->itemChange(QGraphicsItem::ItemScenePositionHasChanged, item->scenePos());
|
||||||
}
|
}
|
||||||
@ -7330,7 +7329,7 @@ void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
// temporarily removing this item from the selection list.
|
// temporarily removing this item from the selection list.
|
||||||
if (d_ptr->selected) {
|
if (d_ptr->selected) {
|
||||||
scene->d_func()->selectedItems.remove(this);
|
scene->d_func()->selectedItems.remove(this);
|
||||||
foreach (QGraphicsItem *item, scene->d_func()->selectedItems) {
|
for (QGraphicsItem *item : qAsConst(scene->d_func()->selectedItems)) {
|
||||||
if (item->isSelected()) {
|
if (item->isSelected()) {
|
||||||
selectionChanged = true;
|
selectionChanged = true;
|
||||||
break;
|
break;
|
||||||
|
@ -495,7 +495,7 @@ void QGraphicsProxyWidgetPrivate::embedSubWindow(QWidget *subWin)
|
|||||||
*/
|
*/
|
||||||
void QGraphicsProxyWidgetPrivate::unembedSubWindow(QWidget *subWin)
|
void QGraphicsProxyWidgetPrivate::unembedSubWindow(QWidget *subWin)
|
||||||
{
|
{
|
||||||
foreach (QGraphicsItem *child, children) {
|
for (QGraphicsItem *child : qAsConst(children)) {
|
||||||
if (child->isWidget()) {
|
if (child->isWidget()) {
|
||||||
if (QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(child))) {
|
if (QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(child))) {
|
||||||
if (proxy->widget() == subWin) {
|
if (proxy->widget() == subWin) {
|
||||||
|
@ -363,12 +363,11 @@ void QGraphicsScenePrivate::_q_emitUpdated()
|
|||||||
// needs to happen in order to keep compatibility with the behavior from
|
// needs to happen in order to keep compatibility with the behavior from
|
||||||
// Qt 4.4 and backward.
|
// Qt 4.4 and backward.
|
||||||
if (isSignalConnected(changedSignalIndex)) {
|
if (isSignalConnected(changedSignalIndex)) {
|
||||||
for (int i = 0; i < views.size(); ++i) {
|
for (auto view : qAsConst(views)) {
|
||||||
QGraphicsView *view = views.at(i);
|
|
||||||
if (!view->d_func()->connectedToScene) {
|
if (!view->d_func()->connectedToScene) {
|
||||||
view->d_func()->connectedToScene = true;
|
view->d_func()->connectedToScene = true;
|
||||||
q->connect(q, SIGNAL(changed(QList<QRectF>)),
|
q->connect(q, SIGNAL(changed(QList<QRectF>)),
|
||||||
views.at(i), SLOT(updateScene(QList<QRectF>)));
|
view, SLOT(updateScene(QList<QRectF>)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -376,11 +375,11 @@ void QGraphicsScenePrivate::_q_emitUpdated()
|
|||||||
updateAll = false;
|
updateAll = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->processPendingUpdates();
|
view->d_func()->processPendingUpdates();
|
||||||
// It's important that we update all views before we dispatch, hence two for-loops.
|
// It's important that we update all views before we dispatch, hence two for-loops.
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->dispatchPendingUpdateRequests();
|
view->d_func()->dispatchPendingUpdateRequests();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,8 +481,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
|
|||||||
Q_ASSERT(calledEmitUpdated);
|
Q_ASSERT(calledEmitUpdated);
|
||||||
// No need for further processing (except resetting the dirty states).
|
// No need for further processing (except resetting the dirty states).
|
||||||
// The growingItemsBoundingRect is updated in _q_emitUpdated.
|
// The growingItemsBoundingRect is updated in _q_emitUpdated.
|
||||||
for (int i = 0; i < topLevelItems.size(); ++i)
|
for (auto topLevelItem : qAsConst(topLevelItems))
|
||||||
resetDirtyItem(topLevelItems.at(i), /*recursive=*/true);
|
resetDirtyItem(topLevelItem, /*recursive=*/true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,8 +490,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
|
|||||||
const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect;
|
const QRectF oldGrowingItemsBoundingRect = growingItemsBoundingRect;
|
||||||
|
|
||||||
// Process items recursively.
|
// Process items recursively.
|
||||||
for (int i = 0; i < topLevelItems.size(); ++i)
|
for (auto topLevelItem : qAsConst(topLevelItems))
|
||||||
processDirtyItemsRecursive(topLevelItems.at(i));
|
processDirtyItemsRecursive(topLevelItem);
|
||||||
|
|
||||||
dirtyGrowingItemsBoundingRect = false;
|
dirtyGrowingItemsBoundingRect = false;
|
||||||
if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect)
|
if (!hasSceneRect && oldGrowingItemsBoundingRect != growingItemsBoundingRect)
|
||||||
@ -501,8 +500,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
|
|||||||
if (wasPendingSceneUpdate)
|
if (wasPendingSceneUpdate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->processPendingUpdates();
|
view->d_func()->processPendingUpdates();
|
||||||
|
|
||||||
if (calledEmitUpdated) {
|
if (calledEmitUpdated) {
|
||||||
// We did a compatibility QGraphicsScene::update in processDirtyItemsRecursive
|
// We did a compatibility QGraphicsScene::update in processDirtyItemsRecursive
|
||||||
@ -512,8 +511,8 @@ void QGraphicsScenePrivate::_q_processDirtyItems()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Immediately dispatch all pending update requests on the views.
|
// Immediately dispatch all pending update requests on the views.
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->dispatchPendingUpdateRequests();
|
view->d_func()->dispatchPendingUpdateRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -555,7 +554,7 @@ void QGraphicsScenePrivate::unregisterScenePosItem(QGraphicsItem *item)
|
|||||||
*/
|
*/
|
||||||
void QGraphicsScenePrivate::_q_updateScenePosDescendants()
|
void QGraphicsScenePrivate::_q_updateScenePosDescendants()
|
||||||
{
|
{
|
||||||
foreach (QGraphicsItem *item, scenePosItems) {
|
for (QGraphicsItem *item : qAsConst(scenePosItems)) {
|
||||||
QGraphicsItem *p = item->d_ptr->parent;
|
QGraphicsItem *p = item->d_ptr->parent;
|
||||||
while (p) {
|
while (p) {
|
||||||
p->d_ptr->scenePosDescendants = 1;
|
p->d_ptr->scenePosDescendants = 1;
|
||||||
@ -608,8 +607,8 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
|
|||||||
//attributes (e.g. sceneTransform).
|
//attributes (e.g. sceneTransform).
|
||||||
if (!item->d_ptr->inDestructor) {
|
if (!item->d_ptr->inDestructor) {
|
||||||
// Remove all children recursively
|
// Remove all children recursively
|
||||||
for (int i = 0; i < item->d_ptr->children.size(); ++i)
|
for (auto child : qAsConst(item->d_ptr->children))
|
||||||
q->removeItem(item->d_ptr->children.at(i));
|
q->removeItem(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item->d_ptr->inDestructor && !item->parentItem() && item->isWidget()) {
|
if (!item->d_ptr->inDestructor && !item->parentItem() && item->isWidget()) {
|
||||||
@ -717,8 +716,7 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
|
|||||||
emit q->selectionChanged();
|
emit q->selectionChanged();
|
||||||
|
|
||||||
#ifndef QT_NO_GESTURES
|
#ifndef QT_NO_GESTURES
|
||||||
QHash<QGesture *, QGraphicsObject *>::iterator it;
|
for (auto it = gestureTargets.begin(); it != gestureTargets.end();) {
|
||||||
for (it = gestureTargets.begin(); it != gestureTargets.end();) {
|
|
||||||
if (it.value() == item)
|
if (it.value() == item)
|
||||||
it = gestureTargets.erase(it);
|
it = gestureTargets.erase(it);
|
||||||
else
|
else
|
||||||
@ -731,8 +729,9 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
|
|||||||
cachedAlreadyDeliveredGestures.remove(dummy);
|
cachedAlreadyDeliveredGestures.remove(dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys())
|
for (auto it = item->d_ptr->gestureContext.constBegin();
|
||||||
ungrabGesture(item, gesture);
|
it != item->d_ptr->gestureContext.constEnd(); ++it)
|
||||||
|
ungrabGesture(item, it.key());
|
||||||
#endif // QT_NO_GESTURES
|
#endif // QT_NO_GESTURES
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1114,7 +1113,7 @@ void QGraphicsScenePrivate::clearKeyboardGrabber()
|
|||||||
|
|
||||||
void QGraphicsScenePrivate::enableMouseTrackingOnViews()
|
void QGraphicsScenePrivate::enableMouseTrackingOnViews()
|
||||||
{
|
{
|
||||||
foreach (QGraphicsView *view, views)
|
for (QGraphicsView *view : qAsConst(views))
|
||||||
view->viewport()->setMouseTracking(true);
|
view->viewport()->setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1377,7 +1376,7 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
|
|||||||
// Set focus on the topmost enabled item that can take focus.
|
// Set focus on the topmost enabled item that can take focus.
|
||||||
bool setFocus = false;
|
bool setFocus = false;
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
|
for (QGraphicsItem *item : qAsConst(cachedItemsUnderMouse)) {
|
||||||
if (item->isBlockedByModalPanel()
|
if (item->isBlockedByModalPanel()
|
||||||
|| (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling)) {
|
|| (item->d_ptr->flags & QGraphicsItem::ItemStopsFocusHandling)) {
|
||||||
// Make sure we don't clear focus.
|
// Make sure we don't clear focus.
|
||||||
@ -1400,8 +1399,8 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
|
|||||||
|
|
||||||
// Check for scene modality.
|
// Check for scene modality.
|
||||||
bool sceneModality = false;
|
bool sceneModality = false;
|
||||||
for (int i = 0; i < modalPanels.size(); ++i) {
|
for (auto modalPanel : qAsConst(modalPanels)) {
|
||||||
if (modalPanels.at(i)->panelModality() == QGraphicsItem::SceneModal) {
|
if (modalPanel->panelModality() == QGraphicsItem::SceneModal) {
|
||||||
sceneModality = true;
|
sceneModality = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1419,7 +1418,7 @@ void QGraphicsScenePrivate::mousePressEventHandler(QGraphicsSceneMouseEvent *mou
|
|||||||
// candidates one at a time, until the event is accepted. It's accepted by
|
// 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
|
// default, so the receiver has to explicitly ignore it for it to pass
|
||||||
// through.
|
// through.
|
||||||
foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
|
for (QGraphicsItem *item : qAsConst(cachedItemsUnderMouse)) {
|
||||||
if (!(item->acceptedMouseButtons() & mouseEvent->button())) {
|
if (!(item->acceptedMouseButtons() & mouseEvent->button())) {
|
||||||
// Skip items that don't accept the event's mouse button.
|
// Skip items that don't accept the event's mouse button.
|
||||||
continue;
|
continue;
|
||||||
@ -1693,8 +1692,10 @@ QGraphicsScene::~QGraphicsScene()
|
|||||||
clear();
|
clear();
|
||||||
|
|
||||||
// Remove this scene from all associated views.
|
// Remove this scene from all associated views.
|
||||||
for (int j = 0; j < d->views.size(); ++j)
|
// Note: d->views is modified by QGraphicsView::setScene, so must make a copy
|
||||||
d->views.at(j)->setScene(nullptr);
|
const auto views = d->views;
|
||||||
|
for (auto view : qAsConst(views))
|
||||||
|
view->setScene(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1812,7 +1813,7 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect
|
|||||||
// in reverse order).
|
// in reverse order).
|
||||||
QList<QGraphicsItem *> itemList = items(sourceRect, Qt::IntersectsItemBoundingRect);
|
QList<QGraphicsItem *> itemList = items(sourceRect, Qt::IntersectsItemBoundingRect);
|
||||||
QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
|
QGraphicsItem **itemArray = new QGraphicsItem *[itemList.size()];
|
||||||
int numItems = itemList.size();
|
const int numItems = itemList.size();
|
||||||
for (int i = 0; i < numItems; ++i)
|
for (int i = 0; i < numItems; ++i)
|
||||||
itemArray[numItems - i - 1] = itemList.at(i);
|
itemArray[numItems - i - 1] = itemList.at(i);
|
||||||
itemList.clear();
|
itemList.clear();
|
||||||
@ -2234,7 +2235,7 @@ QList<QGraphicsItem *> QGraphicsScene::selectedItems() const
|
|||||||
// Optimization: Lazily removes items that are not selected.
|
// Optimization: Lazily removes items that are not selected.
|
||||||
QGraphicsScene *that = const_cast<QGraphicsScene *>(this);
|
QGraphicsScene *that = const_cast<QGraphicsScene *>(this);
|
||||||
QSet<QGraphicsItem *> actuallySelectedSet;
|
QSet<QGraphicsItem *> actuallySelectedSet;
|
||||||
foreach (QGraphicsItem *item, that->d_func()->selectedItems) {
|
for (QGraphicsItem *item : qAsConst(that->d_func()->selectedItems)) {
|
||||||
if (item->isSelected())
|
if (item->isSelected())
|
||||||
actuallySelectedSet << item;
|
actuallySelectedSet << item;
|
||||||
}
|
}
|
||||||
@ -2342,7 +2343,7 @@ void QGraphicsScene::setSelectionArea(const QPainterPath &path,
|
|||||||
switch (selectionOperation) {
|
switch (selectionOperation) {
|
||||||
case Qt::ReplaceSelection:
|
case Qt::ReplaceSelection:
|
||||||
// Deselect all items outside path.
|
// Deselect all items outside path.
|
||||||
foreach (QGraphicsItem *item, unselectItems) {
|
for (QGraphicsItem *item : qAsConst(unselectItems)) {
|
||||||
item->setSelected(false);
|
item->setSelected(false);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
@ -2371,7 +2372,7 @@ void QGraphicsScene::clearSelection()
|
|||||||
++d->selectionChanging;
|
++d->selectionChanging;
|
||||||
bool changed = !d->selectedItems.isEmpty();
|
bool changed = !d->selectedItems.isEmpty();
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, d->selectedItems)
|
for (QGraphicsItem *item : qAsConst(d->selectedItems))
|
||||||
item->setSelected(false);
|
item->setSelected(false);
|
||||||
d->selectedItems.clear();
|
d->selectedItems.clear();
|
||||||
|
|
||||||
@ -2596,9 +2597,9 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_GESTURES
|
#ifndef QT_NO_GESTURES
|
||||||
const auto gestures = item->d_ptr->gestureContext.keys(); // FIXME: iterate over hash directly?
|
for (auto it = item->d_ptr->gestureContext.constBegin();
|
||||||
for (Qt::GestureType gesture : gestures)
|
it != item->d_ptr->gestureContext.constEnd(); ++it)
|
||||||
d->grabGesture(item, gesture);
|
d->grabGesture(item, it.key());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Update selection lists
|
// Update selection lists
|
||||||
@ -2629,8 +2630,8 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
|
|||||||
|
|
||||||
// Add all children recursively
|
// Add all children recursively
|
||||||
item->d_ptr->ensureSortedChildren();
|
item->d_ptr->ensureSortedChildren();
|
||||||
for (int i = 0; i < item->d_ptr->children.size(); ++i)
|
for (auto child : qAsConst(item->d_ptr->children))
|
||||||
addItem(item->d_ptr->children.at(i));
|
addItem(child);
|
||||||
|
|
||||||
// Resolve font and palette.
|
// Resolve font and palette.
|
||||||
item->d_ptr->resolveFont(d->font.resolve());
|
item->d_ptr->resolveFont(d->font.resolve());
|
||||||
@ -3132,7 +3133,7 @@ void QGraphicsScene::setBackgroundBrush(const QBrush &brush)
|
|||||||
{
|
{
|
||||||
Q_D(QGraphicsScene);
|
Q_D(QGraphicsScene);
|
||||||
d->backgroundBrush = brush;
|
d->backgroundBrush = brush;
|
||||||
foreach (QGraphicsView *view, d->views) {
|
for (QGraphicsView *view : qAsConst(d->views)) {
|
||||||
view->resetCachedContent();
|
view->resetCachedContent();
|
||||||
view->viewport()->update();
|
view->viewport()->update();
|
||||||
}
|
}
|
||||||
@ -3221,14 +3222,13 @@ void QGraphicsScene::update(const QRectF &rect)
|
|||||||
d->updatedRects.clear();
|
d->updatedRects.clear();
|
||||||
if (directUpdates) {
|
if (directUpdates) {
|
||||||
// Update all views.
|
// Update all views.
|
||||||
for (int i = 0; i < d->views.size(); ++i)
|
for (auto view : qAsConst(d->views))
|
||||||
d->views.at(i)->d_func()->fullUpdatePending = true;
|
view->d_func()->fullUpdatePending = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (directUpdates) {
|
if (directUpdates) {
|
||||||
// Update all views.
|
// Update all views.
|
||||||
for (int i = 0; i < d->views.size(); ++i) {
|
for (auto view : qAsConst(d->views)) {
|
||||||
QGraphicsView *view = d->views.at(i);
|
|
||||||
if (view->isTransformed())
|
if (view->isTransformed())
|
||||||
view->d_func()->updateRectF(view->viewportTransform().mapRect(rect));
|
view->d_func()->updateRectF(view->viewportTransform().mapRect(rect));
|
||||||
else
|
else
|
||||||
@ -3822,20 +3822,19 @@ void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent)
|
|||||||
#else
|
#else
|
||||||
// Find the first item that does tooltips
|
// Find the first item that does tooltips
|
||||||
Q_D(QGraphicsScene);
|
Q_D(QGraphicsScene);
|
||||||
QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(),
|
const QList<QGraphicsItem *> itemsAtPos = d->itemsAtPosition(helpEvent->screenPos(),
|
||||||
helpEvent->scenePos(),
|
helpEvent->scenePos(),
|
||||||
helpEvent->widget());
|
helpEvent->widget());
|
||||||
QGraphicsItem *toolTipItem = nullptr;
|
QGraphicsItem *toolTipItem = nullptr;
|
||||||
for (int i = 0; i < itemsAtPos.size(); ++i) {
|
for (auto item : itemsAtPos) {
|
||||||
QGraphicsItem *tmp = itemsAtPos.at(i);
|
if (item->d_func()->isProxyWidget()) {
|
||||||
if (tmp->d_func()->isProxyWidget()) {
|
|
||||||
// if the item is a proxy widget, the event is forwarded to it
|
// if the item is a proxy widget, the event is forwarded to it
|
||||||
sendEvent(tmp, helpEvent);
|
sendEvent(item, helpEvent);
|
||||||
if (helpEvent->isAccepted())
|
if (helpEvent->isAccepted())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!tmp->toolTip().isEmpty()) {
|
if (!item->toolTip().isEmpty()) {
|
||||||
toolTipItem = tmp;
|
toolTipItem = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3884,8 +3883,7 @@ bool QGraphicsScenePrivate::dispatchHoverEvent(QGraphicsSceneHoverEvent *hoverEv
|
|||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsItem *item = nullptr;
|
QGraphicsItem *item = nullptr;
|
||||||
for (int i = 0; i < cachedItemsUnderMouse.size(); ++i) {
|
for (auto tmp : qAsConst(cachedItemsUnderMouse)) {
|
||||||
QGraphicsItem *tmp = cachedItemsUnderMouse.at(i);
|
|
||||||
if (itemAcceptsHoverEvents_helper(tmp)) {
|
if (itemAcceptsHoverEvents_helper(tmp)) {
|
||||||
item = tmp;
|
item = tmp;
|
||||||
break;
|
break;
|
||||||
@ -4503,10 +4501,9 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
|
|||||||
QRegion pixmapExposed;
|
QRegion pixmapExposed;
|
||||||
QRectF exposedRect;
|
QRectF exposedRect;
|
||||||
if (!itemCache->allExposed) {
|
if (!itemCache->allExposed) {
|
||||||
for (int i = 0; i < itemCache->exposed.size(); ++i) {
|
for (const auto rect : qAsConst(itemCache->exposed)) {
|
||||||
QRectF r = itemCache->exposed.at(i);
|
exposedRect |= rect;
|
||||||
exposedRect |= r;
|
pixmapExposed += itemToPixmap.mapRect(rect).toAlignedRect();
|
||||||
pixmapExposed += itemToPixmap.mapRect(r).toAlignedRect();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exposedRect = brect;
|
exposedRect = brect;
|
||||||
@ -4664,9 +4661,8 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
|
|||||||
// Map the item's logical expose to pixmap coordinates.
|
// Map the item's logical expose to pixmap coordinates.
|
||||||
QRegion pixmapExposed = scrollExposure;
|
QRegion pixmapExposed = scrollExposure;
|
||||||
if (!itemCache->allExposed) {
|
if (!itemCache->allExposed) {
|
||||||
const QVector<QRectF> &exposed = itemCache->exposed;
|
for (const auto rect : qAsConst(itemCache->exposed))
|
||||||
for (int i = 0; i < exposed.size(); ++i)
|
pixmapExposed += itemToPixmap.mapRect(rect).toRect().adjusted(-1, -1, 1, 1);
|
||||||
pixmapExposed += itemToPixmap.mapRect(exposed.at(i)).toRect().adjusted(-1, -1, 1, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the style option's exposedRect.
|
// Calculate the style option's exposedRect.
|
||||||
@ -4674,11 +4670,10 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
|
|||||||
if (itemCache->allExposed) {
|
if (itemCache->allExposed) {
|
||||||
br = item->boundingRect();
|
br = item->boundingRect();
|
||||||
} else {
|
} else {
|
||||||
const QVector<QRectF> &exposed = itemCache->exposed;
|
for (const auto rect : qAsConst(itemCache->exposed))
|
||||||
for (int i = 0; i < exposed.size(); ++i)
|
br |= rect;
|
||||||
br |= exposed.at(i);
|
|
||||||
QTransform pixmapToItem = itemToPixmap.inverted();
|
QTransform pixmapToItem = itemToPixmap.inverted();
|
||||||
for (const QRect &r : scrollExposure)
|
for (const QRect &r : qAsConst(scrollExposure))
|
||||||
br |= pixmapToItem.mapRect(r);
|
br |= pixmapToItem.mapRect(r);
|
||||||
}
|
}
|
||||||
styleOptionTmp = *option;
|
styleOptionTmp = *option;
|
||||||
@ -4731,8 +4726,8 @@ void QGraphicsScenePrivate::drawItems(QPainter *painter, const QTransform *const
|
|||||||
exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect);
|
exposedSceneRect = viewTransform->inverted().mapRect(exposedSceneRect);
|
||||||
}
|
}
|
||||||
const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder);
|
const QList<QGraphicsItem *> tli = index->estimateTopLevelItems(exposedSceneRect, Qt::AscendingOrder);
|
||||||
for (int i = 0; i < tli.size(); ++i)
|
for (const auto subTree : tli)
|
||||||
drawSubtreeRecursive(tli.at(i), painter, viewTransform, exposedRegion, widget);
|
drawSubtreeRecursive(subTree, painter, viewTransform, exposedRegion, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter,
|
void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter,
|
||||||
@ -4901,9 +4896,11 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
|
|||||||
qreal opacity, const QTransform *effectTransform,
|
qreal opacity, const QTransform *effectTransform,
|
||||||
bool wasDirtyParentSceneTransform, bool drawItem)
|
bool wasDirtyParentSceneTransform, bool drawItem)
|
||||||
{
|
{
|
||||||
|
const auto children = item->d_ptr->children;
|
||||||
|
|
||||||
const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity);
|
const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity);
|
||||||
const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
|
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 setChildClip = itemClipsChildrenToShape;
|
||||||
bool itemHasChildrenStackedBehind = false;
|
bool itemHasChildrenStackedBehind = false;
|
||||||
|
|
||||||
@ -4915,7 +4912,7 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
|
|||||||
item->d_ptr->ensureSortedChildren();
|
item->d_ptr->ensureSortedChildren();
|
||||||
// Items with the 'ItemStacksBehindParent' flag are put in front of the list
|
// Items with the 'ItemStacksBehindParent' flag are put in front of the list
|
||||||
// so all we have to do is to check the first item.
|
// 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);
|
& QGraphicsItem::ItemStacksBehindParent);
|
||||||
|
|
||||||
if (itemHasChildrenStackedBehind) {
|
if (itemHasChildrenStackedBehind) {
|
||||||
@ -4925,8 +4922,8 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw children behind
|
// Draw children behind
|
||||||
for (i = 0; i < item->d_ptr->children.size(); ++i) {
|
for (i = 0; i < children.size(); ++i) {
|
||||||
QGraphicsItem *child = item->d_ptr->children.at(i);
|
QGraphicsItem *child = children.at(i);
|
||||||
if (wasDirtyParentSceneTransform)
|
if (wasDirtyParentSceneTransform)
|
||||||
child->d_ptr->dirtySceneTransform = 1;
|
child->d_ptr->dirtySceneTransform = 1;
|
||||||
if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent))
|
if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent))
|
||||||
@ -5004,8 +5001,8 @@ void QGraphicsScenePrivate::draw(QGraphicsItem *item, QPainter *painter, const Q
|
|||||||
if (setChildClip)
|
if (setChildClip)
|
||||||
setClip(painter, item);
|
setClip(painter, item);
|
||||||
|
|
||||||
for (; i < item->d_ptr->children.size(); ++i) {
|
for (; i < children.size(); ++i) {
|
||||||
QGraphicsItem *child = item->d_ptr->children.at(i);
|
QGraphicsItem *child = children.at(i);
|
||||||
if (wasDirtyParentSceneTransform)
|
if (wasDirtyParentSceneTransform)
|
||||||
child->d_ptr->dirtySceneTransform = 1;
|
child->d_ptr->dirtySceneTransform = 1;
|
||||||
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
|
if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
|
||||||
@ -5083,8 +5080,8 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < views.size(); ++i) {
|
for (auto view : qAsConst(views)) {
|
||||||
QGraphicsViewPrivate *viewPrivate = views.at(i)->d_func();
|
QGraphicsViewPrivate *viewPrivate = view->d_func();
|
||||||
QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport);
|
QRect rect = item->d_ptr->paintedViewBoundingRects.value(viewPrivate->viewport);
|
||||||
rect.translate(viewPrivate->dirtyScrollOffset);
|
rect.translate(viewPrivate->dirtyScrollOffset);
|
||||||
viewPrivate->updateRect(rect);
|
viewPrivate->updateRect(rect);
|
||||||
@ -5239,8 +5236,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
|
|||||||
QRectF dirtyRect;
|
QRectF dirtyRect;
|
||||||
bool uninitializedDirtyRect = true;
|
bool uninitializedDirtyRect = true;
|
||||||
|
|
||||||
for (int j = 0; j < views.size(); ++j) {
|
for (auto view : qAsConst(views)) {
|
||||||
QGraphicsView *view = views.at(j);
|
|
||||||
QGraphicsViewPrivate *viewPrivate = view->d_func();
|
QGraphicsViewPrivate *viewPrivate = view->d_func();
|
||||||
QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport];
|
QRect &paintedViewBoundingRect = item->d_ptr->paintedViewBoundingRects[viewPrivate->viewport];
|
||||||
if (viewPrivate->fullUpdatePending
|
if (viewPrivate->fullUpdatePending
|
||||||
@ -5298,8 +5294,8 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
|
|||||||
const bool bypassUpdateClip = !itemHasContents && wasDirtyParentViewBoundingRects;
|
const bool bypassUpdateClip = !itemHasContents && wasDirtyParentViewBoundingRects;
|
||||||
if (itemClipsChildrenToShape && !bypassUpdateClip) {
|
if (itemClipsChildrenToShape && !bypassUpdateClip) {
|
||||||
// Make sure child updates are clipped to the item's bounding rect.
|
// Make sure child updates are clipped to the item's bounding rect.
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->setUpdateClip(item);
|
view->d_func()->setUpdateClip(item);
|
||||||
}
|
}
|
||||||
if (!dirtyAncestorContainsChildren) {
|
if (!dirtyAncestorContainsChildren) {
|
||||||
dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending
|
dirtyAncestorContainsChildren = item->d_ptr->fullUpdatePending
|
||||||
@ -5308,8 +5304,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
|
|||||||
const bool allChildrenDirty = item->d_ptr->allChildrenDirty;
|
const bool allChildrenDirty = item->d_ptr->allChildrenDirty;
|
||||||
const bool parentIgnoresVisible = item->d_ptr->ignoreVisible;
|
const bool parentIgnoresVisible = item->d_ptr->ignoreVisible;
|
||||||
const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity;
|
const bool parentIgnoresOpacity = item->d_ptr->ignoreOpacity;
|
||||||
for (int i = 0; i < item->d_ptr->children.size(); ++i) {
|
for (auto child : qAsConst(item->d_ptr->children)) {
|
||||||
QGraphicsItem *child = item->d_ptr->children.at(i);
|
|
||||||
if (wasDirtyParentSceneTransform)
|
if (wasDirtyParentSceneTransform)
|
||||||
child->d_ptr->dirtySceneTransform = 1;
|
child->d_ptr->dirtySceneTransform = 1;
|
||||||
if (wasDirtyParentViewBoundingRects)
|
if (wasDirtyParentViewBoundingRects)
|
||||||
@ -5329,8 +5324,8 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
|
|||||||
|
|
||||||
if (itemClipsChildrenToShape) {
|
if (itemClipsChildrenToShape) {
|
||||||
// Reset updateClip.
|
// Reset updateClip.
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->setUpdateClip(nullptr);
|
view->d_func()->setUpdateClip(nullptr);
|
||||||
}
|
}
|
||||||
} else if (wasDirtyParentSceneTransform) {
|
} else if (wasDirtyParentSceneTransform) {
|
||||||
item->d_ptr->invalidateChildrenSceneTransform();
|
item->d_ptr->invalidateChildrenSceneTransform();
|
||||||
@ -5410,8 +5405,8 @@ void QGraphicsScene::drawItems(QPainter *painter,
|
|||||||
|
|
||||||
d->rectAdjust = oldRectAdjust;
|
d->rectAdjust = oldRectAdjust;
|
||||||
// Reset discovery bits.
|
// Reset discovery bits.
|
||||||
for (int i = 0; i < topLevelItems.size(); ++i)
|
for (auto topLevelItem : qAsConst(topLevelItems))
|
||||||
topLevelItems.at(i)->d_ptr->itemDiscovered = 0;
|
topLevelItem->d_ptr->itemDiscovered = 0;
|
||||||
|
|
||||||
painter->setWorldTransform(viewTransform);
|
painter->setWorldTransform(viewTransform);
|
||||||
painter->setOpacity(opacity);
|
painter->setOpacity(opacity);
|
||||||
@ -5903,9 +5898,9 @@ void QGraphicsScenePrivate::addView(QGraphicsView *view)
|
|||||||
{
|
{
|
||||||
views << view;
|
views << view;
|
||||||
#ifndef QT_NO_GESTURES
|
#ifndef QT_NO_GESTURES
|
||||||
const auto gestures = grabbedGestures.keys();
|
for (auto it = grabbedGestures.constBegin();
|
||||||
for (Qt::GestureType gesture : gestures)
|
it != grabbedGestures.constEnd(); ++it)
|
||||||
view->viewport()->grabGesture(gesture);
|
view->viewport()->grabGesture(it.key());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5934,7 +5929,7 @@ int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos)
|
|||||||
{
|
{
|
||||||
int closestTouchPointId = -1;
|
int closestTouchPointId = -1;
|
||||||
qreal closestDistance = qreal(0.);
|
qreal closestDistance = qreal(0.);
|
||||||
foreach (const QTouchEvent::TouchPoint &touchPoint, sceneCurrentTouchPoints) {
|
for (const QTouchEvent::TouchPoint &touchPoint : qAsConst(sceneCurrentTouchPoints)) {
|
||||||
qreal distance = QLineF(scenePos, touchPoint.scenePos()).length();
|
qreal distance = QLineF(scenePos, touchPoint.scenePos()).length();
|
||||||
if (closestTouchPointId == -1|| distance < closestDistance) {
|
if (closestTouchPointId == -1|| distance < closestDistance) {
|
||||||
closestTouchPointId = touchPoint.id();
|
closestTouchPointId = touchPoint.id();
|
||||||
@ -5949,9 +5944,8 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
|
|||||||
typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
|
typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
|
||||||
QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents;
|
QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents;
|
||||||
|
|
||||||
for (int i = 0; i < sceneTouchEvent->touchPoints().count(); ++i) {
|
const auto touchPoints = sceneTouchEvent->touchPoints();
|
||||||
const QTouchEvent::TouchPoint &touchPoint = sceneTouchEvent->touchPoints().at(i);
|
for (const auto &touchPoint : touchPoints) {
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
QGraphicsItem *item = nullptr;
|
QGraphicsItem *item = nullptr;
|
||||||
if (touchPoint.state() == Qt::TouchPointPressed) {
|
if (touchPoint.state() == Qt::TouchPointPressed) {
|
||||||
@ -6049,12 +6043,11 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
|
|||||||
// if the TouchBegin handler recurses, we assume that means the event
|
// if the TouchBegin handler recurses, we assume that means the event
|
||||||
// has been implicitly accepted and continue to send touch events
|
// has been implicitly accepted and continue to send touch events
|
||||||
item->d_ptr->acceptedTouchBeginEvent = true;
|
item->d_ptr->acceptedTouchBeginEvent = true;
|
||||||
bool res = sendTouchBeginEvent(item, &touchEvent)
|
bool res = sendTouchBeginEvent(item, &touchEvent) && touchEvent.isAccepted();
|
||||||
&& touchEvent.isAccepted();
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
// forget about these touch points, we didn't handle them
|
// forget about these touch points, we didn't handle them
|
||||||
for (int i = 0; i < touchEvent.touchPoints().count(); ++i) {
|
const auto unhandledTouchPoints = touchEvent.touchPoints();
|
||||||
const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().at(i);
|
for (const auto &touchPoint : unhandledTouchPoints) {
|
||||||
itemForTouchPointId.remove(touchPoint.id());
|
itemForTouchPointId.remove(touchPoint.id());
|
||||||
sceneCurrentTouchPoints.remove(touchPoint.id());
|
sceneCurrentTouchPoints.remove(touchPoint.id());
|
||||||
}
|
}
|
||||||
@ -6089,7 +6082,7 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
|
|||||||
// Set focus on the topmost enabled item that can take focus.
|
// Set focus on the topmost enabled item that can take focus.
|
||||||
bool setFocus = false;
|
bool setFocus = false;
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
|
for (QGraphicsItem *item : qAsConst(cachedItemsUnderMouse)) {
|
||||||
if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
|
if (item->isEnabled() && ((item->flags() & QGraphicsItem::ItemIsFocusable) && item->d_ptr->mouseSetsFocus)) {
|
||||||
if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
|
if (!item->isWidget() || ((QGraphicsWidget *)item)->focusPolicy() & Qt::ClickFocus) {
|
||||||
setFocus = true;
|
setFocus = true;
|
||||||
@ -6116,7 +6109,7 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
|
|||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
bool eventAccepted = touchEvent->isAccepted();
|
bool eventAccepted = touchEvent->isAccepted();
|
||||||
foreach (QGraphicsItem *item, cachedItemsUnderMouse) {
|
for (QGraphicsItem *item : qAsConst(cachedItemsUnderMouse)) {
|
||||||
// first, try to deliver the touch event
|
// first, try to deliver the touch event
|
||||||
updateTouchPointsForItem(item, touchEvent);
|
updateTouchPointsForItem(item, touchEvent);
|
||||||
bool acceptTouchEvents = item->acceptTouchEvents();
|
bool acceptTouchEvents = item->acceptTouchEvents();
|
||||||
@ -6132,10 +6125,9 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
|
|||||||
touchEvent->spont = false;
|
touchEvent->spont = false;
|
||||||
if (res && eventAccepted) {
|
if (res && eventAccepted) {
|
||||||
// the first item to accept the TouchBegin gets an implicit grab.
|
// the first item to accept the TouchBegin gets an implicit grab.
|
||||||
for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
|
const auto touchPoints = touchEvent->touchPoints();
|
||||||
const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i);
|
for (const auto &touchPoint : touchPoints)
|
||||||
itemForTouchPointId[touchPoint.id()] = item; // can be zero
|
itemForTouchPointId[touchPoint.id()] = item; // can be zero
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (item && item->isPanel())
|
if (item && item->isPanel())
|
||||||
@ -6148,14 +6140,14 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
|
|||||||
|
|
||||||
void QGraphicsScenePrivate::enableTouchEventsOnViews()
|
void QGraphicsScenePrivate::enableTouchEventsOnViews()
|
||||||
{
|
{
|
||||||
foreach (QGraphicsView *view, views)
|
for (QGraphicsView *view : qAsConst(views))
|
||||||
view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
|
view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGraphicsScenePrivate::updateInputMethodSensitivityInViews()
|
void QGraphicsScenePrivate::updateInputMethodSensitivityInViews()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < views.size(); ++i)
|
for (auto view : qAsConst(views))
|
||||||
views.at(i)->d_func()->updateInputMethodSensitivity();
|
view->d_func()->updateInputMethodSensitivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::PanelModality previousModality)
|
void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::PanelModality previousModality)
|
||||||
@ -6171,11 +6163,12 @@ void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::Pane
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSet<QGraphicsItem *> blockedPanels;
|
QSet<QGraphicsItem *> blockedPanels;
|
||||||
QList<QGraphicsItem *> items = q->items(); // ### store panels separately
|
{
|
||||||
for (int i = 0; i < items.count(); ++i) {
|
const auto items_ = q->items();
|
||||||
QGraphicsItem *item = items.at(i);
|
for (const auto &item : items_) {
|
||||||
if (item->isPanel() && item->isBlockedByModalPanel())
|
if (item->isPanel() && item->isBlockedByModalPanel())
|
||||||
blockedPanels.insert(item);
|
blockedPanels.insert(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// blockedPanels contains all currently blocked panels
|
// blockedPanels contains all currently blocked panels
|
||||||
|
|
||||||
@ -6203,8 +6196,8 @@ void QGraphicsScenePrivate::enterModal(QGraphicsItem *panel, QGraphicsItem::Pane
|
|||||||
|
|
||||||
QEvent windowBlockedEvent(QEvent::WindowBlocked);
|
QEvent windowBlockedEvent(QEvent::WindowBlocked);
|
||||||
QEvent windowUnblockedEvent(QEvent::WindowUnblocked);
|
QEvent windowUnblockedEvent(QEvent::WindowUnblocked);
|
||||||
for (int i = 0; i < items.count(); ++i) {
|
const auto items_ = q->items();
|
||||||
QGraphicsItem *item = items.at(i);
|
for (const auto &item : items_) {
|
||||||
if (item->isPanel()) {
|
if (item->isPanel()) {
|
||||||
if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) {
|
if (!blockedPanels.contains(item) && item->isBlockedByModalPanel()) {
|
||||||
// send QEvent::WindowBlocked to newly blocked panels
|
// send QEvent::WindowBlocked to newly blocked panels
|
||||||
@ -6224,20 +6217,23 @@ void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel)
|
|||||||
Q_ASSERT(panel && panel->isPanel());
|
Q_ASSERT(panel && panel->isPanel());
|
||||||
|
|
||||||
QSet<QGraphicsItem *> blockedPanels;
|
QSet<QGraphicsItem *> blockedPanels;
|
||||||
QList<QGraphicsItem *> items = q->items(); // ### same as above
|
{
|
||||||
for (int i = 0; i < items.count(); ++i) {
|
const auto items_ = q->items();
|
||||||
QGraphicsItem *item = items.at(i);
|
for (const auto &item : items_) {
|
||||||
if (item->isPanel() && item->isBlockedByModalPanel())
|
if (item->isPanel() && item->isBlockedByModalPanel())
|
||||||
blockedPanels.insert(item);
|
blockedPanels.insert(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
modalPanels.removeAll(panel);
|
modalPanels.removeAll(panel);
|
||||||
|
|
||||||
QEvent e(QEvent::WindowUnblocked);
|
{
|
||||||
for (int i = 0; i < items.count(); ++i) {
|
QEvent e(QEvent::WindowUnblocked);
|
||||||
QGraphicsItem *item = items.at(i);
|
const auto items_ = q->items();
|
||||||
if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
|
for (const auto &item : items_) {
|
||||||
sendEvent(item, &e);
|
if (item->isPanel() && blockedPanels.contains(item) && !item->isBlockedByModalPanel())
|
||||||
|
sendEvent(item, &e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send GraphicsSceneHoverEnter events to newly unblocked items
|
// send GraphicsSceneHoverEnter events to newly unblocked items
|
||||||
@ -6259,7 +6255,7 @@ void QGraphicsScenePrivate::gestureTargetsAtHotSpots(const QSet<QGesture *> &ges
|
|||||||
if (!gesture->hasHotSpot())
|
if (!gesture->hasHotSpot())
|
||||||
continue;
|
continue;
|
||||||
const Qt::GestureType gestureType = gesture->gestureType();
|
const Qt::GestureType gestureType = gesture->gestureType();
|
||||||
QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, nullptr);
|
const QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, nullptr);
|
||||||
for (int j = 0; j < items.size(); ++j) {
|
for (int j = 0; j < items.size(); ++j) {
|
||||||
QGraphicsItem *item = items.at(j);
|
QGraphicsItem *item = items.at(j);
|
||||||
|
|
||||||
@ -6431,9 +6427,9 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||||||
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
|
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
|
||||||
for (int i = 0; i < cachedTargetItems.size(); ++i) {
|
for (int i = 0; i < cachedTargetItems.size(); ++i) {
|
||||||
QPointer<QGraphicsObject> receiver = cachedTargetItems.at(i);
|
QPointer<QGraphicsObject> receiver = cachedTargetItems.at(i);
|
||||||
QSet<QGesture *> gestures =
|
const QSet<QGesture *> gestures = (undeliveredGestures
|
||||||
undeliveredGestures & cachedItemGestures.value(receiver.data());
|
& cachedItemGestures.value(receiver.data()))
|
||||||
gestures -= cachedAlreadyDeliveredGestures.value(receiver.data());
|
- cachedAlreadyDeliveredGestures.value(receiver.data());
|
||||||
|
|
||||||
if (gestures.isEmpty())
|
if (gestures.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
@ -6448,7 +6444,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||||||
ev.setWidget(event->widget());
|
ev.setWidget(event->widget());
|
||||||
sendEvent(receiver.data(), &ev);
|
sendEvent(receiver.data(), &ev);
|
||||||
QSet<QGesture *> ignoredGestures;
|
QSet<QGesture *> ignoredGestures;
|
||||||
for (QGesture *g : qAsConst(gestures)) {
|
for (QGesture *g : gestures) {
|
||||||
if (!ev.isAccepted() && !ev.isAccepted(g)) {
|
if (!ev.isAccepted() && !ev.isAccepted(g)) {
|
||||||
// if the gesture was ignored by its target, we will update the
|
// if the gesture was ignored by its target, we will update the
|
||||||
// targetItems list with a possible target items (items that
|
// targetItems list with a possible target items (items that
|
||||||
@ -6516,7 +6512,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QGesture *g, startedGestures) {
|
for (QGesture *g : qAsConst(startedGestures)) {
|
||||||
if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) {
|
if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) {
|
||||||
DEBUG() << "lets try to cancel some";
|
DEBUG() << "lets try to cancel some";
|
||||||
// find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them
|
// find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them
|
||||||
@ -6598,17 +6594,17 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original)
|
|||||||
if (!g->hasHotSpot())
|
if (!g->hasHotSpot())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, nullptr);
|
const QList<QGraphicsItem *> items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, nullptr);
|
||||||
for (int j = 0; j < items.size(); ++j) {
|
for (const auto &item : items) {
|
||||||
QGraphicsObject *item = items.at(j)->toGraphicsObject();
|
QGraphicsObject *object = item->toGraphicsObject();
|
||||||
if (!item)
|
if (!object)
|
||||||
continue;
|
continue;
|
||||||
QGraphicsItemPrivate *d = item->QGraphicsItem::d_func();
|
QGraphicsItemPrivate *d = object->QGraphicsItem::d_func();
|
||||||
if (d->gestureContext.contains(g->gestureType())) {
|
if (d->gestureContext.contains(g->gestureType())) {
|
||||||
QList<QGesture *> list;
|
QList<QGesture *> list;
|
||||||
list << g;
|
list << g;
|
||||||
QGestureEvent ev(list);
|
QGestureEvent ev(list);
|
||||||
sendEvent(item, &ev);
|
sendEvent(object, &ev);
|
||||||
if (ev.isAccepted() || ev.isAccepted(g))
|
if (ev.isAccepted() || ev.isAccepted(g))
|
||||||
break; // successfully delivered
|
break; // successfully delivered
|
||||||
}
|
}
|
||||||
@ -6629,7 +6625,7 @@ void QGraphicsScenePrivate::grabGesture(QGraphicsItem *, Qt::GestureType gesture
|
|||||||
{
|
{
|
||||||
(void)QGestureManager::instance(); // create a gesture manager
|
(void)QGestureManager::instance(); // create a gesture manager
|
||||||
if (!grabbedGestures[gesture]++) {
|
if (!grabbedGestures[gesture]++) {
|
||||||
foreach (QGraphicsView *view, views)
|
for (QGraphicsView *view : qAsConst(views))
|
||||||
view->viewport()->grabGesture(gesture);
|
view->viewport()->grabGesture(gesture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6641,7 +6637,7 @@ void QGraphicsScenePrivate::ungrabGesture(QGraphicsItem *item, Qt::GestureType g
|
|||||||
QGraphicsObject *obj = static_cast<QGraphicsObject *>(item);
|
QGraphicsObject *obj = static_cast<QGraphicsObject *>(item);
|
||||||
QGestureManager::instance()->cleanupCachedGestures(obj, gesture);
|
QGestureManager::instance()->cleanupCachedGestures(obj, gesture);
|
||||||
if (!--grabbedGestures[gesture]) {
|
if (!--grabbedGestures[gesture]) {
|
||||||
foreach (QGraphicsView *view, views)
|
for (QGraphicsView *view : qAsConst(views))
|
||||||
view->viewport()->ungrabGesture(gesture);
|
view->viewport()->ungrabGesture(gesture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -693,7 +693,7 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
|
|||||||
mouseEvent.widget());
|
mouseEvent.widget());
|
||||||
}
|
}
|
||||||
// Find the topmost item under the mouse with a cursor.
|
// Find the topmost item under the mouse with a cursor.
|
||||||
foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {
|
for (QGraphicsItem *item : qAsConst(scene->d_func()->cachedItemsUnderMouse)) {
|
||||||
if (item->isEnabled() && item->hasCursor()) {
|
if (item->isEnabled() && item->hasCursor()) {
|
||||||
_q_setViewportCursor(item->cursor());
|
_q_setViewportCursor(item->cursor());
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user