diff options
Diffstat (limited to 'src/plugins/debugger/debuggerprotocol.cpp')
-rw-r--r-- | src/plugins/debugger/debuggerprotocol.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/plugins/debugger/debuggerprotocol.cpp b/src/plugins/debugger/debuggerprotocol.cpp index 35c2d220f3..4a1a7574b4 100644 --- a/src/plugins/debugger/debuggerprotocol.cpp +++ b/src/plugins/debugger/debuggerprotocol.cpp @@ -843,19 +843,47 @@ void DebuggerCommand::arg(const char *value) args = arr; } +void DebuggerCommand::arg(const char *name, bool value) +{ + args = addToJsonObject(args, name, value); +} + void DebuggerCommand::arg(const char *name, const QJsonValue &value) { args = addToJsonObject(args, name, value); } -QByteArray DebuggerCommand::argsToPython() const +static QJsonValue translateJsonToPython(const QJsonValue &value) { - // TODO: Verify that this is really Python. + // TODO: Verify that this covers all incompatibilities between python and json. + switch (value.type()) { + case QJsonValue::Bool: + // Python doesn't understand lowercase "true" or "false" + return QJsonValue(value.toBool() ? 1 : 0); + case QJsonValue::Object: { + QJsonObject object = value.toObject(); + for (QJsonObject::iterator i = object.begin(); i != object.end(); ++i) + i.value() = translateJsonToPython(i.value()); + return object; + } + case QJsonValue::Array: { + QJsonArray array = value.toArray(); + for (QJsonArray::iterator i = array.begin(); i != array.end(); ++i) + *i = translateJsonToPython(*i); + return array; + } + default: + return value; + } +} - if (args.isArray()) - return QJsonDocument(args.toArray()).toJson(QJsonDocument::Compact); +QByteArray DebuggerCommand::argsToPython() const +{ + QJsonValue pythonCompatible(translateJsonToPython(args)); + if (pythonCompatible.isArray()) + return QJsonDocument(pythonCompatible.toArray()).toJson(QJsonDocument::Compact); else - return QJsonDocument(args.toObject()).toJson(QJsonDocument::Compact); + return QJsonDocument(pythonCompatible.toObject()).toJson(QJsonDocument::Compact); } QByteArray DebuggerCommand::argsToString() const |