From e4207a79d14ee85fb4623e6903a64b0a596997f2 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Thu, 29 Sep 2011 14:54:15 +0200 Subject: Fix bug in QGraphicsItem::isVisibleTo(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-21612 Reviewed-by: James Perrett Reviewed-by: Magne Pettersen Zachrisen Change-Id: I570c673a817c3c01593fcd7fa46d545f34e2c38d Merge-request: 1396 Reviewed-by: Jan-Arve Saether Reviewed-on: http://codereview.qt-project.org/5927 Reviewed-by: Qt Sanity Bot Reviewed-by: Jan-Arve Sæther --- src/widgets/graphicsview/qgraphicsitem.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/widgets/graphicsview') diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 07af928243..756c2f2aac 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -2238,7 +2238,8 @@ bool QGraphicsItem::isVisible() const returned. \a parent can be 0, in which case this function will return whether the item is visible to the scene or not. - An item may not be visible to its ancestors even if isVisible() is true. If + An item may not be visible to its ancestors even if isVisible() is true. It + may also be visible to its ancestors even if isVisible() is false. If any ancestor is hidden, the item itself will be implicitly hidden, in which case this function will return false. @@ -2246,15 +2247,16 @@ bool QGraphicsItem::isVisible() const */ bool QGraphicsItem::isVisibleTo(const QGraphicsItem *parent) const { - if (!d_ptr->visible) + const QGraphicsItem *p = this; + if (d_ptr->explicitlyHidden) return false; - if (parent == this) - return true; - if (parentItem() && parentItem()->isVisibleTo(parent)) - return true; - if (!parent && !parentItem()) - return true; - return false; + do { + if (p == parent) + return true; + if (p->d_ptr->explicitlyHidden) + return false; + } while ((p = p->d_ptr->parent)); + return parent == 0; } /*! -- cgit v1.2.3