6#include "QskObjectTree.h"
8#include <qguiapplication.h>
10#include <qquickwindow.h>
12bool QskObjectTree::isRoot(
const QObject*
object )
14 return object == QGuiApplication::instance();
17QObjectList QskObjectTree::childNodes(
const QObject*
object )
21 if (
object ==
nullptr )
23 const auto windows = QGuiApplication::topLevelWindows();
24 children.reserve( windows.count() );
26 for (
auto window : windows )
29 else if ( object->isWindowType() )
31 const auto childObjects =
object->children();
33 for (
auto child : childObjects )
35 if ( child->isWindowType() )
39 if (
auto w = qobject_cast< const QQuickWindow* >(
object ) )
42 children += w->contentItem();
45 else if (
auto item = qobject_cast< const QQuickItem* >(
object ) )
47 const auto childItems = item->childItems();
48 children.reserve( childItems.count() );
50 for (
auto child : childItems )
57QObject* QskObjectTree::parentNode(
const QObject*
object )
59 if (
object ==
nullptr )
62 if ( object->isWindowType() )
64 if ( object->parent() ==
nullptr )
65 return QGuiApplication::instance();
68 if (
auto item = qobject_cast< const QQuickItem* >(
object ) )
70 if ( item->parentItem() )
71 return item->parentItem();
73 return item->window();
76 return object->parent();
79void QskObjectTree::traverseDown( QObject*
object, Visitor& visitor )
81 const auto children = childNodes(
object );
82 for ( QObject* child : children )
84 const bool done = visitor.visitDown( child );
86 traverseDown( child, visitor );
90void QskObjectTree::traverseUp( QObject*
object, Visitor& visitor )
92 QObject* parent = parentNode(
object );
95 const bool done = visitor.visitUp( parent );
97 traverseUp( parent, visitor );