From 3efb1f93e70e32797ae721f6313d32bedf4581dd Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 21 Jan 2019 15:23:25 +0100 Subject: [PATCH] as the root item is no child of the window we have to handle it explicitly, so that traversing does not stop --- src/controls/QskObjectTree.cpp | 28 +++++++++++++--------------- src/controls/QskObjectTree.h | 8 ++++---- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/controls/QskObjectTree.cpp b/src/controls/QskObjectTree.cpp index 7fcee5c6..163a1c7d 100644 --- a/src/controls/QskObjectTree.cpp +++ b/src/controls/QskObjectTree.cpp @@ -21,31 +21,30 @@ QObjectList QskObjectTree::childNodes( const QObject* object ) if ( object == nullptr ) { const auto windows = QGuiApplication::topLevelWindows(); - for ( QWindow* window : windows ) + for ( auto window : windows ) children += window; } else if ( object->isWindowType() ) { const auto childObjects = object->children(); - for ( QObject* child : childObjects ) + for ( auto child : childObjects ) { if ( child->isWindowType() ) - { children += child; - } - else if ( qobject_cast< QQuickItem* >( child ) ) - { - children += child; - } + } + + if ( auto w = qobject_cast< const QQuickWindow* >( object ) ) + { + // For some reason the window is not the parent of its contentItem() + children += w->contentItem(); } } - else + else if ( auto item = qobject_cast< const QQuickItem* >( object ) ) { - const QQuickItem* item = static_cast< const QQuickItem* >( object ); - const auto childItems = item->childItems(); - for ( QQuickItem* child : childItems ) + + for ( auto child : childItems ) children += child; } @@ -59,12 +58,11 @@ QObject* QskObjectTree::parentNode( const QObject* object ) if ( object->isWindowType() ) { - QObject* parentObject = object->parent(); - if ( parentObject == nullptr ) + if ( object->parent() == nullptr ) return QGuiApplication::instance(); } - if ( const QQuickItem* item = qobject_cast< const QQuickItem* >( object ) ) + if ( auto item = qobject_cast< const QQuickItem* >( object ) ) { if ( item->parentItem() ) return item->parentItem(); diff --git a/src/controls/QskObjectTree.h b/src/controls/QskObjectTree.h index a6359e8d..f8c3e757 100644 --- a/src/controls/QskObjectTree.h +++ b/src/controls/QskObjectTree.h @@ -50,10 +50,10 @@ namespace QskObjectTree bool visitDown( QObject* object ) override final { - if ( QskControl* control = qobject_cast< QskControl* >( object ) ) + if ( auto control = qobject_cast< QskControl* >( object ) ) return setImplicitValue( control, m_value ); - if ( QskWindow* window = qobject_cast< QskWindow* >( object ) ) + if ( auto window = qobject_cast< QskWindow* >( object ) ) return setImplicitValue( window, m_value ); return !setProperty( object, m_propertyName.constData(), m_value ); @@ -64,13 +64,13 @@ namespace QskObjectTree if ( isRoot( object ) ) return true; - if ( const QskControl* control = qobject_cast< const QskControl* >( object ) ) + if ( auto control = qobject_cast< const QskControl* >( object ) ) { m_value = value( control ); return true; } - if ( const QskWindow* window = qobject_cast< const QskWindow* >( object ) ) + if ( auto window = qobject_cast< const QskWindow* >( object ) ) { m_value = value( window ); return true;