Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
objecttree.cpp File Reference

ObjectTree: providers, object specs, describe() and QVariant/JSON conversion. More...

#include <sonde/objecttree.h>
#include "threadcheck_p.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtCore/QSet>
#include <QtCore/QLineF>
#include <QtCore/QMetaEnum>
#include <QtCore/QMetaProperty>
#include <QtCore/QPoint>
#include <QtCore/QRect>
#include <QtCore/QRegularExpression>
#include <QtCore/QSize>
#include <QtCore/QUrl>
#include <algorithm>
#include <array>
#include <cstring>
#include <cmath>
#include <limits>
#include <utility>

Classes

struct  Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::Registry
 Registered providers, in registration order. More...
struct  Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::Segment
 One parsed segment of an object spec. More...

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.
namespace  Sonde::ObjectTree
 Process-wide view of the application's object tree, used by the introspection tools and by tools that target objects (clicks, screenshots).

Functions

Registry & Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::registry ()
 The process-wide provider registry.
template<typename List, typename Value>
void Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::upsert (List &list, const QString &key, Value value)
 Replaces the entry for key, or appends one.
void Sonde::ObjectTree::addRootsProvider (const QString &key, RootsProvider provider)
 Registers (or, for an existing key, replaces) a roots provider.
void Sonde::ObjectTree::addChildrenProvider (const QString &key, ChildrenProvider provider)
 Registers (or, for an existing key, replaces) a children provider.
void Sonde::ObjectTree::addInspectProvider (const QString &key, InspectProvider provider)
 Registers (or, for an existing key, replaces) an inspect provider.
QStringList Sonde::ObjectTree::inspectLines (const QObject *object)
 The extra lines every inspect provider gives for object.
QObjectList Sonde::ObjectTree::roots ()
 All roots, without duplicates; always includes the application object.
QObjectList Sonde::ObjectTree::children (QObject *object)
 The children of object according to the providers.
QString Sonde::ObjectTree::idFor (const QObject *object)
 The id of object ("@0x..."), accepted by find().
template<typename Visit>
static bool Sonde::ObjectTree::walk (const QObjectList &start, Visit visit)
 Breadth-first walk from start; visit returns true to stop.
bool Sonde::ObjectTree::contains (const QObject *object)
 Whether object is reachable from the roots (and therefore safe to use).
QLatin1StringView Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::withoutQmlSuffix (QLatin1StringView name)
 name without the _QMLTYPE_<n> or _QML_<n> suffix Qt gives a QML type's class.
bool Sonde::ObjectTree::isOfClass (const QObject *object, QStringView className)
 Whether object is of class className or inherits it.
std::optional< Segment > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::parseSegment (const QString &text, QString *error)
 Parses one spec segment ("Class#name[prop=value]" and its parts).
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::matches (const QObject *o, const Segment &s)
 Whether o matches s (ignoring mnemonic ampersands in property values).
std::optional< QMetaEnum > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::metaEnumFor (QMetaType type)
 Finds the QMetaEnum for an enum or QFlags meta type.
QObject * Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::findObject (const QString &spec, QString *errorMessage)
 find(), writing why nothing matched to errorMessage.
Expected< QObject * > Sonde::ObjectTree::find (const QString &spec)
 Resolves an object spec (see the namespace documentation).
QString Sonde::ObjectTree::describeBrief (const QObject *object)
 Short summary that doesn't change with the object's state: @id Class#name.
QString Sonde::ObjectTree::describe (const QObject *object)
 One-line summary: @id Class#name text="..." (hidden) (disabled).
QJsonValue Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::placeholderFor (QMetaType type)
 A placeholder for a value that can't be converted: "<TypeName>".
QJsonValue Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::toJson (const QVariant &v, int depth)
 variantToJson() with the depth of nesting so far.
QJsonObject Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::gadgetToJson (const QVariant &v, const QMetaObject *mo, int depth)
 The readable properties of a gadget, by name (values converted with toJson()).
std::optional< QJsonValue > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::geometryToJson (const QVariant &v)
 Geometry types as {x, y} / {width, height} / {x, y, width, height}; std::nullopt for other types.
auto Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::metaEnumValue (int value)
 value as QMetaEnum takes it: quint64 since Qt 6.9, int before.
QJsonValue Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::enumToJson (const QVariant &v)
 An enum or flags value as its key name(s), or its number if it has no key.
std::optional< QJsonValue > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::compositeToJson (const QVariant &v, int depth)
 A map, list or gadget converted element by element; std::nullopt for other types.
QJsonValue Sonde::ObjectTree::variantToJson (const QVariant &value)
 Converts a QVariant to JSON.
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::convertJson (const QJsonValue &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant(), writing the value to out and why it failed to error.
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::jsonToGadget (const QJsonObject &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for a gadget: a default-constructed type with each key of json written to the property of that name.
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::fail (QString *error, const QString &message)
 Stores message in error (which may be null) and returns false.
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::intField (const QJsonObject &o, const char *key, int *out, QString *error)
 Reads the number key of o as an int.
template<std::size_t N>
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::intFields (const QJsonObject &o, const std::array< const char *, N > &keys, std::array< int, N > *out, QString *error)
 Reads the int fields keys of o into out, in order.
std::optional< bool > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::jsonToGeometry (const QJsonObject &o, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for the geometry types; std::nullopt if type isn't one.
std::optional< bool > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::jsonToEnum (const QJsonValue &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for an enum or flags type given key name(s); std::nullopt if not applicable.
bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::jsonToObjectPointer (const QJsonValue &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for a QObject pointer type, given an object spec or null.
Expected< QVariant > Sonde::ObjectTree::jsonToVariant (const QJsonValue &json, QMetaType type)
 Converts JSON to a QVariant of type type (the inverse of variantToJson()).

Variables

constexpr int Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::kMaxSearchNodes = 200000
 Safety limit on the number of objects one search visits.
constexpr int Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::kMaxJsonDepth = 16
 How deep variantToJson() descends into lists, maps and gadgets; deeper values become "<TypeName>".

Detailed Description

ObjectTree: providers, object specs, describe() and QVariant/JSON conversion.