Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
objecttree.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <sonde/expected.h>
8#include <sonde/types.h>
9
10#include <QtCore/QObject>
11#include <QtCore/QVariant>
12
33namespace Sonde::ObjectTree {
34
36using RootsProvider = std::function<QObjectList()>;
39using ChildrenProvider = std::function<std::optional<QObjectList>(QObject *)>;
40
42SONDE_CORE_EXPORT void addRootsProvider(const QString &key, RootsProvider provider);
44SONDE_CORE_EXPORT void addChildrenProvider(const QString &key, ChildrenProvider provider);
45
48using InspectProvider = std::function<QStringList(const QObject *)>;
50SONDE_CORE_EXPORT void addInspectProvider(const QString &key, InspectProvider provider);
52SONDE_CORE_EXPORT QStringList inspectLines(const QObject *object);
53
55SONDE_CORE_EXPORT QObjectList roots();
57SONDE_CORE_EXPORT QObjectList children(QObject *object);
58
60SONDE_CORE_EXPORT QString idFor(const QObject *object);
66SONDE_CORE_EXPORT Expected<QObject *> find(const QString &spec);
68SONDE_CORE_EXPORT bool contains(const QObject *object);
69
76SONDE_CORE_EXPORT bool isOfClass(const QObject *object, QStringView className);
77
79SONDE_CORE_EXPORT QString describe(const QObject *object);
80
82SONDE_CORE_EXPORT QString describeBrief(const QObject *object);
83
93SONDE_CORE_EXPORT QJsonValue variantToJson(const QVariant &value);
102SONDE_CORE_EXPORT Expected<QVariant> jsonToVariant(const QJsonValue &json, QMetaType type);
103
104} // namespace Sonde::ObjectTree
A value of type T, or an error of type E, as std::expected.
Definition expected.h:106
Sonde::Expected, Sonde::Unexpected and Sonde::Error: results that are a value or an error (design 003...
Process-wide view of the application's object tree, used by the introspection tools and by tools that...
Definition objecttree.cpp:28
std::function< std::optional< QObjectList >(QObject *)> ChildrenProvider
Returns the children of an object, or std::nullopt to fall through to the next provider and finally Q...
Definition objecttree.h:39
QStringList inspectLines(const QObject *object)
The extra lines every inspect provider gives for object.
Definition objecttree.cpp:83
std::function< QStringList(const QObject *)> InspectProvider
Returns extra "name: value" lines object_inspect shows for an object (e.g.
Definition objecttree.h:48
Expected< QObject * > find(const QString &spec)
Resolves an object spec (see the namespace documentation).
Definition objecttree.cpp:355
QString describe(const QObject *o)
One-line summary: @id Class#name text="..." (hidden) (disabled).
Definition objecttree.cpp:372
bool contains(const QObject *object)
Whether object is reachable from the roots (and therefore safe to use).
Definition objecttree.cpp:148
void addInspectProvider(const QString &key, InspectProvider provider)
Registers (or, for an existing key, replaces) an inspect provider.
Definition objecttree.cpp:77
QJsonValue variantToJson(const QVariant &v)
Converts a QVariant to JSON.
Definition objecttree.cpp:553
QString describeBrief(const QObject *o)
Short summary that doesn't change with the object's state: @id Class#name.
Definition objecttree.cpp:363
QObjectList roots()
All roots, without duplicates; always includes the application object.
Definition objecttree.cpp:94
void addChildrenProvider(const QString &key, ChildrenProvider provider)
Registers (or, for an existing key, replaces) a children provider.
Definition objecttree.cpp:71
QObjectList children(QObject *object)
The children of object according to the providers.
Definition objecttree.cpp:110
std::function< QObjectList()> RootsProvider
Returns additional root objects.
Definition objecttree.h:36
Expected< QVariant > jsonToVariant(const QJsonValue &json, QMetaType type)
Converts JSON to a QVariant of type type (the inverse of variantToJson()).
Definition objecttree.cpp:744
QString idFor(const QObject *object)
The id of object ("@0x..."), accepted by find().
Definition objecttree.cpp:121
void addRootsProvider(const QString &key, RootsProvider provider)
Registers (or, for an existing key, replaces) a roots provider.
Definition objecttree.cpp:65
bool isOfClass(const QObject *object, QStringView className)
Whether object is of class className or inherits it.
Definition objecttree.cpp:177
Value types shared by the Sonde API: tool definitions and results, asynchronous tool-call handles,...