summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview')
-rw-r--r--src/widgets/graphicsview/graphicsview.pri61
-rw-r--r--src/widgets/graphicsview/qgraph_p.h46
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout.cpp71
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout.h40
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp337
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout_p.h210
-rw-r--r--src/widgets/graphicsview/qgraphicsgridlayout.cpp63
-rw-r--r--src/widgets/graphicsview/qgraphicsgridlayout.h40
-rw-r--r--src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp70
-rw-r--r--src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h48
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.cpp591
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.h99
-rw-r--r--src/widgets/graphicsview/qgraphicsitem_p.h115
-rw-r--r--src/widgets/graphicsview/qgraphicsitemanimation.cpp105
-rw-r--r--src/widgets/graphicsview/qgraphicsitemanimation.h50
-rw-r--r--src/widgets/graphicsview/qgraphicslayout.cpp42
-rw-r--r--src/widgets/graphicsview/qgraphicslayout.h42
-rw-r--r--src/widgets/graphicsview/qgraphicslayout_p.cpp42
-rw-r--r--src/widgets/graphicsview/qgraphicslayout_p.h50
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutitem.cpp63
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutitem.h43
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutitem_p.h40
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp46
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h40
-rw-r--r--src/widgets/graphicsview/qgraphicslinearlayout.cpp60
-rw-r--r--src/widgets/graphicsview/qgraphicslinearlayout.h40
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp194
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.h40
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget_p.h42
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp739
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.h77
-rw-r--r--src/widgets/graphicsview/qgraphicsscene_bsp.cpp126
-rw-r--r--src/widgets/graphicsview/qgraphicsscene_bsp_p.h64
-rw-r--r--src/widgets/graphicsview/qgraphicsscene_p.h44
-rw-r--r--src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp40
-rw-r--r--src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h40
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.cpp137
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.h55
-rw-r--r--src/widgets/graphicsview/qgraphicssceneindex.cpp43
-rw-r--r--src/widgets/graphicsview/qgraphicssceneindex_p.h40
-rw-r--r--src/widgets/graphicsview/qgraphicsscenelinearindex.cpp42
-rw-r--r--src/widgets/graphicsview/qgraphicsscenelinearindex_p.h40
-rw-r--r--src/widgets/graphicsview/qgraphicstransform.cpp48
-rw-r--r--src/widgets/graphicsview/qgraphicstransform.h40
-rw-r--r--src/widgets/graphicsview/qgraphicstransform_p.h43
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp646
-rw-r--r--src/widgets/graphicsview/qgraphicsview.h64
-rw-r--r--src/widgets/graphicsview/qgraphicsview_p.h52
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp199
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.h50
-rw-r--r--src/widgets/graphicsview/qgraphicswidget_p.cpp74
-rw-r--r--src/widgets/graphicsview/qgraphicswidget_p.h40
-rw-r--r--src/widgets/graphicsview/qsimplex_p.cpp58
-rw-r--r--src/widgets/graphicsview/qsimplex_p.h40
54 files changed, 1607 insertions, 3964 deletions
diff --git a/src/widgets/graphicsview/graphicsview.pri b/src/widgets/graphicsview/graphicsview.pri
deleted file mode 100644
index d69a6f5c3f..0000000000
--- a/src/widgets/graphicsview/graphicsview.pri
+++ /dev/null
@@ -1,61 +0,0 @@
-# Qt graphicsview module
-
-qtConfig(graphicsview) {
-HEADERS += graphicsview/qgraphicsgridlayout.h \
- graphicsview/qgraphicsitem.h \
- graphicsview/qgraphicsitem_p.h \
- graphicsview/qgraphicslayout.h \
- graphicsview/qgraphicslayout_p.h \
- graphicsview/qgraphicslayoutitem.h \
- graphicsview/qgraphicslayoutitem_p.h \
- graphicsview/qgraphicslinearlayout.h \
- graphicsview/qgraphicsproxywidget.h \
- graphicsview/qgraphicsproxywidget_p.h \
- graphicsview/qgraphicsscene.h \
- graphicsview/qgraphicsscene_bsp_p.h \
- graphicsview/qgraphicsscene_p.h \
- graphicsview/qgraphicsscenebsptreeindex_p.h \
- graphicsview/qgraphicssceneevent.h \
- graphicsview/qgraphicssceneindex_p.h \
- graphicsview/qgraphicsscenelinearindex_p.h \
- graphicsview/qgraphicstransform.h \
- graphicsview/qgraphicstransform_p.h \
- graphicsview/qgraphicsview.h \
- graphicsview/qgraphicsview_p.h \
- graphicsview/qgraphicswidget.h \
- graphicsview/qgraphicswidget_p.h \
- graphicsview/qgraphicslayoutstyleinfo_p.h \
- graphicsview/qgraphicsgridlayoutengine_p.h \
- graphicsview/qgraph_p.h \
- graphicsview/qsimplex_p.h \
- graphicsview/qgraphicsanchorlayout_p.h \
- graphicsview/qgraphicsanchorlayout.h
-
-SOURCES += graphicsview/qgraphicsgridlayout.cpp \
- graphicsview/qgraphicsitem.cpp \
- graphicsview/qgraphicslayout.cpp \
- graphicsview/qgraphicslayout_p.cpp \
- graphicsview/qgraphicslayoutitem.cpp \
- graphicsview/qgraphicslinearlayout.cpp \
- graphicsview/qgraphicsproxywidget.cpp \
- graphicsview/qgraphicsscene.cpp \
- graphicsview/qgraphicsscene_bsp.cpp \
- graphicsview/qgraphicsscenebsptreeindex.cpp \
- graphicsview/qgraphicssceneevent.cpp \
- graphicsview/qgraphicssceneindex.cpp \
- graphicsview/qgraphicsscenelinearindex.cpp \
- graphicsview/qgraphicstransform.cpp \
- graphicsview/qgraphicsview.cpp \
- graphicsview/qgraphicswidget.cpp \
- graphicsview/qgraphicswidget_p.cpp \
- graphicsview/qgraphicslayoutstyleinfo.cpp \
- graphicsview/qgraphicsgridlayoutengine.cpp \
- graphicsview/qsimplex_p.cpp \
- graphicsview/qgraphicsanchorlayout_p.cpp \
- graphicsview/qgraphicsanchorlayout.cpp
-
- qtConfig(easingcurve) {
- HEADERS += graphicsview/qgraphicsitemanimation.h
- SOURCES += graphicsview/qgraphicsitemanimation.cpp
- }
-}
diff --git a/src/widgets/graphicsview/qgraph_p.h b/src/widgets/graphicsview/qgraph_p.h
index dfe9d8fdd3..10c742d42e 100644
--- a/src/widgets/graphicsview/qgraph_p.h
+++ b/src/widgets/graphicsview/qgraph_p.h
@@ -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
#ifndef QGRAPH_P_H
#define QGRAPH_P_H
@@ -56,6 +20,7 @@
#include <QtCore/QQueue>
#include <QtCore/QString>
#include <QtCore/QDebug>
+#include <QtCore/QSet>
#include <functional> // for std::less
@@ -214,8 +179,9 @@ public:
return setOfVertices;
}
- QVector<QPair<Vertex*, Vertex*> > connections() const {
- QVector<QPair<Vertex*, Vertex*> > conns;
+ QList<QPair<Vertex *, Vertex *>> connections() const
+ {
+ QList<QPair<Vertex *, Vertex *>> conns;
for (const_iterator it = constBegin(); it != constEnd(); ++it) {
Vertex *from = it.from();
Vertex *to = it.to();
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp
index ea6a8018ca..4cb7165f37 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout.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 QGraphicsAnchorLayout
@@ -234,12 +198,12 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
}
}
- d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Horizontal);
- d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Vertical);
+ d->removeCenterConstraints(this, Qt::Horizontal);
+ d->removeCenterConstraints(this, Qt::Vertical);
d->deleteLayoutEdges();
- Q_ASSERT(d->itemCenterConstraints[0].isEmpty());
- Q_ASSERT(d->itemCenterConstraints[1].isEmpty());
+ Q_ASSERT(d->itemCenterConstraints[Qt::Horizontal].isEmpty());
+ Q_ASSERT(d->itemCenterConstraints[Qt::Vertical].isEmpty());
Q_ASSERT(d->items.isEmpty());
Q_ASSERT(d->m_vertexList.isEmpty());
}
@@ -353,7 +317,7 @@ void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem,
bool ok = true;
if (orientations & Qt::Horizontal) {
// Currently, if the first is ok, then the rest of the calls should be ok
- ok = addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft) != 0;
+ ok = addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft) != nullptr;
if (ok)
addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
}
@@ -372,7 +336,7 @@ void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->spacings[0] = spacing;
+ d->spacings[Qt::Horizontal] = spacing;
invalidate();
}
@@ -385,7 +349,7 @@ void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->spacings[1] = spacing;
+ d->spacings[Qt::Vertical] = spacing;
invalidate();
}
@@ -404,7 +368,7 @@ void QGraphicsAnchorLayout::setSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->spacings[0] = d->spacings[1] = spacing;
+ d->spacings = {spacing, spacing};
invalidate();
}
@@ -438,8 +402,8 @@ void QGraphicsAnchorLayout::setGeometry(const QRectF &geom)
Q_D(QGraphicsAnchorLayout);
QGraphicsLayout::setGeometry(geom);
- d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Horizontal);
- d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Vertical);
+ d->calculateVertexPositions(Qt::Horizontal);
+ d->calculateVertexPositions(Qt::Vertical);
d->setItemsGeometries(geom);
}
@@ -460,12 +424,12 @@ void QGraphicsAnchorLayout::removeAt(int index)
return;
// Removing an item affects both horizontal and vertical graphs
- d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Horizontal);
- d->removeCenterConstraints(item, QGraphicsAnchorLayoutPrivate::Vertical);
+ d->removeCenterConstraints(item, Qt::Horizontal);
+ d->removeCenterConstraints(item, Qt::Vertical);
d->removeAnchors(item);
d->items.remove(index);
- item->setParentLayoutItem(0);
+ item->setParentLayoutItem(nullptr);
invalidate();
}
@@ -518,9 +482,8 @@ QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, const QSizeF &constra
const_cast<QGraphicsAnchorLayoutPrivate *>(d)->calculateGraphs();
// ### apply constraint!
- QSizeF engineSizeHint(
- d->sizeHints[QGraphicsAnchorLayoutPrivate::Horizontal][which],
- d->sizeHints[QGraphicsAnchorLayoutPrivate::Vertical][which]);
+ QSizeF engineSizeHint{d->sizeHints[Qt::Horizontal][which],
+ d->sizeHints[Qt::Vertical][which]};
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.h b/src/widgets/graphicsview/qgraphicsanchorlayout.h
index 9bea43dd8e..5ddbd83e13 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout.h
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout.h
@@ -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
#ifndef QGRAPHICSANCHORLAYOUT_H
#define QGRAPHICSANCHORLAYOUT_H
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
index 4f44373cad..8a5280d44c 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -1,47 +1,10 @@
-/****************************************************************************
-**
-** 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
#include "qgraphicsanchorlayout_p.h"
#include <QtWidgets/qwidget.h>
#include <QtWidgets/qapplication.h>
-#include <QtCore/qlinkedlist.h>
#include <QtCore/qstack.h>
#ifdef QT_DEBUG
@@ -52,6 +15,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
// To ensure that all variables inside the simplex solver are non-negative,
// we limit the size of anchors in the interval [-limit, limit]. Then before
// sending them to the simplex solver we add "limit" as an offset, so that
@@ -61,7 +26,7 @@ QT_BEGIN_NAMESPACE
const qreal g_offset = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGETSIZE_MAX / 32;
QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version)
- : QObjectPrivate(version), layoutPrivate(0), data(0),
+ : QObjectPrivate(version), layoutPrivate(nullptr), data(nullptr),
sizePolicy(QSizePolicy::Fixed), preferredSize(0),
hasSize(true)
{
@@ -72,7 +37,7 @@ QGraphicsAnchorPrivate::~QGraphicsAnchorPrivate()
if (data) {
// The QGraphicsAnchor was already deleted at this moment. We must clean
// the dangling pointer to avoid double deletion in the AnchorData dtor.
- data->graphicsAnchor = 0;
+ data->graphicsAnchor = nullptr;
layoutPrivate->removeAnchor(data->from, data->to);
}
@@ -194,7 +159,7 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo)
maxPrefSize = maxSize;
return;
} else {
- if (orientation == QGraphicsAnchorLayoutPrivate::Horizontal) {
+ if (!isVertical) {
policy = item->sizePolicy().horizontalPolicy();
minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).width();
prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).width();
@@ -226,9 +191,9 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo)
if (anchorPrivate->hasSize) {
// Anchor has user-defined size
prefSizeHint = anchorPrivate->preferredSize;
- } else {
+ } else if (styleInfo) {
// Fetch size information from style
- const Qt::Orientation orient = Qt::Orientation(QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge) + 1);
+ const Qt::Orientation orient = QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge);
qreal s = styleInfo->defaultSpacing(orient);
if (s < 0) {
QSizePolicy::ControlType controlTypeFrom = from->m_item->sizePolicy().controlType();
@@ -242,6 +207,8 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo)
s = 0;
}
prefSizeHint = s;
+ } else {
+ prefSizeHint = 0;
}
}
@@ -492,9 +459,7 @@ void SequentialAnchorData::updateChildrenSizes()
// "from" or "to", that _contains_ one of them.
AnchorVertex *prev = from;
- for (int i = 0; i < m_edges.count(); ++i) {
- AnchorData *e = m_edges.at(i);
-
+ for (AnchorData *e : m_edges) {
const bool edgeIsForward = (e->from == prev);
if (edgeIsForward) {
e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->minPrefSize,
@@ -529,9 +494,7 @@ void SequentialAnchorData::calculateSizeHints()
AnchorVertex *prev = from;
- for (int i = 0; i < m_edges.count(); ++i) {
- AnchorData *edge = m_edges.at(i);
-
+ for (AnchorData *edge : m_edges) {
const bool edgeIsForward = (edge->from == prev);
if (edgeIsForward) {
minSize += edge->minSize;
@@ -565,12 +528,10 @@ void AnchorData::dump(int indent) {
p->firstEdge->dump(indent+2);
p->secondEdge->dump(indent+2);
} else if (type == Sequential) {
- SequentialAnchorData *s = static_cast<SequentialAnchorData *>(this);
- int kids = s->m_edges.count();
- qDebug("%*s type: sequential(%d):", indent, "", kids);
- for (int i = 0; i < kids; ++i) {
- s->m_edges.at(i)->dump(indent+2);
- }
+ const auto *s = static_cast<SequentialAnchorData *>(this);
+ qDebug("%*s type: sequential(%lld):", indent, "", qint64(s->m_edges.size()));
+ for (AnchorData *e : s->m_edges)
+ e->dump(indent + 2);
} else {
qDebug("%*s type: Normal:", indent, "");
}
@@ -608,7 +569,9 @@ QSimplexConstraint *GraphPath::constraint(const GraphPath &path) const
#ifdef QT_DEBUG
QString GraphPath::toString() const
{
- QString string(QLatin1String("Path: "));
+ QString string;
+ string += "Path: "_L1;
+
for (AnchorData *edge : positives)
string += QString::fromLatin1(" (+++) %1").arg(edge->toString());
@@ -622,19 +585,6 @@ QString GraphPath::toString() const
QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate()
: calculateGraphCacheDirty(true), styleInfoDirty(true)
{
- for (int i = 0; i < NOrientations; ++i) {
- for (int j = 0; j < 3; ++j) {
- sizeHints[i][j] = -1;
- }
- interpolationProgress[i] = -1;
-
- spacings[i] = -1;
- graphHasConflicts[i] = false;
-
- layoutFirstVertex[i] = 0;
- layoutCentralVertex[i] = 0;
- layoutLastVertex[i] = 0;
- }
}
Qt::AnchorPoint QGraphicsAnchorLayoutPrivate::oppositeEdge(Qt::AnchorPoint edge)
@@ -674,7 +624,7 @@ Qt::AnchorPoint QGraphicsAnchorLayoutPrivate::oppositeEdge(Qt::AnchorPoint edge)
*/
AnchorData *QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(AnchorData *newAnchor, bool *feasible)
{
- Orientation orientation = Orientation(newAnchor->orientation);
+ const Qt::Orientation orientation = newAnchor->isVertical ? Qt::Vertical : Qt::Horizontal;
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
*feasible = true;
@@ -710,7 +660,7 @@ AnchorData *QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(AnchorData *new
parallel->isCenterAnchor = true;
- for (int j = 0; j < constraints.count(); ++j) {
+ for (int j = 0; j < constraints.size(); ++j) {
QSimplexConstraint *c = constraints[j];
if (c->variables.contains(child)) {
childConstraints->append(c);
@@ -742,10 +692,8 @@ AnchorData *QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(AnchorData *new
Note that this function doesn't add the created anchor to the graph. This should be done by
the caller.
*/
-static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph,
- AnchorVertex *before,
- const QVector<AnchorVertex*> &vertices,
- AnchorVertex *after)
+static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph, AnchorVertex *before,
+ const QList<AnchorVertex *> &vertices, AnchorVertex *after)
{
#if defined(QT_DEBUG) && 0
QString strVertices;
@@ -757,10 +705,10 @@ static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph,
#endif
AnchorVertex *prev = before;
- QVector<AnchorData *> edges;
- edges.reserve(vertices.count() + 1);
+ QList<AnchorData *> edges;
+ edges.reserve(vertices.size() + 1);
- const int numVertices = vertices.count();
+ const int numVertices = vertices.size();
edges.reserve(numVertices + 1);
// Take from the graph, the edges that will be simplificated
for (int i = 0; i < numVertices; ++i) {
@@ -823,7 +771,7 @@ static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph,
When creating the parallel anchors, the algorithm might identify unfeasible situations. In this
case the simplification process stops and returns \c false. Otherwise returns \c true.
*/
-bool QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation)
+bool QGraphicsAnchorLayoutPrivate::simplifyGraph(Qt::Orientation orientation)
{
if (items.isEmpty())
return true;
@@ -880,13 +828,13 @@ static AnchorVertex *replaceVertex_helper(AnchorData *data, AnchorVertex *oldV,
return other;
}
-bool QGraphicsAnchorLayoutPrivate::replaceVertex(Orientation orientation, AnchorVertex *oldV,
+bool QGraphicsAnchorLayoutPrivate::replaceVertex(Qt::Orientation orientation, AnchorVertex *oldV,
AnchorVertex *newV, const QList<AnchorData *> &edges)
{
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
bool feasible = true;
- for (int i = 0; i < edges.count(); ++i) {
+ for (int i = 0; i < edges.size(); ++i) {
AnchorData *ad = edges[i];
AnchorVertex *otherV = replaceVertex_helper(ad, oldV, newV);
@@ -914,7 +862,7 @@ bool QGraphicsAnchorLayoutPrivate::replaceVertex(Orientation orientation, Anchor
/*!
\internal
*/
-bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation)
+bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Qt::Orientation orientation)
{
Q_Q(QGraphicsAnchorLayout);
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
@@ -934,7 +882,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation)
QList<AnchorVertex *> adjacents = g.adjacentVertices(v);
int index = 0;
- while (index < adjacents.count()) {
+ while (index < adjacents.size()) {
AnchorVertex *next = adjacents.at(index);
index++;
@@ -954,7 +902,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation)
const QList<AnchorVertex *> &vAdjacents = g.adjacentVertices(v);
const QList<AnchorVertex *> &nextAdjacents = g.adjacentVertices(next);
- for (int i = 0; i < vAdjacents.count(); ++i) {
+ for (int i = 0; i < vAdjacents.size(); ++i) {
AnchorVertex *adjacent = vAdjacents.at(i);
if (adjacent != next) {
AnchorData *ad = g.edgeData(v, adjacent);
@@ -962,7 +910,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation)
}
}
- for (int i = 0; i < nextAdjacents.count(); ++i) {
+ for (int i = 0; i < nextAdjacents.size(); ++i) {
AnchorVertex *adjacent = nextAdjacents.at(i);
if (adjacent != v) {
AnchorData *ad = g.edgeData(next, adjacent);
@@ -981,7 +929,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation)
feasible &= replaceVertex(orientation, next, newV, newV->m_secondAnchors);
// Update the layout vertex information if one of the vertices is a layout vertex.
- AnchorVertex *layoutVertex = 0;
+ AnchorVertex *layoutVertex = nullptr;
if (v->m_item == q)
layoutVertex = v;
else if (next->m_item == q)
@@ -1027,7 +975,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation)
Note that there are some catches to this that are not covered by the above explanation, see
the function comments for more details.
*/
-bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutPrivate::Orientation orientation,
+bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(Qt::Orientation orientation,
bool *feasible)
{
Q_Q(QGraphicsAnchorLayout);
@@ -1035,8 +983,8 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
QSet<AnchorVertex *> visited;
QStack<QPair<AnchorVertex *, AnchorVertex *> > stack;
- stack.push(qMakePair(static_cast<AnchorVertex *>(0), layoutFirstVertex[orientation]));
- QVector<AnchorVertex*> candidates;
+ stack.push(qMakePair(static_cast<AnchorVertex *>(nullptr), layoutFirstVertex[orientation]));
+ QList<AnchorVertex *> candidates;
// Walk depth-first, in the stack we store start of the candidate sequence (beforeSequence)
// and the vertex to be visited.
@@ -1065,7 +1013,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
//
// Identifies cases (a) and (b)
- endOfSequence = isLayoutVertex || adjacents.count() != 2;
+ endOfSequence = isLayoutVertex || adjacents.size() != 2;
if (!endOfSequence) {
// This is a tricky part. We peek at the next vertex to find out whether
@@ -1107,7 +1055,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
//
// Add next non-visited vertices to the stack.
//
- for (int i = 0; i < adjacents.count(); ++i) {
+ for (int i = 0; i < adjacents.size(); ++i) {
AnchorVertex *next = adjacents.at(i);
if (visited.contains(next))
continue;
@@ -1146,7 +1094,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
const AnchorData *lastAnchor = g.edgeData(candidates.constLast(), afterSequence);
if (lastAnchor->isCenterAnchor) {
afterSequence = candidates.constLast();
- candidates.remove(candidates.count() - 1);
+ candidates.remove(candidates.size() - 1);
if (candidates.isEmpty())
continue;
@@ -1185,6 +1133,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP
void QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(AnchorData *edge)
{
+ const Qt::Orientation orientation = edge->isVertical ? Qt::Vertical : Qt::Horizontal;
#if 0
static const char *anchortypes[] = {"Normal",
"Sequential",
@@ -1192,18 +1141,16 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(AnchorData *edge)
qDebug("Restoring %s edge.", anchortypes[int(edge->type)]);
#endif
- Graph<AnchorVertex, AnchorData> &g = graph[edge->orientation];
+ Graph<AnchorVertex, AnchorData> &g = graph[orientation];
if (edge->type == AnchorData::Normal) {
g.createEdge(edge->from, edge->to, edge);
} else if (edge->type == AnchorData::Sequential) {
- SequentialAnchorData *sequence = static_cast<SequentialAnchorData *>(edge);
+ const auto *sequence = static_cast<SequentialAnchorData *>(edge);
- for (int i = 0; i < sequence->m_edges.count(); ++i) {
- AnchorData *data = sequence->m_edges.at(i);
+ for (AnchorData *data : sequence->m_edges)
restoreSimplifiedAnchor(data);
- }
delete sequence;
@@ -1212,7 +1159,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(AnchorData *edge)
// Skip parallel anchors that were created by vertex simplification, they will be processed
// later, when restoring vertex simplification.
// ### we could improve this check bit having a bit inside 'edge'
- if (anchorsFromSimplifiedVertices[edge->orientation].contains(edge))
+ if (anchorsFromSimplifiedVertices[orientation].contains(edge))
return;
ParallelAnchorData* parallel = static_cast<ParallelAnchorData*>(edge);
@@ -1235,7 +1182,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorDa
if (!parallel->isCenterAnchor)
return;
- for (int i = 0; i < parallel->m_firstConstraints.count(); ++i) {
+ for (int i = 0; i < parallel->m_firstConstraints.size(); ++i) {
QSimplexConstraint *c = parallel->m_firstConstraints.at(i);
qreal v = c->variables[parallel];
c->variables.remove(parallel);
@@ -1246,7 +1193,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorDa
// addAnchorMaybeParallel().
const bool needsReverse = !parallel->secondForward();
- for (int i = 0; i < parallel->m_secondConstraints.count(); ++i) {
+ for (int i = 0; i < parallel->m_secondConstraints.size(); ++i) {
QSimplexConstraint *c = parallel->m_secondConstraints.at(i);
qreal v = c->variables[parallel];
if (needsReverse)
@@ -1256,7 +1203,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorDa
}
}
-void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Qt::Orientation orientation)
{
#if 0
qDebug("Restoring Simplified Graph for %s",
@@ -1265,8 +1212,8 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientatio
// Restore anchor simplification
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
- QVector<QPair<AnchorVertex*, AnchorVertex*> > connections = g.connections();
- for (int i = 0; i < connections.count(); ++i) {
+ QList<QPair<AnchorVertex *, AnchorVertex *>> connections = g.connections();
+ for (int i = 0; i < connections.size(); ++i) {
AnchorVertex *v1 = connections.at(i).first;
AnchorVertex *v2 = connections.at(i).second;
AnchorData *edge = g.edgeData(v1, v2);
@@ -1285,7 +1232,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientatio
restoreVertices(orientation);
}
-void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::restoreVertices(Qt::Orientation orientation)
{
Q_Q(QGraphicsAnchorLayout);
@@ -1302,14 +1249,14 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation)
// In the next step, we'll change the anchors vertices so that would not be possible anymore.
QList<AnchorData *> &parallelAnchors = anchorsFromSimplifiedVertices[orientation];
- for (int i = parallelAnchors.count() - 1; i >= 0; --i) {
+ for (int i = parallelAnchors.size() - 1; i >= 0; --i) {
ParallelAnchorData *parallel = static_cast<ParallelAnchorData *>(parallelAnchors.at(i));
restoreSimplifiedConstraints(parallel);
}
// Then, we will restore the vertices in the inverse order of creation, this way we ensure that
// the vertex being restored was not wrapped by another simplification.
- for (int i = toRestore.count() - 1; i >= 0; --i) {
+ for (int i = toRestore.size() - 1; i >= 0; --i) {
AnchorVertexPair *pair = toRestore.at(i);
QList<AnchorVertex *> adjacents = g.adjacentVertices(pair);
@@ -1320,7 +1267,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation)
g.createEdge(first, second, pair->m_removedAnchor);
// Restore the anchors for the first child vertex
- for (int j = 0; j < pair->m_firstAnchors.count(); ++j) {
+ for (int j = 0; j < pair->m_firstAnchors.size(); ++j) {
AnchorData *ad = pair->m_firstAnchors.at(j);
Q_ASSERT(ad->from == pair || ad->to == pair);
@@ -1329,7 +1276,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation)
}
// Restore the anchors for the second child vertex
- for (int j = 0; j < pair->m_secondAnchors.count(); ++j) {
+ for (int j = 0; j < pair->m_secondAnchors.size(); ++j) {
AnchorData *ad = pair->m_secondAnchors.at(j);
Q_ASSERT(ad->from == pair || ad->to == pair);
@@ -1337,7 +1284,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation)
g.createEdge(ad->from, ad->to, ad);
}
- for (int j = 0; j < adjacents.count(); ++j) {
+ for (int j = 0; j < adjacents.size(); ++j) {
g.takeEdge(pair, adjacents.at(j));
}
@@ -1356,10 +1303,10 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation)
toRestore.clear();
}
-QGraphicsAnchorLayoutPrivate::Orientation
-QGraphicsAnchorLayoutPrivate::edgeOrientation(Qt::AnchorPoint edge)
+Qt::Orientation
+QGraphicsAnchorLayoutPrivate::edgeOrientation(Qt::AnchorPoint edge) noexcept
{
- return edge > Qt::AnchorRight ? Vertical : Horizontal;
+ return edge > Qt::AnchorRight ? Qt::Vertical : Qt::Horizontal;
}
/*!
@@ -1383,9 +1330,9 @@ void QGraphicsAnchorLayoutPrivate::createLayoutEdges()
data->maxSize = QWIDGETSIZE_MAX;
// Save a reference to layout vertices
- layoutFirstVertex[Horizontal] = internalVertex(layout, Qt::AnchorLeft);
- layoutCentralVertex[Horizontal] = 0;
- layoutLastVertex[Horizontal] = internalVertex(layout, Qt::AnchorRight);
+ layoutFirstVertex[Qt::Horizontal] = internalVertex(layout, Qt::AnchorLeft);
+ layoutCentralVertex[Qt::Horizontal] = nullptr;
+ layoutLastVertex[Qt::Horizontal] = internalVertex(layout, Qt::AnchorRight);
// Vertical
data = new AnchorData;
@@ -1394,9 +1341,9 @@ void QGraphicsAnchorLayoutPrivate::createLayoutEdges()
data->maxSize = QWIDGETSIZE_MAX;
// Save a reference to layout vertices
- layoutFirstVertex[Vertical] = internalVertex(layout, Qt::AnchorTop);
- layoutCentralVertex[Vertical] = 0;
- layoutLastVertex[Vertical] = internalVertex(layout, Qt::AnchorBottom);
+ layoutFirstVertex[Qt::Vertical] = internalVertex(layout, Qt::AnchorTop);
+ layoutCentralVertex[Qt::Vertical] = nullptr;
+ layoutLastVertex[Qt::Vertical] = internalVertex(layout, Qt::AnchorBottom);
}
void QGraphicsAnchorLayoutPrivate::deleteLayoutEdges()
@@ -1443,13 +1390,13 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors(
{
Q_Q(QGraphicsAnchorLayout);
- Orientation orientation;
+ Qt::Orientation orientation;
switch (centerEdge) {
case Qt::AnchorHorizontalCenter:
- orientation = Horizontal;
+ orientation = Qt::Horizontal;
break;
case Qt::AnchorVerticalCenter:
- orientation = Vertical;
+ orientation = Qt::Vertical;
break;
default:
// Don't create center edges unless needed
@@ -1464,7 +1411,7 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors(
Qt::AnchorPoint firstEdge;
Qt::AnchorPoint lastEdge;
- if (orientation == Horizontal) {
+ if (orientation == Qt::Horizontal) {
firstEdge = Qt::AnchorLeft;
lastEdge = Qt::AnchorRight;
} else {
@@ -1509,13 +1456,13 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
{
Q_Q(QGraphicsAnchorLayout);
- Orientation orientation;
+ Qt::Orientation orientation;
switch (centerEdge) {
case Qt::AnchorHorizontalCenter:
- orientation = Horizontal;
+ orientation = Qt::Horizontal;
break;
case Qt::AnchorVerticalCenter:
- orientation = Vertical;
+ orientation = Qt::Vertical;
break;
default:
// Don't remove edges that not the center ones
@@ -1526,7 +1473,7 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
Qt::AnchorPoint firstEdge;
Qt::AnchorPoint lastEdge;
- if (orientation == Horizontal) {
+ if (orientation == Qt::Horizontal) {
firstEdge = Qt::AnchorLeft;
lastEdge = Qt::AnchorRight;
} else {
@@ -1547,7 +1494,7 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
AnchorData *oldData = g.edgeData(first, center);
// Remove center constraint
- for (int i = itemCenterConstraints[orientation].count() - 1; i >= 0; --i) {
+ for (int i = itemCenterConstraints[orientation].size() - 1; i >= 0; --i) {
if (itemCenterConstraints[orientation].at(i)->variables.contains(oldData)) {
delete itemCenterConstraints[orientation].takeAt(i);
break;
@@ -1568,7 +1515,7 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
// this is only called from removeAnchors()
// first, remove all non-internal anchors
QList<AnchorVertex*> adjacents = g.adjacentVertices(center);
- for (int i = 0; i < adjacents.count(); ++i) {
+ for (int i = 0; i < adjacents.size(); ++i) {
AnchorVertex *v = adjacents.at(i);
if (v->m_item != item) {
removeAnchor_helper(center, internalVertex(v->m_item, v->m_edge));
@@ -1581,23 +1528,23 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors(
}
if (item == q) {
- layoutCentralVertex[orientation] = 0;
+ layoutCentralVertex[orientation] = nullptr;
}
}
void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem *item,
- Orientation orientation)
+ Qt::Orientation orientation)
{
// Remove the item center constraints associated to this item
// ### This is a temporary solution. We should probably use a better
// data structure to hold items and/or their associated constraints
// so that we can remove those easily
- AnchorVertex *first = internalVertex(item, orientation == Horizontal ?
+ AnchorVertex *first = internalVertex(item, orientation == Qt::Horizontal ?
Qt::AnchorLeft :
Qt::AnchorTop);
- AnchorVertex *center = internalVertex(item, orientation == Horizontal ?
+ AnchorVertex *center = internalVertex(item, orientation == Qt::Horizontal ?
Qt::AnchorHorizontalCenter :
Qt::AnchorVerticalCenter);
@@ -1636,29 +1583,29 @@ QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *fi
qreal *spacing)
{
Q_Q(QGraphicsAnchorLayout);
- if ((firstItem == 0) || (secondItem == 0)) {
+ if ((firstItem == nullptr) || (secondItem == nullptr)) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"Cannot anchor NULL items");
- return 0;
+ return nullptr;
}
if (firstItem == secondItem) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"Cannot anchor the item to itself");
- return 0;
+ return nullptr;
}
if (edgeOrientation(secondEdge) != edgeOrientation(firstEdge)) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"Cannot anchor edges of different orientations");
- return 0;
+ return nullptr;
}
const QGraphicsLayoutItem *parentWidget = q->parentLayoutItem();
if (firstItem == parentWidget || secondItem == parentWidget) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"You cannot add the parent of the layout to the layout.");
- return 0;
+ return nullptr;
}
// In QGraphicsAnchorLayout, items are represented in its internal
@@ -1703,7 +1650,7 @@ QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *fi
// Right ? 0 0
if (firstItem == q
|| secondItem == q
- || pickEdge(firstEdge, Horizontal) == Qt::AnchorHorizontalCenter
+ || pickEdge(firstEdge, Qt::Horizontal) == Qt::AnchorHorizontalCenter
|| oppositeEdge(firstEdge) != secondEdge) {
graphicsAnchor->setSpacing(0);
} else {
@@ -1731,7 +1678,7 @@ void QGraphicsAnchorLayoutPrivate::addAnchor_helper(QGraphicsLayoutItem *firstIt
{
Q_Q(QGraphicsAnchorLayout);
- const Orientation orientation = edgeOrientation(firstEdge);
+ const Qt::Orientation orientation = edgeOrientation(firstEdge);
// Create or increase the reference count for the related vertices.
AnchorVertex *v1 = addInternalVertex(firstItem, firstEdge);
@@ -1746,7 +1693,7 @@ void QGraphicsAnchorLayoutPrivate::addAnchor_helper(QGraphicsLayoutItem *firstIt
if (firstItem == secondItem)
data->item = firstItem;
- data->orientation = orientation;
+ data->isVertical = orientation == Qt::Vertical;
// Create a bi-directional edge in the sense it can be transversed both
// from v1 or v2. "data" however is shared between the two references
@@ -1770,13 +1717,13 @@ QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::getAnchor(QGraphicsLayoutItem *fi
{
// Do not expose internal anchors
if (firstItem == secondItem)
- return 0;
+ return nullptr;
- const Orientation orientation = edgeOrientation(firstEdge);
+ const Qt::Orientation orientation = edgeOrientation(firstEdge);
AnchorVertex *v1 = internalVertex(firstItem, firstEdge);
AnchorVertex *v2 = internalVertex(secondItem, secondEdge);
- QGraphicsAnchor *graphicsAnchor = 0;
+ QGraphicsAnchor *graphicsAnchor = nullptr;
AnchorData *data = graph[orientation].edgeData(v1, v2);
if (data) {
@@ -1811,7 +1758,7 @@ void QGraphicsAnchorLayoutPrivate::removeAnchor(AnchorVertex *firstVertex,
removeAnchor_helper(firstVertex, secondVertex);
// Ensure no dangling pointer is left behind
- firstVertex = secondVertex = 0;
+ firstVertex = secondVertex = nullptr;
// Checking if the item stays in the layout or not
bool keepFirstItem = false;
@@ -1877,7 +1824,7 @@ void QGraphicsAnchorLayoutPrivate::removeAnchor_helper(AnchorVertex *v1, AnchorV
Q_ASSERT(v1 && v2);
// Remove edge from graph
- const Orientation o = edgeOrientation(v1->m_edge);
+ const Qt::Orientation o = edgeOrientation(v1->m_edge);
graph[o].removeEdge(v1, v2);
// Decrease vertices reference count (may trigger a deletion)
@@ -1938,7 +1885,7 @@ void QGraphicsAnchorLayoutPrivate::removeVertex(QGraphicsLayoutItem *item, Qt::A
{
if (AnchorVertex *v = internalVertex(item, edge)) {
Graph<AnchorVertex, AnchorData> &g = graph[edgeOrientation(edge)];
- const QList<AnchorVertex *> allVertices = graph[edgeOrientation(edge)].adjacentVertices(v);
+ const auto allVertices = g.adjacentVertices(v);
for (auto *v2 : allVertices) {
g.removeEdge(v, v2);
removeInternalVertex(item, edge);
@@ -2017,13 +1964,13 @@ QLayoutStyleInfo &QGraphicsAnchorLayoutPrivate::styleInfo() const
if (styleInfoDirty) {
Q_Q(const QGraphicsAnchorLayout);
//### Fix this if QGV ever gets support for Metal style or different Aqua sizes.
- QWidget *wid = 0;
+ QWidget *wid = nullptr;
QGraphicsLayoutItem *parent = q->parentLayoutItem();
while (parent && parent->isLayout()) {
parent = parent->parentLayoutItem();
}
- QGraphicsWidget *w = 0;
+ QGraphicsWidget *w = nullptr;
if (parent) {
QGraphicsItem *parentItem = parent->graphicsItem();
if (parentItem && parentItem->isWidget())
@@ -2032,8 +1979,8 @@ QLayoutStyleInfo &QGraphicsAnchorLayoutPrivate::styleInfo() const
QStyle *style = w ? w->style() : QApplication::style();
cachedStyleInfo = QLayoutStyleInfo(style, wid);
- cachedStyleInfo.setDefaultSpacing(Qt::Horizontal, spacings[0]);
- cachedStyleInfo.setDefaultSpacing(Qt::Vertical, spacings[1]);
+ cachedStyleInfo.setDefaultSpacing(Qt::Horizontal, spacings[Qt::Horizontal]);
+ cachedStyleInfo.setDefaultSpacing(Qt::Vertical, spacings[Qt::Vertical]);
styleInfoDirty = false;
}
@@ -2051,8 +1998,8 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs()
{
if (!calculateGraphCacheDirty)
return;
- calculateGraphs(Horizontal);
- calculateGraphs(Vertical);
+ calculateGraphs(Qt::Horizontal);
+ calculateGraphs(Qt::Vertical);
calculateGraphCacheDirty = false;
}
@@ -2061,7 +2008,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs()
QList<AnchorData *> getVariables(const QList<QSimplexConstraint *> &constraints)
{
QSet<AnchorData *> variableSet;
- for (int i = 0; i < constraints.count(); ++i) {
+ for (int i = 0; i < constraints.size(); ++i) {
const QSimplexConstraint *c = constraints.at(i);
for (auto it = c->variables.cbegin(), end = c->variables.cend(); it != end; ++it)
variableSet.insert(static_cast<AnchorData *>(it.key()));
@@ -2078,7 +2025,7 @@ QList<AnchorData *> getVariables(const QList<QSimplexConstraint *> &constraints)
In a nutshell it should do:
1) Refresh anchor nominal sizes, that is, the size that each anchor would
- have if no other restrictions applied. This is done by quering the
+ have if no other restrictions applied. This is done by querying the
layout style and the sizeHints of the items belonging to the layout.
2) Simplify the graph by grouping together parallel and sequential anchors
@@ -2092,8 +2039,7 @@ QList<AnchorData *> getVariables(const QList<QSimplexConstraint *> &constraints)
4) Once the root anchors had its sizes calculated, propagate that to the
anchors they represent.
*/
-void QGraphicsAnchorLayoutPrivate::calculateGraphs(
- QGraphicsAnchorLayoutPrivate::Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::calculateGraphs(Qt::Orientation orientation)
{
#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL)
lastCalculationUsedSimplex[orientation] = false;
@@ -2177,7 +2123,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs(
*/
static void shiftConstraints(const QList<QSimplexConstraint *> &constraints, qreal amount)
{
- for (int i = 0; i < constraints.count(); ++i) {
+ for (int i = 0; i < constraints.size(); ++i) {
QSimplexConstraint *c = constraints.at(i);
const qreal multiplier = std::accumulate(c->variables.cbegin(), c->variables.cend(), qreal(0));
c->constant += multiplier * amount;
@@ -2190,7 +2136,7 @@ static void shiftConstraints(const QList<QSimplexConstraint *> &constraints, qre
Calculate the sizes for all anchors which are part of the trunk. This works
on top of a (possibly) simplified graph.
*/
-bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const GraphPath &path,
+bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Qt::Orientation orientation, const GraphPath &path,
const QList<QSimplexConstraint *> &constraints,
const QList<AnchorData *> &variables)
{
@@ -2199,7 +2145,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const
#if 0
qDebug("Simplex %s for trunk of %s", needsSimplex ? "used" : "NOT used",
- orientation == Horizontal ? "Horizontal" : "Vertical");
+ orientation == Qt::Horizontal ? "Horizontal" : "Vertical");
#endif
if (needsSimplex) {
@@ -2235,8 +2181,8 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const
} else {
// No Simplex is necessary because the path was simplified all the way to a single
// anchor.
- Q_ASSERT(path.positives.count() == 1);
- Q_ASSERT(path.negatives.count() == 0);
+ Q_ASSERT(path.positives.size() == 1);
+ Q_ASSERT(path.negatives.size() == 0);
AnchorData *ad = *path.positives.cbegin();
ad->sizeAtMinimum = ad->minSize;
@@ -2267,7 +2213,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList<QSimplexConstra
if (feasible) {
// Propagate size at preferred to other sizes. Semi-floats always will be
// in their sizeAtPreferred.
- for (int j = 0; j < variables.count(); ++j) {
+ for (int j = 0; j < variables.size(); ++j) {
AnchorData *ad = variables.at(j);
Q_ASSERT(ad);
ad->sizeAtMinimum = ad->sizeAtPreferred;
@@ -2285,13 +2231,13 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList<QSimplexConstra
Traverse the graph refreshing the size hints. Edges will query their associated
item or graphicsAnchor for their size hints.
*/
-void QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(Qt::Orientation orientation)
{
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
- QVector<QPair<AnchorVertex *, AnchorVertex *> > vertices = g.connections();
+ QList<QPair<AnchorVertex *, AnchorVertex *>> vertices = g.connections();
QLayoutStyleInfo styleInf = styleInfo();
- for (int i = 0; i < vertices.count(); ++i) {
+ for (int i = 0; i < vertices.size(); ++i) {
AnchorData *data = g.edgeData(vertices.at(i).first, vertices.at(i).second);
data->refreshSizeHints(&styleInf);
}
@@ -2307,7 +2253,7 @@ void QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(Orientation orientation)
The list of paths is used later to generate a list of constraints.
*/
-void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::findPaths(Qt::Orientation orientation)
{
QQueue<QPair<AnchorVertex *, AnchorVertex *> > queue;
@@ -2359,7 +2305,7 @@ void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation)
the constraints and store them in a list so they can be used later
by the Simplex solver.
*/
-void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Qt::Orientation orientation)
{
const auto vertices = graphPaths[orientation].uniqueKeys();
for (AnchorVertex *vertex : vertices) {
@@ -2378,12 +2324,12 @@ void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Orientation orientation)
/*!
\internal
*/
-void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Qt::Orientation orientation)
{
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
- const QVector<QPair<AnchorVertex *, AnchorVertex *> > &vertices = g.connections();
+ const QList<QPair<AnchorVertex *, AnchorVertex *>> &vertices = g.connections();
- for (int i = 0; i < vertices.count(); ++i) {
+ for (int i = 0; i < vertices.size(); ++i) {
AnchorData *ad = g.edgeData(vertices.at(i).first, vertices.at(i).second);
ad->updateChildrenSizes();
}
@@ -2403,8 +2349,8 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
// Look for the layout edge. That can be either the first half in case the
// layout is split in two, or the whole layout anchor.
- Orientation orient = Orientation(anchors.first()->orientation);
- AnchorData *layoutEdge = 0;
+ const Qt::Orientation orient = anchors.first()->isVertical ? Qt::Vertical : Qt::Horizontal;
+ AnchorData *layoutEdge = nullptr;
if (layoutCentralVertex[orient]) {
layoutEdge = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]);
} else {
@@ -2423,7 +2369,7 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
actualMax = -layoutEdge->minSize;
}
if (actualMax != expectedMax) {
- layoutEdge = 0;
+ layoutEdge = nullptr;
}
// For each variable, create constraints based on size hints
@@ -2490,14 +2436,14 @@ QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin
\internal
*/
QGraphicsAnchorLayoutPrivate::GraphParts
-QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation)
+QGraphicsAnchorLayoutPrivate::getGraphParts(Qt::Orientation orientation)
{
GraphParts result;
Q_ASSERT(layoutFirstVertex[orientation] && layoutLastVertex[orientation]);
- AnchorData *edgeL1 = 0;
- AnchorData *edgeL2 = 0;
+ AnchorData *edgeL1 = nullptr;
+ AnchorData *edgeL2 = nullptr;
// The layout may have a single anchor between Left and Right or two half anchors
// passing through the center
@@ -2526,7 +2472,7 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation)
// Check if this constraint have some overlap with current
// trunk variables...
- for (QSimplexVariable *ad : qAsConst(trunkVariables)) {
+ for (QSimplexVariable *ad : std::as_const(trunkVariables)) {
if (c->variables.contains(ad)) {
match = true;
break;
@@ -2567,7 +2513,7 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation)
Use all visited Anchors on findPaths() so we can identify non-float Items.
*/
-void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &visited, Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &visited, Qt::Orientation orientation)
{
QSet<QGraphicsLayoutItem *> nonFloating;
@@ -2575,7 +2521,7 @@ void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &
identifyNonFloatItems_helper(ad, &nonFloating);
QSet<QGraphicsLayoutItem *> floatItems;
- for (QGraphicsLayoutItem *item : qAsConst(items)) {
+ for (QGraphicsLayoutItem *item : std::as_const(items)) {
if (!nonFloating.contains(item))
floatItems.insert(item);
}
@@ -2600,7 +2546,7 @@ void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems_helper(const AnchorData
nonFloatingItemsIdentifiedSoFar->insert(ad->item);
break;
case AnchorData::Sequential:
- foreach (const AnchorData *d, static_cast<const SequentialAnchorData *>(ad)->m_edges)
+ for (const AnchorData *d : static_cast<const SequentialAnchorData *>(ad)->m_edges)
identifyNonFloatItems_helper(d, nonFloatingItemsIdentifiedSoFar);
break;
case AnchorData::Parallel:
@@ -2625,7 +2571,7 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
qreal left;
qreal right;
- q->getContentsMargins(&left, &top, &right, 0);
+ q->getContentsMargins(&left, &top, &right, nullptr);
const Qt::LayoutDirection visualDir = visualDirection();
if (visualDir == Qt::RightToLeft)
qSwap(left, right);
@@ -2634,10 +2580,10 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
top += geom.top();
right = geom.right() - right;
- foreach (QGraphicsLayoutItem *item, items) {
+ for (QGraphicsLayoutItem *item : std::as_const(items)) {
QRectF newGeom;
QSizeF itemPreferredSize = item->effectiveSizeHint(Qt::PreferredSize);
- if (m_floatItems[Horizontal].contains(item)) {
+ if (m_floatItems[Qt::Horizontal].contains(item)) {
newGeom.setLeft(0);
newGeom.setRight(itemPreferredSize.width());
} else {
@@ -2653,7 +2599,7 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
}
}
- if (m_floatItems[Vertical].contains(item)) {
+ if (m_floatItems[Qt::Vertical].contains(item)) {
newGeom.setTop(0);
newGeom.setBottom(itemPreferredSize.height());
} else {
@@ -2674,8 +2620,7 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
Calculate the position of each vertex based on the paths to each of
them as well as the current edges sizes.
*/
-void QGraphicsAnchorLayoutPrivate::calculateVertexPositions(
- QGraphicsAnchorLayoutPrivate::Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::calculateVertexPositions(Qt::Orientation orientation)
{
QQueue<QPair<AnchorVertex *, AnchorVertex *> > queue;
QSet<AnchorVertex *> visited;
@@ -2706,7 +2651,7 @@ void QGraphicsAnchorLayoutPrivate::calculateVertexPositions(
interpolateEdge(pair.first, edge);
QList<AnchorVertex *> adjacents = graph[orientation].adjacentVertices(pair.second);
- for (int i = 0; i < adjacents.count(); ++i) {
+ for (int i = 0; i < adjacents.size(); ++i) {
if (!visited.contains(adjacents.at(i)))
queue.enqueue(qMakePair(pair.second, adjacents.at(i)));
}
@@ -2721,12 +2666,12 @@ void QGraphicsAnchorLayoutPrivate::calculateVertexPositions(
the edges.
*/
void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation(
- Orientation orientation)
+ Qt::Orientation orientation)
{
Q_Q(QGraphicsAnchorLayout);
qreal current;
- current = (orientation == Horizontal) ? q->contentsRect().width() : q->contentsRect().height();
+ current = (orientation == Qt::Horizontal) ? q->contentsRect().width() : q->contentsRect().height();
QPair<Interval, qreal> result;
result = getFactor(current,
@@ -2757,7 +2702,7 @@ void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation(
*/
void QGraphicsAnchorLayoutPrivate::interpolateEdge(AnchorVertex *base, AnchorData *edge)
{
- const Orientation orientation = Orientation(edge->orientation);
+ const Qt::Orientation orientation = edge->isVertical ? Qt::Vertical : Qt::Horizontal;
const QPair<Interval, qreal> factor(interpolationInterval[orientation],
interpolationProgress[orientation]);
@@ -2790,7 +2735,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList<QSimplexConstraint *>
for (iter = path.negatives.constBegin(); iter != path.negatives.constEnd(); ++iter)
objective.variables.insert(*iter, -1.0);
- const qreal objectiveOffset = (path.positives.count() - path.negatives.count()) * g_offset;
+ const qreal objectiveOffset = (path.positives.size() - path.negatives.size()) * g_offset;
simplex.setObjective(&objective);
// Calculate minimum values
@@ -2953,9 +2898,9 @@ bool QGraphicsAnchorLayoutPrivate::hasConflicts() const
QGraphicsAnchorLayoutPrivate *that = const_cast<QGraphicsAnchorLayoutPrivate*>(this);
that->calculateGraphs();
- bool floatConflict = !m_floatItems[0].isEmpty() || !m_floatItems[1].isEmpty();
+ bool floatConflict = !m_floatItems[Qt::Horizontal].isEmpty() || !m_floatItems[Qt::Vertical].isEmpty();
- return graphHasConflicts[0] || graphHasConflicts[1] || floatConflict;
+ return graphHasConflicts[Qt::Horizontal] || graphHasConflicts[Qt::Vertical] || floatConflict;
}
#ifdef QT_DEBUG
@@ -2966,8 +2911,8 @@ void QGraphicsAnchorLayoutPrivate::dumpGraph(const QString &name)
qWarning("Could not write to %ls", qUtf16Printable(file.fileName()));
QString str = QString::fromLatin1("digraph anchorlayout {\nnode [shape=\"rect\"]\n%1}");
- QString dotContents = graph[0].serializeToDot();
- dotContents += graph[1].serializeToDot();
+ QString dotContents = graph[Qt::Horizontal].serializeToDot();
+ dotContents += graph[Qt::Vertical].serializeToDot();
file.write(str.arg(dotContents).toLocal8Bit());
file.close();
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h
index b5f14948ac..880e262d34 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h
@@ -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
#ifndef QGRAPHICSANCHORLAYOUT_P_H
#define QGRAPHICSANCHORLAYOUT_P_H
@@ -60,6 +24,10 @@
#include "qgraph_p.h"
#include "qsimplex_p.h"
+#include <QtGui/private/qgridlayoutengine_p.h>
+
+#include <array>
+
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
@@ -79,25 +47,22 @@ namespace QtGraphicsAnchorLayout {
Represents a vertex (anchorage point) in the internal graph
*/
-struct AnchorVertex {
- enum Type {
- Normal = 0,
- Pair
- };
-
+struct AnchorVertex
+{
AnchorVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge)
- : m_item(item), m_edge(edge), m_type(Normal) {}
+ : m_item(item), m_edge(edge) {}
AnchorVertex()
- : m_item(nullptr), m_edge(Qt::AnchorPoint(0)), m_type(Normal) {}
+ : m_item(nullptr), m_edge(Qt::AnchorPoint(0)) {}
+
+ virtual ~AnchorVertex() = default;
#ifdef QT_DEBUG
- inline QString toString() const;
+ virtual inline QString toString() const;
#endif
QGraphicsLayoutItem *m_item;
Qt::AnchorPoint m_edge;
- uint m_type : 1;
// Current distance from this vertex to the layout edge (Left or Top)
// Value is calculated from the current anchors sizes.
@@ -129,7 +94,7 @@ struct AnchorData : public QSimplexVariable {
sizeAtMinimum(0), sizeAtPreferred(0),
sizeAtMaximum(0), item(nullptr), graphicsAnchor(nullptr),
type(Normal), isLayoutAnchor(false),
- isCenterAnchor(false), orientation(0),
+ isCenterAnchor(false), isVertical(false),
dependency(Independent) {}
virtual ~AnchorData();
@@ -168,7 +133,7 @@ struct AnchorData : public QSimplexVariable {
qreal sizeAtMaximum;
// References to the classes that represent this anchor in the public world
- // An anchor may represent a LayoutItem, it may also be acessible externally
+ // An anchor may represent a LayoutItem, it may also be accessible externally
// through a GraphicsAnchor "handler".
QGraphicsLayoutItem *item;
QGraphicsAnchor *graphicsAnchor;
@@ -176,7 +141,7 @@ struct AnchorData : public QSimplexVariable {
uint type : 2; // either Normal, Sequential or Parallel
uint isLayoutAnchor : 1; // if this anchor is an internal layout anchor
uint isCenterAnchor : 1;
- uint orientation : 1;
+ uint isVertical : 1;
uint dependency : 2; // either Independent, Master or Slave
};
@@ -189,21 +154,22 @@ inline QString AnchorData::toString() const
struct SequentialAnchorData : public AnchorData
{
- SequentialAnchorData(const QVector<AnchorVertex *> &vertices, const QVector<AnchorData *> &edges)
- : AnchorData(), m_children(vertices), m_edges(edges)
+ SequentialAnchorData(const QList<AnchorVertex *> &vertices, const QList<AnchorData *> &edges)
+ : AnchorData(), m_edges(edges)
{
type = AnchorData::Sequential;
- orientation = m_edges.at(0)->orientation;
+ isVertical = m_edges.at(0)->isVertical;
#ifdef QT_DEBUG
name = QString::fromLatin1("%1 -- %2").arg(vertices.first()->toString(), vertices.last()->toString());
+#else
+ Q_UNUSED(vertices);
#endif
}
virtual void updateChildrenSizes() override;
void calculateSizeHints();
- QVector<AnchorVertex*> m_children; // list of vertices in the sequence
- QVector<AnchorData*> m_edges; // keep the list of edges too.
+ const QList<AnchorData *> m_edges; // keep the list of edges too.
};
struct ParallelAnchorData : public AnchorData
@@ -212,7 +178,7 @@ struct ParallelAnchorData : public AnchorData
: AnchorData(), firstEdge(first), secondEdge(second)
{
type = AnchorData::Parallel;
- orientation = first->orientation;
+ isVertical = first->isVertical;
// This assert whether the child anchors share their vertices
Q_ASSERT(((first->from == second->from) && (first->to == second->to)) ||
@@ -246,8 +212,8 @@ struct ParallelAnchorData : public AnchorData
struct AnchorVertexPair : public AnchorVertex {
AnchorVertexPair(AnchorVertex *v1, AnchorVertex *v2, AnchorData *data)
- : AnchorVertex(), m_first(v1), m_second(v2), m_removedAnchor(data) {
- m_type = AnchorVertex::Pair;
+ : AnchorVertex(), m_first(v1), m_second(v2), m_removedAnchor(data)
+ {
}
AnchorVertex *m_first;
@@ -256,50 +222,56 @@ struct AnchorVertexPair : public AnchorVertex {
AnchorData *m_removedAnchor;
QList<AnchorData *> m_firstAnchors;
QList<AnchorData *> m_secondAnchors;
+
+#ifdef QT_DEBUG
+ inline QString toString() const override
+ {
+ return QString::fromLatin1("(%1, %2)").arg(m_first->toString(), m_second->toString());
+ }
+#endif
};
#ifdef QT_DEBUG
inline QString AnchorVertex::toString() const
{
- if (m_type == Pair) {
- const AnchorVertexPair *vp = static_cast<const AnchorVertexPair *>(this);
- return QString::fromLatin1("(%1, %2)").arg(vp->m_first->toString(), vp->m_second->toString());
- } else if (!m_item) {
+ using namespace Qt::StringLiterals;
+
+ if (!m_item)
return QString::fromLatin1("NULL_%1").arg(quintptr(this));
- }
+
QString edge;
switch (m_edge) {
case Qt::AnchorLeft:
- edge = QLatin1String("Left");
+ edge = "Left"_L1;
break;
case Qt::AnchorHorizontalCenter:
- edge = QLatin1String("HorizontalCenter");
+ edge = "HorizontalCenter"_L1;
break;
case Qt::AnchorRight:
- edge = QLatin1String("Right");
+ edge = "Right"_L1;
break;
case Qt::AnchorTop:
- edge = QLatin1String("Top");
+ edge = "Top"_L1;
break;
case Qt::AnchorVerticalCenter:
- edge = QLatin1String("VerticalCenter");
+ edge = "VerticalCenter"_L1;
break;
case Qt::AnchorBottom:
- edge = QLatin1String("Bottom");
+ edge = "Bottom"_L1;
break;
default:
- edge = QLatin1String("None");
+ edge = "None"_L1;
break;
}
QString itemName;
if (m_item->isLayout()) {
- itemName = QLatin1String("layout");
+ itemName = "layout"_L1;
} else {
if (QGraphicsItem *item = m_item->graphicsItem()) {
itemName = item->data(0).toString();
}
}
- edge.insert(0, QLatin1String("%1_"));
+ edge.insert(0, "%1_"_L1);
return edge.arg(itemName);
}
#endif
@@ -330,7 +302,7 @@ public:
} // namespace QtGraphicsAnchorLayout
using namespace QtGraphicsAnchorLayout;
-Q_DECLARE_TYPEINFO(GraphPath, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(GraphPath, Q_RELOCATABLE_TYPE);
class QGraphicsAnchorLayoutPrivate;
/*!
@@ -388,15 +360,9 @@ public:
MaxPreferredToMaximum
};
- // Several structures internal to the layout are duplicated to handle
- // both Horizontal and Vertical restrictions.
- //
- // Orientation is used to reference the right structure in each context
- enum Orientation {
- Horizontal = 0,
- Vertical,
- NOrientations
- };
+ typedef Qt::Orientation Orientation [[deprecated]];
+ [[deprecated]] static inline constexpr Qt::Orientation Horizontal = Qt::Horizontal;
+ [[deprecated]] static inline constexpr Qt::Orientation Vertical = Qt::Vertical;
QGraphicsAnchorLayoutPrivate();
@@ -408,13 +374,13 @@ public:
static Qt::AnchorPoint oppositeEdge(
Qt::AnchorPoint edge);
- static Orientation edgeOrientation(Qt::AnchorPoint edge);
+ static Qt::Orientation edgeOrientation(Qt::AnchorPoint edge) noexcept;
- static Qt::AnchorPoint pickEdge(Qt::AnchorPoint edge, Orientation orientation)
+ static Qt::AnchorPoint pickEdge(Qt::AnchorPoint edge, Qt::Orientation orientation)
{
- if (orientation == Vertical && int(edge) <= 2)
+ if (orientation == Qt::Vertical && int(edge) <= 2)
return (Qt::AnchorPoint)(edge + 3);
- else if (orientation == Horizontal && int(edge) >= 3) {
+ else if (orientation == Qt::Horizontal && int(edge) >= 3) {
return (Qt::AnchorPoint)(edge - 3);
}
return edge;
@@ -426,7 +392,7 @@ public:
void createItemEdges(QGraphicsLayoutItem *item);
void createCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge);
void removeCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge, bool substitute = true);
- void removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation);
+ void removeCenterConstraints(QGraphicsLayoutItem *item, Qt::Orientation orientation);
QGraphicsAnchor *acquireGraphicsAnchor(AnchorData *data)
{
@@ -473,40 +439,40 @@ public:
// Activation
void calculateGraphs();
- void calculateGraphs(Orientation orientation);
+ void calculateGraphs(Qt::Orientation orientation);
// Simplification
- bool simplifyGraph(Orientation orientation);
- bool simplifyVertices(Orientation orientation);
- bool simplifyGraphIteration(Orientation orientation, bool *feasible);
+ bool simplifyGraph(Qt::Orientation orientation);
+ bool simplifyVertices(Qt::Orientation orientation);
+ bool simplifyGraphIteration(Qt::Orientation orientation, bool *feasible);
- bool replaceVertex(Orientation orientation, AnchorVertex *oldV,
+ bool replaceVertex(Qt::Orientation orientation, AnchorVertex *oldV,
AnchorVertex *newV, const QList<AnchorData *> &edges);
- void restoreSimplifiedGraph(Orientation orientation);
+ void restoreSimplifiedGraph(Qt::Orientation orientation);
void restoreSimplifiedAnchor(AnchorData *edge);
void restoreSimplifiedConstraints(ParallelAnchorData *parallel);
- void restoreVertices(Orientation orientation);
+ void restoreVertices(Qt::Orientation orientation);
- bool calculateTrunk(Orientation orientation, const GraphPath &trunkPath,
+ bool calculateTrunk(Qt::Orientation orientation, const GraphPath &trunkPath,
const QList<QSimplexConstraint *> &constraints,
const QList<AnchorData *> &variables);
bool calculateNonTrunk(const QList<QSimplexConstraint *> &constraints,
const QList<AnchorData *> &variables);
// Support functions for calculateGraph()
- void refreshAllSizeHints(Orientation orientation);
- void findPaths(Orientation orientation);
- void constraintsFromPaths(Orientation orientation);
- void updateAnchorSizes(Orientation orientation);
+ void refreshAllSizeHints(Qt::Orientation orientation);
+ void findPaths(Qt::Orientation orientation);
+ void constraintsFromPaths(Qt::Orientation orientation);
+ void updateAnchorSizes(Qt::Orientation orientation);
QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors);
struct GraphParts {
QList<QSimplexConstraint *> trunkConstraints;
QList<QSimplexConstraint *> nonTrunkConstraints;
};
- GraphParts getGraphParts(Orientation orientation);
- void identifyFloatItems(const QSet<AnchorData *> &visited, Orientation orientation);
+ GraphParts getGraphParts(Qt::Orientation orientation);
+ void identifyFloatItems(const QSet<AnchorData *> &visited, Qt::Orientation orientation);
void identifyNonFloatItems_helper(const AnchorData *ad, QSet<QGraphicsLayoutItem *> *nonFloatingItemsIdentifiedSoFar);
inline AnchorVertex *internalVertex(const QPair<QGraphicsLayoutItem*, Qt::AnchorPoint> &itemEdge) const
@@ -519,7 +485,7 @@ public:
return internalVertex(qMakePair(const_cast<QGraphicsLayoutItem *>(item), edge));
}
- inline void changeLayoutVertex(Orientation orientation, AnchorVertex *oldV, AnchorVertex *newV)
+ inline void changeLayoutVertex(Qt::Orientation orientation, AnchorVertex *oldV, AnchorVertex *newV)
{
if (layoutFirstVertex[orientation] == oldV)
layoutFirstVertex[orientation] = newV;
@@ -536,8 +502,8 @@ public:
// Geometry interpolation methods
void setItemsGeometries(const QRectF &geom);
- void calculateVertexPositions(Orientation orientation);
- void setupEdgesInterpolation(Orientation orientation);
+ void calculateVertexPositions(Qt::Orientation orientation);
+ void setupEdgesInterpolation(Qt::Orientation orientation);
void interpolateEdge(AnchorVertex *base, AnchorData *edge);
// Linear Programming solver methods
@@ -552,12 +518,12 @@ public:
#endif
- qreal spacings[NOrientations];
+ QHVContainer<qreal> spacings = {-1, -1};
// Size hints from simplex engine
- qreal sizeHints[2][3];
+ QHVContainer<std::array<qreal, 3>> sizeHints = {{-1, -1, -1}, {-1, -1, -1}};
// Items
- QVector<QGraphicsLayoutItem *> items;
+ QList<QGraphicsLayoutItem *> items;
// Mapping between high level anchorage points (Item, Edge) to low level
// ones (Graph Vertices)
@@ -565,31 +531,31 @@ public:
QHash<QPair<QGraphicsLayoutItem*, Qt::AnchorPoint>, QPair<AnchorVertex *, int> > m_vertexList;
// Internal graph of anchorage points and anchors, for both orientations
- Graph<AnchorVertex, AnchorData> graph[2];
+ QHVContainer<Graph<AnchorVertex, AnchorData>> graph;
- AnchorVertex *layoutFirstVertex[2];
- AnchorVertex *layoutCentralVertex[2];
- AnchorVertex *layoutLastVertex[2];
+ QHVContainer<AnchorVertex *> layoutFirstVertex = {};
+ QHVContainer<AnchorVertex *> layoutCentralVertex = {};
+ QHVContainer<AnchorVertex *> layoutLastVertex = {};
// Combined anchors in order of creation
- QList<AnchorVertexPair *> simplifiedVertices[2];
- QList<AnchorData *> anchorsFromSimplifiedVertices[2];
+ QHVContainer<QList<AnchorVertexPair *>> simplifiedVertices;
+ QHVContainer<QList<AnchorData *>> anchorsFromSimplifiedVertices;
// Graph paths and constraints, for both orientations
- QMultiHash<AnchorVertex *, GraphPath> graphPaths[2];
- QList<QSimplexConstraint *> constraints[2];
- QList<QSimplexConstraint *> itemCenterConstraints[2];
+ QHVContainer<QMultiHash<AnchorVertex *, GraphPath>> graphPaths;
+ QHVContainer<QList<QSimplexConstraint *>> constraints;
+ QHVContainer<QList<QSimplexConstraint *>> itemCenterConstraints;
// The interpolation interval and progress based on the current size
// as well as the key values (minimum, preferred and maximum)
- Interval interpolationInterval[2];
- qreal interpolationProgress[2];
+ QHVContainer<Interval> interpolationInterval;
+ QHVContainer<qreal> interpolationProgress = {-1, -1};
- bool graphHasConflicts[2];
- QSet<QGraphicsLayoutItem *> m_floatItems[2];
+ QHVContainer<bool> graphHasConflicts = {};
+ QHVContainer<QSet<QGraphicsLayoutItem *>> m_floatItems;
#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL)
- bool lastCalculationUsedSimplex[2];
+ QHVContainer<bool> lastCalculationUsedSimplex;
#endif
uint calculateGraphCacheDirty : 1;
diff --git a/src/widgets/graphicsview/qgraphicsgridlayout.cpp b/src/widgets/graphicsview/qgraphicsgridlayout.cpp
index 6b7052a0ab..e4599d20bb 100644
--- a/src/widgets/graphicsview/qgraphicsgridlayout.cpp
+++ b/src/widgets/graphicsview/qgraphicsgridlayout.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 QGraphicsGridLayout
@@ -47,13 +11,16 @@
\inmodule QtWidgets
The most common way to use QGraphicsGridLayout is to construct an object
- on the heap with no parent, add widgets and layouts by calling addItem(),
- and finally assign the layout to a widget by calling
- QGraphicsWidget::setLayout(). QGraphicsGridLayout automatically computes
+ on the heap, passing a parent widget to the constructor, then add widgets
+ and layouts by calling addItem(). QGraphicsGridLayout automatically computes
the dimensions of the grid as you add items.
\snippet code/src_gui_graphicsview_qgraphicsgridlayout.cpp 0
+ Alternatively, if you do not pass a parent widget to the layout's constructor,
+ you will need to call QGraphicsWidget::setLayout() to set this layout as the
+ top-level layout for that widget, the widget will take ownership of the layout.
+
The layout takes ownership of the items. In some cases when the layout
item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a
ambiguity in ownership because the layout item belongs to two ownership hierarchies.
@@ -137,7 +104,7 @@ QGraphicsGridLayout::~QGraphicsGridLayout()
// ~QGraphicsLayoutItem.
removeAt(i);
if (item) {
- item->setParentLayoutItem(0);
+ item->setParentLayoutItem(nullptr);
if (item->ownedByLayout())
delete item;
}
@@ -179,7 +146,7 @@ void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column
}
/*!
- \fn QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = 0)
+ \fn QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment)
Adds \a item to the grid on \a row and \a column. You can specify
an optional \a alignment for \a item.
@@ -535,11 +502,11 @@ QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const
Q_D(const QGraphicsGridLayout);
if (row < 0 || row >= rowCount() || column < 0 || column >= columnCount()) {
qWarning("QGraphicsGridLayout::itemAt: invalid row, column %d, %d", row, column);
- return 0;
+ return nullptr;
}
if (QGraphicsGridLayoutEngineItem *engineItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(row, column)))
return engineItem->layoutItem();
- return 0;
+ return nullptr;
}
/*!
@@ -583,13 +550,11 @@ void QGraphicsGridLayout::removeAt(int index)
if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index))) {
if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
- layoutItem->setParentLayoutItem(0);
+ layoutItem->setParentLayoutItem(nullptr);
d->engine.removeItem(gridItem);
// recalculate rowInfo.count if we remove an item that is on the right/bottommost row
- for (int j = 0; j < NOrientations; ++j) {
- // 0: Hor, 1: Ver
- const Qt::Orientation orient = (j == 0 ? Qt::Horizontal : Qt::Vertical);
+ for (const Qt::Orientation orient : {Qt::Horizontal, Qt::Vertical}) {
const int oldCount = d->engine.rowCount(orient);
if (gridItem->lastRow(orient) == oldCount - 1) {
const int newCount = d->engine.effectiveLastRow(orient) + 1;
diff --git a/src/widgets/graphicsview/qgraphicsgridlayout.h b/src/widgets/graphicsview/qgraphicsgridlayout.h
index 4c0a1b4527..bf2cf383d8 100644
--- a/src/widgets/graphicsview/qgraphicsgridlayout.h
+++ b/src/widgets/graphicsview/qgraphicsgridlayout.h
@@ -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
#ifndef QGRAPHICSGRIDLAYOUT_H
#define QGRAPHICSGRIDLAYOUT_H
diff --git a/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp b/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp
index 5797d9e539..db0818d93e 100644
--- a/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp
+++ b/src/widgets/graphicsview/qgraphicsgridlayoutengine.cpp
@@ -1,70 +1,14 @@
-/****************************************************************************
-**
-** 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
#include "qgraphicsgridlayoutengine_p.h"
#include "qgraphicslayoutitem_p.h"
#include "qgraphicslayout_p.h"
#include "qgraphicswidget.h"
-#include <private/qgraphicswidget_p.h>
QT_BEGIN_NAMESPACE
-bool QGraphicsGridLayoutEngineItem::isHidden() const
-{
- if (QGraphicsItem *item = q_layoutItem->graphicsItem())
- return QGraphicsItemPrivate::get(item)->explicitlyHidden;
- return false;
-}
-
-/*!
- \internal
-
- If this returns true, the layout will arrange just as if the item was never added to the layout.
- (Note that this shouldn't lead to a "double spacing" where the item was hidden)
- ### Qt6: Move to QGraphicsLayoutItem and make virtual
-*/
-bool QGraphicsGridLayoutEngineItem::isIgnored() const
-{
- return isHidden() && !q_layoutItem->sizePolicy().retainSizeWhenHidden();
-}
-
/*
returns \c true if the size policy returns \c true for either hasHeightForWidth()
or hasWidthForHeight()
@@ -83,6 +27,16 @@ Qt::Orientation QGraphicsGridLayoutEngineItem::dynamicConstraintOrientation() co
return Qt::Horizontal;
}
+/*!
+ \internal
+
+ If this returns true, the layout will arrange just as if the item was never added to the layout.
+ (Note that this shouldn't lead to a "double spacing" where the item was hidden)
+*/
+bool QGraphicsGridLayoutEngineItem::isEmpty() const
+{
+ return q_layoutItem->isEmpty();
+}
void QGraphicsGridLayoutEngine::setAlignment(QGraphicsLayoutItem *graphicsLayoutItem, Qt::Alignment alignment)
{
diff --git a/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h b/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h
index 2f2c547977..f3b2ec3731 100644
--- a/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h
+++ b/src/widgets/graphicsview/qgraphicsgridlayoutengine_p.h
@@ -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
#ifndef QGRAPHICSGRIDLAYOUTENGINE_P_H
#define QGRAPHICSGRIDLAYOUTENGINE_P_H
@@ -89,10 +53,6 @@ public:
return q_layoutItem->effectiveSizeHint(which, constraint);
}
- bool isHidden() const;
-
- virtual bool isIgnored() const override;
-
virtual void setGeometry(const QRectF &rect) override
{
q_layoutItem->setGeometry(rect);
@@ -101,6 +61,8 @@ public:
virtual bool hasDynamicConstraint() const override;
virtual Qt::Orientation dynamicConstraintOrientation() const override;
+ virtual bool isEmpty() const override;
+
QGraphicsLayoutItem *layoutItem() const { return q_layoutItem; }
protected:
@@ -121,7 +83,7 @@ public:
int indexOf(QGraphicsLayoutItem *item) const
{
- for (int i = 0; i < q_items.count(); ++i) {
+ for (int i = 0; i < q_items.size(); ++i) {
if (item == static_cast<QGraphicsGridLayoutEngineItem*>(q_items.at(i))->layoutItem())
return i;
}
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp
index b58a8c0b3c..17ea830cab 100644
--- a/src/widgets/graphicsview/qgraphicsitem.cpp
+++ b/src/widgets/graphicsview/qgraphicsitem.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) 2021 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 QGraphicsItem
@@ -132,7 +96,6 @@
\image graphicsview-parentchild.png
- \target Transformations
\section1 Transformations
QGraphicsItem supports projective transformations in addition to its base
@@ -244,7 +207,7 @@
\li keyPressEvent() and keyReleaseEvent() handle key press and release events
\li mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(), and
mouseDoubleClickEvent() handles mouse press, move, release, click and
- doubleclick events
+ double-click events
\endlist
You can filter events for any other item by installing event filters. This
@@ -429,16 +392,12 @@
in Qt 4.5.
\value ItemUsesExtendedStyleOption The item makes use of either
- \l{QStyleOptionGraphicsItem::} {exposedRect} or
- \l{QStyleOptionGraphicsItem::} {matrix} in
+ \l{QStyleOptionGraphicsItem::} {exposedRect} in
QStyleOptionGraphicsItem. By default, the
\l{QStyleOptionGraphicsItem::} {exposedRect} is initialized to the
- item's boundingRect() and the
- \l{QStyleOptionGraphicsItem::}{matrix} is untransformed. You can
+ item's boundingRect(). You can
enable this flag for the style options to be set up with more
- fine-grained values. Note that
- QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag
- and always initialized to 1. Use
+ fine-grained values. Use
QStyleOptionGraphicsItem::levelOfDetailFromTransform() if you need
a higher value. This flag was introduced in Qt 4.6.
@@ -530,9 +489,6 @@
setEnabled() in itemChange() as this notification is delivered. The return
value is ignored.
- \value ItemMatrixChange The item's affine transformation matrix is
- changing. This value is obsolete; you can use ItemTransformChange instead.
-
\value ItemPositionChange The item's position changes. This notification
is sent if the ItemSendsGeometryChanges flag is enabled, and when the
item's local position changes, relative to its parent (i.e., as a result
@@ -836,6 +792,8 @@
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN_TAGGED(QGraphicsItem*, QGraphicsItem_ptr)
+
static inline void _q_adjustRect(QRect *rect)
{
Q_ASSERT(rect);
@@ -946,7 +904,6 @@ QGraphicsItemPrivate::QGraphicsItemPrivate()
scenePosDescendants(false),
pendingPolish(false),
mayHaveChildWithGraphicsEffect(false),
- isDeclarativeItem(false),
sendParentChangeNotification(false),
dirtyChildrenBoundingRect(true),
globalStackingOrder(-1),
@@ -1078,7 +1035,7 @@ void QGraphicsItemPrivate::setIsMemberOfGroup(bool enabled)
Q_Q(QGraphicsItem);
isMemberOfGroup = enabled;
if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {
- foreach (QGraphicsItem *child, children)
+ for (QGraphicsItem *child : std::as_const(children))
child->d_func()->setIsMemberOfGroup(enabled);
}
}
@@ -1250,7 +1207,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q
if (isWidget)
static_cast<QGraphicsWidgetPrivate *>(this)->fixFocusChainBeforeReparenting((newParent &&
- newParent->isWidget()) ? static_cast<QGraphicsWidget *>(newParent) : 0,
+ newParent->isWidget()) ? static_cast<QGraphicsWidget *>(newParent) : nullptr,
scene);
if (scene) {
// Deliver the change to the index
@@ -1293,7 +1250,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q
// Ensure any last parent focus scope does not point to this item or any of
// its descendents.
QGraphicsItem *p = parent;
- QGraphicsItem *parentFocusScopeItem = 0;
+ QGraphicsItem *parentFocusScopeItem = nullptr;
while (p) {
if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) {
// If this item's focus scope's focus scope item points
@@ -1301,7 +1258,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q
QGraphicsItem *fsi = p->d_ptr->focusScopeItem;
if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {
parentFocusScopeItem = fsi;
- p->d_ptr->focusScopeItem = 0;
+ p->d_ptr->focusScopeItem = nullptr;
fsi->d_ptr->focusScopeItemChange(false);
}
break;
@@ -1321,7 +1278,7 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q
if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) {
if (subFocusItem && subFocusItem != q_ptr) {
// Find the subFocusItem's topmost focus scope within the new parent's focusscope
- QGraphicsItem *ancestorScope = 0;
+ QGraphicsItem *ancestorScope = nullptr;
QGraphicsItem *p2 = subFocusItem->d_ptr->parent;
while (p2 && p2 != p) {
if (p2->d_ptr->flags & QGraphicsItem::ItemIsFocusScope)
@@ -1479,7 +1436,6 @@ void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, con
const QRectF brect = q->boundingRect();
option->state = QStyle::State_None;
option->rect = brect.toRect();
- option->levelOfDetail = 1;
option->exposedRect = brect;
// Style animations require a QObject-based animation target.
@@ -1505,9 +1461,6 @@ void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, con
if (!(flags & QGraphicsItem::ItemUsesExtendedStyleOption))
return;
- // Initialize QStyleOptionGraphicsItem specific values (matrix, exposedRect).
- option->matrix = worldTransform.toAffine(); //### discards perspective
-
if (!allItems) {
// Determine the item's exposed area
option->exposedRect = QRectF();
@@ -1582,7 +1535,7 @@ QGraphicsItem::~QGraphicsItem()
p->wasDeleted = true; // needed, so that destroying the declarative data does the right thing
if (QAbstractDeclarativeData::destroyed)
QAbstractDeclarativeData::destroyed(p->declarativeData, o);
- p->declarativeData = 0;
+ p->declarativeData = nullptr;
p->wasDeleted = false;
}
}
@@ -1594,22 +1547,21 @@ QGraphicsItem::~QGraphicsItem()
if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
if (QGestureManager *manager = QGestureManager::instance(QGestureManager::DontForceCreation)) {
- const auto types = d_ptr->gestureContext.keys(); // FIXME: iterate over the map directly?
- for (Qt::GestureType type : types)
- manager->cleanupCachedGestures(o, type);
+ for (auto it = d_ptr->gestureContext.constBegin(); it != d_ptr->gestureContext.constEnd(); ++it)
+ manager->cleanupCachedGestures(o, it.key());
}
}
#endif
clearFocus();
- setFocusProxy(0);
+ setFocusProxy(nullptr);
// Update focus scope item ptr.
QGraphicsItem *p = d_ptr->parent;
while (p) {
if (p->flags() & ItemIsFocusScope) {
if (p->d_ptr->focusScopeItem == this)
- p->d_ptr->focusScopeItem = 0;
+ p->d_ptr->focusScopeItem = nullptr;
break;
}
p = p->d_ptr->parent;
@@ -1625,7 +1577,7 @@ QGraphicsItem::~QGraphicsItem()
d_ptr->scene->d_func()->removeItemHelper(this);
} else {
d_ptr->resetFocusProxy();
- setParentItem(0);
+ setParentItem(nullptr);
}
#if QT_CONFIG(graphicseffect)
@@ -1634,7 +1586,7 @@ QGraphicsItem::~QGraphicsItem()
if (d_ptr->transformData) {
for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i);
- static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0;
+ static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = nullptr;
delete t;
}
}
@@ -1746,7 +1698,7 @@ QGraphicsWidget *QGraphicsItem::parentWidget() const
QGraphicsItem *p = parentItem();
while (p && !p->isWidget())
p = p->parentItem();
- return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : 0;
+ return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : nullptr;
}
/*!
@@ -1806,7 +1758,7 @@ QGraphicsItem *QGraphicsItem::panel() const
*/
QGraphicsObject *QGraphicsItem::toGraphicsObject()
{
- return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : 0;
+ return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : nullptr;
}
/*!
@@ -1817,7 +1769,7 @@ QGraphicsObject *QGraphicsItem::toGraphicsObject()
*/
const QGraphicsObject *QGraphicsItem::toGraphicsObject() const
{
- return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0;
+ return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : nullptr;
}
/*!
@@ -1854,15 +1806,6 @@ void QGraphicsItem::setParentItem(QGraphicsItem *newParent)
}
/*!
- \fn QList<QGraphicsItem *> QGraphicsItem::children() const
- \obsolete
-
- Use childItems() instead.
-
- \sa setParentItem()
-*/
-
-/*!
\since 4.4
Returns a list of this item's children.
@@ -2219,7 +2162,7 @@ bool QGraphicsItem::isBlockedByModalPanel(QGraphicsItem **blockingPanel) const
return false;
- QGraphicsItem *dummy = 0;
+ QGraphicsItem *dummy = nullptr;
if (!blockingPanel)
blockingPanel = &dummy;
@@ -2231,7 +2174,7 @@ bool QGraphicsItem::isBlockedByModalPanel(QGraphicsItem **blockingPanel) const
if (!scene_d->popupWidgets.isEmpty() && scene_d->popupWidgets.first() == this)
return false;
- for (int i = 0; i < scene_d->modalPanels.count(); ++i) {
+ for (int i = 0; i < scene_d->modalPanels.size(); ++i) {
QGraphicsItem *modalPanel = scene_d->modalPanels.at(i);
if (modalPanel->panelModality() == QGraphicsItem::SceneModal) {
// Scene modal panels block all non-descendents.
@@ -2252,7 +2195,7 @@ bool QGraphicsItem::isBlockedByModalPanel(QGraphicsItem **blockingPanel) const
return false;
}
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
/*!
Returns the item's tool tip, or an empty QString if no tool tip has been
set.
@@ -2276,7 +2219,7 @@ void QGraphicsItem::setToolTip(const QString &toolTip)
d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString());
itemChange(ItemToolTipHasChanged, toolTipVariant);
}
-#endif // QT_NO_TOOLTIP
+#endif // QT_CONFIG(tooltip)
#ifndef QT_NO_CURSOR
/*!
@@ -2292,7 +2235,7 @@ void QGraphicsItem::setToolTip(const QString &toolTip)
If no cursor has been set, the cursor of the item beneath is used.
\sa setCursor(), hasCursor(), unsetCursor(), QWidget::cursor,
- QApplication::overrideCursor()
+ QGuiApplication::overrideCursor()
*/
QCursor QGraphicsItem::cursor() const
{
@@ -2312,7 +2255,7 @@ QCursor QGraphicsItem::cursor() const
If no cursor has been set, the cursor of the item beneath is used.
\sa cursor(), hasCursor(), unsetCursor(), QWidget::cursor,
- QApplication::overrideCursor()
+ QGuiApplication::overrideCursor()
*/
void QGraphicsItem::setCursor(const QCursor &cursor)
{
@@ -2326,12 +2269,17 @@ void QGraphicsItem::setCursor(const QCursor &cursor)
view->viewport()->setMouseTracking(true);
// Note: Some of this logic is duplicated in QGraphicsView's mouse events.
if (view->underMouse()) {
- const auto itemsUnderCursor = view->items(view->mapFromGlobal(QCursor::pos()));
- for (QGraphicsItem *itemUnderCursor : itemsUnderCursor) {
- if (itemUnderCursor->hasCursor()) {
- QMetaObject::invokeMethod(view, "_q_setViewportCursor",
- Q_ARG(QCursor, itemUnderCursor->cursor()));
- break;
+ const QPoint viewPoint = view->mapFromGlobal(QCursor::pos());
+ const QPointF cursorPos = mapFromScene(view->mapToScene(viewPoint));
+ // the cursor can only change if the current item is under the mouse
+ if (boundingRect().contains(cursorPos)) {
+ const auto itemsUnderCursor = view->items(viewPoint);
+ for (QGraphicsItem *itemUnderCursor : itemsUnderCursor) {
+ if (itemUnderCursor->hasCursor()) {
+ QMetaObject::invokeMethod(view, "_q_setViewportCursor",
+ Q_ARG(QCursor, itemUnderCursor->cursor()));
+ break;
+ }
}
}
break;
@@ -2415,7 +2363,7 @@ bool QGraphicsItem::isVisibleTo(const QGraphicsItem *parent) const
if (p->d_ptr->explicitlyHidden)
return false;
} while ((p = p->d_ptr->parent));
- return parent == 0;
+ return parent == nullptr;
}
/*!
@@ -2509,7 +2457,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly,
const bool updateChildren = update && !((flags & QGraphicsItem::ItemClipsChildrenToShape
|| flags & QGraphicsItem::ItemContainsChildrenInShape)
&& !(flags & QGraphicsItem::ItemHasNoContents));
- foreach (QGraphicsItem *child, children) {
+ for (QGraphicsItem *child : std::as_const(children)) {
if (!newVisible || !child->d_ptr->explicitlyHidden)
child->d_ptr->setVisibleHelper(newVisible, false, updateChildren, hiddenByPanel);
}
@@ -2668,23 +2616,25 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
// Certain properties are dropped when an item is disabled.
if (!newEnabled) {
- if (scene && scene->mouseGrabberItem() == q_ptr)
- q_ptr->ungrabMouse();
- if (q_ptr->hasFocus()) {
- // Disabling the closest non-panel ancestor of the focus item
- // causes focus to pop to the next item, otherwise it's cleared.
- QGraphicsItem *focusItem = scene->focusItem();
- bool clear = true;
- if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {
- do {
- if (focusItem == q_ptr) {
- clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
- break;
- }
- } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
+ if (scene) {
+ if (scene->mouseGrabberItem() == q_ptr)
+ q_ptr->ungrabMouse();
+ if (q_ptr->hasFocus()) {
+ // Disabling the closest non-panel ancestor of the focus item
+ // causes focus to pop to the next item, otherwise it's cleared.
+ QGraphicsItem *focusItem = scene->focusItem();
+ bool clear = true;
+ if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {
+ do {
+ if (focusItem == q_ptr) {
+ clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
+ break;
+ }
+ } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
+ }
+ if (clear)
+ q_ptr->clearFocus();
}
- if (clear)
- q_ptr->clearFocus();
}
if (q_ptr->isSelected())
q_ptr->setSelected(false);
@@ -2699,7 +2649,7 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
if (update)
q_ptr->update();
- foreach (QGraphicsItem *child, children) {
+ for (QGraphicsItem *child : std::as_const(children)) {
if (!newEnabled || !child->d_ptr->explicitlyDisabled)
child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false);
}
@@ -2728,7 +2678,7 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo
If you disable a parent item, all its children will also be disabled. If
you enable a parent item, all children will be enabled, unless they have
been explicitly disabled (i.e., if you call setEnabled(false) on a child,
- it will not be reenabled if its parent is disabled, and then enabled
+ it will not be re-enabled if its parent is disabled, and then enabled
again).
Items are enabled by default.
@@ -2954,7 +2904,7 @@ void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect)
if (d_ptr->graphicsEffect) {
delete d_ptr->graphicsEffect;
- d_ptr->graphicsEffect = 0;
+ d_ptr->graphicsEffect = nullptr;
} else if (d_ptr->parent) {
d_ptr->parent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();
}
@@ -2979,7 +2929,7 @@ void QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively()
if (itemPrivate->mayHaveChildWithGraphicsEffect)
return;
itemPrivate->mayHaveChildWithGraphicsEffect = 1;
- } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
+ } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : nullptr));
#endif
}
@@ -3021,7 +2971,7 @@ QRectF QGraphicsItemPrivate::effectiveBoundingRect(const QRectF &rect) const
Returns the effective bounding rect of the item.
If the item has no effect, this is the same as the item's bounding rect.
If the item has an effect, the effective rect can be larger than the item's
- bouding rect, depending on the effect.
+ bounding rect, depending on the effect.
\sa boundingRect()
*/
@@ -3140,7 +3090,7 @@ Qt::MouseButtons QGraphicsItem::acceptedMouseButtons() const
mouse events to the first item beneath it that does.
To disable mouse events for an item (i.e., make it transparent for mouse
- events), call setAcceptedMouseButtons(0).
+ events), call setAcceptedMouseButtons(Qt::NoButton).
\sa acceptedMouseButtons(), mousePressEvent()
*/
@@ -3169,12 +3119,6 @@ bool QGraphicsItem::acceptHoverEvents() const
return d_ptr->acceptsHover;
}
-/*!
- \fn bool QGraphicsItem::acceptsHoverEvents() const
- \obsolete
-
- Call acceptHoverEvents() instead.
-*/
/*!
\since 4.4
@@ -3218,13 +3162,6 @@ void QGraphicsItem::setAcceptHoverEvents(bool enabled)
}
}
-/*!
- \fn void QGraphicsItem::setAcceptsHoverEvents(bool enabled)
- \obsolete
-
- Use setAcceptHoverEvents(\a enabled) instead.
-*/
-
/*! \since 4.6
Returns \c true if an item accepts \l{QTouchEvent}{touch events};
@@ -3275,7 +3212,7 @@ bool QGraphicsItem::filtersChildEvents() const
\since 4.6
If \a enabled is true, this item is set to filter all events for
- all its children (i.e., all events intented for any of its
+ all its children (i.e., all events intended for any of its
children are instead sent to this item); otherwise, if \a enabled
is false, this item will only handle its own events. The default
value is false.
@@ -3292,7 +3229,7 @@ void QGraphicsItem::setFiltersChildEvents(bool enabled)
}
/*!
- \obsolete
+ \deprecated
Returns \c true if this item handles child events (i.e., all events
intended for any of its children are instead sent to this item);
@@ -3314,10 +3251,10 @@ bool QGraphicsItem::handlesChildEvents() const
}
/*!
- \obsolete
+ \deprecated
If \a enabled is true, this item is set to handle all events for
- all its children (i.e., all events intented for any of its
+ all its children (i.e., all events intended for any of its
children are instead sent to this item); otherwise, if \a enabled
is false, this item will only handle its own events. The default
value is false.
@@ -3391,13 +3328,13 @@ void QGraphicsItem::setActive(bool active)
if (!activePanel || activePanel == thisPanel) {
// Deactivate this item, and reactivate the parent panel,
// or the last active panel (if any).
- QGraphicsItem *nextToActivate = 0;
+ QGraphicsItem *nextToActivate = nullptr;
if (d_ptr->parent)
nextToActivate = d_ptr->parent->panel();
if (!nextToActivate)
nextToActivate = d_ptr->scene->d_func()->lastActivePanel;
if (nextToActivate == this || isAncestorOf(nextToActivate))
- nextToActivate = 0;
+ nextToActivate = nullptr;
d_ptr->scene->setActivePanel(nextToActivate);
}
}
@@ -3494,7 +3431,7 @@ void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool clim
}
// Update the child focus chain.
- QGraphicsItem *commonAncestor = 0;
+ QGraphicsItem *commonAncestor = nullptr;
if (scene && scene->focusItem() && scene->focusItem()->panel() == q_ptr->panel()) {
commonAncestor = scene->focusItem()->commonAncestorItem(f);
scene->focusItem()->d_ptr->clearSubFocus(scene->focusItem(), commonAncestor);
@@ -3547,7 +3484,7 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB
while (p) {
if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
if (p->d_ptr->focusScopeItem == q_ptr) {
- p->d_ptr->focusScopeItem = 0;
+ p->d_ptr->focusScopeItem = nullptr;
if (!subFocusItem->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere
focusScopeItemChange(false);
}
@@ -3567,7 +3504,7 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB
clearSubFocus(q_ptr);
// If this item has the scene's input focus, clear it.
- scene->setFocusItem(0);
+ scene->setFocusItem(nullptr);
}
}
@@ -3616,7 +3553,7 @@ void QGraphicsItem::setFocusProxy(QGraphicsItem *item)
qWarning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene");
return;
}
- for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) {
+ for (QGraphicsItem *f = item->focusProxy(); f != nullptr; f = f->focusProxy()) {
if (f == this) {
qWarning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);
return;
@@ -3979,7 +3916,7 @@ void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
sceneRect = sceneTransform().mapRect(rect);
else
sceneRect = sceneBoundingRect();
- foreach (QGraphicsView *view, d_ptr->scene->d_func()->views)
+ for (QGraphicsView *view : std::as_const(d_ptr->scene->d_func()->views))
view->ensureVisible(sceneRect, xmargin, ymargin);
}
}
@@ -3992,24 +3929,6 @@ void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin).
*/
-#if QT_DEPRECATED_SINCE(5, 13)
-/*!
- \obsolete
-
- Returns the item's affine transformation matrix. This is a subset or the
- item's full transformation matrix, and might not represent the item's full
- transformation.
-
- Use transform() instead.
-
- \sa setTransform(), sceneTransform()
-*/
-QMatrix QGraphicsItem::matrix() const
-{
- return transform().toAffine();
-}
-#endif
-
/*!
\since 4.3
@@ -4318,22 +4237,6 @@ void QGraphicsItem::setTransformOriginPoint(const QPointF &origin)
\sa setTransformOriginPoint(), {Transformations}
*/
-
-#if QT_DEPRECATED_SINCE(5, 13)
-/*!
- \obsolete
-
- Use sceneTransform() instead.
-
- \sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}
-*/
-QMatrix QGraphicsItem::sceneMatrix() const
-{
- d_ptr->ensureSceneTransform();
- return d_ptr->sceneTransform.toAffine();
-}
-#endif
-
/*!
\since 4.3
@@ -4347,7 +4250,8 @@ QMatrix QGraphicsItem::sceneMatrix() const
\snippet code/src_gui_graphicsview_qgraphicsitem.cpp 4
Unlike transform(), which returns only an item's local transformation, this
- function includes the item's (and any parents') position, and all the transfomation properties.
+ function includes the item's (and any parents') position, and all the
+ transformation properties.
\sa transform(), setTransform(), scenePos(), {The Graphics View Coordinate System}, {Transformations}
*/
@@ -4447,7 +4351,7 @@ QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) c
QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) const
{
// Catch simple cases first.
- if (other == 0) {
+ if (other == nullptr) {
qWarning("QGraphicsItem::itemTransform: null pointer passed");
return QTransform();
}
@@ -4544,50 +4448,6 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co
return x;
}
-#if QT_DEPRECATED_SINCE(5, 13)
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
-/*!
- \obsolete
-
- Sets the item's affine transformation matrix. This is a subset or the
- item's full transformation matrix, and might not represent the item's full
- transformation.
-
- Use setTransform() instead.
-
- \sa transform(), {The Graphics View Coordinate System}
-*/
-void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
-{
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
-
- QTransform newTransform(combine ? QTransform(matrix) * d_ptr->transformData->transform : QTransform(matrix));
- if (d_ptr->transformData->transform == newTransform)
- return;
-
- // Update and set the new transformation.
- if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
- d_ptr->setTransformHelper(newTransform);
- return;
- }
-
- // Notify the item that the transformation matrix is changing.
- const QVariant newMatrixVariant = QVariant::fromValue<QMatrix>(newTransform.toAffine());
- newTransform = QTransform(qvariant_cast<QMatrix>(itemChange(ItemMatrixChange, newMatrixVariant)));
- if (d_ptr->transformData->transform == newTransform)
- return;
-
- // Update and set the new transformation.
- d_ptr->setTransformHelper(newTransform);
-
- // Send post-notification.
- itemChange(ItemTransformHasChanged, QVariant::fromValue<QTransform>(newTransform));
-}
-QT_WARNING_POP
-#endif
-
/*!
\since 4.3
@@ -4600,7 +4460,7 @@ QT_WARNING_POP
To simplify interaction with items using a transformed view, QGraphicsItem
provides mapTo... and mapFrom... functions that can translate between
items' and the scene's coordinates. For example, you can call mapToScene()
- to map an item coordiate to a scene coordinate, or mapFromScene() to map
+ to map an item coordinate to a scene coordinate, or mapFromScene() to map
from scene coordinates to item coordinates.
The transformation matrix is combined with the item's rotation(), scale()
@@ -4641,18 +4501,6 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
d_ptr->sendScenePosChange();
}
-#if QT_DEPRECATED_SINCE(5, 13)
-/*!
- \obsolete
-
- Use resetTransform() instead.
-*/
-void QGraphicsItem::resetMatrix()
-{
- resetTransform();
-}
-#endif
-
/*!
\since 4.3
@@ -4668,81 +4516,6 @@ void QGraphicsItem::resetTransform()
}
/*!
- \fn void QGraphicsItem::rotate(qreal angle)
- \obsolete
-
- Use
-
- \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 20
-
- instead.
-
- Rotates the current item transformation \a angle degrees clockwise around
- its origin. To translate around an arbitrary point (x, y), you need to
- combine translation and rotation with setTransform().
-
- Example:
-
- \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 6
-
- \sa setTransform(), transform(), scale(), shear(), translate()
-*/
-
-/*!
- \fn void QGraphicsItem::scale(qreal sx, qreal sy)
- \obsolete
-
- Use
-
- \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 21
-
- instead.
-
- Scales the current item transformation by (\a sx, \a sy) around its
- origin. To scale from an arbitrary point (x, y), you need to combine
- translation and scaling with setTransform().
-
- Example:
-
- \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 7
-
- \sa setTransform(), transform()
-*/
-
-/*!
- \fn void QGraphicsItem::shear(qreal sh, qreal sv)
- \obsolete
-
- Use
-
- \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 22
-
- instead.
-
- Shears the current item transformation by (\a sh, \a sv).
-
- \sa setTransform(), transform()
-*/
-
-/*!
- \fn void QGraphicsItem::translate(qreal dx, qreal dy)
- \obsolete
-
- Use setPos() or setTransformOriginPoint() instead. For identical
- behavior, use
-
- \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 23
-
- Translates the current item transformation by (\a dx, \a dy).
-
- If all you want is to move an item, you should call moveBy() or
- setPos() instead; this function changes the item's translation,
- which is conceptually separate from its position.
-
- \sa setTransform(), transform()
-*/
-
-/*!
This virtual function is called twice for all items by the
QGraphicsScene::advance() slot. In the first phase, all items are called
with \a phase == 0, indicating that items on the scene are about to
@@ -4853,7 +4626,7 @@ inline void QGraphicsItemPrivate::sendScenePosChange()
if (flags & QGraphicsItem::ItemSendsScenePositionChanges)
q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos());
if (scenePosDescendants) {
- foreach (QGraphicsItem *item, scene->d_func()->scenePosItems) {
+ for (QGraphicsItem *item : std::as_const(scene->d_func()->scenePosItems)) {
if (q->isAncestorOf(item))
item->itemChange(QGraphicsItem::ItemScenePositionHasChanged, item->scenePos());
}
@@ -4887,7 +4660,7 @@ void QGraphicsItem::stackBefore(const QGraphicsItem *sibling)
}
QList<QGraphicsItem *> *siblings = d_ptr->parent
? &d_ptr->parent->d_ptr->children
- : (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems : 0);
+ : (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems : nullptr);
if (!siblings) {
qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
return;
@@ -4944,7 +4717,7 @@ QRectF QGraphicsItem::childrenBoundingRect() const
return d_ptr->childrenBoundingRect;
d_ptr->childrenBoundingRect = QRectF();
- d_ptr->childrenBoundingRectHelper(0, &d_ptr->childrenBoundingRect, 0);
+ d_ptr->childrenBoundingRectHelper(nullptr, &d_ptr->childrenBoundingRect, nullptr);
d_ptr->dirtyChildrenBoundingRect = 0;
return d_ptr->childrenBoundingRect;
}
@@ -5157,7 +4930,7 @@ bool QGraphicsItem::contains(const QPointF &point) const
The default implementation is based on shape intersection, and it calls
shape() on both items. Because the complexity of arbitrary shape-shape
intersection grows with an order of magnitude when the shapes are complex,
- this operation can be noticably time consuming. You have the option of
+ this operation can be noticeably time-consuming. You have the option of
reimplementing this function in a subclass of QGraphicsItem to provide a
custom algorithm. This allows you to make use of natural constraints in
the shapes of your own items, in order to improve the performance of the
@@ -5227,7 +5000,7 @@ bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelection
_q_adjustRect(&rectB);
if (!rectA.intersects(rectB)) {
// This we can determine efficiently. If the two rects neither
- // intersect nor contain eachother, then the two items do not collide.
+ // intersect nor contain each other, then the two items do not collide.
return false;
}
@@ -5417,7 +5190,7 @@ QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) c
// Render
QStyleOptionGraphicsItem option;
- const_cast<QGraphicsItem *>(this)->paint(&p, &option, 0);
+ const_cast<QGraphicsItem *>(this)->paint(&p, &option, nullptr);
p.end();
// Transform QRegion back to device space
@@ -5488,7 +5261,7 @@ void QGraphicsItem::setBoundingRegionGranularity(qreal granularity)
/*!
\fn virtual void QGraphicsItem::paint(QPainter *painter, const
- QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0
+ QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) = 0
This function, which is usually called by QGraphicsView, paints the
contents of an item in local coordinates.
@@ -5570,7 +5343,7 @@ void QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively()
if (!itemPrivate->updateDueToGraphicsEffect)
static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
}
- } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
+ } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : nullptr));
}
void QGraphicsItemPrivate::invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::InvalidateReason reason)
@@ -5734,7 +5507,7 @@ void QGraphicsItemPrivate::ensureSceneTransformRecursive(QGraphicsItem **topMost
if (*topMostDirtyItem == q_ptr) {
if (!dirtySceneTransform)
return; // OK, neither my ancestors nor I have dirty scene transforms.
- *topMostDirtyItem = 0;
+ *topMostDirtyItem = nullptr;
} else if (*topMostDirtyItem) {
return; // Continue backtrack.
}
@@ -5766,7 +5539,7 @@ void QGraphicsItemPrivate::setSubFocus(QGraphicsItem *rootItem, QGraphicsItem *s
if (parent != q_ptr && parent->d_ptr->subFocusItem) {
if (parent->d_ptr->subFocusItem == q_ptr)
break;
- parent->d_ptr->subFocusItem->d_ptr->clearSubFocus(0, stopItem);
+ parent->d_ptr->subFocusItem->d_ptr->clearSubFocus(nullptr, stopItem);
}
parent->d_ptr->subFocusItem = q_ptr;
parent->d_ptr->subFocusItemChange();
@@ -5788,7 +5561,7 @@ void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem, QGraphicsItem
do {
if (parent->d_ptr->subFocusItem != q_ptr)
break;
- parent->d_ptr->subFocusItem = 0;
+ parent->d_ptr->subFocusItem = nullptr;
if (parent != stopItem && !parent->isAncestorOf(stopItem))
parent->d_ptr->subFocusItemChange();
} while (!parent->isPanel() && (parent = parent->d_ptr->parent));
@@ -5803,7 +5576,7 @@ void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem, QGraphicsItem
void QGraphicsItemPrivate::resetFocusProxy()
{
for (int i = 0; i < focusProxyRefs.size(); ++i)
- *focusProxyRefs.at(i) = 0;
+ *focusProxyRefs.at(i) = nullptr;
focusProxyRefs.clear();
}
@@ -6728,7 +6501,7 @@ void QGraphicsItem::setData(int key, const QVariant &value)
}
/*!
- \fn T qgraphicsitem_cast(QGraphicsItem *item)
+ \fn template <class T> qgraphicsitem_cast(QGraphicsItem *item)
\relates QGraphicsItem
\since 4.2
@@ -7221,7 +6994,7 @@ void QGraphicsItem::keyReleaseEvent(QKeyEvent *event)
If you do reimplement this function, \a event will by default be
accepted (see QEvent::accept()), and this item is then the mouse
grabber. This allows the item to receive future move, release and
- doubleclick events. If you call QEvent::ignore() on \a event, this
+ double-click events. If you call QEvent::ignore() on \a event, this
item will lose the mouse grab, and \a event will propagate to any
topmost item beneath. No further mouse events will be delivered to
this item unless a new mouse press event is received.
@@ -7309,7 +7082,7 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
selectedItems = d_ptr->scene->selectedItems();
initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;
if (initialPositions.isEmpty()) {
- for (QGraphicsItem *item : qAsConst(selectedItems))
+ for (QGraphicsItem *item : std::as_const(selectedItems))
initialPositions[item] = item->pos();
initialPositions[this] = pos();
}
@@ -7317,7 +7090,7 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
// Find the active view.
- QGraphicsView *view = 0;
+ QGraphicsView *view = nullptr;
if (event->widget())
view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget());
@@ -7325,7 +7098,7 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
int i = 0;
bool movedMe = false;
while (i <= selectedItems.size()) {
- QGraphicsItem *item = 0;
+ QGraphicsItem *item = nullptr;
if (i < selectedItems.size())
item = selectedItems.at(i);
else
@@ -7343,14 +7116,14 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if ((item->flags() & ItemIsMovable) && !QGraphicsItemPrivate::movableAncestorIsSelected(item)) {
QPointF currentParentPos;
QPointF buttonDownParentPos;
- if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorIgnoresTransformations) {
+ if (view && (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorIgnoresTransformations)) {
// Items whose ancestors ignore transformations need to
// map screen coordinates to local coordinates, then map
// those to the parent.
QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted();
currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))));
buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))));
- } else if (item->flags() & ItemIgnoresTransformations) {
+ } else if (view && (item->flags() & ItemIgnoresTransformations)) {
// Root items that ignore transformations need to
// calculate their diff by mapping viewport coordinates
// directly to parent coordinates.
@@ -7418,7 +7191,7 @@ void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
// temporarily removing this item from the selection list.
if (d_ptr->selected) {
scene->d_func()->selectedItems.remove(this);
- foreach (QGraphicsItem *item, scene->d_func()->selectedItems) {
+ for (QGraphicsItem *item : std::as_const(scene->d_func()->selectedItems)) {
if (item->isSelected()) {
selectionChanged = true;
break;
@@ -7442,11 +7215,11 @@ void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
/*!
This event handler, for event \a event, can be reimplemented to
- receive mouse doubleclick events for this item.
+ receive mouse double-click events for this item.
When doubleclicking an item, the item 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.
+ double-click event, and finally a release event.
Calling QEvent::ignore() or QEvent::accept() on \a event has no
effect.
@@ -7716,11 +7489,8 @@ void QGraphicsItem::prepareGeometryChange()
\internal
Highlights \a item as selected.
-
- NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in
- qgraphicssvgitem.cpp!
*/
-static void qt_graphicsItem_highlightSelected(
+void Q_WIDGETS_EXPORT qt_graphicsItem_highlightSelected(
QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
{
const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
@@ -7879,66 +7649,6 @@ void QGraphicsObject::updateMicroFocus()
QGraphicsItem::updateMicroFocus();
}
-void QGraphicsItemPrivate::children_append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item)
-{
- if (item) {
- QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(list->object);
- if (QGraphicsItemPrivate::get(graphicsObject)->sendParentChangeNotification) {
- item->setParentItem(graphicsObject);
- } else {
- QGraphicsItemPrivate::get(item)->setParentItemHelper(graphicsObject, 0, 0);
- }
- }
-}
-
-int QGraphicsItemPrivate::children_count(QDeclarativeListProperty<QGraphicsObject> *list)
-{
- QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
- return d->children.count();
-}
-
-QGraphicsObject *QGraphicsItemPrivate::children_at(QDeclarativeListProperty<QGraphicsObject> *list, int index)
-{
- QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
- if (index >= 0 && index < d->children.count())
- return d->children.at(index)->toGraphicsObject();
- else
- return 0;
-}
-
-void QGraphicsItemPrivate::children_clear(QDeclarativeListProperty<QGraphicsObject> *list)
-{
- QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
- int childCount = d->children.count();
- if (d->sendParentChangeNotification) {
- for (int index = 0; index < childCount; index++)
- d->children.at(0)->setParentItem(0);
- } else {
- for (int index = 0; index < childCount; index++)
- QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, 0, 0);
- }
-}
-
-/*!
- Returns a list of this item's children.
-
- The items are sorted by stacking order. This takes into account both the
- items' insertion order and their Z-values.
-
-*/
-QDeclarativeListProperty<QGraphicsObject> QGraphicsItemPrivate::childrenList()
-{
- Q_Q(QGraphicsItem);
- if (isObject) {
- QGraphicsObject *that = static_cast<QGraphicsObject *>(q);
- return QDeclarativeListProperty<QGraphicsObject>(that, &children, children_append,
- children_count, children_at, children_clear);
- } else {
- //QGraphicsItem is not supported for this property
- return QDeclarativeListProperty<QGraphicsObject>();
- }
-}
-
/*!
\internal
Returns the width of the item
@@ -8108,7 +7818,7 @@ void QGraphicsItemPrivate::resetHeight()
/*!
\property QGraphicsObject::rotation
- This property holds the rotation of the item in degrees.
+ \brief the rotation of the item in degrees.
This specifies how many degrees to rotate the item around its transformOrigin.
The default rotation is 0 degrees (i.e. not rotated at all).
@@ -8117,12 +7827,12 @@ void QGraphicsItemPrivate::resetHeight()
/*!
\fn QGraphicsObject::rotationChanged()
- This signal gets emitted whenever the roation of the item changes.
+ This signal gets emitted whenever the rotation of the item changes.
*/
/*!
\property QGraphicsObject::scale
- This property holds the scale of the item.
+ \brief the scale of the item.
A scale of less than 1 means the item will be displayed smaller than
normal, and a scale of greater than 1 means the item will be
@@ -8156,7 +7866,7 @@ void QGraphicsItemPrivate::resetHeight()
/*!
\fn void QGraphicsObject::enabledChanged()
- This signal gets emitted whenever the item get's enabled or disabled.
+ This signal gets emitted whenever the item gets enabled or disabled.
\sa isEnabled()
*/
@@ -8184,7 +7894,7 @@ void QGraphicsItemPrivate::resetHeight()
\property QGraphicsObject::transformOriginPoint
\brief the transformation origin
- This property sets a specific point in the items coordiante system as the
+ This property sets a specific point in the item's coordinate system as the
origin for scale and rotation.
\sa scale, rotation, QGraphicsItem::transformOriginPoint()
@@ -9780,9 +9490,9 @@ QRectF QGraphicsPixmapItem::boundingRect() const
return QRectF();
if (d->flags & ItemIsSelectable) {
qreal pw = 1.0;
- return QRectF(d->offset, QSizeF(d->pixmap.size()) / d->pixmap.devicePixelRatio()).adjusted(-pw/2, -pw/2, pw/2, pw/2);
+ return QRectF(d->offset, d->pixmap.deviceIndependentSize()).adjusted(-pw/2, -pw/2, pw/2, pw/2);
} else {
- return QRectF(d->offset, QSizeF(d->pixmap.size()) / d->pixmap.devicePixelRatio());
+ return QRectF(d->offset, d->pixmap.deviceIndependentSize());
}
}
@@ -9944,7 +9654,7 @@ class QGraphicsTextItemPrivate
{
public:
QGraphicsTextItemPrivate()
- : control(0), pageNumber(0), useDefaultImpl(false), tabChangesFocus(false), clickCausedFocus(0)
+ : control(nullptr), pageNumber(0), useDefaultImpl(false), tabChangesFocus(false), clickCausedFocus(0)
{ }
mutable QWidgetTextControl *control;
@@ -10287,6 +9997,7 @@ bool QGraphicsTextItem::sceneEvent(QEvent *event)
case QEvent::GraphicsSceneMouseRelease:
case QEvent::KeyPress:
case QEvent::KeyRelease:
+ case QEvent::InputMethod:
// Reset the focus widget's input context, regardless
// of how this item gained or lost focus.
if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) {
@@ -10502,18 +10213,22 @@ void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const
{
QVariant v;
- if (query == Qt::ImHints)
+ if (query == Qt::ImEnabled)
+ return isEnabled();
+ else if (query == Qt::ImHints)
v = int(inputMethodHints());
else if (dd->control)
v = dd->control->inputMethodQuery(query, QVariant());
- if (v.type() == QVariant::RectF)
- v = v.toRectF().translated(-dd->controlOffset());
- else if (v.type() == QVariant::PointF)
- v = v.toPointF() - dd->controlOffset();
- else if (v.type() == QVariant::Rect)
- v = v.toRect().translated(-dd->controlOffset().toPoint());
- else if (v.type() == QVariant::Point)
- v = v.toPoint() - dd->controlOffset().toPoint();
+ if (dd->control) {
+ if (v.userType() == QMetaType::QRectF)
+ v = v.toRectF().translated(-dd->controlOffset());
+ else if (v.userType() == QMetaType::QPointF)
+ v = v.toPointF() - dd->controlOffset();
+ else if (v.userType() == QMetaType::QRect)
+ v = v.toRect().translated(-dd->controlOffset().toPoint());
+ else if (v.userType() == QMetaType::QPoint)
+ v = v.toPoint() - dd->controlOffset().toPoint();
+ }
return v;
}
@@ -10588,16 +10303,16 @@ QWidgetTextControl *QGraphicsTextItemPrivate::textControl() const
control = new QWidgetTextControl(that);
control->setTextInteractionFlags(Qt::NoTextInteraction);
- QObject::connect(control, SIGNAL(updateRequest(QRectF)),
- qq, SLOT(_q_update(QRectF)));
- QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)),
- qq, SLOT(_q_updateBoundingRect(QSizeF)));
- QObject::connect(control, SIGNAL(visibilityRequest(QRectF)),
- qq, SLOT(_q_ensureVisible(QRectF)));
- QObject::connect(control, SIGNAL(linkActivated(QString)),
- qq, SIGNAL(linkActivated(QString)));
- QObject::connect(control, SIGNAL(linkHovered(QString)),
- qq, SIGNAL(linkHovered(QString)));
+ QObject::connect(control, &QWidgetTextControl::updateRequest, qq,
+ [dd = that->dd](const QRectF &rect) { dd->_q_update(rect); });
+ QObject::connect(control, &QWidgetTextControl::documentSizeChanged, qq,
+ [dd = that->dd](QSizeF size) { dd->_q_updateBoundingRect(size); });
+ QObject::connect(control, &QWidgetTextControl::visibilityRequest, qq,
+ [dd = that->dd](const QRectF &rect) { dd->_q_ensureVisible(rect); });
+ QObject::connect(control, &QWidgetTextControl::linkActivated, qq,
+ &QGraphicsTextItem::linkActivated);
+ QObject::connect(control, &QWidgetTextControl::linkHovered, qq,
+ &QGraphicsTextItem::linkHovered);
const QSizeF pgSize = control->document()->pageSize();
if (pgSize.height() != -1) {
@@ -10800,7 +10515,7 @@ void QGraphicsSimpleTextItemPrivate::updateBoundingRect()
br = QRectF();
} else {
QString tmp = text;
- tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ tmp.replace(u'\n', QChar::LineSeparator);
QStackTextEngine engine(tmp, font);
QTextLayout layout(&engine);
br = setupTextLayout(&layout);
@@ -10961,7 +10676,7 @@ void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic
painter->setFont(d->font);
QString tmp = d->text;
- tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ tmp.replace(u'\n', QChar::LineSeparator);
QStackTextEngine engine(tmp, d->font);
QTextLayout layout(&engine);
@@ -10973,9 +10688,9 @@ void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic
} else {
QTextLayout::FormatRange range;
range.start = 0;
- range.length = layout.text().length();
+ range.length = layout.text().size();
range.format.setTextOutline(d->pen);
- layout.setFormats(QVector<QTextLayout::FormatRange>(1, range));
+ layout.setFormats(QList<QTextLayout::FormatRange>(1, range));
}
setupTextLayout(&layout);
@@ -11227,7 +10942,7 @@ void QGraphicsItemGroup::removeFromGroup(QGraphicsItem *item)
// ### Expensive, we could maybe use dirtySceneTransform bit for optimization
item->setTransform(itemTransform);
- item->d_func()->setIsMemberOfGroup(item->group() != 0);
+ item->d_func()->setIsMemberOfGroup(item->group() != nullptr);
// ### Quite expensive. But removeFromGroup() isn't called very often.
prepareGeometryChange();
@@ -11391,7 +11106,7 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP
if (effectRect.isEmpty())
return QPixmap();
- const auto dpr = info ? info->painter->device()->devicePixelRatioF() : 1.0;
+ const auto dpr = info ? info->painter->device()->devicePixelRatio() : 1.0;
QPixmap pixmap(QRectF(effectRectF.topLeft(), effectRectF.size() * dpr).toAlignedRect().size());
pixmap.setDevicePixelRatio(dpr);
pixmap.fill(Qt::transparent);
@@ -11407,18 +11122,18 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP
QTransform sceneTransform = item->sceneTransform();
QTransform newEffectTransform = sceneTransform.inverted();
newEffectTransform *= effectTransform;
- scened->draw(item, &pixmapPainter, 0, &sceneTransform, 0, 0, qreal(1.0),
+ scened->draw(item, &pixmapPainter, nullptr, &sceneTransform, nullptr, nullptr, qreal(1.0),
&newEffectTransform, false, true);
} else if (deviceCoordinates) {
// Device coordinates with info.
- scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0,
+ scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, nullptr,
info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
info->drawItem);
} else {
// Item coordinates with info.
QTransform newEffectTransform = info->transformPtr->inverted();
newEffectTransform *= effectTransform;
- scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0,
+ scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, nullptr,
info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform,
info->drawItem);
}
@@ -11442,8 +11157,7 @@ static void formatGraphicsItemHelper(QDebug debug, const QGraphicsItem *item)
debug << ", flags=" << item->flags();
}
-// FIXME: Qt 6: Make this QDebug operator<<(QDebug debug, const QGraphicsItem *item)
-QDebug operator<<(QDebug debug, QGraphicsItem *item)
+QDebug operator<<(QDebug debug, const QGraphicsItem *item)
{
QDebugStateSaver saver(debug);
debug.nospace();
@@ -11453,7 +11167,7 @@ QDebug operator<<(QDebug debug, QGraphicsItem *item)
return debug;
}
- if (QGraphicsObject *o = item->toGraphicsObject())
+ if (const QGraphicsObject *o = item->toGraphicsObject())
debug << o->metaObject()->className();
else
debug << "QGraphicsItem";
@@ -11474,8 +11188,7 @@ QDebug operator<<(QDebug debug, QGraphicsItem *item)
return debug;
}
-// FIXME: Qt 6: Make this QDebug operator<<(QDebug debug, const QGraphicsObject *item)
-QDebug operator<<(QDebug debug, QGraphicsObject *item)
+QDebug operator<<(QDebug debug, const QGraphicsObject *item)
{
QDebugStateSaver saver(debug);
debug.nospace();
@@ -11521,14 +11234,6 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change)
case QGraphicsItem::ItemFlagsHaveChanged:
str = "ItemFlagsHaveChanged";
break;
-#if QT_DEPRECATED_SINCE(5, 14)
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- case QGraphicsItem::ItemMatrixChange:
- str = "ItemMatrixChange";
- break;
-QT_WARNING_POP
-#endif
case QGraphicsItem::ItemParentChange:
str = "ItemParentChange";
break;
diff --git a/src/widgets/graphicsview/qgraphicsitem.h b/src/widgets/graphicsview/qgraphicsitem.h
index d66a4917e5..f82c600b3a 100644
--- a/src/widgets/graphicsview/qgraphicsitem.h
+++ b/src/widgets/graphicsview/qgraphicsitem.h
@@ -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
#ifndef QGRAPHICSITEM_H
#define QGRAPHICSITEM_H
@@ -71,7 +35,6 @@ class QGraphicsTransform;
class QGraphicsWidget;
class QInputMethodEvent;
class QKeyEvent;
-class QMatrix;
class QMenu;
class QPainter;
class QPen;
@@ -110,9 +73,6 @@ public:
enum GraphicsItemChange {
ItemPositionChange,
-#if QT_DEPRECATED_SINCE(5, 14)
- ItemMatrixChange Q_DECL_ENUMERATOR_DEPRECATED_X("Use ItemTransformChange instead"),
-#endif
ItemVisibleChange = 2,
ItemEnabledChange,
ItemSelectedChange,
@@ -173,9 +133,6 @@ public:
QGraphicsWidget *window() const;
QGraphicsItem *panel() const;
void setParentItem(QGraphicsItem *parent);
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline QList<QGraphicsItem *> children() const { return childItems(); }
-#endif
QList<QGraphicsItem *> childItems() const;
bool isWidget() const;
bool isWindow() const;
@@ -198,7 +155,7 @@ public:
void setPanelModality(PanelModality panelModality);
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel = nullptr) const;
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
QString toolTip() const;
void setToolTip(const QString &toolTip);
#endif
@@ -237,10 +194,6 @@ public:
Qt::MouseButtons acceptedMouseButtons() const;
void setAcceptedMouseButtons(Qt::MouseButtons buttons);
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline bool acceptsHoverEvents() const { return acceptHoverEvents(); }
- QT_DEPRECATED inline void setAcceptsHoverEvents(bool enabled) { setAcceptHoverEvents(enabled); }
-#endif
bool acceptHoverEvents() const;
void setAcceptHoverEvents(bool enabled);
bool acceptTouchEvents() const;
@@ -285,28 +238,12 @@ public:
inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
// Local transformation
-#if QT_DEPRECATED_SINCE(5, 13)
- QT_DEPRECATED_X("Use transform() instead")
- QMatrix matrix() const;
- QT_DEPRECATED_X("Use sceneTransform() instead")
- QMatrix sceneMatrix() const;
- QT_DEPRECATED_X("Use setTransform() instead")
- void setMatrix(const QMatrix &matrix, bool combine = false);
- QT_DEPRECATED_X("Use resetTransform() instead")
- void resetMatrix();
-#endif
QTransform transform() const;
QTransform sceneTransform() const;
QTransform deviceTransform(const QTransform &viewportTransform) const;
QTransform itemTransform(const QGraphicsItem *other, bool *ok = nullptr) const;
void setTransform(const QTransform &matrix, bool combine = false);
void resetTransform();
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline void rotate(qreal angle) { setTransform(QTransform().rotate(angle), true); }
- QT_DEPRECATED inline void scale(qreal sx, qreal sy) { setTransform(QTransform::fromScale(sx, sy), true); }
- QT_DEPRECATED inline void shear(qreal sh, qreal sv) { setTransform(QTransform().shear(sh, sv), true); }
- QT_DEPRECATED inline void translate(qreal dx, qreal dy) { setTransform(QTransform::fromTranslate(dx, dy), true); }
-#endif
void setRotation(qreal angle);
qreal rotation() const;
@@ -495,7 +432,7 @@ private:
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsItem::GraphicsItemFlags)
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
Q_DECLARE_INTERFACE(QGraphicsItem, "org.qt-project.Qt.QGraphicsItem")
#endif
@@ -548,7 +485,8 @@ inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal
class Q_WIDGETS_EXPORT QGraphicsObject : public QObject, public QGraphicsItem
{
Q_OBJECT
- Q_PROPERTY(QGraphicsObject* parent READ parentObject WRITE setParentItem NOTIFY parentChanged DESIGNABLE false)
+ Q_PROPERTY(QGraphicsObject* parent READ parentObject WRITE setParentItem NOTIFY parentChanged
+ DESIGNABLE false)
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
@@ -562,10 +500,10 @@ class Q_WIDGETS_EXPORT QGraphicsObject : public QObject, public QGraphicsItem
#if QT_CONFIG(graphicseffect)
Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect)
#endif
- Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), QDeclarativeListProperty<QGraphicsObject> children READ childrenList DESIGNABLE false NOTIFY childrenChanged)
- Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
- Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
- Q_CLASSINFO("DefaultProperty", "children")
+ Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal width READ width WRITE setWidth
+ NOTIFY widthChanged RESET resetWidth FINAL)
+ Q_PRIVATE_PROPERTY(QGraphicsItem::d_func(), qreal height READ height WRITE setHeight
+ NOTIFY heightChanged RESET resetHeight FINAL)
Q_INTERFACES(QGraphicsItem)
public:
explicit QGraphicsObject(QGraphicsItem *parent = nullptr);
@@ -964,9 +902,6 @@ protected:
private:
Q_DISABLE_COPY(QGraphicsTextItem)
- Q_PRIVATE_SLOT(dd, void _q_updateBoundingRect(const QSizeF &))
- Q_PRIVATE_SLOT(dd, void _q_update(QRectF))
- Q_PRIVATE_SLOT(dd, void _q_ensureVisible(QRectF))
QGraphicsTextItemPrivate *dd;
friend class QGraphicsTextItemPrivate;
};
@@ -1035,19 +970,19 @@ template <class T> inline T qgraphicsitem_cast(QGraphicsItem *item)
{
typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Item;
return int(Item::Type) == int(QGraphicsItem::Type)
- || (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : 0;
+ || (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : nullptr;
}
template <class T> inline T qgraphicsitem_cast(const QGraphicsItem *item)
{
typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Item;
return int(Item::Type) == int(QGraphicsItem::Type)
- || (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : 0;
+ || (item && int(Item::Type) == item->type()) ? static_cast<T>(item) : nullptr;
}
#ifndef QT_NO_DEBUG_STREAM
-Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem *item);
-Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsObject *item);
+Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, const QGraphicsItem *item);
+Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, const QGraphicsObject *item);
Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change);
Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag);
Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags);
@@ -1055,10 +990,6 @@ Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QGraphicsItem *)
-
-QT_BEGIN_NAMESPACE
-
-QT_END_NAMESPACE
+QT_DECL_METATYPE_EXTERN_TAGGED(QGraphicsItem*, QGraphicsItem_ptr, Q_WIDGETS_EXPORT)
#endif // QGRAPHICSITEM_H
diff --git a/src/widgets/graphicsview/qgraphicsitem_p.h b/src/widgets/graphicsview/qgraphicsitem_p.h
index 92d85f7125..bf6ebb96a2 100644
--- a/src/widgets/graphicsview/qgraphicsitem_p.h
+++ b/src/widgets/graphicsview/qgraphicsitem_p.h
@@ -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
#ifndef QGRAPHICSITEM_P_H
#define QGRAPHICSITEM_P_H
@@ -67,63 +31,6 @@ QT_BEGIN_NAMESPACE
class QGraphicsItemPrivate;
-#ifndef QDECLARATIVELISTPROPERTY
-#define QDECLARATIVELISTPROPERTY
-template<typename T>
-class QDeclarativeListProperty {
-public:
- typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*);
- typedef int (*CountFunction)(QDeclarativeListProperty<T> *);
- typedef T *(*AtFunction)(QDeclarativeListProperty<T> *, int);
- typedef void (*ClearFunction)(QDeclarativeListProperty<T> *);
-
- QDeclarativeListProperty()
- : object(nullptr), data(nullptr), append(nullptr), count(nullptr), at(nullptr), clear(nullptr), dummy1(nullptr), dummy2(nullptr) {}
- QDeclarativeListProperty(QObject *o, QList<T *> &list)
- : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at),
- clear(qlist_clear), dummy1(nullptr), dummy2(nullptr) {}
- QDeclarativeListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0,
- ClearFunction r = 0)
- : object(o), data(d), append(a), count(c), at(t), clear(r), dummy1(nullptr), dummy2(nullptr) {}
-
- bool operator==(const QDeclarativeListProperty &o) const {
- return object == o.object &&
- data == o.data &&
- append == o.append &&
- count == o.count &&
- at == o.at &&
- clear == o.clear;
- }
-
- QObject *object;
- void *data;
-
- AppendFunction append;
-
- CountFunction count;
- AtFunction at;
-
- ClearFunction clear;
-
- void *dummy1;
- void *dummy2;
-
-private:
- static void qlist_append(QDeclarativeListProperty *p, T *v) {
- ((QList<T *> *)p->data)->append(v);
- }
- static int qlist_count(QDeclarativeListProperty *p) {
- return ((QList<T *> *)p->data)->count();
- }
- static T *qlist_at(QDeclarativeListProperty *p, int idx) {
- return ((QList<T *> *)p->data)->at(idx);
- }
- static void qlist_clear(QDeclarativeListProperty *p) {
- return ((QList<T *> *)p->data)->clear();
- }
-};
-#endif
-
class QGraphicsItemCache
{
public:
@@ -144,7 +51,7 @@ public:
QHash<QPaintDevice *, DeviceData> deviceData;
// List of logical exposed rects
- QVector<QRectF> exposed;
+ QList<QRectF> exposed;
bool allExposed;
// Empty cache
@@ -226,7 +133,6 @@ public:
void resolveDepth();
void addChild(QGraphicsItem *child);
void removeChild(QGraphicsItem *child);
- QDeclarativeListProperty<QGraphicsObject> childrenList();
void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant,
const QVariant *thisPointerVariant);
void childrenBoundingRectHelper(QTransform *x, QRectF *rect, QGraphicsItem *topMostEffectItem);
@@ -289,7 +195,7 @@ public:
}
struct ExtraStruct {
- ExtraStruct() {} // for QVector, don't use
+ ExtraStruct() { } // for QList, don't use
ExtraStruct(Extra type, const QVariant &value)
: type(type), value(value)
{ }
@@ -301,7 +207,7 @@ public:
{ return type < extra; }
};
- QVector<ExtraStruct> extras;
+ QList<ExtraStruct> extras;
QGraphicsItemCache *maybeExtraItemCache() const;
QGraphicsItemCache *extraItemCache() const;
@@ -414,11 +320,6 @@ public:
virtual void subFocusItemChange();
virtual void focusScopeItemChange(bool isSubFocusItem);
- static void children_append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item);
- static int children_count(QDeclarativeListProperty<QGraphicsObject> *list);
- static QGraphicsObject *children_at(QDeclarativeListProperty<QGraphicsObject> *list, int);
- static void children_clear(QDeclarativeListProperty<QGraphicsObject> *list);
-
inline QTransform transformToParent() const;
inline void ensureSortedChildren();
static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b);
@@ -514,16 +415,15 @@ public:
quint32 scenePosDescendants : 1;
quint32 pendingPolish : 1;
quint32 mayHaveChildWithGraphicsEffect : 1;
- quint32 isDeclarativeItem : 1;
quint32 sendParentChangeNotification : 1;
quint32 dirtyChildrenBoundingRect : 1;
- quint32 padding : 19;
+ quint32 padding : 20;
// Optional stacking order
int globalStackingOrder;
QGraphicsItem *q_ptr;
};
-Q_DECLARE_TYPEINFO(QGraphicsItemPrivate::ExtraStruct, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QGraphicsItemPrivate::ExtraStruct, Q_RELOCATABLE_TYPE);
struct QGraphicsItemPrivate::TransformData
{
@@ -624,7 +524,6 @@ public:
return item->type() == QGraphicsPixmapItem::Type
&& !(item->flags() & QGraphicsItem::ItemIsSelectable)
&& item->d_ptr->children.size() == 0;
- //|| (item->d_ptr->isObject && qobject_cast<QDeclarativeImage *>(q_func()));
}
const QStyleOption *styleOption() const override
diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp
index ad77e2f260..23dd9fcc7d 100644
--- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp
+++ b/src/widgets/graphicsview/qgraphicsitemanimation.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 QGraphicsItemAnimation
@@ -87,7 +51,6 @@
#include <QtCore/qpoint.h>
#include <QtCore/qpointer.h>
#include <QtCore/qpair.h>
-#include <QtGui/qmatrix.h>
#include <algorithm>
@@ -106,7 +69,7 @@ class QGraphicsItemAnimationPrivate
{
public:
inline QGraphicsItemAnimationPrivate()
- : q(0), timeLine(0), item(0), step(0)
+ : q(nullptr), timeLine(nullptr), item(nullptr), step(0)
{ }
QGraphicsItemAnimation *q;
@@ -127,22 +90,23 @@ public:
qreal step;
qreal value;
};
- QVector<Pair> xPosition;
- QVector<Pair> yPosition;
- QVector<Pair> rotation;
- QVector<Pair> verticalScale;
- QVector<Pair> horizontalScale;
- QVector<Pair> verticalShear;
- QVector<Pair> horizontalShear;
- QVector<Pair> xTranslation;
- QVector<Pair> yTranslation;
-
- qreal linearValueForStep(qreal step, const QVector<Pair> &source, qreal defaultValue = 0);
- void insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method);
+ QList<Pair> xPosition;
+ QList<Pair> yPosition;
+ QList<Pair> rotation;
+ QList<Pair> verticalScale;
+ QList<Pair> horizontalScale;
+ QList<Pair> verticalShear;
+ QList<Pair> horizontalShear;
+ QList<Pair> xTranslation;
+ QList<Pair> yTranslation;
+
+ qreal linearValueForStep(qreal step, const QList<Pair> &source, qreal defaultValue = 0);
+ void insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char *method);
};
Q_DECLARE_TYPEINFO(QGraphicsItemAnimationPrivate::Pair, Q_PRIMITIVE_TYPE);
-qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, const QVector<Pair> &source, qreal defaultValue)
+qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, const QList<Pair> &source,
+ qreal defaultValue)
{
if (source.isEmpty())
return defaultValue;
@@ -172,14 +136,15 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, const QVecto
return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore));
}
-void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method)
+void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList,
+ const char *method)
{
if (!check_step_valid(step, method))
return;
const Pair pair = { step, value };
- const QVector<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair);
+ const QList<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair);
if (result == binList->end() || pair < *result)
binList->insert(result, pair);
else
@@ -294,19 +259,6 @@ QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::posList() const
return list;
}
-#if QT_DEPRECATED_SINCE(5, 14)
-/*!
- Returns the matrix used to transform the item at the specified \a step value.
-
- \obsolete Use transformAt() instead
-*/
-QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const
-{
- check_step_valid(step, "matrixAt");
- return transformAt(step).toAffine();
-}
-#endif
-
/*!
Returns the transform used for the item at the specified \a step value.
@@ -564,23 +516,6 @@ void QGraphicsItemAnimation::setStep(qreal step)
afterAnimationStep(step);
}
-#if QT_DEPRECATED_SINCE(5, 13)
-/*!
- Resets the item to its starting position and transformation.
-
- \obsolete
-
- You can call setStep(0) instead.
-*/
-void QGraphicsItemAnimation::reset()
-{
- if (!d->item)
- return;
- d->startPos = d->item->pos();
- d->startTransform = d->item->transform();
-}
-#endif
-
/*!
\fn void QGraphicsItemAnimation::beforeAnimationStep(qreal step)
diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.h b/src/widgets/graphicsview/qgraphicsitemanimation.h
index 3051fb2e2b..5fb6484c74 100644
--- a/src/widgets/graphicsview/qgraphicsitemanimation.h
+++ b/src/widgets/graphicsview/qgraphicsitemanimation.h
@@ -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
#ifndef QGRAPHICSITEMANIMATION_H
#define QGRAPHICSITEMANIMATION_H
@@ -48,11 +12,9 @@ QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
class QGraphicsItem;
-class QMatrix;
class QPointF;
class QTimeLine;
class QTransform;
-template <class T1, class T2> struct QPair;
class QGraphicsItemAnimationPrivate;
class Q_WIDGETS_EXPORT QGraphicsItemAnimation : public QObject
@@ -72,10 +34,6 @@ public:
QList<QPair<qreal, QPointF> > posList() const;
void setPosAt(qreal step, const QPointF &pos);
-#if QT_DEPRECATED_SINCE(5, 14)
- QT_DEPRECATED_X("Use transformAt() instead")
- QMatrix matrixAt(qreal step) const;
-#endif
QTransform transformAt(qreal step) const;
qreal rotationAt(qreal step) const;
@@ -101,10 +59,6 @@ public:
public Q_SLOTS:
void setStep(qreal x);
-#if QT_DEPRECATED_SINCE(5, 13)
- QT_DEPRECATED_X("Use setStep(0) instead")
- void reset();
-#endif
protected:
virtual void beforeAnimationStep(qreal step);
diff --git a/src/widgets/graphicsview/qgraphicslayout.cpp b/src/widgets/graphicsview/qgraphicslayout.cpp
index 8b52b57580..672f78afb8 100644
--- a/src/widgets/graphicsview/qgraphicslayout.cpp
+++ b/src/widgets/graphicsview/qgraphicslayout.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
#include "qapplication.h"
@@ -146,7 +110,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- Contructs a QGraphicsLayout object.
+ Constructs a QGraphicsLayout object.
\a parent is passed to QGraphicsLayoutItem's constructor and the
QGraphicsLayoutItem's isLayout argument is set to \e true.
diff --git a/src/widgets/graphicsview/qgraphicslayout.h b/src/widgets/graphicsview/qgraphicslayout.h
index efcafa5e6a..b95a6b839f 100644
--- a/src/widgets/graphicsview/qgraphicslayout.h
+++ b/src/widgets/graphicsview/qgraphicslayout.h
@@ -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
#ifndef QGRAPHICSLAYOUT_H
#define QGRAPHICSLAYOUT_H
@@ -83,7 +47,7 @@ private:
friend class QGraphicsWidget;
};
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
Q_DECLARE_INTERFACE(QGraphicsLayout, "org.qt-project.Qt.QGraphicsLayout")
#endif
diff --git a/src/widgets/graphicsview/qgraphicslayout_p.cpp b/src/widgets/graphicsview/qgraphicslayout_p.cpp
index 59ed7acd72..e902ed8612 100644
--- a/src/widgets/graphicsview/qgraphicslayout_p.cpp
+++ b/src/widgets/graphicsview/qgraphicslayout_p.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
#include "qglobal.h"
@@ -97,7 +61,7 @@ void QGraphicsLayoutPrivate::getMargin(qreal *result, qreal userMargin, QStyle::
*result = 0.0;
if (QGraphicsItem *layoutParentItem = parentItem()) {
if (layoutParentItem->isWidget())
- *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, 0);
+ *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, nullptr);
}
}
}
diff --git a/src/widgets/graphicsview/qgraphicslayout_p.h b/src/widgets/graphicsview/qgraphicslayout_p.h
index 0d91151e22..06eab2ba50 100644
--- a/src/widgets/graphicsview/qgraphicslayout_p.h
+++ b/src/widgets/graphicsview/qgraphicslayout_p.h
@@ -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
#ifndef QGRAPHICSLAYOUT_P_H
#define QGRAPHICSLAYOUT_P_H
@@ -70,7 +34,7 @@ class QGraphicsWidget;
inline bool qt_graphicsLayoutDebug()
{
static int checked_env = -1;
- if(checked_env == -1)
+ if (checked_env == -1)
checked_env = !!qEnvironmentVariableIntValue("QT_GRAPHICSLAYOUT_DEBUG");
return checked_env;
}
@@ -87,8 +51,8 @@ public:
Q_ASSERT(style);
if (widget) //###
m_styleOption.initFrom(widget);
- m_defaultSpacing[0] = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
- m_defaultSpacing[1] = style->pixelMetric(QStyle::PM_LayoutVerticalSpacing);
+ m_defaultSpacing[0] = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, &m_styleOption, widget);
+ m_defaultSpacing[1] = style->pixelMetric(QStyle::PM_LayoutVerticalSpacing, &m_styleOption, widget);
}
inline void invalidate() { m_valid = false; m_style = nullptr; m_widget = nullptr; }
@@ -103,11 +67,11 @@ public:
inline void setDefaultSpacing(Qt::Orientation o, qreal spacing){
if (spacing >= 0)
- m_defaultSpacing[o - 1] = spacing;
+ m_defaultSpacing[int(o) - 1] = spacing;
}
inline qreal defaultSpacing(Qt::Orientation o) const {
- return m_defaultSpacing[o - 1];
+ return m_defaultSpacing[int(o) - 1];
}
inline qreal perItemSpacing(QSizePolicy::ControlType control1,
diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.cpp b/src/widgets/graphicsview/qgraphicslayoutitem.cpp
index 1192bad51e..f6aad09810 100644
--- a/src/widgets/graphicsview/qgraphicslayoutitem.cpp
+++ b/src/widgets/graphicsview/qgraphicslayoutitem.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
#include "qglobal.h"
@@ -45,6 +9,7 @@
#include "qgraphicslayoutitem_p.h"
#include "qwidget.h"
#include "qgraphicswidget.h"
+#include "qgraphicsitem_p.h"
#include <QtDebug>
@@ -105,7 +70,7 @@ static void normalizeHints(qreal &minimum, qreal &preferred, qreal &maximum, qre
\internal
*/
QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate(QGraphicsLayoutItem *par, bool layout)
- : parent(par), userSizeHints(0), isLayout(layout), ownedByLayout(false), graphicsItem(0)
+ : parent(par), userSizeHints(nullptr), isLayout(layout), ownedByLayout(false), graphicsItem(nullptr)
{
}
@@ -826,6 +791,26 @@ void QGraphicsLayoutItem::updateGeometry()
}
/*!
+ \since 6.0
+
+ Returns \c true if this item is empty, i.e whether it has no content and
+ should not occupy any space.
+
+ The default implementation returns \c true true if the item has been hidden,
+ unless its \l{sizePolicy()}{size policy} has retainSizeWhenHidden set to \c true
+
+ \sa sizePolicy()
+*/
+bool QGraphicsLayoutItem::isEmpty() const
+{
+ bool isHidden = false;
+ if (QGraphicsItem *item = graphicsItem())
+ isHidden = QGraphicsItemPrivate::get(item)->explicitlyHidden;
+
+ return isHidden && !sizePolicy().retainSizeWhenHidden();
+}
+
+/*!
Returns the parent of this QGraphicsLayoutItem, or \nullptr if there is
no parent, or if the parent does not inherit from QGraphicsLayoutItem
(QGraphicsLayoutItem is often used through multiple inheritance with
diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.h b/src/widgets/graphicsview/qgraphicslayoutitem.h
index 86a0a87361..43194ee729 100644
--- a/src/widgets/graphicsview/qgraphicslayoutitem.h
+++ b/src/widgets/graphicsview/qgraphicslayoutitem.h
@@ -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
#ifndef QGRAPHICSLAYOUTITEM_H
#define QGRAPHICSLAYOUTITEM_H
@@ -94,6 +58,7 @@ public:
virtual void updateGeometry();
+ virtual bool isEmpty() const;
QGraphicsLayoutItem *parentLayoutItem() const;
void setParentLayoutItem(QGraphicsLayoutItem *parent);
@@ -116,7 +81,7 @@ private:
friend class QGraphicsLayout;
};
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
Q_DECLARE_INTERFACE(QGraphicsLayoutItem, "org.qt-project.Qt.QGraphicsLayoutItem")
#endif
diff --git a/src/widgets/graphicsview/qgraphicslayoutitem_p.h b/src/widgets/graphicsview/qgraphicslayoutitem_p.h
index 6aaa85381e..70fb82c78c 100644
--- a/src/widgets/graphicsview/qgraphicslayoutitem_p.h
+++ b/src/widgets/graphicsview/qgraphicslayoutitem_p.h
@@ -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
#ifndef QGRAPHICSLAYOUTITEM_P_H
#define QGRAPHICSLAYOUTITEM_P_H
diff --git a/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp b/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp
index da2510a8cb..6bd57470f3 100644
--- a/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp
+++ b/src/widgets/graphicsview/qgraphicslayoutstyleinfo.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
#include "qgraphicslayoutstyleinfo_p.h"
@@ -48,7 +12,7 @@
QT_BEGIN_NAMESPACE
QGraphicsLayoutStyleInfo::QGraphicsLayoutStyleInfo(const QGraphicsLayoutPrivate *layout)
- : m_layout(layout), m_style(0)
+ : m_layout(layout), m_style(nullptr)
{
m_widget.reset(new QWidget); // pixelMetric might need a widget ptr
m_styleOption.initFrom(m_widget.get());
@@ -80,7 +44,9 @@ qreal QGraphicsLayoutStyleInfo::perItemSpacing(QLayoutPolicy::ControlType contro
qreal QGraphicsLayoutStyleInfo::spacing(Qt::Orientation orientation) const
{
Q_ASSERT(style());
- return style()->pixelMetric(orientation == Qt::Horizontal ? QStyle::PM_LayoutHorizontalSpacing : QStyle::PM_LayoutVerticalSpacing);
+ return style()->pixelMetric(orientation == Qt::Horizontal
+ ? QStyle::PM_LayoutHorizontalSpacing : QStyle::PM_LayoutVerticalSpacing,
+ &m_styleOption, widget());
}
qreal QGraphicsLayoutStyleInfo::windowMargin(Qt::Orientation orientation) const
diff --git a/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h b/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h
index 9807efb26e..a3c0c22606 100644
--- a/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h
+++ b/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h
@@ -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
#ifndef QGRAPHICSLAYOUTSTYLEINFO_P_H
#define QGRAPHICSLAYOUTSTYLEINFO_P_H
diff --git a/src/widgets/graphicsview/qgraphicslinearlayout.cpp b/src/widgets/graphicsview/qgraphicslinearlayout.cpp
index 22633df4e3..04693734d2 100644
--- a/src/widgets/graphicsview/qgraphicslinearlayout.cpp
+++ b/src/widgets/graphicsview/qgraphicslinearlayout.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 QGraphicsLinearLayout
@@ -50,12 +14,16 @@
passing Qt::Vertical to QGraphicsLinearLayout's constructor.
The most common way to use QGraphicsLinearLayout is to construct an object
- on the heap with no parent, add widgets and layouts by calling addItem(),
- and finally assign the layout to a widget by calling
- QGraphicsWidget::setLayout().
+ on the heap, passing a parent widget to the constructor, then add widgets
+ and layouts by calling addItem().
\snippet code/src_gui_graphicsview_qgraphicslinearlayout.cpp 0
+ Alternatively, if you do not pass a parent widget to the layout's constructor,
+ you will need to call QGraphicsWidget::setLayout() to set this layout as the
+ top-level layout for that widget, the widget will take ownership of
+ the layout.
+
You can add widgets, layouts, stretches (addStretch(), insertStretch() or
setStretchFactor()), and spacings (setItemSpacing()) to a linear
layout. The layout takes ownership of the items. In some cases when the layout
@@ -211,7 +179,7 @@ QGraphicsLinearLayout::~QGraphicsLinearLayout()
// ~QGraphicsLayoutItem.
removeAt(i);
if (item) {
- item->setParentLayoutItem(0);
+ item->setParentLayoutItem(nullptr);
if (item->ownedByLayout())
delete item;
}
@@ -310,7 +278,7 @@ void QGraphicsLinearLayout::removeItem(QGraphicsLayoutItem *item)
{
Q_D(QGraphicsLinearLayout);
if (QGraphicsGridLayoutEngineItem *gridItem = d->engine.findLayoutItem(item)) {
- item->setParentLayoutItem(0);
+ item->setParentLayoutItem(nullptr);
d->removeGridItem(gridItem);
delete gridItem;
invalidate();
@@ -333,7 +301,7 @@ void QGraphicsLinearLayout::removeAt(int index)
if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index))) {
if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
- layoutItem->setParentLayoutItem(0);
+ layoutItem->setParentLayoutItem(nullptr);
d->removeGridItem(gridItem);
delete gridItem;
invalidate();
@@ -483,9 +451,9 @@ QGraphicsLayoutItem *QGraphicsLinearLayout::itemAt(int index) const
Q_D(const QGraphicsLinearLayout);
if (index < 0 || index >= d->engine.itemCount()) {
qWarning("QGraphicsLinearLayout::itemAt: invalid index %d", index);
- return 0;
+ return nullptr;
}
- QGraphicsLayoutItem *item = 0;
+ QGraphicsLayoutItem *item = nullptr;
if (QGraphicsGridLayoutEngineItem *gridItem = static_cast<QGraphicsGridLayoutEngineItem *>(d->engine.itemAt(index)))
item = gridItem->layoutItem();
return item;
diff --git a/src/widgets/graphicsview/qgraphicslinearlayout.h b/src/widgets/graphicsview/qgraphicslinearlayout.h
index d27191adb3..d71c64aa5f 100644
--- a/src/widgets/graphicsview/qgraphicslinearlayout.h
+++ b/src/widgets/graphicsview/qgraphicslinearlayout.h
@@ -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
#ifndef QGRAPHICSLINEARLAYOUT_H
#define QGRAPHICSLINEARLAYOUT_H
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index c60dca7a90..1ff4814142 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.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
#include "qglobal.h"
@@ -183,7 +147,9 @@ QT_BEGIN_NAMESPACE
\warning This class is provided for convenience when bridging
QWidgets and QGraphicsItems, it should not be used for
- high-performance scenarios.
+ high-performance scenarios. In particular, embedding widgets into a scene
+ that is then displayed through a QGraphicsView that uses an OpenGL viewport
+ will not work for all combinations.
\sa QGraphicsScene::addWidget(), QGraphicsWidget
*/
@@ -237,6 +203,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneHoverEvent
mouseEvent.setButton(Qt::NoButton);
mouseEvent.setButtons({ });
mouseEvent.setModifiers(event->modifiers());
+ mouseEvent.setTimestamp(event->timestamp());
sendWidgetMouseEvent(&mouseEvent);
event->setAccepted(mouseEvent.isAccepted());
}
@@ -291,7 +258,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
}
if (!lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(embeddedMouseGrabber ? embeddedMouseGrabber : receiver, 0, event->screenPos());
+ QApplicationPrivate::dispatchEnterLeave(embeddedMouseGrabber ? embeddedMouseGrabber : receiver, nullptr, event->screenPos());
lastWidgetUnderMouse = receiver;
}
@@ -302,6 +269,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
QMouseEvent mouseEvent(type, pos, receiver->mapTo(receiver->topLevelWidget(), pos.toPoint()),
receiver->mapToGlobal(pos.toPoint()),
event->button(), event->buttons(), event->modifiers(), event->source());
+ mouseEvent.setTimestamp(event->timestamp());
QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber;
QApplicationPrivate::sendMouseEvent(receiver, &mouseEvent, alienWidget, widget,
@@ -315,10 +283,10 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
if (q->rect().contains(event->pos()) && q->acceptHoverEvents())
lastWidgetUnderMouse = alienWidget ? alienWidget : widget;
else // released on the frame our outside the item, or doesn't accept hover events.
- lastWidgetUnderMouse = 0;
+ lastWidgetUnderMouse = nullptr;
QApplicationPrivate::dispatchEnterLeave(lastWidgetUnderMouse, embeddedMouseGrabber, event->screenPos());
- embeddedMouseGrabber = 0;
+ embeddedMouseGrabber = nullptr;
#ifndef QT_NO_CURSOR
// ### Restore the cursor, don't override it.
@@ -368,20 +336,20 @@ void QGraphicsProxyWidgetPrivate::removeSubFocusHelper(QWidget *widget, Qt::Focu
QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next) const
{
if (!widget)
- return 0;
+ return nullptr;
// Run around the focus chain until we find a widget that can take tab focus.
if (!child) {
- child = next ? (QWidget *)widget : widget->d_func()->focus_prev;
+ child = next ? widget.data() : widget->previousInFocusChain();
} else {
- child = next ? child->d_func()->focus_next : child->d_func()->focus_prev;
- if ((next && child == widget) || (!next && child == widget->d_func()->focus_prev)) {
- return 0;
+ child = next ? child->nextInFocusChain() : child->previousInFocusChain();
+ if ((next && child == widget) || (!next && child == widget->previousInFocusChain())) {
+ return nullptr;
}
}
if (!child)
- return 0;
+ return nullptr;
QWidget *oldChild = child;
uint focus_flag = qt_tab_all_widgets() ? Qt::TabFocus : Qt::StrongFocus;
@@ -392,9 +360,9 @@ QWidget *QGraphicsProxyWidgetPrivate::findFocusChild(QWidget *child, bool next)
&& !(child->d_func()->extra && child->d_func()->extra->focus_proxy)) {
return child;
}
- child = next ? child->d_func()->focus_next : child->d_func()->focus_prev;
- } while (child != oldChild && !(next && child == widget) && !(!next && child == widget->d_func()->focus_prev));
- return 0;
+ child = next ? child->nextInFocusChain() : child->previousInFocusChain();
+ } while (child != oldChild && !(next && child == widget) && !(!next && child == widget->previousInFocusChain()));
+ return nullptr;
}
/*!
@@ -405,9 +373,9 @@ void QGraphicsProxyWidgetPrivate::_q_removeWidgetSlot()
Q_Q(QGraphicsProxyWidget);
if (!widget.isNull()) {
if (const auto &extra = widget->d_func()->extra)
- extra->proxyWidget = 0;
+ extra->proxyWidget = nullptr;
}
- widget = 0;
+ widget = nullptr;
delete q;
}
@@ -430,7 +398,7 @@ void QGraphicsProxyWidgetPrivate::updateProxyGeometryFromWidget()
QRectF widgetGeometry = widget->geometry();
QWidget *parentWidget = widget->parentWidget();
if (widget->isWindow()) {
- QGraphicsProxyWidget *proxyParent = 0;
+ QGraphicsProxyWidget *proxyParent = nullptr;
if (parentWidget && (proxyParent = qobject_cast<QGraphicsProxyWidget *>(q->parentWidget()))) {
// Nested window proxy (e.g., combobox popup), map widget to the
// parent widget's global coordinates, and map that to the parent
@@ -493,11 +461,11 @@ void QGraphicsProxyWidgetPrivate::embedSubWindow(QWidget *subWin)
*/
void QGraphicsProxyWidgetPrivate::unembedSubWindow(QWidget *subWin)
{
- foreach (QGraphicsItem *child, children) {
+ for (QGraphicsItem *child : std::as_const(children)) {
if (child->isWidget()) {
if (QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(child))) {
if (proxy->widget() == subWin) {
- proxy->setWidget(0);
+ proxy->setWidget(nullptr);
scene->removeItem(proxy);
delete proxy;
return;
@@ -554,7 +522,7 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget()
/*!
Embeds \a widget into this proxy widget. The embedded widget must reside
exclusively either inside or outside of Graphics View. You cannot embed a
- widget as long as it is is visible elsewhere in the UI, at the same time.
+ widget as long as it is visible elsewhere in the UI, at the same time.
\a widget must be a top-level widget whose parent is \nullptr.
@@ -570,8 +538,8 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget()
After this function returns, QGraphicsProxyWidget will keep its state
synchronized with that of \a widget whenever possible.
- If a widget is already embedded by this proxy when this function is
- called, that widget will first be automatically unembedded. Passing 0 for
+ If a widget is already embedded by this proxy when this function is called,
+ that widget will first be automatically unembedded. Passing \nullptr for
the \a widget argument will only unembed the widget, and the ownership of
the currently embedded widget will be passed on to the caller.
Every child widget that are embedded will also be embedded and their proxy
@@ -579,7 +547,7 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget()
Note that widgets with the Qt::WA_PaintOnScreen widget attribute
set and widgets that wrap an external application or controller
- cannot be embedded. Examples are QGLWidget and QAxWidget.
+ cannot be embedded. Examples are QOpenGLWidget and QAxWidget.
\sa widget()
*/
@@ -598,7 +566,7 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto
QObject::disconnect(widget, SIGNAL(destroyed()), q, SLOT(_q_removeWidgetSlot()));
widget->removeEventFilter(q);
widget->setAttribute(Qt::WA_DontShowOnScreen, false);
- widget->d_func()->extra->proxyWidget = 0;
+ widget->d_func()->extra->proxyWidget = nullptr;
resolveFont(inheritedFontResolveMask);
resolvePalette(inheritedPaletteResolveMask);
widget->update();
@@ -830,6 +798,10 @@ bool QGraphicsProxyWidget::event(QEvent *event)
return QGraphicsWidget::event(event);
switch (event->type()) {
+ case QEvent::WindowActivate:
+ case QEvent::WindowDeactivate:
+ QCoreApplication::sendEvent(d->widget, event);
+ break;
case QEvent::StyleChange:
// Propagate style changes to the embedded widget.
if (!d->styleChangeMode) {
@@ -841,7 +813,7 @@ bool QGraphicsProxyWidget::event(QEvent *event)
case QEvent::FontChange: {
// Propagate to widget.
QWidgetPrivate *wd = d->widget->d_func();
- int mask = d->font.resolve() | d->inheritedFontResolveMask;
+ int mask = d->font.resolveMask() | d->inheritedFontResolveMask;
wd->inheritedFontResolveMask = mask;
wd->resolveFont();
break;
@@ -849,7 +821,7 @@ bool QGraphicsProxyWidget::event(QEvent *event)
case QEvent::PaletteChange: {
// Propagate to widget.
QWidgetPrivate *wd = d->widget->d_func();
- int mask = d->palette.resolve() | d->inheritedPaletteResolveMask;
+ int mask = d->palette.resolveMask() | d->inheritedPaletteResolveMask;
wd->inheritedPaletteResolveMask = mask;
wd->resolvePalette();
break;
@@ -888,7 +860,7 @@ bool QGraphicsProxyWidget::event(QEvent *event)
}
break;
}
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
case QEvent::GraphicsSceneHelp: {
// Propagate the help event (for tooltip) to the widget under mouse
if (d->lastWidgetUnderMouse) {
@@ -914,16 +886,13 @@ bool QGraphicsProxyWidget::event(QEvent *event)
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd: {
- if (event->spontaneous())
- qt_sendSpontaneousEvent(d->widget, event);
- else
- QCoreApplication::sendEvent(d->widget, event);
-
- if (event->isAccepted())
+ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
+ bool res = QApplicationPrivate::translateRawTouchEvent(d->widget, touchEvent);
+ if (res & touchEvent->isAccepted())
return true;
break;
- }
+ }
default:
break;
}
@@ -979,7 +948,7 @@ bool QGraphicsProxyWidget::eventFilter(QObject *object, QEvent *event)
d->styleChangeMode = QGraphicsProxyWidgetPrivate::NoMode;
}
break;
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
case QEvent::ToolTipChange:
// Propagate tooltip change to the proxy.
if (!d->tooltipChangeMode) {
@@ -1042,6 +1011,7 @@ void QGraphicsProxyWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent *even
// Send mouse event. ### Doesn't propagate the event.
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
pos.toPoint(), globalPos, event->modifiers());
+ contextMenuEvent.setTimestamp(event->timestamp());
QCoreApplication::sendEvent(receiver, &contextMenuEvent);
event->setAccepted(contextMenuEvent.isAccepted());
@@ -1081,7 +1051,7 @@ void QGraphicsProxyWidget::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
return;
QDragLeaveEvent proxyDragLeave;
QCoreApplication::sendEvent(d->dragDropWidget, &proxyDragLeave);
- d->dragDropWidget = 0;
+ d->dragDropWidget = nullptr;
#endif
}
@@ -1143,7 +1113,7 @@ void QGraphicsProxyWidget::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
// Leave the last drag drop item
QDragLeaveEvent dragLeave;
QCoreApplication::sendEvent(d->dragDropWidget, &dragLeave);
- d->dragDropWidget = 0;
+ d->dragDropWidget = nullptr;
}
// Propagate
event->setDropAction(Qt::IgnoreAction);
@@ -1165,7 +1135,7 @@ void QGraphicsProxyWidget::dropEvent(QGraphicsSceneDragDropEvent *event)
QDropEvent dropEvent(widgetPos, event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
QCoreApplication::sendEvent(d->dragDropWidget, &dropEvent);
event->setAccepted(dropEvent.isAccepted());
- d->dragDropWidget = 0;
+ d->dragDropWidget = nullptr;
}
#endif
}
@@ -1188,8 +1158,8 @@ void QGraphicsProxyWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_D(QGraphicsProxyWidget);
// If hoverMove was compressed away, make sure we update properly here.
if (d->lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse, event->screenPos());
- d->lastWidgetUnderMouse = 0;
+ QApplicationPrivate::dispatchEnterLeave(nullptr, d->lastWidgetUnderMouse, event->screenPos());
+ d->lastWidgetUnderMouse = nullptr;
}
}
@@ -1205,13 +1175,13 @@ void QGraphicsProxyWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
// Ignore events on the window frame.
if (!d->widget || !rect().contains(event->pos())) {
if (d->lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse, event->screenPos());
- d->lastWidgetUnderMouse = 0;
+ QApplicationPrivate::dispatchEnterLeave(nullptr, d->lastWidgetUnderMouse, event->screenPos());
+ d->lastWidgetUnderMouse = nullptr;
}
return;
}
- d->embeddedMouseGrabber = 0;
+ d->embeddedMouseGrabber = nullptr;
d->sendWidgetMouseEvent(event);
}
@@ -1230,7 +1200,7 @@ void QGraphicsProxyWidget::ungrabMouseEvent(QEvent *event)
{
Q_D(QGraphicsProxyWidget);
Q_UNUSED(event);
- d->embeddedMouseGrabber = 0;
+ d->embeddedMouseGrabber = nullptr;
}
/*!
@@ -1287,6 +1257,19 @@ void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
if (!receiver)
receiver = d->widget;
+ // high precision event streams go to the grabber, which will be the
+ // QGraphicsView's viewport. We need to change that temporarily, otherwise
+ // the event we send to the receiver get grabbed by the viewport, resulting
+ // in infinite recursion
+ QPointer<QWidget> prev_grabber = QApplicationPrivate::wheel_widget;
+ if (event->phase() == Qt::ScrollBegin) {
+ QApplicationPrivate::wheel_widget = receiver;
+ } else if (event->phase() != Qt::NoScrollPhase && QApplicationPrivate::wheel_widget != receiver) {
+ // this event is part of a stream that didn't start here, so ignore
+ event->ignore();
+ return;
+ }
+
// Map event position from us to the receiver
pos = d->mapToReceiver(pos, receiver);
@@ -1298,13 +1281,21 @@ void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
angleDelta.setY(event->delta());
// pixelDelta, inverted, scrollPhase and source from the original QWheelEvent
// were not preserved in the QGraphicsSceneWheelEvent unfortunately
- QWheelEvent wheelEvent(pos, event->screenPos(), QPoint(), angleDelta,
- event->buttons(), event->modifiers(), Qt::NoScrollPhase, false);
+ QWheelEvent wheelEvent(pos, event->screenPos(), event->pixelDelta(), angleDelta,
+ event->buttons(), event->modifiers(), event->phase(),
+ event->isInverted(), Qt::MouseEventSynthesizedByQt,
+ QPointingDevice::primaryPointingDevice());
QPointer<QWidget> focusWidget = d->widget->focusWidget();
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
qt_sendSpontaneousEvent(receiver, &wheelEvent);
event->setAccepted(wheelEvent.isAccepted());
+ if (event->phase() == Qt::ScrollBegin) {
+ // reset the wheel grabber if the event wasn't accepted
+ if (!wheelEvent.isAccepted())
+ QApplicationPrivate::wheel_widget = prev_grabber;
+ }
+
// ### Remove, this should be done by proper focusIn/focusOut events.
if (focusWidget && !focusWidget->hasFocus()) {
focusWidget->update();
@@ -1372,12 +1363,12 @@ void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event)
switch (event->reason()) {
case Qt::TabFocusReason: {
- if (QWidget *focusChild = d->findFocusChild(0, true))
+ if (QWidget *focusChild = d->findFocusChild(nullptr, true))
focusChild->setFocus(event->reason());
break;
}
case Qt::BacktabFocusReason:
- if (QWidget *focusChild = d->findFocusChild(0, false))
+ if (QWidget *focusChild = d->findFocusChild(nullptr, false))
focusChild->setFocus(event->reason());
break;
default:
@@ -1387,6 +1378,11 @@ void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event)
break;
}
+ // QTBUG-88016
+ if (d->widget && d->widget->focusWidget()
+ && d->widget->focusWidget()->testAttribute(Qt::WA_InputMethodEnabled))
+ QApplication::inputMethod()->reset();
+
d->proxyIsGivingFocus = false;
}
@@ -1402,8 +1398,14 @@ void QGraphicsProxyWidget::focusOutEvent(QFocusEvent *event)
if (d->widget) {
// We need to explicitly remove subfocus from the embedded widget's
// focus widget.
- if (QWidget *focusWidget = d->widget->focusWidget())
+ if (QWidget *focusWidget = d->widget->focusWidget()) {
+ // QTBUG-88016 proxyWidget set QTextEdit(QLineEdit etc.) when input preview text,
+ // inputMethod should be reset when proxyWidget lost focus
+ if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
+ QApplication::inputMethod()->reset();
+
d->removeSubFocusHelper(focusWidget, event->reason());
+ }
}
}
@@ -1441,17 +1443,17 @@ QVariant QGraphicsProxyWidget::inputMethodQuery(Qt::InputMethodQuery query) cons
focusWidget = d->widget;
QVariant v = focusWidget->inputMethodQuery(query);
QPointF focusWidgetPos = subWidgetRect(focusWidget).topLeft();
- switch (v.type()) {
- case QVariant::RectF:
+ switch (v.userType()) {
+ case QMetaType::QRectF:
v = v.toRectF().translated(focusWidgetPos);
break;
- case QVariant::PointF:
+ case QMetaType::QPointF:
v = v.toPointF() + focusWidgetPos;
break;
- case QVariant::Rect:
+ case QMetaType::QRect:
v = v.toRect().translated(focusWidgetPos.toPoint());
break;
- case QVariant::Point:
+ case QMetaType::QPoint:
v = v.toPoint() + focusWidgetPos.toPoint();
break;
default:
@@ -1538,6 +1540,10 @@ void QGraphicsProxyWidget::paint(QPainter *painter, const QStyleOptionGraphicsIt
if (exposedWidgetRect.isEmpty())
return;
+ // When rendering to pdf etc. painting may go outside widget boundaries unless clipped
+ if (painter->device()->devType() != QInternal::Widget && (flags() & ItemClipsChildrenToShape))
+ painter->setClipRect(d->widget->geometry(), Qt::IntersectClip);
+
d->widget->render(painter, exposedWidgetRect.topLeft(), exposedWidgetRect);
}
@@ -1578,16 +1584,16 @@ QGraphicsProxyWidget *QGraphicsProxyWidget::createProxyForChildWidget(QWidget *c
return proxy;
if (!child->parentWidget()) {
qWarning("QGraphicsProxyWidget::createProxyForChildWidget: top-level widget not in a QGraphicsScene");
- return 0;
+ return nullptr;
}
QGraphicsProxyWidget *parentProxy = createProxyForChildWidget(child->parentWidget());
if (!parentProxy)
- return 0;
+ return nullptr;
if (!QMetaObject::invokeMethod(parentProxy, "newProxyWidget", Qt::DirectConnection,
Q_RETURN_ARG(QGraphicsProxyWidget*, proxy), Q_ARG(const QWidget*, child)))
- return 0;
+ return nullptr;
proxy->setParent(parentProxy);
proxy->setWidget(child);
return proxy;
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.h b/src/widgets/graphicsview/qgraphicsproxywidget.h
index aa51500ecb..7149f5701a 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.h
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.h
@@ -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
#ifndef QGRAPHICSPROXYWIDGET_H
#define QGRAPHICSPROXYWIDGET_H
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget_p.h b/src/widgets/graphicsview/qgraphicsproxywidget_p.h
index 593b686e0e..328faad0be 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget_p.h
+++ b/src/widgets/graphicsview/qgraphicsproxywidget_p.h
@@ -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
#ifndef QGRAPHICSPROXYWIDGET_P_H
#define QGRAPHICSPROXYWIDGET_P_H
@@ -55,6 +19,8 @@
#include "qgraphicsproxywidget.h"
#include "private/qgraphicswidget_p.h"
+#include <QtCore/qpointer.h>
+
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index a47d0d879d..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
@@ -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,11 +344,11 @@ 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;
}
@@ -443,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);
@@ -463,7 +431,7 @@ void QGraphicsScenePrivate::_q_polishItems()
}
}
- if (unpolishedItems.count() == oldUnpolishedCount) {
+ if (unpolishedItems.size() == oldUnpolishedCount) {
// No new items were added to the vector.
unpolishedItems.clear();
} else {
@@ -482,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;
}
@@ -491,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)
@@ -501,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
@@ -512,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();
}
/*!
@@ -555,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;
@@ -602,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.
@@ -625,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);
@@ -633,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) {
@@ -651,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
@@ -705,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
@@ -731,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
}
@@ -752,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;
@@ -764,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);
@@ -841,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.
@@ -849,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;
}
}
@@ -869,7 +837,7 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
}
#endif //QT_NO_IM
- focusItem = 0;
+ focusItem = nullptr;
QFocusEvent event(QEvent::FocusOut, focusReason);
sendEvent(lastFocusItem, &event);
}
@@ -877,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;
@@ -1038,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;
}
/*!
@@ -1114,7 +1082,7 @@ void QGraphicsScenePrivate::clearKeyboardGrabber()
void QGraphicsScenePrivate::enableMouseTrackingOnViews()
{
- foreach (QGraphicsView *view, views)
+ for (QGraphicsView *view : std::as_const(views))
view->viewport()->setMouseTracking(true);
}
@@ -1253,7 +1221,7 @@ bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event)
bool spont = event->spontaneous();
if (spont ? qt_sendSpontaneousEvent(o, event) : QCoreApplication::sendEvent(o, event))
return true;
- event->spont = spont;
+ event->m_spont = spont;
}
return item->sceneEvent(event);
}
@@ -1365,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())
@@ -1377,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.
@@ -1400,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;
}
@@ -1409,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())
@@ -1419,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;
@@ -1438,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());
@@ -1531,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);
}
@@ -1545,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);
}
@@ -1571,7 +1539,7 @@ 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());
}
}
@@ -1588,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);
}
@@ -1602,7 +1570,7 @@ void QGraphicsScenePrivate::setPalette_helper(const QPalette &palette)
void QGraphicsScenePrivate::resolvePalette()
{
QPalette naturalPalette = QGuiApplication::palette();
- naturalPalette.resolve(0);
+ naturalPalette.setResolveMask(0);
QPalette resolvedPalette = palette.resolve(naturalPalette);
updatePalette(resolvedPalette);
}
@@ -1628,7 +1596,7 @@ 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());
}
}
@@ -1693,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);
}
/*!
@@ -1812,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();
@@ -1830,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.
@@ -1852,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
@@ -1937,29 +1907,6 @@ void QGraphicsScene::setBspTreeDepth(int depth)
bspTree->setBspTreeDepth(depth);
}
-#if QT_DEPRECATED_SINCE(5, 13)
-/*!
- \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;
-}
-#endif
-
/*!
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
@@ -1990,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
@@ -2150,23 +2085,6 @@ 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
- \nullptr 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 \nullptr
@@ -2204,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 \nullptr 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.
@@ -2234,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;
}
@@ -2274,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);
}
/*!
@@ -2342,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;
}
@@ -2351,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)
@@ -2369,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)
@@ -2432,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;
@@ -2446,7 +2335,7 @@ QGraphicsItemGroup *QGraphicsScene::createItemGroup(const QList<QGraphicsItem *>
} while ((parent = parent->parentItem()));
if (commonIndex == -1) {
- commonAncestor = 0;
+ commonAncestor = nullptr;
break;
}
@@ -2480,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
@@ -2530,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
@@ -2568,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();
}
@@ -2588,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
@@ -2621,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();
@@ -2896,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;
@@ -2936,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;
}
@@ -2993,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()
@@ -3038,7 +2931,7 @@ void QGraphicsScene::clearFocus()
if (d->hasFocus) {
d->hasFocus = false;
d->passiveFocusItem = d->focusItem;
- setFocusItem(0, Qt::OtherFocusReason);
+ setFocusItem(nullptr, Qt::OtherFocusReason);
}
}
@@ -3124,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();
}
@@ -3182,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;
}
@@ -3213,14 +3106,13 @@ 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
@@ -3361,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;
}
@@ -3449,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;
@@ -3484,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.
@@ -3613,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();
}
@@ -3697,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);
@@ -3717,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;
}
}
@@ -3735,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;
}
}
@@ -3785,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())
@@ -3809,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;
}
}
@@ -3875,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;
@@ -3886,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.
@@ -3942,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());
@@ -4122,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
@@ -4134,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().
@@ -4181,7 +4078,8 @@ void QGraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
// 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);
@@ -4222,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);
}
/*!
@@ -4354,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()) {
@@ -4495,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;
@@ -4656,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.
@@ -4666,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;
@@ -4723,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,
@@ -4748,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) { \
@@ -4806,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.
@@ -4858,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)
{
@@ -4893,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;
@@ -4907,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) {
@@ -4917,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))
@@ -4936,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;
@@ -4996,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))
@@ -5075,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);
@@ -5231,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
@@ -5290,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
@@ -5300,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)
@@ -5321,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();
@@ -5332,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
@@ -5354,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
@@ -5378,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;
@@ -5402,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);
@@ -5462,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 {
@@ -5478,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))
) {
@@ -5644,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,7 +5580,7 @@ void QGraphicsScene::setPalette(const QPalette &palette)
{
Q_D(QGraphicsScene);
QPalette naturalPalette = QGuiApplication::palette();
- naturalPalette.resolve(0);
+ naturalPalette.setResolveMask(0);
QPalette resolvedPalette = palette.resolve(naturalPalette);
d->setPalette_helper(resolvedPalette);
}
@@ -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);
@@ -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;
@@ -6440,7 +6333,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
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
@@ -6497,7 +6390,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
}
gestureTargetsAtHotSpots(ignoredGestures, Qt::ReceivePartialGestures,
- &cachedItemGestures, &targetsSet, 0, 0);
+ &cachedItemGestures, &targetsSet, nullptr, nullptr);
cachedTargetItems = targetsSet.values();
std::sort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
@@ -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;
@@ -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);
}
}
diff --git a/src/widgets/graphicsview/qgraphicsscene.h b/src/widgets/graphicsview/qgraphicsscene.h
index e72ed99a7b..33fb747277 100644
--- a/src/widgets/graphicsview/qgraphicsscene.h
+++ b/src/widgets/graphicsview/qgraphicsscene.h
@@ -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
#ifndef QGRAPHICSSCENE_H
#define QGRAPHICSSCENE_H
@@ -47,7 +11,6 @@
#include <QtGui/qbrush.h>
#include <QtGui/qfont.h>
#include <QtGui/qtransform.h>
-#include <QtGui/qmatrix.h>
#include <QtGui/qpen.h>
QT_REQUIRE_CONFIG(graphicsview);
@@ -102,9 +65,6 @@ class Q_WIDGETS_EXPORT QGraphicsScene : public QObject
Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
Q_PROPERTY(QFont font READ font WRITE setFont)
-#if QT_DEPRECATED_SINCE(5, 13)
- Q_PROPERTY(bool sortCacheEnabled READ isSortCacheEnabled WRITE setSortCacheEnabled)
-#endif
Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
Q_PROPERTY(qreal minimumRenderSize READ minimumRenderSize WRITE setMinimumRenderSize)
Q_PROPERTY(bool focusOnTouch READ focusOnTouch WRITE setFocusOnTouch)
@@ -142,11 +102,6 @@ public:
ItemIndexMethod itemIndexMethod() const;
void setItemIndexMethod(ItemIndexMethod method);
-#if QT_DEPRECATED_SINCE(5, 13)
- QT_DEPRECATED bool isSortCacheEnabled() const;
- QT_DEPRECATED void setSortCacheEnabled(bool enabled);
-#endif
-
int bspTreeDepth() const;
void setBspTreeDepth(int depth);
@@ -158,37 +113,19 @@ public:
QList<QGraphicsItem *> items(const QRectF &rect, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
QList<QGraphicsItem *> items(const QPolygonF &polygon, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
QList<QGraphicsItem *> items(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, Qt::SortOrder order = Qt::DescendingOrder, const QTransform &deviceTransform = QTransform()) const;
-
- QList<QGraphicsItem *> collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline QGraphicsItem *itemAt(const QPointF &position) const {
- QList<QGraphicsItem *> itemsAtPoint = items(position);
- return itemsAtPoint.isEmpty() ? nullptr : itemsAtPoint.first();
- }
-#endif
- QGraphicsItem *itemAt(const QPointF &pos, const QTransform &deviceTransform) const;
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const
- { return items(QRectF(x, y, w, h), mode); }
-#endif
inline QList<QGraphicsItem *> items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order,
const QTransform &deviceTransform = QTransform()) const
{ return items(QRectF(x, y, w, h), mode, order, deviceTransform); }
-#if QT_DEPRECATED_SINCE(5, 0)
- QT_DEPRECATED inline QGraphicsItem *itemAt(qreal x, qreal y) const {
- QList<QGraphicsItem *> itemsAtPoint = items(QPointF(x, y));
- return itemsAtPoint.isEmpty() ? nullptr : itemsAtPoint.first();
- }
-#endif
+
+ QList<QGraphicsItem *> collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
+ QGraphicsItem *itemAt(const QPointF &pos, const QTransform &deviceTransform) const;
inline QGraphicsItem *itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
{ return itemAt(QPointF(x, y), deviceTransform); }
QList<QGraphicsItem *> selectedItems() const;
QPainterPath selectionArea() const;
void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform);
- void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, const QTransform &deviceTransform = QTransform());
- void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionOperation selectionOperation, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, const QTransform &deviceTransform = QTransform());
- // ### Qt6 merge the last 2 functions and add a default: Qt::ItemSelectionOperation selectionOperation = Qt::ReplaceSelection
+ void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionOperation selectionOperation = Qt::ReplaceSelection, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape, const QTransform &deviceTransform = QTransform());
QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
void destroyItemGroup(QGraphicsItemGroup *group);
@@ -295,7 +232,7 @@ protected:
QWidget *widget = nullptr);
protected Q_SLOTS:
- QT6_VIRTUAL bool focusNextPrevChild(bool next);
+ virtual bool focusNextPrevChild(bool next);
Q_SIGNALS:
void changed(const QList<QRectF> &region);
diff --git a/src/widgets/graphicsview/qgraphicsscene_bsp.cpp b/src/widgets/graphicsview/qgraphicsscene_bsp.cpp
index 75eb50a3ac..1ba6fe787a 100644
--- a/src/widgets/graphicsview/qgraphicsscene_bsp.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene_bsp.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
#include "qgraphicsscene_bsp_p.h"
@@ -44,57 +8,14 @@
QT_BEGIN_NAMESPACE
-class QGraphicsSceneInsertItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
-{
-public:
- QGraphicsItem *item;
-
- void visit(QList<QGraphicsItem *> *items) override
- { items->prepend(item); }
-};
-
-class QGraphicsSceneRemoveItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
-{
-public:
- QGraphicsItem *item;
-
- void visit(QList<QGraphicsItem *> *items) override
- { items->removeAll(item); }
-};
-
-class QGraphicsSceneFindItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
-{
-public:
- QList<QGraphicsItem *> *foundItems;
- bool onlyTopLevelItems;
-
- void visit(QList<QGraphicsItem *> *items) override
- {
- for (int i = 0; i < items->size(); ++i) {
- QGraphicsItem *item = items->at(i);
- if (onlyTopLevelItems && item->d_ptr->parent)
- item = item->topLevelItem();
- if (!item->d_func()->itemDiscovered && item->d_ptr->visible) {
- item->d_func()->itemDiscovered = 1;
- foundItems->prepend(item);
- }
- }
- }
-};
QGraphicsSceneBspTree::QGraphicsSceneBspTree()
: leafCnt(0)
{
- insertVisitor = new QGraphicsSceneInsertItemBspTreeVisitor;
- removeVisitor = new QGraphicsSceneRemoveItemBspTreeVisitor;
- findVisitor = new QGraphicsSceneFindItemBspTreeVisitor;
}
QGraphicsSceneBspTree::~QGraphicsSceneBspTree()
{
- delete insertVisitor;
- delete removeVisitor;
- delete findVisitor;
}
void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth)
@@ -103,7 +24,7 @@ void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth)
leafCnt = 0;
nodes.resize((1 << (depth + 1)) - 1);
nodes.fill(Node());
- leaves.resize(1 << depth);
+ leaves.resize(1ll << depth);
leaves.fill(QList<QGraphicsItem *>());
initialize(rect, depth, 0);
@@ -118,14 +39,16 @@ void QGraphicsSceneBspTree::clear()
void QGraphicsSceneBspTree::insertItem(QGraphicsItem *item, const QRectF &rect)
{
- insertVisitor->item = item;
- climbTree(insertVisitor, rect);
+ climbTree([item](QList<QGraphicsItem *> *items){
+ items->prepend(item);
+ }, rect);
}
void QGraphicsSceneBspTree::removeItem(QGraphicsItem *item, const QRectF &rect)
{
- removeVisitor->item = item;
- climbTree(removeVisitor, rect);
+ climbTree([item](QList<QGraphicsItem *> *items){
+ items->removeAll(item);
+ }, rect);
}
void QGraphicsSceneBspTree::removeItems(const QSet<QGraphicsItem *> &items)
@@ -144,14 +67,22 @@ void QGraphicsSceneBspTree::removeItems(const QSet<QGraphicsItem *> &items)
QList<QGraphicsItem *> QGraphicsSceneBspTree::items(const QRectF &rect, bool onlyTopLevelItems) const
{
- QList<QGraphicsItem *> tmp;
- findVisitor->foundItems = &tmp;
- findVisitor->onlyTopLevelItems = onlyTopLevelItems;
- climbTree(findVisitor, rect);
+ QList<QGraphicsItem *> foundItems;
+ climbTree([&foundItems, onlyTopLevelItems](QList<QGraphicsItem *> *items) {
+ for (int i = 0; i < items->size(); ++i) {
+ QGraphicsItem *item = items->at(i);
+ if (onlyTopLevelItems && item->d_ptr->parent)
+ item = item->topLevelItem();
+ if (!item->d_func()->itemDiscovered && item->d_ptr->visible) {
+ item->d_func()->itemDiscovered = 1;
+ foundItems.prepend(item);
+ }
+ }
+ }, rect);
// Reset discovery bits.
- for (int i = 0; i < tmp.size(); ++i)
- tmp.at(i)->d_ptr->itemDiscovered = 0;
- return tmp;
+ for (const auto &foundItem : std::as_const(foundItems))
+ foundItem->d_ptr->itemDiscovered = 0;
+ return foundItems;
}
int QGraphicsSceneBspTree::leafCount() const
@@ -190,7 +121,7 @@ void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth, int index)
Node *node = &nodes[index];
if (index == 0) {
node->type = Node::Horizontal;
- node->offset = rect.center().x();
+ node->offset = rect.center().y();
}
if (depth) {
@@ -230,7 +161,8 @@ void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth, int index)
}
}
-void QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor *visitor, const QRectF &rect, int index) const
+template<typename Visitor>
+void QGraphicsSceneBspTree::climbTree(Visitor &&visitor, const QRectF &rect, int index) const
{
if (nodes.isEmpty())
return;
@@ -240,7 +172,7 @@ void QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor *visitor, con
switch (node.type) {
case Node::Leaf: {
- visitor->visit(const_cast<QList<QGraphicsItem*>*>(&leaves[node.leafIndex]));
+ visitor(const_cast<QList<QGraphicsItem*>*>(&leaves[node.leafIndex]));
break;
}
case Node::Vertical:
@@ -272,7 +204,7 @@ QRectF QGraphicsSceneBspTree::rectForIndex(int index) const
QRectF rect = rectForIndex(parentIdx);
const Node *parent = &nodes.at(parentIdx);
- if (parent->type == Node::Horizontal) {
+ if (parent->type == Node::Vertical) {
if (index & 1)
rect.setRight(parent->offset);
else
diff --git a/src/widgets/graphicsview/qgraphicsscene_bsp_p.h b/src/widgets/graphicsview/qgraphicsscene_bsp_p.h
index 26e612b2dd..9e0fa919b7 100644
--- a/src/widgets/graphicsview/qgraphicsscene_bsp_p.h
+++ b/src/widgets/graphicsview/qgraphicsscene_bsp_p.h
@@ -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
#ifndef QGRAPHICSSCENEBSPTREE_P_H
#define QGRAPHICSSCENEBSPTREE_P_H
@@ -53,20 +17,14 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include <QtCore/qlist.h>
-
#include <QtCore/qrect.h>
#include <QtCore/qset.h>
-#include <QtCore/qvector.h>
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
class QGraphicsItem;
-class QGraphicsSceneBspTreeVisitor;
-class QGraphicsSceneInsertItemBspTreeVisitor;
-class QGraphicsSceneRemoveItemBspTreeVisitor;
-class QGraphicsSceneFindItemBspTreeVisitor;
class QGraphicsSceneBspTree
{
@@ -104,24 +62,14 @@ public:
private:
void initialize(const QRectF &rect, int depth, int index);
- void climbTree(QGraphicsSceneBspTreeVisitor *visitor, const QRectF &rect, int index = 0) const;
+ template<typename Visitor>
+ void climbTree(Visitor &&visitor, const QRectF &rect, int index = 0) const;
QRectF rectForIndex(int index) const;
- QVector<Node> nodes;
- QVector<QList<QGraphicsItem *> > leaves;
+ QList<Node> nodes;
+ QList<QList<QGraphicsItem *>> leaves;
int leafCnt;
QRectF rect;
-
- QGraphicsSceneInsertItemBspTreeVisitor *insertVisitor;
- QGraphicsSceneRemoveItemBspTreeVisitor *removeVisitor;
- QGraphicsSceneFindItemBspTreeVisitor *findVisitor;
-};
-
-class QGraphicsSceneBspTreeVisitor
-{
-public:
- virtual ~QGraphicsSceneBspTreeVisitor() { }
- virtual void visit(QList<QGraphicsItem *> *items) = 0;
};
QT_END_NAMESPACE
diff --git a/src/widgets/graphicsview/qgraphicsscene_p.h b/src/widgets/graphicsview/qgraphicsscene_p.h
index 9ecfca8ebf..c4b8b4e867 100644
--- a/src/widgets/graphicsview/qgraphicsscene_p.h
+++ b/src/widgets/graphicsview/qgraphicsscene_p.h
@@ -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
#ifndef QGRAPHICSSCENE_P_H
#define QGRAPHICSSCENE_P_H
@@ -142,7 +106,7 @@ public:
QPainterPath selectionArea;
int selectionChanging;
QSet<QGraphicsItem *> selectedItems;
- QVector<QGraphicsItem *> unpolishedItems;
+ QList<QGraphicsItem *> unpolishedItems;
QList<QGraphicsItem *> topLevelItems;
QHash<QGraphicsItem *, QPointF> movingItemsInitialPositions;
@@ -309,7 +273,7 @@ public:
QStyleOptionGraphicsItem styleOptionTmp;
- QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
+ QMap<int, QEventPoint> sceneCurrentTouchPoints;
QMap<int, QGraphicsItem *> itemForTouchPointId;
static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
int findClosestTouchPointId(const QPointF &scenePos);
diff --git a/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp
index 69ddf54bc7..8a11489308 100644
--- a/src/widgets/graphicsview/qgraphicsscenebsptreeindex.cpp
+++ b/src/widgets/graphicsview/qgraphicsscenebsptreeindex.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 QGraphicsSceneBspTreeIndex
diff --git a/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h b/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h
index 7e0e525a6b..bd9894d5fe 100644
--- a/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h
+++ b/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore 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
//
// W A R N I N G
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp
index 768dd07d4e..0ace03b553 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.cpp
+++ b/src/widgets/graphicsview/qgraphicssceneevent.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 QGraphicsSceneEvent
@@ -278,8 +242,8 @@ class QGraphicsSceneEventPrivate
{
public:
inline QGraphicsSceneEventPrivate()
- : widget(0),
- q_ptr(0)
+ : widget(nullptr),
+ q_ptr(nullptr)
{ }
inline virtual ~QGraphicsSceneEventPrivate()
@@ -287,6 +251,7 @@ public:
QWidget *widget;
QGraphicsSceneEvent *q_ptr;
+ quint64 timestamp = 0;
};
/*!
@@ -339,6 +304,26 @@ void QGraphicsSceneEvent::setWidget(QWidget *widget)
d_ptr->widget = widget;
}
+/*!
+ \since 6.2
+
+ Returns the timestamp of the original event, or 0 if the
+ original event does not report a time stamp.
+*/
+quint64 QGraphicsSceneEvent::timestamp() const
+{
+ return d_ptr->timestamp;
+}
+/*!
+ \internal
+
+ Sets the timestamp for the event to \a ts.
+*/
+void QGraphicsSceneEvent::setTimestamp(quint64 ts)
+{
+ d_ptr->timestamp = ts;
+}
+
class QGraphicsSceneMouseEventPrivate : public QGraphicsSceneEventPrivate
{
Q_DECLARE_PUBLIC(QGraphicsSceneMouseEvent)
@@ -695,10 +680,13 @@ public:
QPointF pos;
QPointF scenePos;
QPoint screenPos;
+ QPoint pixelDelta;
Qt::MouseButtons buttons;
Qt::KeyboardModifiers modifiers;
int delta = 0;
Qt::Orientation orientation = Qt::Horizontal;
+ Qt::ScrollPhase scrollPhase = Qt::NoScrollPhase;
+ bool inverted = false;
};
/*!
@@ -865,6 +853,73 @@ void QGraphicsSceneWheelEvent::setOrientation(Qt::Orientation orientation)
d->orientation = orientation;
}
+/*!
+ \since 6.2
+
+ Returns the scrolling phase of this wheel event.
+
+ \sa QWheelEvent::phase
+*/
+Qt::ScrollPhase QGraphicsSceneWheelEvent::phase() const
+{
+ Q_D(const QGraphicsSceneWheelEvent);
+ return d->scrollPhase;
+}
+
+/*!
+ \internal
+*/
+void QGraphicsSceneWheelEvent::setPhase(Qt::ScrollPhase scrollPhase)
+{
+ Q_D(QGraphicsSceneWheelEvent);
+ d->scrollPhase = scrollPhase;
+}
+
+/*!
+ \since 6.2
+
+ Returns the scrolling distance in pixels on screen. This value is
+ provided on platforms that support high-resolution pixel-based
+ delta values, such as \macos. The value should be used directly
+ to scroll content on screen.
+
+ \sa QWheelEvent::pixelDelta
+*/
+QPoint QGraphicsSceneWheelEvent::pixelDelta() const
+{
+ Q_D(const QGraphicsSceneWheelEvent);
+ return d->pixelDelta;
+}
+
+/*!
+ \internal
+*/
+void QGraphicsSceneWheelEvent::setPixelDelta(QPoint pixelDelta)
+{
+ Q_D(QGraphicsSceneWheelEvent);
+ d->pixelDelta = pixelDelta;
+}
+
+/*!
+ Returns whether the delta values delivered with the event are inverted.
+
+ \since 6.2
+*/
+bool QGraphicsSceneWheelEvent::isInverted() const
+{
+ Q_D(const QGraphicsSceneWheelEvent);
+ return d->inverted;
+}
+
+/*!
+ \internal
+*/
+void QGraphicsSceneWheelEvent::setInverted(bool inverted)
+{
+ Q_D(QGraphicsSceneWheelEvent);
+ d->inverted = inverted;
+}
+
class QGraphicsSceneContextMenuEventPrivate : public QGraphicsSceneEventPrivate
{
Q_DECLARE_PUBLIC(QGraphicsSceneContextMenuEvent)
@@ -1290,7 +1345,7 @@ class QGraphicsSceneDragDropEventPrivate : public QGraphicsSceneEventPrivate
Q_DECLARE_PUBLIC(QGraphicsSceneDragDropEvent)
public:
inline QGraphicsSceneDragDropEventPrivate()
- : source(0), mimeData(0)
+ : source(nullptr), mimeData(nullptr)
{ }
QPointF pos;
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h
index 9d940be2c0..ca9dd639a3 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.h
+++ b/src/widgets/graphicsview/qgraphicssceneevent.h
@@ -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
#ifndef QGRAPHICSSCENEEVENT_H
#define QGRAPHICSSCENEEVENT_H
@@ -47,9 +11,6 @@
#include <QtCore/qrect.h>
#include <QtGui/qpolygon.h>
#include <QtCore/qset.h>
-#if QT_DEPRECATED_SINCE(5, 5)
-#include <QtCore/qhash.h>
-#endif
QT_REQUIRE_CONFIG(graphicsview);
@@ -70,6 +31,9 @@ public:
QWidget *widget() const;
void setWidget(QWidget *widget);
+ quint64 timestamp() const;
+ void setTimestamp(quint64 ts);
+
protected:
QGraphicsSceneEvent(QGraphicsSceneEventPrivate &dd, Type type = None);
QScopedPointer<QGraphicsSceneEventPrivate> d_ptr;
@@ -160,6 +124,15 @@ public:
Qt::Orientation orientation() const;
void setOrientation(Qt::Orientation orientation);
+ Qt::ScrollPhase phase() const;
+ void setPhase(Qt::ScrollPhase scrollPhase);
+
+ QPoint pixelDelta() const;
+ void setPixelDelta(QPoint delta);
+
+ bool isInverted() const;
+ void setInverted(bool inverted);
+
private:
Q_DECLARE_PRIVATE(QGraphicsSceneWheelEvent)
Q_DISABLE_COPY(QGraphicsSceneWheelEvent)
diff --git a/src/widgets/graphicsview/qgraphicssceneindex.cpp b/src/widgets/graphicsview/qgraphicssceneindex.cpp
index c2e9cb4729..7c54bfe179 100644
--- a/src/widgets/graphicsview/qgraphicssceneindex.cpp
+++ b/src/widgets/graphicsview/qgraphicssceneindex.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 QGraphicsSceneIndex
\brief The QGraphicsSceneIndex class provides a base class to implement
@@ -60,6 +24,7 @@
#include "qgraphicswidget.h"
#include "qgraphicssceneindex_p.h"
#include "qgraphicsscenebsptreeindex_p.h"
+#include <QtGui/qpainterpath.h>
QT_BEGIN_NAMESPACE
@@ -580,7 +545,7 @@ void QGraphicsSceneIndex::clear()
/*!
This method is called when an \a item has been deleted.
- The default implementation call removeItem. Be carefull,
+ The default implementation calls removeItem. Be careful,
if your implementation of removeItem use pure virtual method
of QGraphicsItem like boundingRect(), then you should reimplement
this method.
diff --git a/src/widgets/graphicsview/qgraphicssceneindex_p.h b/src/widgets/graphicsview/qgraphicssceneindex_p.h
index e13c2a3cd3..8bd2ef4854 100644
--- a/src/widgets/graphicsview/qgraphicssceneindex_p.h
+++ b/src/widgets/graphicsview/qgraphicssceneindex_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore 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
#ifndef QGRAPHICSSCENEINDEX_H
#define QGRAPHICSSCENEINDEX_H
diff --git a/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp b/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp
index 06f9125612..c014783438 100644
--- a/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp
+++ b/src/widgets/graphicsview/qgraphicsscenelinearindex.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 QGraphicsSceneLinearIndex
@@ -54,7 +18,7 @@
#include <private/qgraphicsscenelinearindex_p.h>
/*!
- \fn QGraphicsSceneLinearIndex::QGraphicsSceneLinearIndex(QGraphicsScene *scene = 0):
+ \fn QGraphicsSceneLinearIndex::QGraphicsSceneLinearIndex(QGraphicsScene *scene = nullptr):
Construct a linear index for the given \a scene.
*/
diff --git a/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h b/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h
index ead52c1fb0..e0a038a927 100644
--- a/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h
+++ b/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore 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
#ifndef QGRAPHICSSCENELINEARINDEX_H
#define QGRAPHICSSCENELINEARINDEX_H
diff --git a/src/widgets/graphicsview/qgraphicstransform.cpp b/src/widgets/graphicsview/qgraphicstransform.cpp
index 0f0d9aaddc..172bdff081 100644
--- a/src/widgets/graphicsview/qgraphicstransform.cpp
+++ b/src/widgets/graphicsview/qgraphicstransform.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDeclarative 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 QGraphicsTransform
@@ -112,7 +76,7 @@ void QGraphicsTransformPrivate::setItem(QGraphicsItem *i)
Q_ASSERT(d_ptr->transformData);
d_ptr->transformData->graphicsTransforms.removeAll(q);
d_ptr->dirtySceneTransform = 1;
- item = 0;
+ item = nullptr;
}
item = i;
@@ -138,7 +102,7 @@ QGraphicsTransform::QGraphicsTransform(QObject *parent)
QGraphicsTransform::~QGraphicsTransform()
{
Q_D(QGraphicsTransform);
- d->setItem(0);
+ d->setItem(nullptr);
}
/*!
@@ -593,6 +557,6 @@ void QGraphicsRotation::applyTo(QMatrix4x4 *matrix) const
\sa QGraphicsRotation::axis
*/
-#include "moc_qgraphicstransform.cpp"
-
QT_END_NAMESPACE
+
+#include "moc_qgraphicstransform.cpp"
diff --git a/src/widgets/graphicsview/qgraphicstransform.h b/src/widgets/graphicsview/qgraphicstransform.h
index b8455781c5..903320cb62 100644
--- a/src/widgets/graphicsview/qgraphicstransform.h
+++ b/src/widgets/graphicsview/qgraphicstransform.h
@@ -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
#ifndef QGRAPHICSTRANSFORM_H
#define QGRAPHICSTRANSFORM_H
diff --git a/src/widgets/graphicsview/qgraphicstransform_p.h b/src/widgets/graphicsview/qgraphicstransform_p.h
index 05e12c3e64..4c08c1c106 100644
--- a/src/widgets/graphicsview/qgraphicstransform_p.h
+++ b/src/widgets/graphicsview/qgraphicstransform_p.h
@@ -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
#ifndef QGRAPHICSTRANSFORM_P_H
#define QGRAPHICSTRANSFORM_P_H
@@ -60,8 +24,7 @@ QT_BEGIN_NAMESPACE
class QGraphicsItem;
-// ### Qt 6: unexport again, if QtQuick1's QDeclarativeTranslatePrivate is gone by then
-class Q_WIDGETS_EXPORT QGraphicsTransformPrivate : public QObjectPrivate {
+class QGraphicsTransformPrivate : public QObjectPrivate {
public:
Q_DECLARE_PUBLIC(QGraphicsTransform)
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 4c270b1af2..9505e2529a 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.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) 2021 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
static const int QGRAPHICSVIEW_REGION_RECT_THRESHOLD = 50;
@@ -89,15 +53,15 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
By default, QGraphicsView provides a regular QWidget for the viewport
widget. You can access this widget by calling viewport(), or you can
replace it by calling setViewport(). To render using OpenGL, simply call
- setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport
- widget.
+ setViewport(new QOpenGLWidget). QGraphicsView takes ownership of the
+ viewport widget.
QGraphicsView supports affine transformations, using QTransform. You can
either pass a matrix to setTransform(), or you can call one of the
convenience functions rotate(), scale(), translate() or shear(). The most
two common transformations are scaling, which is used to implement
zooming, and rotation. QGraphicsView keeps the center of the view fixed
- during a transformation. Because of the scene alignment (setAligment()),
+ during a transformation. Because of the scene alignment (setAlignment()),
translating the view will have no visual impact.
You can interact with the items on the scene by using the mouse and
@@ -107,7 +71,7 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
the events and reacts to them. For example, if you click on a selectable
item, the item will typically let the scene know that it has been
selected, and it will also redraw itself to display a selection
- rectangle. Similiary, if you click and drag the mouse to move a movable
+ rectangle. Similarly, if you click and drag the mouse to move a movable
item, it's the item that handles the mouse moves and moves itself. Item
interaction is enabled by default, and you can toggle it by calling
setInteractive().
@@ -121,8 +85,22 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
view coordinates and scene coordinates, and to find items on the scene
using view coordinates.
+ When using a QOpenGLWidget as a viewport, stereoscopic rendering is
+ supported. This is done using the same pattern as QOpenGLWidget::paintGL.
+ To enable it, enable the QSurfaceFormat::StereoBuffers flag. Because of
+ how the flag is handled internally, set QSurfaceFormat::StereoBuffers flag
+ globally before the window is created using QSurfaceFormat::setDefaultFormat().
+ If the flag is enabled and there is hardware support for stereoscopic
+ rendering, then drawBackground() and drawForeground() will be triggered twice
+ each frame. Call QOpenGLWidget::currentTargetBuffer() to query which buffer
+ is currently being drawn to.
+
\image graphicsview-view.png
+ \note Using an OpenGL viewport limits the ability to use QGraphicsProxyWidget.
+ Not all combinations of widgets and styles can be supported with such a setup.
+ You should carefully test your UI and make the necessary adjustments.
+
\sa QGraphicsScene, QGraphicsItem, QGraphicsSceneEvent
*/
@@ -155,8 +133,8 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
fastest when QGraphicsView spends more time figuring out what to draw than
it would spend drawing (e.g., when very many small items are repeatedly
updated). This is the preferred update mode for viewports that do not
- support partial updates, such as QGLWidget, and for viewports that need to
- disable scroll optimization.
+ support partial updates, such as QOpenGLWidget, and for viewports that
+ need to disable scroll optimization.
\value MinimalViewportUpdate QGraphicsView will determine the minimal
viewport region that requires a redraw, minimizing the time spent drawing
@@ -194,8 +172,6 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
Note that setting a flag usually imposes a side effect, and this effect
can vary between paint devices and platforms.
- \value DontClipPainter This value is obsolete and has no effect.
-
\value DontSavePainterState When rendering, QGraphicsView protects the
painter state (see QPainter::save()) when rendering the background or
foreground, and when rendering each item. This allows you to leave the
@@ -283,17 +259,16 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
#include <QtCore/qmath.h>
#include <QtCore/qscopedvaluerollback.h>
#include <QtWidgets/qapplication.h>
-#include <QtWidgets/qdesktopwidget.h>
-#include <private/qdesktopwidget_p.h>
#include <QtGui/qevent.h>
#include <QtWidgets/qlayout.h>
#include <QtGui/qtransform.h>
-#include <QtGui/qmatrix.h>
#include <QtGui/qpainter.h>
+#include <QtGui/qpainterpath.h>
#include <QtWidgets/qscrollbar.h>
#include <QtWidgets/qstyleoption.h>
#include <private/qevent_p.h>
+#include <QtGui/private/qeventpoint_p.h>
QT_BEGIN_NAMESPACE
@@ -310,21 +285,13 @@ inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for sing
void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent)
{
- QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
- for (int i = 0; i < touchPoints.count(); ++i) {
- QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
- const QSizeF ellipseDiameters = touchPoint.ellipseDiameters();
+ for (int i = 0; i < touchEvent->pointCount(); ++i) {
+ auto &pt = touchEvent->point(i);
// the scene will set the item local pos, startPos, lastPos, and rect before delivering to
// an item, but for now those functions are returning the view's local coordinates
- touchPoint.setScenePos(d->mapToScene(touchPoint.pos()));
- touchPoint.setStartScenePos(d->mapToScene(touchPoint.startPos()));
- touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos()));
- touchPoint.setEllipseDiameters(ellipseDiameters);
-
+ QMutableEventPoint::setScenePosition(pt, d->mapToScene(pt.position()));
// screenPos, startScreenPos, and lastScreenPos are already set
}
-
- touchEvent->setTouchPoints(touchPoints);
}
/*!
@@ -348,11 +315,10 @@ QGraphicsViewPrivate::QGraphicsViewPrivate()
hasUpdateClip(false),
mousePressButton(Qt::NoButton),
leftIndent(0), topIndent(0),
- lastMouseEvent(QEvent::None, QPointF(), QPointF(), QPointF(), Qt::NoButton, { }, { }),
alignment(Qt::AlignCenter),
transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor),
viewportUpdateMode(QGraphicsView::MinimalViewportUpdate),
- scene(0),
+ scene(nullptr),
#if QT_CONFIG(rubberband)
rubberBanding(false),
rubberBandSelectionMode(Qt::IntersectsItemShape),
@@ -362,7 +328,7 @@ QGraphicsViewPrivate::QGraphicsViewPrivate()
#ifndef QT_NO_CURSOR
hasStoredOriginalCursor(false),
#endif
- lastDragDropEvent(0),
+ lastDragDropEvent(nullptr),
updateSceneSlotReimplementedChecked(false)
{
styleOptions.reserve(QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS);
@@ -379,12 +345,12 @@ void QGraphicsViewPrivate::recalculateContentSize()
{
Q_Q(QGraphicsView);
- QSize maxSize = q->maximumViewportSize();
+ const QSize maxSize = q->maximumViewportSize();
int width = maxSize.width();
int height = maxSize.height();
- QRectF viewRect = matrix.mapRect(q->sceneRect());
+ const QRectF viewRect = matrix.mapRect(q->sceneRect());
- bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, q));
+ bool frameOnlyAround = (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, nullptr, q));
if (frameOnlyAround) {
if (hbarpolicy == Qt::ScrollBarAlwaysOn)
height -= frameWidth * 2;
@@ -394,9 +360,8 @@ void QGraphicsViewPrivate::recalculateContentSize()
// Adjust the maximum width and height of the viewport based on the width
// of visible scroll bars.
- int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q);
- if (frameOnlyAround)
- scrollBarExtent += frameWidth * 2;
+ const int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, q)
+ + (frameOnlyAround ? frameWidth * 2 : 0);
// We do not need to subtract the width scrollbars whose policy is
// Qt::ScrollBarAlwaysOn, this was already done by maximumViewportSize().
@@ -418,62 +383,70 @@ void QGraphicsViewPrivate::recalculateContentSize()
// Setting the ranges of these scroll bars can/will cause the values to
// change, and scrollContentsBy() will be called correspondingly. This
// will reset the last center point.
- QPointF savedLastCenterPoint = lastCenterPoint;
+ const QPointF savedLastCenterPoint = lastCenterPoint;
// Remember the former indent settings
- qreal oldLeftIndent = leftIndent;
- qreal oldTopIndent = topIndent;
+ const qreal oldLeftIndent = leftIndent;
+ const qreal oldTopIndent = topIndent;
// If the whole scene fits horizontally, we center the scene horizontally,
// and ignore the horizontal scroll bars.
- int left = q_round_bound(viewRect.left());
- int right = q_round_bound(viewRect.right() - width);
+ const int left = q_round_bound(viewRect.left());
+ const int right = q_round_bound(viewRect.right() - width);
if (left >= right) {
- hbar->setRange(0, 0);
-
switch (alignment & Qt::AlignHorizontal_Mask) {
case Qt::AlignLeft:
leftIndent = -viewRect.left();
break;
case Qt::AlignRight:
- leftIndent = width - viewRect.width() - viewRect.left() - 1;
+ leftIndent = maxSize.width() - viewRect.width() - viewRect.left() - 1;
break;
case Qt::AlignHCenter:
default:
- leftIndent = width / 2 - (viewRect.left() + viewRect.right()) / 2;
+ leftIndent = maxSize.width() / 2 - (viewRect.left() + viewRect.right()) / 2;
break;
}
+
+ hbar->setRange(0, 0);
} else {
+ leftIndent = 0;
+
hbar->setRange(left, right);
hbar->setPageStep(width);
hbar->setSingleStep(width / 20);
- leftIndent = 0;
+
+ if (oldLeftIndent != 0)
+ hbar->setValue(-oldLeftIndent);
}
// If the whole scene fits vertically, we center the scene vertically, and
// ignore the vertical scroll bars.
- int top = q_round_bound(viewRect.top());
- int bottom = q_round_bound(viewRect.bottom() - height);
+ const int top = q_round_bound(viewRect.top());
+ const int bottom = q_round_bound(viewRect.bottom() - height);
if (top >= bottom) {
- vbar->setRange(0, 0);
-
switch (alignment & Qt::AlignVertical_Mask) {
case Qt::AlignTop:
topIndent = -viewRect.top();
break;
case Qt::AlignBottom:
- topIndent = height - viewRect.height() - viewRect.top() - 1;
+ topIndent = maxSize.height() - viewRect.height() - viewRect.top() - 1;
break;
case Qt::AlignVCenter:
default:
- topIndent = height / 2 - (viewRect.top() + viewRect.bottom()) / 2;
+ topIndent = maxSize.height() / 2 - (viewRect.top() + viewRect.bottom()) / 2;
break;
}
+
+ vbar->setRange(0, 0);
} else {
+ topIndent = 0;
+
vbar->setRange(top, bottom);
vbar->setPageStep(height);
vbar->setSingleStep(height / 20);
- topIndent = 0;
+
+ if (oldTopIndent != 0)
+ vbar->setValue(-oldTopIndent);
}
// Restorethe center point from before the ranges changed.
@@ -510,8 +483,8 @@ void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor)
if (q->underMouse()) {
// Last scene pos: lastMouseMoveScenePoint
// Current mouse pos:
- QPointF transformationDiff = q->mapToScene(viewport->rect().center())
- - q->mapToScene(viewport->mapFromGlobal(QCursor::pos()));
+ QPointF transformationDiff = mapToScene(viewport->rect().toRectF().center())
+ - mapToScene(viewport->mapFromGlobal(QCursor::pos().toPointF()));
q->centerOn(lastMouseMoveScenePoint + transformationDiff);
} else {
q->centerOn(lastCenterPoint);
@@ -531,8 +504,7 @@ void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor)
*/
void QGraphicsViewPrivate::updateLastCenterPoint()
{
- Q_Q(QGraphicsView);
- lastCenterPoint = q->mapToScene(viewport->rect().center());
+ lastCenterPoint = mapToScene(viewport->rect().toRectF().center());
}
/*!
@@ -611,12 +583,33 @@ void QGraphicsViewPrivate::updateScroll()
/*!
\internal
+
+ * don't start scrolling when a drag mode has been set
+ * don't start scrolling on a movable item
+*/
+bool QGraphicsViewPrivate::canStartScrollingAt(const QPoint &startPos) const
+{
+ Q_Q(const QGraphicsView);
+ if (q->dragMode() != QGraphicsView::NoDrag)
+ return false;
+
+ const QGraphicsItem *childItem = q->itemAt(startPos);
+
+ if (!startPos.isNull() && childItem && (childItem->flags() & QGraphicsItem::ItemIsMovable))
+ return false;
+
+ return QAbstractScrollAreaPrivate::canStartScrollingAt(startPos);
+}
+
+/*!
+ \internal
*/
void QGraphicsViewPrivate::replayLastMouseEvent()
{
if (!useLastMouseEvent || !scene)
return;
- mouseMoveEventHandler(&lastMouseEvent);
+ QSinglePointEvent *spe = static_cast<QSinglePointEvent *>(&lastMouseEvent);
+ mouseMoveEventHandler(static_cast<QMouseEvent *>(spe));
}
/*!
@@ -625,8 +618,7 @@ void QGraphicsViewPrivate::replayLastMouseEvent()
void QGraphicsViewPrivate::storeMouseEvent(QMouseEvent *event)
{
useLastMouseEvent = true;
- lastMouseEvent = QMouseEvent(QEvent::MouseMove, event->localPos(), event->windowPos(), event->screenPos(),
- event->button(), event->buttons(), event->modifiers());
+ lastMouseEvent = *event;
}
void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
@@ -651,8 +643,8 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
mouseEvent.setWidget(viewport);
mouseEvent.setButtonDownScenePos(mousePressButton, mousePressScenePoint);
mouseEvent.setButtonDownScreenPos(mousePressButton, mousePressScreenPoint);
- mouseEvent.setScenePos(q->mapToScene(event->pos()));
- mouseEvent.setScreenPos(event->globalPos());
+ mouseEvent.setScenePos(q->mapToScene(event->position().toPoint()));
+ mouseEvent.setScreenPos(event->globalPosition().toPoint());
mouseEvent.setLastScenePos(lastMouseMoveScenePoint);
mouseEvent.setLastScreenPos(lastMouseMoveScreenPoint);
mouseEvent.setButtons(event->buttons());
@@ -660,6 +652,7 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
mouseEvent.setModifiers(event->modifiers());
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
+ mouseEvent.setTimestamp(event->timestamp());
lastMouseMoveScenePoint = mouseEvent.scenePos();
lastMouseMoveScreenPoint = mouseEvent.screenPos();
mouseEvent.setAccepted(false);
@@ -689,7 +682,7 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
mouseEvent.widget());
}
// Find the topmost item under the mouse with a cursor.
- foreach (QGraphicsItem *item, scene->d_func()->cachedItemsUnderMouse) {
+ for (QGraphicsItem *item : std::as_const(scene->d_func()->cachedItemsUnderMouse)) {
if (item->isEnabled() && item->hasCursor()) {
_q_setViewportCursor(item->cursor());
return;
@@ -719,7 +712,7 @@ QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRec
option.shape = QRubberBand::Rectangle;
QRegion tmp;
- tmp += rect;
+ tmp += rect.adjusted(-1, -1, 1, 1);
if (widget->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, widget, &mask))
tmp &= mask.region;
return tmp;
@@ -731,7 +724,7 @@ void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)
if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding)
return;
// Check for enough drag distance
- if ((mousePressViewPoint - event->pos()).manhattanLength() < QApplication::startDragDistance())
+ if ((mousePressViewPoint - event->position().toPoint()).manhattanLength() < QApplication::startDragDistance())
return;
// Update old rubberband
@@ -758,7 +751,7 @@ void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)
// Update rubberband position
const QPoint mp = q->mapFromScene(mousePressScenePoint);
- const QPoint ep = event->pos();
+ const QPoint ep = event->position().toPoint();
rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()),
qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1);
@@ -782,6 +775,27 @@ void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event)
if (scene)
scene->setSelectionArea(selectionArea, rubberBandSelectionOperation, rubberBandSelectionMode, q->viewportTransform());
}
+
+void QGraphicsViewPrivate::clearRubberBand()
+{
+ Q_Q(QGraphicsView);
+ if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding)
+ return;
+
+ if (viewportUpdateMode != QGraphicsView::NoViewportUpdate) {
+ if (viewportUpdateMode != QGraphicsView::FullViewportUpdate)
+ q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect));
+ else
+ updateAll();
+ }
+
+ rubberBanding = false;
+ rubberBandSelectionOperation = Qt::ReplaceSelection;
+ if (!rubberBandRect.isNull()) {
+ rubberBandRect = QRect();
+ emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF());
+ }
+}
#endif
/*!
@@ -805,7 +819,7 @@ void QGraphicsViewPrivate::_q_setViewportCursor(const QCursor &cursor)
void QGraphicsViewPrivate::_q_unsetViewportCursor()
{
Q_Q(QGraphicsView);
- const auto items = q->items(lastMouseEvent.pos());
+ const auto items = q->items(lastMouseEvent.position().toPoint());
for (QGraphicsItem *item : items) {
if (item->isEnabled() && item->hasCursor()) {
_q_setViewportCursor(item->cursor());
@@ -841,6 +855,7 @@ void QGraphicsViewPrivate::storeDragDropEvent(const QGraphicsSceneDragDropEvent
lastDragDropEvent->setMimeData(event->mimeData());
lastDragDropEvent->setWidget(event->widget());
lastDragDropEvent->setSource(event->source());
+ lastDragDropEvent->setTimestamp(event->timestamp());
}
/*!
@@ -851,10 +866,10 @@ void QGraphicsViewPrivate::populateSceneDragDropEvent(QGraphicsSceneDragDropEven
{
#if QT_CONFIG(draganddrop)
Q_Q(QGraphicsView);
- dest->setScenePos(q->mapToScene(source->pos()));
- dest->setScreenPos(q->mapToGlobal(source->pos()));
- dest->setButtons(source->mouseButtons());
- dest->setModifiers(source->keyboardModifiers());
+ dest->setScenePos(q->mapToScene(source->position().toPoint()));
+ dest->setScreenPos(q->mapToGlobal(source->position().toPoint()));
+ dest->setButtons(source->buttons());
+ dest->setModifiers(source->modifiers());
dest->setPossibleActions(source->possibleActions());
dest->setProposedAction(source->proposedAction());
dest->setDropAction(source->dropAction());
@@ -862,8 +877,8 @@ void QGraphicsViewPrivate::populateSceneDragDropEvent(QGraphicsSceneDragDropEven
dest->setWidget(viewport);
dest->setSource(qobject_cast<QWidget *>(source->source()));
#else
- Q_UNUSED(dest)
- Q_UNUSED(source)
+ Q_UNUSED(dest);
+ Q_UNUSED(source);
#endif
}
@@ -963,7 +978,7 @@ static inline void QRect_unite(QRect *rect, const QRect &other)
/*
Calling this function results in update rects being clipped to the item's
bounding rect. Note that updates prior to this function call is not clipped.
- The clip is removed by passing 0.
+ The clip is removed by passing \nullptr.
*/
void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item)
{
@@ -1162,7 +1177,7 @@ QList<QGraphicsItem *> QGraphicsViewPrivate::findItems(const QRegion &exposedReg
void QGraphicsViewPrivate::updateInputMethodSensitivity()
{
Q_Q(QGraphicsView);
- QGraphicsItem *focusItem = 0;
+ QGraphicsItem *focusItem = nullptr;
bool enabled = scene && (focusItem = scene->focusItem())
&& (focusItem->d_ptr->flags & QGraphicsItem::ItemAcceptsInputMethod);
q->setAttribute(Qt::WA_InputMethodEnabled, enabled);
@@ -1174,7 +1189,7 @@ void QGraphicsViewPrivate::updateInputMethodSensitivity()
}
QGraphicsProxyWidget *proxy = focusItem->d_ptr->isWidget && focusItem->d_ptr->isProxyWidget()
- ? static_cast<QGraphicsProxyWidget *>(focusItem) : 0;
+ ? static_cast<QGraphicsProxyWidget *>(focusItem) : nullptr;
if (!proxy) {
q->setInputMethodHints(focusItem->inputMethodHints());
} else if (QWidget *widget = proxy->widget()) {
@@ -1192,7 +1207,7 @@ void QGraphicsViewPrivate::updateInputMethodSensitivity()
QGraphicsView::QGraphicsView(QWidget *parent)
: QAbstractScrollArea(*new QGraphicsViewPrivate, parent)
{
- setViewport(0);
+ setViewport(nullptr);
setAcceptDrops(true);
setBackgroundRole(QPalette::Base);
// Investigate leaving these disabled by default.
@@ -1208,7 +1223,7 @@ QGraphicsView::QGraphicsView(QGraphicsScene *scene, QWidget *parent)
: QAbstractScrollArea(*new QGraphicsViewPrivate, parent)
{
setScene(scene);
- setViewport(0);
+ setViewport(nullptr);
setAcceptDrops(true);
setBackgroundRole(QPalette::Base);
// Investigate leaving these disabled by default.
@@ -1222,7 +1237,7 @@ QGraphicsView::QGraphicsView(QGraphicsScene *scene, QWidget *parent)
QGraphicsView::QGraphicsView(QGraphicsViewPrivate &dd, QWidget *parent)
: QAbstractScrollArea(dd, parent)
{
- setViewport(0);
+ setViewport(nullptr);
setAcceptDrops(true);
setBackgroundRole(QPalette::Base);
// Investigate leaving these disabled by default.
@@ -1250,7 +1265,7 @@ QSize QGraphicsView::sizeHint() const
if (d->scene) {
QSizeF baseSize = d->matrix.mapRect(sceneRect()).size();
baseSize += QSizeF(d->frameWidth * 2, d->frameWidth * 2);
- return baseSize.boundedTo((3 * QDesktopWidgetPrivate::size()) / 4).toSize();
+ return baseSize.boundedTo((3 * QGuiApplication::primaryScreen()->virtualSize()) / 4).toSize();
}
return QAbstractScrollArea::sizeHint();
}
@@ -1485,6 +1500,10 @@ void QGraphicsView::setDragMode(DragMode mode)
if (d->dragMode == mode)
return;
+#if QT_CONFIG(rubberband)
+ d->clearRubberBand();
+#endif
+
#ifndef QT_NO_CURSOR
if (d->dragMode == ScrollHandDrag)
viewport()->unsetCursor();
@@ -1539,7 +1558,7 @@ void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode)
is currently doing an itemselection with rubber band. When the user is not using the
rubber band this functions returns (a null) QRectF().
- Notice that part of this QRect can be outise the visual viewport. It can e.g
+ Notice that part of this QRect can be outside the visual viewport. It can e.g
contain negative values.
\sa rubberBandSelectionMode, rubberBandChanged()
@@ -1717,7 +1736,7 @@ void QGraphicsView::setScene(QGraphicsScene *scene)
QEvent windowDeactivate(QEvent::WindowDeactivate);
QCoreApplication::sendEvent(d->scene, &windowDeactivate);
}
- if(hasFocus())
+ if (hasFocus())
d->scene->clearFocus();
}
@@ -1796,59 +1815,6 @@ void QGraphicsView::setSceneRect(const QRectF &rect)
}
/*!
- Returns the current transformation matrix for the view. If no current
- transformation is set, the identity matrix is returned.
-
- \sa setMatrix(), transform(), rotate(), scale(), shear(), translate()
-*/
-QMatrix QGraphicsView::matrix() const
-{
- Q_D(const QGraphicsView);
- return d->matrix.toAffine();
-}
-
-/*!
- Sets the view's current transformation matrix to \a matrix.
-
- If \a combine is true, then \a matrix is combined with the current matrix;
- otherwise, \a matrix \e replaces the current matrix. \a combine is false
- by default.
-
- The transformation matrix tranforms the scene into view coordinates. Using
- the default transformation, provided by the identity matrix, one pixel in
- the view represents one unit in the scene (e.g., a 10x10 rectangular item
- is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is
- applied, the scene will be drawn in 1:2 (e.g., a 10x10 rectangular item is
- then drawn using 20x20 pixels in the view).
-
- Example:
-
- \snippet code/src_gui_graphicsview_qgraphicsview.cpp 3
-
- To simplify interation with items using a transformed view, QGraphicsView
- provides mapTo... and mapFrom... functions that can translate between
- scene and view coordinates. For example, you can call mapToScene() to map
- a view coordinate to a floating point scene coordinate, or mapFromScene()
- to map from floating point scene coordinates to view coordinates.
-
- \sa matrix(), setTransform(), rotate(), scale(), shear(), translate()
-*/
-void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine)
-{
- setTransform(QTransform(matrix), combine);
-}
-
-/*!
- Resets the view transformation matrix to the identity matrix.
-
- \sa resetTransform()
-*/
-void QGraphicsView::resetMatrix()
-{
- resetTransform();
-}
-
-/*!
Rotates the current view transformation \a angle degrees clockwise.
\sa setTransform(), transform(), scale(), shear(), translate()
@@ -1925,14 +1891,14 @@ void QGraphicsView::centerOn(const QPointF &pos)
qint64 horizontal = 0;
horizontal += horizontalScrollBar()->minimum();
horizontal += horizontalScrollBar()->maximum();
- horizontal -= int(viewPoint.x() - width / 2.0);
+ horizontal -= qRound(viewPoint.x() - width / 2.0);
horizontalScrollBar()->setValue(horizontal);
} else {
- horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0));
+ horizontalScrollBar()->setValue(qRound(viewPoint.x() - width / 2.0));
}
}
if (!d->topIndent)
- verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0));
+ verticalScrollBar()->setValue(qRound(viewPoint.y() - height / 2.0));
d->lastCenterPoint = oldCenterPoint;
}
@@ -2374,9 +2340,9 @@ QGraphicsItem *QGraphicsView::itemAt(const QPoint &pos) const
{
Q_D(const QGraphicsView);
if (!d->scene)
- return 0;
+ return nullptr;
const QList<QGraphicsItem *> itemsAtPos = items(pos);
- return itemsAtPos.isEmpty() ? 0 : itemsAtPos.first();
+ return itemsAtPos.isEmpty() ? nullptr : itemsAtPos.first();
}
/*!
@@ -2463,7 +2429,7 @@ QPolygonF QGraphicsView::mapToScene(const QRect &rect) const
QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const
{
QPolygonF poly;
- poly.reserve(polygon.count());
+ poly.reserve(polygon.size());
for (const QPoint &point : polygon)
poly << mapToScene(point);
return poly;
@@ -2559,7 +2525,7 @@ QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const
QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const
{
QPolygon poly;
- poly.reserve(polygon.count());
+ poly.reserve(polygon.size());
for (const QPointF &point : polygon)
poly << mapFromScene(point);
return poly;
@@ -2589,13 +2555,13 @@ QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const
return QVariant();
QVariant value = d->scene->inputMethodQuery(query);
- if (value.type() == QVariant::RectF)
+ if (value.userType() == QMetaType::QRectF)
value = d->mapRectFromScene(value.toRectF());
- else if (value.type() == QVariant::PointF)
+ else if (value.userType() == QMetaType::QPointF)
value = mapFromScene(value.toPointF());
- else if (value.type() == QVariant::Rect)
+ else if (value.userType() == QMetaType::QRect)
value = d->mapRectFromScene(value.toRect()).toRect();
- else if (value.type() == QVariant::Point)
+ else if (value.userType() == QMetaType::QPoint)
value = mapFromScene(value.toPoint());
return value;
}
@@ -2672,8 +2638,8 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects)
return;
// Extract and reset dirty scene rect info.
- QVector<QRect> dirtyViewportRects;
- dirtyViewportRects.reserve(d->dirtyRegion.rectCount() + rects.count());
+ QList<QRect> dirtyViewportRects;
+ dirtyViewportRects.reserve(d->dirtyRegion.rectCount() + rects.size());
for (const QRect &dirtyRect : d->dirtyRegion)
dirtyViewportRects += dirtyRect;
d->dirtyRegion = QRegion();
@@ -2702,7 +2668,7 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects)
dirtyViewportRects << xrect;
}
- for (const QRect &rect : qAsConst(dirtyViewportRects)) {
+ for (const QRect &rect : std::as_const(dirtyViewportRects)) {
// Add the exposed rect to the update region. In rect update
// mode, we only count the bounding rect of items.
if (!boundingRectUpdate) {
@@ -2761,12 +2727,15 @@ void QGraphicsView::setupViewport(QWidget *widget)
return;
}
- const bool isGLWidget = widget->inherits("QGLWidget") || widget->inherits("QOpenGLWidget");
+ const bool isGLWidget = widget->inherits("QOpenGLWidget");
d->accelerateScrolling = !(isGLWidget);
widget->setFocusPolicy(Qt::StrongFocus);
+ if (isGLWidget)
+ d->stereoEnabled = QWidgetPrivate::get(widget)->isStereoEnabled();
+
if (!isGLWidget) {
// autoFillBackground enables scroll acceleration.
widget->setAutoFillBackground(true);
@@ -2887,14 +2856,13 @@ bool QGraphicsView::viewportEvent(QEvent *event)
d->scene->d_func()->removePopup(d->scene->d_func()->popupWidgets.constFirst());
}
d->useLastMouseEvent = false;
- // a hack to pass a viewport pointer to the scene inside the leave event
- Q_ASSERT(event->d == 0);
- QScopedValueRollback<QEventPrivate *> rb(event->d);
- event->d = reinterpret_cast<QEventPrivate *>(viewport());
- QCoreApplication::sendEvent(d->scene, event);
+ QGraphicsSceneEvent leaveEvent(QEvent::GraphicsSceneLeave);
+ leaveEvent.setWidget(viewport());
+ QCoreApplication::sendEvent(d->scene, &leaveEvent);
+ event->setAccepted(leaveEvent.isAccepted());
break;
}
-#ifndef QT_NO_TOOLTIP
+#if QT_CONFIG(tooltip)
case QEvent::ToolTip: {
QHelpEvent *toolTip = static_cast<QHelpEvent *>(event);
QGraphicsSceneHelpEvent helpEvent(QEvent::GraphicsSceneHelp);
@@ -2937,7 +2905,7 @@ bool QGraphicsView::viewportEvent(QEvent *event)
if (d->scene && d->sceneInteractionAllowed) {
// Convert and deliver the touch event to the scene.
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- touchEvent->setTarget(viewport());
+ QMutableTouchEvent::from(touchEvent)->setTarget(viewport());
QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);
QCoreApplication::sendEvent(d->scene, touchEvent);
} else {
@@ -2991,6 +2959,7 @@ void QGraphicsView::contextMenuEvent(QContextMenuEvent *event)
contextEvent.setModifiers(event->modifiers());
contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason()));
contextEvent.setAccepted(event->isAccepted());
+ contextEvent.setTimestamp(event->timestamp());
QCoreApplication::sendEvent(d->scene, &contextEvent);
event->setAccepted(contextEvent.isAccepted());
}
@@ -3019,7 +2988,7 @@ void QGraphicsView::dropEvent(QDropEvent *event)
event->setDropAction(sceneEvent.dropAction());
delete d->lastDragDropEvent;
- d->lastDragDropEvent = 0;
+ d->lastDragDropEvent = nullptr;
}
/*!
@@ -3077,7 +3046,7 @@ void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event)
sceneEvent.setWidget(d->lastDragDropEvent->widget());
sceneEvent.setSource(d->lastDragDropEvent->source());
delete d->lastDragDropEvent;
- d->lastDragDropEvent = 0;
+ d->lastDragDropEvent = nullptr;
// Send it to the scene.
QCoreApplication::sendEvent(d->scene, &sceneEvent);
@@ -3185,9 +3154,9 @@ void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
return;
d->storeMouseEvent(event);
- d->mousePressViewPoint = event->pos();
+ d->mousePressViewPoint = event->position().toPoint();
d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
- d->mousePressScreenPoint = event->globalPos();
+ d->mousePressScreenPoint = event->globalPosition().toPoint();
d->lastMouseMoveScenePoint = d->mousePressScenePoint;
d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
d->mousePressButton = event->button();
@@ -3206,6 +3175,7 @@ void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
mouseEvent.setModifiers(event->modifiers());
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
+ mouseEvent.setTimestamp(event->timestamp());
if (event->spontaneous())
qt_sendSpontaneousEvent(d->scene, &mouseEvent);
else
@@ -3234,9 +3204,9 @@ void QGraphicsView::mousePressEvent(QMouseEvent *event)
if (d->sceneInteractionAllowed) {
// Store some of the event's button-down data.
- d->mousePressViewPoint = event->pos();
+ d->mousePressViewPoint = event->position().toPoint();
d->mousePressScenePoint = mapToScene(d->mousePressViewPoint);
- d->mousePressScreenPoint = event->globalPos();
+ d->mousePressScreenPoint = event->globalPosition().toPoint();
d->lastMouseMoveScenePoint = d->mousePressScenePoint;
d->lastMouseMoveScreenPoint = d->mousePressScreenPoint;
d->mousePressButton = event->button();
@@ -3257,6 +3227,7 @@ void QGraphicsView::mousePressEvent(QMouseEvent *event)
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
mouseEvent.setAccepted(false);
+ mouseEvent.setTimestamp(event->timestamp());
if (event->spontaneous())
qt_sendSpontaneousEvent(d->scene, &mouseEvent);
else
@@ -3316,7 +3287,7 @@ void QGraphicsView::mouseMoveEvent(QMouseEvent *event)
if (d->handScrolling) {
QScrollBar *hBar = horizontalScrollBar();
QScrollBar *vBar = verticalScrollBar();
- QPoint delta = event->pos() - d->lastMouseEvent.pos();
+ QPoint delta = event->position().toPoint() - d->lastMouseEvent.position().toPoint();
hBar->setValue(hBar->value() + (isRightToLeft() ? delta.x() : -delta.x()));
vBar->setValue(vBar->value() - delta.y());
@@ -3338,20 +3309,7 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event)
#if QT_CONFIG(rubberband)
if (d->dragMode == QGraphicsView::RubberBandDrag && d->sceneInteractionAllowed && !event->buttons()) {
- if (d->rubberBanding) {
- if (d->viewportUpdateMode != QGraphicsView::NoViewportUpdate){
- if (d->viewportUpdateMode != FullViewportUpdate)
- viewport()->update(d->rubberBandRegion(viewport(), d->rubberBandRect));
- else
- d->updateAll();
- }
- d->rubberBanding = false;
- d->rubberBandSelectionOperation = Qt::ReplaceSelection;
- if (!d->rubberBandRect.isNull()) {
- d->rubberBandRect = QRect();
- emit rubberBandChanged(d->rubberBandRect, QPointF(), QPointF());
- }
- }
+ d->clearRubberBand();
} else
#endif
if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
@@ -3383,8 +3341,8 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event)
mouseEvent.setWidget(viewport());
mouseEvent.setButtonDownScenePos(d->mousePressButton, d->mousePressScenePoint);
mouseEvent.setButtonDownScreenPos(d->mousePressButton, d->mousePressScreenPoint);
- mouseEvent.setScenePos(mapToScene(event->pos()));
- mouseEvent.setScreenPos(event->globalPos());
+ mouseEvent.setScenePos(mapToScene(event->position().toPoint()));
+ mouseEvent.setScreenPos(event->globalPosition().toPoint());
mouseEvent.setLastScenePos(d->lastMouseMoveScenePoint);
mouseEvent.setLastScreenPos(d->lastMouseMoveScreenPoint);
mouseEvent.setButtons(event->buttons());
@@ -3393,6 +3351,7 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event)
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
mouseEvent.setAccepted(false);
+ mouseEvent.setTimestamp(event->timestamp());
if (event->spontaneous())
qt_sendSpontaneousEvent(d->scene, &mouseEvent);
else
@@ -3431,8 +3390,12 @@ void QGraphicsView::wheelEvent(QWheelEvent *event)
wheelEvent.setModifiers(event->modifiers());
const bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
wheelEvent.setDelta(horizontal ? event->angleDelta().x() : event->angleDelta().y());
+ wheelEvent.setPixelDelta(event->pixelDelta());
+ wheelEvent.setPhase(event->phase());
+ wheelEvent.setInverted(event->isInverted());
wheelEvent.setOrientation(horizontal ? Qt::Horizontal : Qt::Vertical);
wheelEvent.setAccepted(false);
+ wheelEvent.setTimestamp(event->timestamp());
QCoreApplication::sendEvent(d->scene, &wheelEvent);
event->setAccepted(wheelEvent.isAccepted());
if (!event->isAccepted())
@@ -3474,132 +3437,146 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
painter.setWorldTransform(viewportTransform());
const QTransform viewTransform = painter.worldTransform();
- // Draw background
- if (d->cacheMode & CacheBackground) {
- // Recreate the background pixmap, and flag the whole background as
- // exposed.
- if (d->mustResizeBackgroundPixmap) {
- const qreal dpr = d->viewport->devicePixelRatioF();
- d->backgroundPixmap = QPixmap(viewport()->size() * dpr);
- d->backgroundPixmap.setDevicePixelRatio(dpr);
- QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
- if (!bgBrush.isOpaque())
- d->backgroundPixmap.fill(Qt::transparent);
- QPainter p(&d->backgroundPixmap);
- p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush);
- d->backgroundPixmapExposed = QRegion(viewport()->rect());
- d->mustResizeBackgroundPixmap = false;
- }
+ const auto actuallyDraw = [&]() {
+ // Draw background
+ if (d->cacheMode & CacheBackground) {
+ // Recreate the background pixmap, and flag the whole background as
+ // exposed.
+ if (d->mustResizeBackgroundPixmap) {
+ const qreal dpr = d->viewport->devicePixelRatio();
+ d->backgroundPixmap = QPixmap(viewport()->size() * dpr);
+ d->backgroundPixmap.setDevicePixelRatio(dpr);
+ QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
+ if (!bgBrush.isOpaque())
+ d->backgroundPixmap.fill(Qt::transparent);
+ QPainter p(&d->backgroundPixmap);
+ p.fillRect(0, 0, d->backgroundPixmap.width(), d->backgroundPixmap.height(), bgBrush);
+ d->backgroundPixmapExposed = QRegion(viewport()->rect());
+ d->mustResizeBackgroundPixmap = false;
+ }
- // Redraw exposed areas
- if (!d->backgroundPixmapExposed.isEmpty()) {
- QPainter backgroundPainter(&d->backgroundPixmap);
- backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
- if (viewTransformed)
- backgroundPainter.setTransform(viewTransform);
- QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
- drawBackground(&backgroundPainter, backgroundExposedSceneRect);
- d->backgroundPixmapExposed = QRegion();
- }
+ // Redraw exposed areas
+ if (!d->backgroundPixmapExposed.isEmpty()) {
+ QPainter backgroundPainter(&d->backgroundPixmap);
+ backgroundPainter.setClipRegion(d->backgroundPixmapExposed, Qt::ReplaceClip);
+ if (viewTransformed)
+ backgroundPainter.setTransform(viewTransform);
+ QRectF backgroundExposedSceneRect = mapToScene(d->backgroundPixmapExposed.boundingRect()).boundingRect();
+ drawBackground(&backgroundPainter, backgroundExposedSceneRect);
+ d->backgroundPixmapExposed = QRegion();
+ }
- // Blit the background from the background pixmap
- if (viewTransformed) {
- painter.setWorldTransform(QTransform());
- painter.drawPixmap(QPoint(), d->backgroundPixmap);
- painter.setWorldTransform(viewTransform);
+ // Blit the background from the background pixmap
+ if (viewTransformed) {
+ painter.setWorldTransform(QTransform());
+ painter.drawPixmap(QPoint(), d->backgroundPixmap);
+ painter.setWorldTransform(viewTransform);
+ } else {
+ painter.drawPixmap(QPoint(), d->backgroundPixmap);
+ }
} else {
- painter.drawPixmap(QPoint(), d->backgroundPixmap);
+ if (!(d->optimizationFlags & DontSavePainterState))
+ painter.save();
+
+ drawBackground(&painter, exposedSceneRect);
+ if (!(d->optimizationFlags & DontSavePainterState))
+ painter.restore();
}
- } else {
- if (!(d->optimizationFlags & DontSavePainterState))
- painter.save();
- drawBackground(&painter, exposedSceneRect);
- if (!(d->optimizationFlags & DontSavePainterState))
- painter.restore();
- }
- // Items
- if (!(d->optimizationFlags & IndirectPainting)) {
- const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust;
- if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
- d->scene->d_func()->rectAdjust = 1;
- else
- d->scene->d_func()->rectAdjust = 2;
- d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : 0,
- &d->exposedRegion, viewport());
- d->scene->d_func()->rectAdjust = oldRectAdjust;
- // Make sure the painter's world transform is restored correctly when
- // drawing without painter state protection (DontSavePainterState).
- // We only change the worldTransform() so there's no need to do a full-blown
- // save() and restore(). Also note that we don't have to do this in case of
- // IndirectPainting (the else branch), because in that case we always save()
- // and restore() in QGraphicsScene::drawItems().
- if (!d->scene->d_func()->painterStateProtection)
- painter.setOpacity(1.0);
- painter.setWorldTransform(viewTransform);
- } else {
- // Make sure we don't have unpolished items before we draw
- if (!d->scene->d_func()->unpolishedItems.isEmpty())
- d->scene->d_func()->_q_polishItems();
- // We reset updateAll here (after we've issued polish events)
- // so that we can discard update requests coming from polishEvent().
- d->scene->d_func()->updateAll = false;
-
- // Find all exposed items
- bool allItems = false;
- QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
- if (!itemList.isEmpty()) {
- // Generate the style options.
- const int numItems = itemList.size();
- QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
- QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
- QTransform transform(Qt::Uninitialized);
- for (int i = 0; i < numItems; ++i) {
- QGraphicsItem *item = itemArray[i];
- QGraphicsItemPrivate *itemd = item->d_ptr.data();
- itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);
- // Cache the item's area in view coordinates.
- // Note that we have to do this here in case the base class implementation
- // (QGraphicsScene::drawItems) is not called. If it is, we'll do this
- // operation twice, but that's the price one has to pay for using indirect
- // painting :-/.
- const QRectF brect = adjustedItemEffectiveBoundingRect(item);
- if (!itemd->itemIsUntransformable()) {
- transform = item->sceneTransform();
- if (viewTransformed)
- transform *= viewTransform;
- } else {
- transform = item->deviceTransform(viewTransform);
+ // Items
+ if (!(d->optimizationFlags & IndirectPainting)) {
+ const quint32 oldRectAdjust = d->scene->d_func()->rectAdjust;
+ if (d->optimizationFlags & QGraphicsView::DontAdjustForAntialiasing)
+ d->scene->d_func()->rectAdjust = 1;
+ else
+ d->scene->d_func()->rectAdjust = 2;
+ d->scene->d_func()->drawItems(&painter, viewTransformed ? &viewTransform : nullptr,
+ &d->exposedRegion, viewport());
+ d->scene->d_func()->rectAdjust = oldRectAdjust;
+ // Make sure the painter's world transform is restored correctly when
+ // drawing without painter state protection (DontSavePainterState).
+ // We only change the worldTransform() so there's no need to do a full-blown
+ // save() and restore(). Also note that we don't have to do this in case of
+ // IndirectPainting (the else branch), because in that case we always save()
+ // and restore() in QGraphicsScene::drawItems().
+ if (!d->scene->d_func()->painterStateProtection)
+ painter.setOpacity(1.0);
+ painter.setWorldTransform(viewTransform);
+ } else {
+ // Make sure we don't have unpolished items before we draw
+ if (!d->scene->d_func()->unpolishedItems.isEmpty())
+ d->scene->d_func()->_q_polishItems();
+ // We reset updateAll here (after we've issued polish events)
+ // so that we can discard update requests coming from polishEvent().
+ d->scene->d_func()->updateAll = false;
+
+ // Find all exposed items
+ bool allItems = false;
+ QList<QGraphicsItem *> itemList = d->findItems(d->exposedRegion, &allItems, viewTransform);
+ if (!itemList.isEmpty()) {
+ // Generate the style options.
+ const int numItems = itemList.size();
+ QGraphicsItem **itemArray = &itemList[0]; // Relies on QList internals, but is perfectly valid.
+ QStyleOptionGraphicsItem *styleOptionArray = d->allocStyleOptionsArray(numItems);
+ QTransform transform(Qt::Uninitialized);
+ for (int i = 0; i < numItems; ++i) {
+ QGraphicsItem *item = itemArray[i];
+ QGraphicsItemPrivate *itemd = item->d_ptr.data();
+ itemd->initStyleOption(&styleOptionArray[i], viewTransform, d->exposedRegion, allItems);
+ // Cache the item's area in view coordinates.
+ // Note that we have to do this here in case the base class implementation
+ // (QGraphicsScene::drawItems) is not called. If it is, we'll do this
+ // operation twice, but that's the price one has to pay for using indirect
+ // painting :-/.
+ const QRectF brect = adjustedItemEffectiveBoundingRect(item);
+ if (!itemd->itemIsUntransformable()) {
+ transform = item->sceneTransform();
+ if (viewTransformed)
+ transform *= viewTransform;
+ } else {
+ transform = item->deviceTransform(viewTransform);
+ }
+ itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());
}
- itemd->paintedViewBoundingRects.insert(d->viewport, transform.mapRect(brect).toRect());
+ // Draw the items.
+ drawItems(&painter, numItems, itemArray, styleOptionArray);
+ d->freeStyleOptionsArray(styleOptionArray);
}
- // Draw the items.
- drawItems(&painter, numItems, itemArray, styleOptionArray);
- d->freeStyleOptionsArray(styleOptionArray);
}
- }
- // Foreground
- drawForeground(&painter, exposedSceneRect);
+ // Foreground
+ drawForeground(&painter, exposedSceneRect);
-#if QT_CONFIG(rubberband)
- // Rubberband
- if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {
- painter.restore();
- QStyleOptionRubberBand option;
- option.initFrom(viewport());
- option.rect = d->rubberBandRect;
- option.shape = QRubberBand::Rectangle;
-
- QStyleHintReturnMask mask;
- if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {
- // painter clipping for masked rubberbands
- painter.setClipRegion(mask.region, Qt::IntersectClip);
+ #if QT_CONFIG(rubberband)
+ // Rubberband
+ if (d->rubberBanding && !d->rubberBandRect.isEmpty()) {
+ painter.restore();
+ QStyleOptionRubberBand option;
+ option.initFrom(viewport());
+ option.rect = d->rubberBandRect;
+ option.shape = QRubberBand::Rectangle;
+
+ QStyleHintReturnMask mask;
+ if (viewport()->style()->styleHint(QStyle::SH_RubberBand_Mask, &option, viewport(), &mask)) {
+ // painter clipping for masked rubberbands
+ painter.setClipRegion(mask.region, Qt::IntersectClip);
+ }
+
+ viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport());
}
+ #endif
+ };
- viewport()->style()->drawControl(QStyle::CE_RubberBand, &option, &painter, viewport());
+ actuallyDraw();
+
+ // For stereo we want to draw everything twice, once to each buffer
+ if (d->stereoEnabled) {
+ QWidgetPrivate* w = QWidgetPrivate::get(viewport());
+ if (w->toggleStereoTargetBuffer()) {
+ actuallyDraw();
+ w->toggleStereoTargetBuffer();
+ }
}
-#endif
painter.end();
@@ -3740,7 +3717,12 @@ void QGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
return;
}
+ const bool wasAa = painter->testRenderHint(QPainter::Antialiasing);
+ if (wasAa)
+ painter->setRenderHints(QPainter::Antialiasing, false);
painter->fillRect(rect, d->backgroundBrush);
+ if (wasAa)
+ painter->setRenderHints(QPainter::Antialiasing, true);
}
/*!
@@ -3772,7 +3754,7 @@ void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect)
}
/*!
- \obsolete
+ \deprecated
Draws the items \a items in the scene using \a painter, after the
background and before the foreground are drawn. \a numItems is the number
@@ -3794,7 +3776,7 @@ void QGraphicsView::drawItems(QPainter *painter, int numItems,
{
Q_D(QGraphicsView);
if (d->scene) {
- QWidget *widget = painter->device() == viewport() ? viewport() : 0;
+ QWidget *widget = painter->device() == viewport() ? viewport() : nullptr;
d->scene->drawItems(painter, numItems, items, options, widget);
}
}
@@ -3844,7 +3826,7 @@ bool QGraphicsView::isTransformed() const
otherwise, \a matrix \e replaces the current matrix. \a combine is false
by default.
- The transformation matrix tranforms the scene into view coordinates. Using
+ The transformation matrix transforms the scene into view coordinates. Using
the default transformation, provided by the identity matrix, one pixel in
the view represents one unit in the scene (e.g., a 10x10 rectangular item
is drawn using 10x10 pixels in the view). If a 2x2 scaling matrix is
@@ -3855,13 +3837,13 @@ bool QGraphicsView::isTransformed() const
\snippet code/src_gui_graphicsview_qgraphicsview.cpp 7
- To simplify interation with items using a transformed view, QGraphicsView
+ To simplify interaction with items using a transformed view, QGraphicsView
provides mapTo... and mapFrom... functions that can translate between
scene and view coordinates. For example, you can call mapToScene() to map
- a view coordiate to a floating point scene coordinate, or mapFromScene()
+ a view coordinate to a floating point scene coordinate, or mapFromScene()
to map from floating point scene coordinates to view coordinates.
- \sa transform(), rotate(), scale(), shear(), translate()
+ \sa transform(), resetTransform(), rotate(), scale(), shear(), translate()
*/
void QGraphicsView::setTransform(const QTransform &matrix, bool combine )
{
diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h
index 1389796c3f..554c5a4b4e 100644
--- a/src/widgets/graphicsview/qgraphicsview.h
+++ b/src/widgets/graphicsview/qgraphicsview.h
@@ -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
#ifndef QGRAPHICSVIEW_H
#define QGRAPHICSVIEW_H
@@ -68,13 +32,17 @@ class Q_WIDGETS_EXPORT QGraphicsView : public QAbstractScrollArea
Q_PROPERTY(QPainter::RenderHints renderHints READ renderHints WRITE setRenderHints)
Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode)
Q_PROPERTY(CacheMode cacheMode READ cacheMode WRITE setCacheMode)
- Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor WRITE setTransformationAnchor)
+ Q_PROPERTY(ViewportAnchor transformationAnchor READ transformationAnchor
+ WRITE setTransformationAnchor)
Q_PROPERTY(ViewportAnchor resizeAnchor READ resizeAnchor WRITE setResizeAnchor)
- Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode WRITE setViewportUpdateMode)
+ Q_PROPERTY(ViewportUpdateMode viewportUpdateMode READ viewportUpdateMode
+ WRITE setViewportUpdateMode)
#if QT_CONFIG(rubberband)
- Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode WRITE setRubberBandSelectionMode)
+ Q_PROPERTY(Qt::ItemSelectionMode rubberBandSelectionMode READ rubberBandSelectionMode
+ WRITE setRubberBandSelectionMode)
#endif
- Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags WRITE setOptimizationFlags)
+ Q_PROPERTY(OptimizationFlags optimizationFlags READ optimizationFlags
+ WRITE setOptimizationFlags)
public:
enum ViewportAnchor {
@@ -107,12 +75,9 @@ public:
Q_ENUM(ViewportUpdateMode)
enum OptimizationFlag {
-#if QT_DEPRECATED_SINCE(5, 14)
- DontClipPainter Q_DECL_ENUMERATOR_DEPRECATED_X("This flag is unused") = 0x1, // obsolete
-#endif
- DontSavePainterState = 0x2,
- DontAdjustForAntialiasing = 0x4,
- IndirectPainting = 0x8
+ DontSavePainterState = 0x1,
+ DontAdjustForAntialiasing = 0x2,
+ IndirectPainting = 0x4
};
Q_DECLARE_FLAGS(OptimizationFlags, OptimizationFlag)
@@ -165,9 +130,6 @@ public:
void setSceneRect(const QRectF &rect);
inline void setSceneRect(qreal x, qreal y, qreal w, qreal h);
- QMatrix matrix() const;
- void setMatrix(const QMatrix &matrix, bool combine = false);
- void resetMatrix();
QTransform transform() const;
QTransform viewportTransform() const;
bool isTransformed() const;
diff --git a/src/widgets/graphicsview/qgraphicsview_p.h b/src/widgets/graphicsview/qgraphicsview_p.h
index 01af61d6ba..7f1682beca 100644
--- a/src/widgets/graphicsview/qgraphicsview_p.h
+++ b/src/widgets/graphicsview/qgraphicsview_p.h
@@ -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
#ifndef QGRAPHICSVIEW_P_H
#define QGRAPHICSVIEW_P_H
@@ -54,13 +18,15 @@
#include <QtWidgets/private/qtwidgetsglobal_p.h>
#include "qgraphicsview.h"
-#include <QtGui/qevent.h>
+#include <QtGui/private/qevent_p.h>
#include <QtCore/qcoreapplication.h>
#include "qgraphicssceneevent.h"
#include <QtWidgets/qstyleoption.h>
#include <private/qabstractscrollarea_p.h>
#include <private/qapplication_p.h>
+#include <QtCore/qpointer.h>
+
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
@@ -117,12 +83,13 @@ public:
QTransform matrix;
qint64 scrollX, scrollY;
void updateScroll();
+ bool canStartScrollingAt(const QPoint &startPos) const override;
qreal leftIndent;
qreal topIndent;
// Replaying mouse events
- QMouseEvent lastMouseEvent;
+ QMutableSinglePointEvent lastMouseEvent;
void replayLastMouseEvent();
void storeMouseEvent(QMouseEvent *event);
void mouseMoveEventHandler(QMouseEvent *event);
@@ -135,11 +102,14 @@ public:
QGraphicsView::ViewportUpdateMode viewportUpdateMode;
QGraphicsView::OptimizationFlags optimizationFlags;
+ bool stereoEnabled = false; // Set in setupViewport()
+
QPointer<QGraphicsScene> scene;
#if QT_CONFIG(rubberband)
QRect rubberBandRect;
QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const;
void updateRubberBand(const QMouseEvent *event);
+ void clearRubberBand();
bool rubberBanding;
Qt::ItemSelectionMode rubberBandSelectionMode;
Qt::ItemSelectionOperation rubberBandSelectionOperation;
@@ -148,7 +118,7 @@ public:
QGraphicsView::CacheMode cacheMode;
- QVector<QStyleOptionGraphicsItem> styleOptions;
+ QList<QStyleOptionGraphicsItem> styleOptions;
QStyleOptionGraphicsItem *allocStyleOptionsArray(int numItems);
void freeStyleOptionsArray(QStyleOptionGraphicsItem *array);
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp
index cf041b9817..3679723bc4 100644
--- a/src/widgets/graphicsview/qgraphicswidget.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget.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) 2021 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
#include "qglobal.h"
@@ -55,16 +19,20 @@
#include <private/qshortcutmap_p.h>
#endif
#include <QtCore/qmutex.h>
+#include <QtCore/QScopeGuard>
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qgraphicsview.h>
#include <QtWidgets/qgraphicsproxywidget.h>
#include <QtGui/qpalette.h>
+#include <QtGui/qpainterpath.h>
#include <QtWidgets/qstyleoption.h>
#include <qdebug.h>
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\class QGraphicsWidget
\brief The QGraphicsWidget class is the base class for all widget
@@ -172,7 +140,7 @@ QT_BEGIN_NAMESPACE
window, a tool, a popup, etc).
*/
QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
- : QGraphicsObject(*new QGraphicsWidgetPrivate, 0), QGraphicsLayoutItem(0, false)
+ : QGraphicsObject(*new QGraphicsWidgetPrivate, nullptr), QGraphicsLayoutItem(nullptr, false)
{
Q_D(QGraphicsWidget);
d->init(parent, wFlags);
@@ -184,7 +152,7 @@ QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
Constructs a new QGraphicsWidget, using \a dd as parent.
*/
QGraphicsWidget::QGraphicsWidget(QGraphicsWidgetPrivate &dd, QGraphicsItem *parent, Qt::WindowFlags wFlags)
- : QGraphicsObject(dd, 0), QGraphicsLayoutItem(0, false)
+ : QGraphicsObject(dd, nullptr), QGraphicsLayoutItem(nullptr, false)
{
Q_D(QGraphicsWidget);
d->init(parent, wFlags);
@@ -231,9 +199,9 @@ QGraphicsWidget::~QGraphicsWidget()
Q_D(QGraphicsWidget);
#ifndef QT_NO_ACTION
// Remove all actions from this widget
- for (int i = 0; i < d->actions.size(); ++i) {
- QActionPrivate *apriv = d->actions.at(i)->d_func();
- apriv->graphicsWidgets.removeAll(this);
+ for (auto action : std::as_const(d->actions)) {
+ QActionPrivate *apriv = action->d_func();
+ apriv->associatedObjects.removeAll(this);
}
d->actions.clear();
#endif
@@ -241,7 +209,7 @@ QGraphicsWidget::~QGraphicsWidget()
if (QGraphicsScene *scn = scene()) {
QGraphicsScenePrivate *sceneD = scn->d_func();
if (sceneD->tabFocusFirst == this)
- sceneD->tabFocusFirst = (d->focusNext == this ? 0 : d->focusNext);
+ sceneD->tabFocusFirst = (d->focusNext == this ? nullptr : d->focusNext);
}
d->focusPrev->d_func()->focusNext = d->focusNext;
d->focusNext->d_func()->focusPrev = d->focusPrev;
@@ -263,15 +231,15 @@ QGraphicsWidget::~QGraphicsWidget()
if (item->isWidget()) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
if (widget->parentLayoutItem() == d->layout)
- widget->setParentLayoutItem(0);
+ widget->setParentLayoutItem(nullptr);
}
}
- d->layout = 0;
+ d->layout = nullptr;
delete temp;
}
// Remove this graphics widget from widgetStyles
- widgetStyles()->setStyleForWidget(this, 0);
+ widgetStyles()->setStyleForWidget(this, nullptr);
// Unset the parent here, when we're still a QGraphicsWidget.
// It is otherwise done in ~QGraphicsItem() where we'd be
@@ -351,6 +319,19 @@ void QGraphicsWidget::resize(const QSizeF &size)
void QGraphicsWidget::setGeometry(const QRectF &rect)
{
QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func();
+ // Package relayout of children in a scope guard so we can just return early
+ // when this widget's geometry is sorted out.
+ const auto relayoutChildren = qScopeGuard([this, wd]() {
+ if (QGraphicsLayout::instantInvalidatePropagation()) {
+ if (QGraphicsLayout *lay = wd->layout) {
+ if (!lay->isActivated()) {
+ QEvent layoutRequest(QEvent::LayoutRequest);
+ QCoreApplication::sendEvent(this, &layoutRequest);
+ }
+ }
+ }
+ });
+
QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr.data();
QRectF newGeom;
QPointF oldPos = d->geom.topLeft();
@@ -360,9 +341,8 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
newGeom.setSize(rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize))
.boundedTo(effectiveSizeHint(Qt::MaximumSize)));
- if (newGeom == d->geom) {
- goto relayoutChildrenAndReturn;
- }
+ if (newGeom == d->geom)
+ return;
// setPos triggers ItemPositionChange, which can adjust position
wd->inSetGeometry = 1;
@@ -370,67 +350,48 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
wd->inSetGeometry = 0;
newGeom.moveTopLeft(pos());
- if (newGeom == d->geom) {
- goto relayoutChildrenAndReturn;
- }
+ if (newGeom == d->geom)
+ return;
- // Update and prepare to change the geometry (remove from index) if the size has changed.
- if (wd->scene) {
- if (rect.topLeft() == d->geom.topLeft()) {
- prepareGeometryChange();
- }
- }
+ // Update and prepare to change the geometry (remove from index) if
+ // the size has changed.
+ if (wd->scene && rect.topLeft() == d->geom.topLeft())
+ prepareGeometryChange();
}
// Update the layout item geometry
- {
- bool moved = oldPos != pos();
- if (moved) {
- // Send move event.
- QGraphicsSceneMoveEvent event;
- event.setOldPos(oldPos);
- event.setNewPos(pos());
- QCoreApplication::sendEvent(this, &event);
- if (wd->inSetPos) {
- //set the new pos
- d->geom.moveTopLeft(pos());
- emit geometryChanged();
- goto relayoutChildrenAndReturn;
- }
+ if (oldPos != pos()) {
+ // Send move event.
+ QGraphicsSceneMoveEvent event;
+ event.setOldPos(oldPos);
+ event.setNewPos(pos());
+ QCoreApplication::sendEvent(this, &event);
+ if (wd->inSetPos) {
+ // Set the new position:
+ d->geom.moveTopLeft(pos());
+ emit geometryChanged();
+ return;
}
- QSizeF oldSize = size();
- QGraphicsLayoutItem::setGeometry(newGeom);
- // Send resize event
- bool resized = newGeom.size() != oldSize;
- if (resized) {
+ }
+
+ QSizeF oldSize = size();
+ QGraphicsLayoutItem::setGeometry(newGeom);
+ // Send resize event, if appropriate:
+ if (newGeom.size() != oldSize) {
+ if (oldSize.width() != newGeom.size().width())
+ emit widthChanged();
+ if (oldSize.height() != newGeom.size().height())
+ emit heightChanged();
+ QGraphicsLayout *lay = wd->layout;
+ if (!QGraphicsLayout::instantInvalidatePropagation() || !lay || lay->isActivated()) {
QGraphicsSceneResizeEvent re;
re.setOldSize(oldSize);
re.setNewSize(newGeom.size());
- if (oldSize.width() != newGeom.size().width())
- emit widthChanged();
- if (oldSize.height() != newGeom.size().height())
- emit heightChanged();
- QGraphicsLayout *lay = wd->layout;
- if (QGraphicsLayout::instantInvalidatePropagation()) {
- if (!lay || lay->isActivated()) {
- QCoreApplication::sendEvent(this, &re);
- }
- } else {
- QCoreApplication::sendEvent(this, &re);
- }
+ QCoreApplication::sendEvent(this, &re);
}
}
emit geometryChanged();
-relayoutChildrenAndReturn:
- if (QGraphicsLayout::instantInvalidatePropagation()) {
- if (QGraphicsLayout *lay = wd->layout) {
- if (!lay->isActivated()) {
- QEvent layoutRequest(QEvent::LayoutRequest);
- QCoreApplication::sendEvent(this, &layoutRequest);
- }
- }
- }
}
/*!
@@ -615,7 +576,7 @@ void QGraphicsWidget::unsetWindowFrameMargins()
QStyleOptionTitleBar bar;
d->initStyleOptionTitleBar(&bar);
QStyle *style = this->style();
- qreal margin = style->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth);
+ const qreal margin = style->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, &bar);
qreal titleBarHeight = d->titleBarHeight(bar);
setWindowFrameMargins(margin, titleBarHeight, margin, margin);
} else {
@@ -942,7 +903,7 @@ QStyle *QGraphicsWidget::style() const
*/
void QGraphicsWidget::setStyle(QStyle *style)
{
- setAttribute(Qt::WA_SetStyle, style != 0);
+ setAttribute(Qt::WA_SetStyle, style != nullptr);
widgetStyles()->setStyleForWidget(this, style);
// Deliver StyleChange to the widget itself (doesn't propagate).
@@ -976,13 +937,13 @@ QFont QGraphicsWidget::font() const
{
Q_D(const QGraphicsWidget);
QFont fnt = d->font;
- fnt.resolve(fnt.resolve() | d->inheritedFontResolveMask);
+ fnt.setResolveMask(fnt.resolveMask() | d->inheritedFontResolveMask);
return fnt;
}
void QGraphicsWidget::setFont(const QFont &font)
{
Q_D(QGraphicsWidget);
- setAttribute(Qt::WA_SetFont, font.resolve() != 0);
+ setAttribute(Qt::WA_SetFont, font.resolveMask() != 0);
QFont naturalFont = d->naturalWidgetFont();
QFont resolvedFont = font.resolve(naturalFont);
@@ -1022,7 +983,7 @@ QPalette QGraphicsWidget::palette() const
void QGraphicsWidget::setPalette(const QPalette &palette)
{
Q_D(QGraphicsWidget);
- setAttribute(Qt::WA_SetPalette, palette.resolve() != 0);
+ setAttribute(Qt::WA_SetPalette, palette.resolveMask() != 0);
QPalette naturalPalette = d->naturalWidgetPalette();
QPalette resolvedPalette = palette.resolve(naturalPalette);
@@ -1557,7 +1518,7 @@ bool QGraphicsWidget::focusNextPrevChild(bool next)
{
Q_D(QGraphicsWidget);
// Let the parent's focusNextPrevChild implementation decide what to do.
- QGraphicsWidget *parent = 0;
+ QGraphicsWidget *parent = nullptr;
if (!isWindow() && (parent = parentWidget()))
return parent->focusNextPrevChild(next);
if (!d->scene)
@@ -1995,7 +1956,7 @@ void QGraphicsWidget::setShortcutAutoRepeat(int id, bool enabled)
*/
void QGraphicsWidget::addAction(QAction *action)
{
- insertAction(0, action);
+ insertAction(nullptr, action);
}
/*!
@@ -2005,14 +1966,10 @@ void QGraphicsWidget::addAction(QAction *action)
\sa removeAction(), QMenu, addAction(), QWidget::addActions()
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
void QGraphicsWidget::addActions(const QList<QAction *> &actions)
-#else
-void QGraphicsWidget::addActions(QList<QAction *> actions)
-#endif
{
- for (int i = 0; i < actions.count(); ++i)
- insertAction(0, actions.at(i));
+ for (int i = 0; i < actions.size(); ++i)
+ insertAction(nullptr, actions.at(i));
}
/*!
@@ -2041,14 +1998,14 @@ void QGraphicsWidget::insertAction(QAction *before, QAction *action)
int pos = d->actions.indexOf(before);
if (pos < 0) {
- before = 0;
+ before = nullptr;
pos = d->actions.size();
}
d->actions.insert(pos, action);
if (index == -1) {
QActionPrivate *apriv = action->d_func();
- apriv->graphicsWidgets.append(this);
+ apriv->associatedObjects.append(this);
}
QActionEvent e(QEvent::ActionAdded, action, before);
@@ -2066,13 +2023,9 @@ void QGraphicsWidget::insertAction(QAction *before, QAction *action)
\sa removeAction(), QMenu, insertAction(), QWidget::insertActions()
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
void QGraphicsWidget::insertActions(QAction *before, const QList<QAction *> &actions)
-#else
-void QGraphicsWidget::insertActions(QAction *before, QList<QAction *> actions)
-#endif
{
- for (int i = 0; i < actions.count(); ++i)
+ for (int i = 0; i < actions.size(); ++i)
insertAction(before, actions.at(i));
}
@@ -2091,7 +2044,7 @@ void QGraphicsWidget::removeAction(QAction *action)
Q_D(QGraphicsWidget);
QActionPrivate *apriv = action->d_func();
- apriv->graphicsWidgets.removeAll(this);
+ apriv->associatedObjects.removeAll(this);
if (d->actions.removeAll(action)) {
QActionEvent e(QEvent::ActionRemoved, action);
@@ -2150,7 +2103,7 @@ void QGraphicsWidget::setTabOrder(QGraphicsWidget *first, QGraphicsWidget *secon
return;
}
QGraphicsScene *scene = first ? first->scene() : second->scene();
- if (!scene && (!first || !second)) {
+ if (!scene) {
qWarning("QGraphicsWidget::setTabOrder: assigning tab order from/to the"
" scene requires the item to be in a scene.");
return;
@@ -2346,7 +2299,7 @@ void QGraphicsWidget::paintWindowFrame(QPainter *painter, const QStyleOptionGrap
frameOptions.palette.setCurrentColorGroup(isActive ? QPalette::Active : QPalette::Normal);
frameOptions.rect = windowFrameRect;
- frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, widget);
+ frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, nullptr, widget);
frameOptions.midLineWidth = 1;
style()->drawPrimitive(QStyle::PE_FrameWindow, &frameOptions, painter, widget);
@@ -2414,7 +2367,7 @@ void QGraphicsWidget::dumpFocusChain()
qWarning("Found a focus chain that is not circular, (next == 0)");
break;
}
- qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromLatin1("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
+ qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromLatin1("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << "next:"_L1 << next->d_func()->focusNext->data(0) << "prev:"_L1 << next->d_func()->focusPrev->data(0);
if (visited.contains(next)) {
qWarning("Already visited this node. However, I expected to dump until I found myself.");
break;
diff --git a/src/widgets/graphicsview/qgraphicswidget.h b/src/widgets/graphicsview/qgraphicswidget.h
index 6c5171cc02..3e2c93b6cc 100644
--- a/src/widgets/graphicsview/qgraphicswidget.h
+++ b/src/widgets/graphicsview/qgraphicswidget.h
@@ -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
#ifndef QGRAPHICSWIDGET_H
#define QGRAPHICSWIDGET_H
@@ -43,7 +7,7 @@
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtGui/qfont.h>
#if QT_CONFIG(action)
-# include <QtWidgets/qaction.h>
+# include <QtGui/qaction.h>
#endif
#include <QtWidgets/qgraphicslayoutitem.h>
#include <QtWidgets/qgraphicsitem.h>
@@ -70,7 +34,8 @@ class Q_WIDGETS_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphic
Q_INTERFACES(QGraphicsItem QGraphicsLayoutItem)
Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
Q_PROPERTY(QFont font READ font WRITE setFont)
- Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
+ Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
+ RESET unsetLayoutDirection)
Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
@@ -148,13 +113,8 @@ public:
#ifndef QT_NO_ACTION
//actions
void addAction(QAction *action);
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
void addActions(const QList<QAction*> &actions);
void insertActions(QAction *before, const QList<QAction*> &actions);
-#else
- void addActions(QList<QAction*> actions);
- void insertActions(QAction *before, QList<QAction*> actions);
-#endif
void insertAction(QAction *before, QAction *action);
void removeAction(QAction *action);
QList<QAction*> actions() const;
diff --git a/src/widgets/graphicsview/qgraphicswidget_p.cpp b/src/widgets/graphicsview/qgraphicswidget_p.cpp
index 0156faf8e4..6c12dc7754 100644
--- a/src/widgets/graphicsview/qgraphicswidget_p.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget_p.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
#include "qglobal.h"
@@ -51,8 +15,6 @@
#include <QtWidgets/QStyleOptionTitleBar>
#include <QtWidgets/QGraphicsSceneMouseEvent>
-#include <private/qmemory_p.h>
-
QT_BEGIN_NAMESPACE
void QGraphicsWidgetPrivate::init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
@@ -121,7 +83,7 @@ QGraphicsWidgetPrivate::~QGraphicsWidgetPrivate()
void QGraphicsWidgetPrivate::ensureMargins() const
{
if (!margins)
- margins = qt_make_unique<QMarginsF>();
+ margins = std::make_unique<QMarginsF>();
}
/*!
@@ -133,7 +95,7 @@ void QGraphicsWidgetPrivate::ensureMargins() const
void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
{
if (!windowFrameMargins)
- windowFrameMargins = qt_make_unique<QMarginsF>();
+ windowFrameMargins = std::make_unique<QMarginsF>();
}
/*!
@@ -145,12 +107,12 @@ void QGraphicsWidgetPrivate::ensureWindowFrameMargins() const
void QGraphicsWidgetPrivate::ensureWindowData()
{
if (!windowData)
- windowData = qt_make_unique<WindowData>();
+ windowData = std::make_unique<WindowData>();
}
void QGraphicsWidgetPrivate::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);
}
@@ -172,7 +134,7 @@ void QGraphicsWidgetPrivate::updatePalette(const QPalette &palette)
// Calculate new mask.
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
inheritedPaletteResolveMask = 0;
- int mask = palette.resolve() | inheritedPaletteResolveMask;
+ int mask = palette.resolveMask() | inheritedPaletteResolveMask;
// Propagate to children.
for (int i = 0; i < children.size(); ++i) {
@@ -239,13 +201,13 @@ QPalette QGraphicsWidgetPrivate::naturalWidgetPalette() const
} else if (scene) {
palette = scene->palette();
}
- palette.resolve(0);
+ palette.setResolveMask(0);
return palette;
}
void QGraphicsWidgetPrivate::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);
}
@@ -270,7 +232,7 @@ void QGraphicsWidgetPrivate::updateFont(const QFont &font)
// Calculate new mask.
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
inheritedFontResolveMask = 0;
- int mask = font.resolve() | inheritedFontResolveMask;
+ int mask = font.resolveMask() | inheritedFontResolveMask;
// Propagate to children.
for (int i = 0; i < children.size(); ++i) {
@@ -300,7 +262,7 @@ QFont QGraphicsWidgetPrivate::naturalWidgetFont() const
} else if (scene) {
naturalFont = scene->font();
}
- naturalFont.resolve(0);
+ naturalFont.setResolveMask(0);
return naturalFont;
}
@@ -322,7 +284,7 @@ void QGraphicsWidgetPrivate::initStyleOptionTitleBar(QStyleOptionTitleBar *optio
option->titleBarState = Qt::WindowNoState;
}
QFont windowTitleFont = QApplication::font("QMdiSubWindowTitleBar");
- QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, 0);
+ QRect textRect = q->style()->subControlRect(QStyle::CC_TitleBar, option, QStyle::SC_TitleBarLabel, nullptr);
option->text = QFontMetrics(windowTitleFont).elidedText(
windowData->windowTitle, Qt::ElideRight, textRect.width());
}
@@ -690,7 +652,7 @@ void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent
break;
case Qt::TitleBarArea:
windowData->buttonRect = q->style()->subControlRect(
- QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0);
+ QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, nullptr);
if (windowData->buttonRect.contains(pos.toPoint()))
windowData->buttonMouseOver = true;
event->ignore();
@@ -707,7 +669,7 @@ void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent
Q_UNUSED(cursorShape);
#endif
// update buttons if we hover over them
- windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0);
+ windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), nullptr);
if (windowData->hoveredSubControl != QStyle::SC_TitleBarCloseButton)
windowData->hoveredSubControl = QStyle::SC_TitleBarLabel;
@@ -781,12 +743,13 @@ void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *new
if (!parent && oldScene && oldScene != newScene && oldScene->d_func()->tabFocusFirst == q) {
// detach from old scene's top level focus chain.
- oldScene->d_func()->tabFocusFirst = (focusAfter != q) ? focusAfter : 0;
+ oldScene->d_func()->tabFocusFirst = (focusAfter != q) ? focusAfter : nullptr;
}
// detach from current focus chain; skip this widget subtree.
focusBefore->d_func()->focusNext = focusAfter;
- focusAfter->d_func()->focusPrev = focusBefore;
+ if (focusAfter)
+ focusAfter->d_func()->focusPrev = focusBefore;
if (newParent) {
// attach to new parent's focus chain as the last element
@@ -802,7 +765,8 @@ void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *new
newFocusLast->d_func()->focusNext = q;
focusLast->d_func()->focusNext = newFocusAfter;
- newFocusAfter->d_func()->focusPrev = focusLast;
+ if (newFocusAfter)
+ newFocusAfter->d_func()->focusPrev = focusLast;
focusPrev = newFocusLast;
} else {
// no new parent, so just link up our own prev->last widgets.
diff --git a/src/widgets/graphicsview/qgraphicswidget_p.h b/src/widgets/graphicsview/qgraphicswidget_p.h
index e4cc2c3016..868969cc94 100644
--- a/src/widgets/graphicsview/qgraphicswidget_p.h
+++ b/src/widgets/graphicsview/qgraphicswidget_p.h
@@ -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
#ifndef QGRAPHICSWIDGET_P_H
#define QGRAPHICSWIDGET_P_H
diff --git a/src/widgets/graphicsview/qsimplex_p.cpp b/src/widgets/graphicsview/qsimplex_p.cpp
index e18f1fa4c4..948437bf68 100644
--- a/src/widgets/graphicsview/qsimplex_p.cpp
+++ b/src/widgets/graphicsview/qsimplex_p.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
#include "qsimplex_p.h"
@@ -46,6 +10,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\internal
\class QSimplex
@@ -76,7 +42,7 @@ QT_BEGIN_NAMESPACE
/*!
\internal
*/
-QSimplex::QSimplex() : objective(0), rows(0), columns(0), firstArtificial(0), matrix(0)
+QSimplex::QSimplex() : objective(nullptr), rows(0), columns(0), firstArtificial(0), matrix(nullptr)
{
}
@@ -93,7 +59,7 @@ QSimplex::~QSimplex()
*/
void QSimplex::clearDataStructures()
{
- if (matrix == 0)
+ if (matrix == nullptr)
return;
// Matrix
@@ -101,7 +67,7 @@ void QSimplex::clearDataStructures()
columns = 0;
firstArtificial = 0;
free(matrix);
- matrix = 0;
+ matrix = nullptr;
// Constraints
for (int i = 0; i < constraints.size(); ++i) {
@@ -113,7 +79,7 @@ void QSimplex::clearDataStructures()
// Other
variables.clear();
- objective = 0;
+ objective = nullptr;
}
/*!
@@ -195,7 +161,7 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> &newConstraints)
QSimplexVariable *artificial;
Q_ASSERT(constraints[i]->helper.first == 0);
- Q_ASSERT(constraints[i]->artificial == 0);
+ Q_ASSERT(constraints[i]->artificial == nullptr);
switch(constraints[i]->ratio) {
case QSimplexConstraint::LessOrEqual:
@@ -354,7 +320,7 @@ void QSimplex::dumpMatrix()
{
qDebug("---- Simplex Matrix ----\n");
- QString str(QLatin1String(" "));
+ QString str(" "_L1);
for (int j = 0; j < columns; ++j)
str += QString::fromLatin1(" <%1 >").arg(j, 2);
qDebug("%s", qPrintable(str));
@@ -551,7 +517,7 @@ qreal QSimplex::solver(SolverFactor factor)
// Return the value calculated by the simplex plus the value of the
// fixed variables.
- return (factor * valueAt(0, columns - 1)) + resultOffset;
+ return (qToUnderlying(factor) * valueAt(0, columns - 1)) + resultOffset;
}
/*!
@@ -614,7 +580,7 @@ bool QSimplex::simplifyConstraints(QList<QSimplexConstraint *> *constraints)
QList<QSimplexConstraint *>::iterator iter = constraints->begin();
while (iter != constraints->end()) {
QSimplexConstraint *c = *iter;
- if ((c->ratio == QSimplexConstraint::Equal) && (c->variables.count() == 1)) {
+ if ((c->ratio == QSimplexConstraint::Equal) && (c->variables.size() == 1)) {
// Check whether this is a constraint of type Var == K
// If so, save its value to "results".
QSimplexVariable *variable = c->variables.constBegin().key();
diff --git a/src/widgets/graphicsview/qsimplex_p.h b/src/widgets/graphicsview/qsimplex_p.h
index a69cef6115..800c8fe934 100644
--- a/src/widgets/graphicsview/qsimplex_p.h
+++ b/src/widgets/graphicsview/qsimplex_p.h
@@ -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
#ifndef QSIMPLEX_P_H
#define QSIMPLEX_P_H