38 lines
857 B
C
38 lines
857 B
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <QJsonObject>
|
||
|
|
#include <QVector>
|
||
|
|
#include <QString>
|
||
|
|
#include <QHash>
|
||
|
|
|
||
|
|
// 轻量级设备树模型:从 daemon_config.json 的 device_tree 字段加载
|
||
|
|
|
||
|
|
struct DeviceTreeNode
|
||
|
|
{
|
||
|
|
QString id;
|
||
|
|
QString name;
|
||
|
|
QString type;
|
||
|
|
QString endpoint;
|
||
|
|
QString driver;
|
||
|
|
QString capabilitiesRef;
|
||
|
|
QJsonObject params;
|
||
|
|
QVector<QString> childrenIds;
|
||
|
|
bool enabled{true};
|
||
|
|
};
|
||
|
|
|
||
|
|
class DeviceTreeModel
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
// 从给定的 JSON 根对象(包含 device_tree 字段)加载
|
||
|
|
bool loadFromDaemonConfig(const QJsonObject& root, QString* errorMessage = nullptr);
|
||
|
|
|
||
|
|
const QVector<DeviceTreeNode>& nodes() const { return m_nodes; }
|
||
|
|
|
||
|
|
const DeviceTreeNode* findById(const QString& id) const;
|
||
|
|
|
||
|
|
private:
|
||
|
|
QVector<DeviceTreeNode> m_nodes;
|
||
|
|
QHash<QString, int> m_indexById;
|
||
|
|
};
|
||
|
|
|