From 98db99657649d4668c766eaa36b8d29c58d19754 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 25 Feb 2021 16:58:27 +0100 Subject: Add nullptr checks to QGraphicsView classes The styleInfo parameter defaults to nullptr, and the scene can evidently be nullptr since we test for it before ungrabbing the mouse. Fixes static analyzer warnings fbd03604cc701651595a2ea33c5562b4 and 30fcb05194f3a2d121fc57b05e0ccf10 Pick-to: 6.1 Change-Id: I8e9d4fe4055115c366ada1cbb22a8f0839ba41da Reviewed-by: David Skoland Reviewed-by: Richard Moe Gustavsen --- .../graphicsview/qgraphicsanchorlayout_p.cpp | 4 ++- src/widgets/graphicsview/qgraphicsitem.cpp | 38 ++++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index be26b2785e..9da290974b 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -225,7 +225,7 @@ 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 = QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge); qreal s = styleInfo->defaultSpacing(orient); @@ -241,6 +241,8 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) s = 0; } prefSizeHint = s; + } else { + prefSizeHint = 0; } } diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index e426e09adf..bad40b0cff 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -2652,23 +2652,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(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(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); @@ -7149,14 +7151,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. -- cgit v1.2.3 From 95e34f7fbc0f2e9ca582278f9a772b27ebf93d5f Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 25 Feb 2021 17:04:06 +0100 Subject: QGraphicsWidget: Check for nullptrs in focus chain handling The while loops terminate if focusAfter becomes nullptr (unless we break earlier), so don't dereference those pointers without checking first. Fixes static analzyer warnings 979f2d508db4d5838f6c9b296120ce60 and 481f2ec7b5851bf19414478428f944b7 Pick-to: 6.1 Change-Id: I60fc5999907fe3b3146d7047ee1eff197719ab31 Reviewed-by: David Skoland Reviewed-by: Oliver Eftevaag Reviewed-by: Richard Moe Gustavsen --- src/widgets/graphicsview/qgraphicswidget_p.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/graphicsview/qgraphicswidget_p.cpp b/src/widgets/graphicsview/qgraphicswidget_p.cpp index 0580c6d938..d989455596 100644 --- a/src/widgets/graphicsview/qgraphicswidget_p.cpp +++ b/src/widgets/graphicsview/qgraphicswidget_p.cpp @@ -784,7 +784,8 @@ void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *new // 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 @@ -800,7 +801,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. -- cgit v1.2.3 From d984fd13adf1592646eafa9912bce44ee2158d92 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 25 Feb 2021 17:07:49 +0100 Subject: QGraphicsWidget: don't dereference nullptr Unlikely that one item is nullptr and the other item doesn't have a scene, but we do already test for the scene pointer, so don't continue if it's nullptr. Fixes static analyzer warning f59576ecf6618447c4f9c7be93fc737f Pick-to: 6.1 Change-Id: I6d436bb1211ddd412821d6978bab25192033f5e5 Reviewed-by: David Skoland Reviewed-by: Richard Moe Gustavsen --- src/widgets/graphicsview/qgraphicswidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp index fea9e18b9c..a4b1b8ea6c 100644 --- a/src/widgets/graphicsview/qgraphicswidget.cpp +++ b/src/widgets/graphicsview/qgraphicswidget.cpp @@ -2143,7 +2143,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; -- cgit v1.2.3 From cc7911beb11d69f556f1b5d31d3c4c56b7503086 Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Wed, 3 Feb 2021 14:32:43 +0800 Subject: fix: Print a warning message if the Xcb EGL initialize failed Before, No matter what the value of "success" is, Will print the "Xcb EGL gl-integration successfully initialized". If egl initialization fails, this line of printing will be very confusing. Change-Id: I6a06e2c14372913823c56ffe2fd8b831e084c719 Reviewed-by: Shawn Rutledge --- .../platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp index 36b971f52d..f3630d57b9 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp @@ -87,7 +87,11 @@ bool QXcbEglIntegration::initialize(QXcbConnection *connection) m_native_interface_handler.reset(new QXcbEglNativeInterfaceHandler(connection->nativeInterface())); - qCDebug(lcQpaGl) << "Xcb EGL gl-integration successfully initialized"; + if (success) + qCDebug(lcQpaGl) << "Xcb EGL gl-integration successfully initialized"; + else + qCWarning(lcQpaGl) << "Xcb EGL gl-integration initialize failed"; + return success; } -- cgit v1.2.3