Commit 9720c0d7 authored by Aurindam Jana's avatar Aurindam Jana

QmlDebugging: Show Object Tree in Console

Show QML/Javascript objects as a tree when
evaluated in the console.

Change-Id: I42901bf9bda3f18fb9fb1ca309a8370ccbe37c0a
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 4667371b
......@@ -804,11 +804,11 @@ void QmlEngine::onDebugQueryStateChanged(
QmlJsDebugClient::QDeclarativeDebugExpressionQuery *query =
qobject_cast<QmlJsDebugClient::QDeclarativeDebugExpressionQuery *>(
sender());
if (query && state != QmlJsDebugClient::QDeclarativeDebugQuery::Error)
qtMessageLogHandler()->
appendItem(new QtMessageLogItem(QtMessageLogHandler::UndefinedType,
query->result().toString()));
else
if (query && state != QmlJsDebugClient::QDeclarativeDebugQuery::Error) {
QtMessageLogItem *item = constructLogItemTree(query->result());
if (item)
qtMessageLogHandler()->appendItem(item);
} else
qtMessageLogHandler()->
appendItem(new QtMessageLogItem(QtMessageLogHandler::ErrorType,
_("Error evaluating expression.")));
......@@ -1050,6 +1050,47 @@ bool QmlEngine::canEvaluateScript(const QString &script)
return d->m_interpreter.canEvaluate();
}
QtMessageLogItem *QmlEngine::constructLogItemTree(
const QVariant &result, const QString &key)
{
if (!result.isValid())
return 0;
QtMessageLogItem *item = new QtMessageLogItem();
if (result.type() == QVariant::Map) {
if (key.isEmpty())
item->setText(_("Object"));
else
item->setText(QString(_("%1: Object")).arg(key));
QMapIterator<QString, QVariant> i(result.toMap());
while (i.hasNext()) {
i.next();
QtMessageLogItem *child = constructLogItemTree(i.value(), i.key());
if (child)
item->insertChild(item->childCount(), child);
}
} else if (result.type() == QVariant::List) {
if (key.isEmpty())
item->setText(_("List"));
else
item->setText(QString(_("[%1] : List")).arg(key));
QVariantList resultList = result.toList();
for (int i = 0; i < resultList.count(); i++) {
QtMessageLogItem *child = constructLogItemTree(resultList.at(i),
QString::number(i));
if (child)
item->insertChild(item->childCount(), child);
}
} else if (result.canConvert(QVariant::String)) {
item->setText(result.toString());
} else {
item->setText(_("Unknown Value"));
}
return item;
}
QmlAdapter *QmlEngine::adapter() const
{
return &d->m_adapter;
......
......@@ -53,6 +53,7 @@ class QmlAdapter;
namespace Internal {
class QtMessageLogItem;
class QmlEnginePrivate;
class QmlEngine : public DebuggerEngine
......@@ -182,6 +183,8 @@ private:
void updateEditor(Core::IEditor *editor, const QTextDocument *document);
bool canEvaluateScript(const QString &script);
QtMessageLogItem *constructLogItemTree(const QVariant &result,
const QString &key = QString());
private:
friend class QmlCppEngine;
......
......@@ -113,8 +113,6 @@ private:
const QVariant &refsVal);
void updateBreakpoints(const QVariant &bodyVal);
QVariant valueFromRef(int handle, const QVariant &refsVal);
void expandLocalsAndWatchers(const QVariant &bodyVal, const QVariant &refsVal);
void highlightExceptionCode(int lineNumber, const QString &filePath,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment