4#include <QJSValueIterator>
8#include <simgear/structure/commands.hxx>
14void convertJSObjectToPropertyNode(QJSValue js, SGPropertyNode *node);
16void convertSingleJSValue(QJSValue v, SGPropertyNode* node)
19 node->setDoubleValue(v.toNumber());
20 }
else if (v.isBool()) {
21 node->setBoolValue(v.toBool());
22 }
else if (v.isString()) {
23 node->setStringValue(v.toString().toStdString());
25 qWarning() << Q_FUNC_INFO <<
"unhandld JS type";
29void convertJSObjectToPropertyNode(QJSValue js, SGPropertyNode* node)
31 QJSValueIterator it(js);
32 while (it.hasNext()) {
34 const auto propName = it.name().toStdString();
35 QJSValue v = it.value();
38 SGPropertyNode_ptr childNode = node->getChild(propName,
true);
39 convertJSObjectToPropertyNode(v, childNode);
40 }
else if (v.isArray()) {
47 QJSValueIterator arrayIt(v);
49 while (arrayIt.hasNext()) {
51 SGPropertyNode_ptr childNode = node->getChild(propName, propIndex++,
true);
52 if (arrayIt.value().isArray()) {
54 qWarning() << Q_FUNC_INFO <<
"arrays of array not possible";
55 }
else if (arrayIt.value().isObject()) {
56 convertJSObjectToPropertyNode(arrayIt.value(), childNode);
59 convertSingleJSValue(arrayIt.value(), childNode);
63 convertSingleJSValue(v, node->getChild(propName,
true));
77 const std::string cmdName =
name.toStdString();
79 SGCommandMgr* mgr = SGCommandMgr::instance();
80 if (!mgr->getCommand(cmdName)) {
81 qWarning() <<
"No such command" <<
name;
85 SGPropertyNode_ptr propArgs(
new SGPropertyNode);
88 if (args.isObject()) {
89 convertJSObjectToPropertyNode(args, propArgs);
94 return mgr->execute(cmdName, propArgs,
globals->get_props());
99 SGPropertyNode_ptr node =
fgGetNode(path.toStdString(), create);
Q_INVOKABLE bool command(QString name, QJSValue args)
Q_INVOKABLE FGQmlPropertyNode * property(QString path, bool create=false) const
retrieve a property by its global path
FGQmlInstance(QObject *parent=nullptr)
void setNode(SGPropertyNode_ptr node)
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.