2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-04-18 14:20:54 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-04-18 14:20:54 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 14:20:54 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-04-18 14:20:54 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-04-18 14:20:54 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 14:20:54 +02:00
|
|
|
|
|
|
|
|
#include "qmlinspectoragent.h"
|
2015-08-26 11:51:56 +02:00
|
|
|
#include "qmlengine.h"
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <debugger/debuggeractions.h>
|
|
|
|
|
#include <debugger/debuggercore.h>
|
|
|
|
|
#include <debugger/debuggerengine.h>
|
2017-04-27 15:39:30 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <debugger/watchhandler.h>
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2015-08-26 11:51:56 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/idocument.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
#include <qmldebug/qmldebugconstants.h>
|
2015-08-26 11:51:56 +02:00
|
|
|
#include <qmldebug/qmlenginedebugclient.h>
|
|
|
|
|
#include <qmldebug/qmltoolsclient.h>
|
|
|
|
|
|
2015-01-10 23:40:32 +02:00
|
|
|
#include <utils/fileutils.h>
|
2012-04-18 14:20:54 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/savedaction.h>
|
2014-08-26 15:53:13 +02:00
|
|
|
|
2012-05-15 16:39:11 +02:00
|
|
|
#include <QElapsedTimer>
|
2015-08-26 11:51:56 +02:00
|
|
|
#include <QFileInfo>
|
2014-08-26 15:53:13 +02:00
|
|
|
#include <QLoggingCategory>
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
using namespace QmlDebug;
|
2012-09-28 14:40:57 +02:00
|
|
|
using namespace QmlDebug::Constants;
|
2012-05-10 10:29:11 +02:00
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2018-10-12 09:33:30 +03:00
|
|
|
Q_LOGGING_CATEGORY(qmlInspectorLog, "qtc.dbg.qmlinspector", QtWarningMsg)
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
/*!
|
|
|
|
|
* DebuggerAgent updates the watchhandler with the object tree data.
|
|
|
|
|
*/
|
2015-08-26 11:51:56 +02:00
|
|
|
QmlInspectorAgent::QmlInspectorAgent(QmlEngine *engine, QmlDebugConnection *connection)
|
|
|
|
|
: m_qmlEngine(engine)
|
|
|
|
|
, m_inspectorToolsContext("Debugger.QmlInspector")
|
|
|
|
|
, m_selectAction(new QAction(this))
|
|
|
|
|
, m_showAppOnTopAction(action(ShowAppOnTop))
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
m_debugIdToIname.insert(WatchItem::InvalidId, "inspect");
|
2014-07-28 14:23:52 +02:00
|
|
|
connect(action(ShowQmlObjectTree),
|
2015-08-26 11:51:56 +02:00
|
|
|
&Utils::SavedAction::valueChanged, this, &QmlInspectorAgent::updateState);
|
2016-11-03 16:03:06 +01:00
|
|
|
connect(action(SortStructMembers), &Utils::SavedAction::valueChanged,
|
|
|
|
|
this, &QmlInspectorAgent::updateState);
|
2012-05-14 23:26:23 +02:00
|
|
|
m_delayQueryTimer.setSingleShot(true);
|
2012-05-29 22:21:04 +02:00
|
|
|
m_delayQueryTimer.setInterval(100);
|
2015-01-29 18:37:56 +01:00
|
|
|
connect(&m_delayQueryTimer, &QTimer::timeout,
|
|
|
|
|
this, &QmlInspectorAgent::queryEngineContext);
|
2015-08-26 11:51:56 +02:00
|
|
|
|
2018-11-15 13:33:45 +01:00
|
|
|
m_engineClient = new QmlEngineDebugClient(connection);
|
|
|
|
|
connect(m_engineClient, &BaseEngineDebugClient::newState,
|
|
|
|
|
this, &QmlInspectorAgent::updateState);
|
|
|
|
|
connect(m_engineClient, &BaseEngineDebugClient::result,
|
|
|
|
|
this, &QmlInspectorAgent::onResult);
|
|
|
|
|
connect(m_engineClient, &BaseEngineDebugClient::newObject,
|
|
|
|
|
this, &QmlInspectorAgent::newObject);
|
|
|
|
|
connect(m_engineClient, &BaseEngineDebugClient::valueChanged,
|
|
|
|
|
this, &QmlInspectorAgent::onValueChanged);
|
|
|
|
|
updateState();
|
2015-08-26 11:51:56 +02:00
|
|
|
|
2018-11-15 13:33:45 +01:00
|
|
|
m_toolsClient = new QmlToolsClient(connection);
|
|
|
|
|
connect(m_toolsClient, &BaseToolsClient::newState,
|
2015-08-26 11:51:56 +02:00
|
|
|
this, &QmlInspectorAgent::toolsClientStateChanged);
|
2018-11-15 13:33:45 +01:00
|
|
|
connect(m_toolsClient, &BaseToolsClient::currentObjectsChanged,
|
|
|
|
|
this, &QmlInspectorAgent::selectObjectsFromToolsClient);
|
|
|
|
|
connect(m_toolsClient, &BaseToolsClient::logActivity,
|
|
|
|
|
m_qmlEngine.data(), &QmlEngine::logServiceActivity);
|
|
|
|
|
connect(m_toolsClient, &BaseToolsClient::reloaded,
|
|
|
|
|
this, &QmlInspectorAgent::onReloaded);
|
2015-08-26 11:51:56 +02:00
|
|
|
|
|
|
|
|
// toolbar
|
2018-10-07 22:38:47 +03:00
|
|
|
m_selectAction->setObjectName("QML Select Action");
|
2015-08-26 11:51:56 +02:00
|
|
|
m_selectAction->setCheckable(true);
|
|
|
|
|
m_showAppOnTopAction->setCheckable(true);
|
2018-11-15 13:33:45 +01:00
|
|
|
enableTools(m_toolsClient->state() == QmlDebugClient::Enabled);
|
2015-08-26 11:51:56 +02:00
|
|
|
|
|
|
|
|
connect(m_selectAction, &QAction::triggered,
|
|
|
|
|
this, &QmlInspectorAgent::onSelectActionTriggered);
|
|
|
|
|
connect(m_showAppOnTopAction, &QAction::triggered,
|
|
|
|
|
this, &QmlInspectorAgent::onShowAppOnTopChanged);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
int QmlInspectorAgent::engineId(const WatchItem *data) const
|
|
|
|
|
{
|
|
|
|
|
int id = -1;
|
|
|
|
|
for (; data; data = data->parent())
|
|
|
|
|
id = data->id >= 0 ? data->id : id;
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quint32 QmlInspectorAgent::queryExpressionResult(int debugId, const QString &expression,
|
|
|
|
|
int engineId)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2018-11-15 17:14:48 +01:00
|
|
|
qCDebug(qmlInspectorLog)
|
|
|
|
|
<< __FUNCTION__ << '(' << debugId << expression << engineId << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
return m_engineClient->queryExpressionResult(debugId, expression, engineId);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
void QmlInspectorAgent::assignValue(const WatchItem *data,
|
2012-05-23 14:55:48 +02:00
|
|
|
const QString &expr, const QVariant &valueV)
|
|
|
|
|
{
|
2018-11-15 13:33:45 +01:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << data->id << ')' << data->iname;
|
2012-05-23 14:55:48 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (data->id != WatchItem::InvalidId) {
|
2012-05-23 14:55:48 +02:00
|
|
|
QString val(valueV.toString());
|
2016-06-07 17:04:53 +02:00
|
|
|
QString expression = QString("%1 = %2;").arg(expr).arg(val);
|
2018-11-15 17:14:48 +01:00
|
|
|
queryExpressionResult(data->id, expression, engineId(data));
|
2012-05-23 14:55:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
void QmlInspectorAgent::updateWatchData(const WatchItem &data)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << data.id << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (data.id != WatchItem::InvalidId && !m_fetchDataIds.contains(data.id)) {
|
2012-04-18 14:20:54 +02:00
|
|
|
// objects
|
2012-05-18 02:28:41 +02:00
|
|
|
m_fetchDataIds << data.id;
|
2012-05-14 23:26:23 +02:00
|
|
|
fetchObject(data.id);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 13:33:45 +01:00
|
|
|
void QmlInspectorAgent::watchDataSelected(int id)
|
2012-11-23 13:35:44 +01:00
|
|
|
{
|
2015-03-19 12:42:53 +01:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << id << ')';
|
2012-11-23 13:35:44 +01:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (id != WatchItem::InvalidId) {
|
2015-03-19 12:42:53 +01:00
|
|
|
QTC_ASSERT(m_debugIdLocations.keys().contains(id), return);
|
2018-11-15 13:33:45 +01:00
|
|
|
jumpToObjectDefinitionInEditor(m_debugIdLocations.value(id));
|
|
|
|
|
m_toolsClient->selectObjects({id});
|
2012-11-23 13:35:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 16:42:25 +01:00
|
|
|
void QmlInspectorAgent::selectObjectsInTree(const QList<int> &debugIds)
|
|
|
|
|
{
|
|
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugIds << ')';
|
|
|
|
|
|
|
|
|
|
for (int debugId : debugIds) {
|
|
|
|
|
if (m_debugIdToIname.contains(debugId)) {
|
|
|
|
|
const QString iname = m_debugIdToIname.value(debugId);
|
|
|
|
|
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
|
|
|
|
|
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-11-15 16:42:25 +01:00
|
|
|
// We can't multi-select in the watch handler for now ...
|
|
|
|
|
m_qmlEngine->watchHandler()->setCurrentItem(iname);
|
|
|
|
|
m_objectsToSelect.removeOne(debugId);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we may have to fetch it
|
|
|
|
|
m_objectsToSelect.append(debugId);
|
|
|
|
|
fetchObject(debugId);
|
|
|
|
|
}
|
2012-05-25 17:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-26 11:51:56 +02:00
|
|
|
void QmlInspectorAgent::addObjectWatch(int objectDebugId)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << objectDebugId << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (objectDebugId == WatchItem::InvalidId)
|
2015-08-26 11:51:56 +02:00
|
|
|
return;
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
|
2015-08-26 11:51:56 +02:00
|
|
|
return;
|
2012-04-18 14:20:54 +02:00
|
|
|
|
|
|
|
|
// already set
|
|
|
|
|
if (m_objectWatches.contains(objectDebugId))
|
2015-08-26 11:51:56 +02:00
|
|
|
return;
|
2012-04-18 14:20:54 +02:00
|
|
|
|
|
|
|
|
// is flooding the debugging output log!
|
2012-11-26 20:43:43 +02:00
|
|
|
// log(LogSend, QString::fromLatin1("WATCH_PROPERTY %1").arg(objectDebugId));
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2012-05-14 23:26:23 +02:00
|
|
|
if (m_engineClient->addWatch(objectDebugId))
|
2012-04-18 14:20:54 +02:00
|
|
|
m_objectWatches.append(objectDebugId);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 16:11:43 +02:00
|
|
|
void QmlInspectorAgent::updateState()
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2018-11-15 13:33:45 +01:00
|
|
|
m_qmlEngine->logServiceStateChange(m_engineClient->name(), m_engineClient->serviceVersion(),
|
|
|
|
|
m_engineClient->state());
|
|
|
|
|
|
|
|
|
|
if (m_engineClient->state() == QmlDebugClient::Enabled && boolSetting(ShowQmlObjectTree))
|
2012-04-18 14:20:54 +02:00
|
|
|
reloadEngines();
|
2018-11-15 13:33:45 +01:00
|
|
|
else
|
2012-05-14 23:26:23 +02:00
|
|
|
clearObjectTree();
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
|
|
|
|
|
const QByteArray &type)
|
|
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "() ...";
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2012-08-22 11:58:33 +02:00
|
|
|
if (type == "FETCH_OBJECT_R") {
|
2016-06-07 17:04:53 +02:00
|
|
|
log(LogReceive, QString("FETCH_OBJECT_R %1").arg(
|
2012-05-10 10:29:11 +02:00
|
|
|
qvariant_cast<ObjectReference>(value).idString()));
|
2012-08-22 11:58:33 +02:00
|
|
|
} else if (type == "SET_BINDING_R"
|
|
|
|
|
|| type == "RESET_BINDING_R"
|
|
|
|
|
|| type == "SET_METHOD_BODY_R") {
|
2015-08-26 11:51:56 +02:00
|
|
|
// FIXME: This is not supported anymore.
|
2018-10-07 22:38:47 +03:00
|
|
|
QString msg = type + tr("Success:");
|
|
|
|
|
msg += ' ';
|
|
|
|
|
msg += value.toBool() ? '1' : '0';
|
2015-08-26 11:51:56 +02:00
|
|
|
// if (!value.toBool())
|
|
|
|
|
// emit automaticUpdateFailed();
|
2012-06-04 17:17:50 +02:00
|
|
|
log(LogReceive, msg);
|
2012-04-18 14:20:54 +02:00
|
|
|
} else {
|
|
|
|
|
log(LogReceive, QLatin1String(type));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_objectTreeQueryIds.contains(queryId)) {
|
2012-11-23 17:15:29 +01:00
|
|
|
m_objectTreeQueryIds.removeOne(queryId);
|
2012-05-10 17:06:29 +02:00
|
|
|
if (value.type() == QVariant::List) {
|
2018-05-30 15:42:51 +02:00
|
|
|
const QVariantList objList = value.toList();
|
|
|
|
|
for (const QVariant &var : objList) {
|
2012-05-10 17:06:29 +02:00
|
|
|
// TODO: check which among the list is the actual
|
|
|
|
|
// object that needs to be selected.
|
2012-11-23 17:15:29 +01:00
|
|
|
verifyAndInsertObjectInTree(qvariant_cast<ObjectReference>(var));
|
2012-05-10 17:06:29 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2012-11-23 17:15:29 +01:00
|
|
|
verifyAndInsertObjectInTree(qvariant_cast<ObjectReference>(value));
|
2012-05-10 17:06:29 +02:00
|
|
|
}
|
2012-05-14 23:26:23 +02:00
|
|
|
} else if (queryId == m_engineQueryId) {
|
|
|
|
|
m_engineQueryId = 0;
|
|
|
|
|
QList<EngineReference> engines = qvariant_cast<QList<EngineReference> >(value);
|
|
|
|
|
QTC_ASSERT(engines.count(), return);
|
2018-11-15 17:14:48 +01:00
|
|
|
m_engines = engines;
|
2012-05-14 23:26:23 +02:00
|
|
|
queryEngineContext();
|
2012-04-18 14:20:54 +02:00
|
|
|
} else {
|
2018-11-15 17:14:48 +01:00
|
|
|
int index = m_rootContextQueryIds.indexOf(queryId);
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
m_qmlEngine->expressionEvaluated(queryId, value);
|
|
|
|
|
} else {
|
|
|
|
|
Q_ASSERT(index < m_engines.length());
|
|
|
|
|
const int engineId = m_engines.at(index).debugId();
|
|
|
|
|
m_rootContexts.insert(engineId, qvariant_cast<ContextReference>(value));
|
|
|
|
|
if (m_rootContexts.size() == m_engines.size()) {
|
|
|
|
|
clearObjectTree();
|
|
|
|
|
for (const auto &engine : m_engines) {
|
|
|
|
|
QString name = engine.name();
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = QString::fromLatin1("Engine %1").arg(engine.debugId());
|
2018-11-22 12:12:43 +01:00
|
|
|
verifyAndInsertObjectInTree(ObjectReference(engine.debugId(), name),
|
|
|
|
|
engine.debugId());
|
2018-11-15 17:14:48 +01:00
|
|
|
updateObjectTree(m_rootContexts[engine.debugId()], engine.debugId());
|
|
|
|
|
}
|
|
|
|
|
m_rootContextQueryIds.clear();
|
|
|
|
|
m_rootContexts.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "done";
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-11 16:49:45 +02:00
|
|
|
void QmlInspectorAgent::newObject(int engineId, int /*objectId*/, int /*parentId*/)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "()";
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-10-07 22:38:47 +03:00
|
|
|
log(LogReceive, "OBJECT_CREATED");
|
2012-05-14 23:26:23 +02:00
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
for (const auto &engine : qAsConst(m_engines)) {
|
|
|
|
|
if (engine.debugId() == engineId) {
|
|
|
|
|
m_delayQueryTimer.start();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-25 17:09:46 +02:00
|
|
|
static void sortChildrenIfNecessary(WatchItem *propertiesWatch)
|
|
|
|
|
{
|
|
|
|
|
if (boolSetting(SortStructMembers)) {
|
|
|
|
|
propertiesWatch->sortChildren([](const WatchItem *item1, const WatchItem *item2) {
|
|
|
|
|
return item1->name < item2->name;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool insertChildren(WatchItem *parent, const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
switch (value.type()) {
|
|
|
|
|
case QVariant::Map: {
|
|
|
|
|
const QVariantMap map = value.toMap();
|
|
|
|
|
for (auto it = map.begin(), end = map.end(); it != end; ++it) {
|
2018-07-23 22:28:49 +02:00
|
|
|
auto child = new WatchItem;
|
2018-05-25 17:09:46 +02:00
|
|
|
child->name = it.key();
|
|
|
|
|
child->value = it.value().toString();
|
|
|
|
|
child->type = QLatin1String(it.value().typeName());
|
|
|
|
|
child->valueEditable = false;
|
|
|
|
|
child->wantsChildren = insertChildren(child, it.value());
|
|
|
|
|
parent->appendChild(child);
|
|
|
|
|
}
|
|
|
|
|
sortChildrenIfNecessary(parent);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case QVariant::List: {
|
|
|
|
|
const QVariantList list = value.toList();
|
|
|
|
|
for (int i = 0, end = list.size(); i != end; ++i) {
|
2018-07-23 22:28:49 +02:00
|
|
|
auto child = new WatchItem;
|
2018-05-25 17:09:46 +02:00
|
|
|
const QVariant &value = list.at(i);
|
|
|
|
|
child->arrayIndex = i;
|
|
|
|
|
child->value = value.toString();
|
|
|
|
|
child->type = QLatin1String(value.typeName());
|
|
|
|
|
child->valueEditable = false;
|
|
|
|
|
child->wantsChildren = insertChildren(child, value);
|
|
|
|
|
parent->appendChild(child);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-23 14:55:48 +02:00
|
|
|
void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyName,
|
|
|
|
|
const QVariant &value)
|
|
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString iname = m_debugIdToIname.value(debugId) +
|
2016-06-09 11:42:37 +02:00
|
|
|
".[properties]." + QString::fromLatin1(propertyName);
|
2015-08-26 11:51:56 +02:00
|
|
|
WatchHandler *watchHandler = m_qmlEngine->watchHandler();
|
2018-11-15 13:33:45 +01:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')' << iname << value.toString();
|
2015-03-19 12:42:53 +01:00
|
|
|
if (WatchItem *item = watchHandler->findItem(iname)) {
|
|
|
|
|
item->value = value.toString();
|
2018-05-25 17:09:46 +02:00
|
|
|
item->removeChildren();
|
|
|
|
|
item->wantsChildren = insertChildren(item, value);
|
2015-03-19 12:42:53 +01:00
|
|
|
item->update();
|
2012-05-23 14:55:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
void QmlInspectorAgent::reloadEngines()
|
|
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "()";
|
2012-04-18 14:20:54 +02:00
|
|
|
|
|
|
|
|
if (!isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
log(LogSend, "LIST_ENGINES");
|
2012-04-18 14:20:54 +02:00
|
|
|
|
|
|
|
|
m_engineQueryId = m_engineClient->queryAvailableEngines();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-14 23:26:23 +02:00
|
|
|
void QmlInspectorAgent::queryEngineContext()
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__;
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
|
2012-04-18 14:20:54 +02:00
|
|
|
return;
|
|
|
|
|
|
2018-10-07 22:38:47 +03:00
|
|
|
log(LogSend, "LIST_OBJECTS");
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
for (const auto &engine : qAsConst(m_engines))
|
|
|
|
|
m_rootContextQueryIds.append(m_engineClient->queryRootContexts(engine));
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-14 23:26:23 +02:00
|
|
|
void QmlInspectorAgent::fetchObject(int debugId)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
|
2012-05-14 23:26:23 +02:00
|
|
|
return;
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-10-07 22:38:47 +03:00
|
|
|
log(LogSend, "FETCH_OBJECT " + QString::number(debugId));
|
2012-05-14 23:26:23 +02:00
|
|
|
quint32 queryId = m_engineClient->queryObject(debugId);
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')'
|
|
|
|
|
<< " - query id" << queryId;
|
2012-05-14 23:26:23 +02:00
|
|
|
m_objectTreeQueryIds << queryId;
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
void QmlInspectorAgent::updateObjectTree(const ContextReference &context, int engineId)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << context << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
|
2012-04-18 14:20:54 +02:00
|
|
|
return;
|
|
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
for (const ObjectReference &obj : context.objects())
|
|
|
|
|
verifyAndInsertObjectInTree(obj, engineId);
|
2012-10-01 17:13:21 +02:00
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
for (const ContextReference &child : context.contexts())
|
|
|
|
|
updateObjectTree(child, engineId);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 17:14:48 +01:00
|
|
|
void QmlInspectorAgent::verifyAndInsertObjectInTree(const ObjectReference &object, int engineId)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << object << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2012-05-14 23:26:23 +02:00
|
|
|
if (!object.isValid())
|
|
|
|
|
return;
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2012-11-23 17:15:29 +01:00
|
|
|
// Find out the correct position in the tree
|
|
|
|
|
// Objects are inserted to the tree if they satisfy one of the two conditions.
|
2015-12-16 17:17:38 +01:00
|
|
|
// Condition 1: Object is a root object i.e. parentId == WatchItem::InvalidId.
|
2012-11-23 17:15:29 +01:00
|
|
|
// Condition 2: Object has an expanded parent i.e. siblings are known.
|
|
|
|
|
// If the two conditions are not met then we push the object to a stack and recursively
|
|
|
|
|
// fetch parents till we find a previously expanded parent.
|
|
|
|
|
|
2015-08-26 11:51:56 +02:00
|
|
|
WatchHandler *handler = m_qmlEngine->watchHandler();
|
2012-11-23 17:15:29 +01:00
|
|
|
const int objectDebugId = object.debugId();
|
2018-11-22 12:12:43 +01:00
|
|
|
int parentId = object.parentId();
|
|
|
|
|
|
|
|
|
|
if (engineId == -1) {
|
|
|
|
|
// Find engineId if missing.
|
|
|
|
|
const auto it = m_debugIdToIname.find(objectDebugId);
|
|
|
|
|
if (it != m_debugIdToIname.end()) {
|
|
|
|
|
const QString iname = *it;
|
|
|
|
|
const int firstIndex = strlen("inspect");
|
|
|
|
|
const int secondIndex = iname.indexOf('.', firstIndex + 1);
|
|
|
|
|
if (secondIndex != -1)
|
|
|
|
|
engineId = iname.mid(firstIndex + 1, secondIndex - firstIndex - 1).toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Still not found? Maybe we're loading the engine itself.
|
|
|
|
|
if (engineId == -1) {
|
|
|
|
|
for (const auto &engine : m_engines) {
|
|
|
|
|
if (engine.debugId() == objectDebugId) {
|
|
|
|
|
engineId = engine.debugId();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (objectDebugId == engineId) {
|
|
|
|
|
// Don't load an engine's parent
|
|
|
|
|
parentId = -1;
|
|
|
|
|
} else if (parentId == -1) {
|
|
|
|
|
// Find parentId if missing
|
|
|
|
|
const auto it = m_debugIdToIname.find(objectDebugId);
|
|
|
|
|
if (it != m_debugIdToIname.end()) {
|
|
|
|
|
const QString iname = *it;
|
|
|
|
|
int lastIndex = iname.lastIndexOf('.');
|
|
|
|
|
int secondLastIndex = iname.lastIndexOf('.', lastIndex - 1);
|
|
|
|
|
if (secondLastIndex != WatchItem::InvalidId)
|
|
|
|
|
parentId = iname.mid(secondLastIndex + 1, lastIndex - secondLastIndex - 1).toInt();
|
|
|
|
|
else
|
|
|
|
|
parentId = engineId;
|
|
|
|
|
} else {
|
|
|
|
|
parentId = engineId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-23 17:15:29 +01:00
|
|
|
if (m_debugIdToIname.contains(parentId)) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString parentIname = m_debugIdToIname.value(parentId);
|
2018-11-22 12:12:43 +01:00
|
|
|
if (parentId != WatchItem::InvalidId && parentId != engineId
|
|
|
|
|
&& !handler->isExpandedIName(parentIname)) {
|
2018-11-15 17:14:48 +01:00
|
|
|
m_objectStack.push(QPair<ObjectReference, int>(object, engineId));
|
2014-06-02 10:43:26 +02:00
|
|
|
handler->fetchMore(parentIname);
|
2012-11-23 17:15:29 +01:00
|
|
|
return; // recursive
|
|
|
|
|
}
|
2018-11-22 12:12:43 +01:00
|
|
|
insertObjectInTree(object, parentId);
|
2012-05-29 22:21:04 +02:00
|
|
|
|
2012-11-23 17:15:29 +01:00
|
|
|
} else {
|
2018-11-15 17:14:48 +01:00
|
|
|
m_objectStack.push(QPair<ObjectReference, int>(object, engineId));
|
2012-11-23 17:15:29 +01:00
|
|
|
fetchObject(parentId);
|
|
|
|
|
return; // recursive
|
|
|
|
|
}
|
|
|
|
|
if (!m_objectStack.isEmpty()) {
|
2018-11-15 17:14:48 +01:00
|
|
|
const auto &top = m_objectStack.top();
|
2012-11-23 17:15:29 +01:00
|
|
|
// We want to expand only a particular branch and not the whole tree. Hence, we do not
|
2018-11-15 17:14:48 +01:00
|
|
|
// expand siblings. If this is the engine, we add add root objects with the same engine ID
|
|
|
|
|
// as children.
|
2018-11-22 12:12:43 +01:00
|
|
|
if (object.children().contains(top.first)
|
|
|
|
|
|| (top.first.parentId() == objectDebugId)
|
|
|
|
|
|| (top.first.parentId() < 0 && objectDebugId == top.second)) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString objectIname = m_debugIdToIname.value(objectDebugId);
|
2012-11-23 17:15:29 +01:00
|
|
|
if (!handler->isExpandedIName(objectIname)) {
|
2014-06-02 10:43:26 +02:00
|
|
|
handler->fetchMore(objectIname);
|
2012-11-23 17:15:29 +01:00
|
|
|
} else {
|
2018-11-15 17:14:48 +01:00
|
|
|
verifyAndInsertObjectInTree(top.first, top.second);
|
|
|
|
|
m_objectStack.pop();
|
2012-11-23 17:15:29 +01:00
|
|
|
return; // recursive
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 12:12:43 +01:00
|
|
|
void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object, int parentId)
|
2012-11-23 17:15:29 +01:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << object << ')';
|
2012-05-29 22:21:04 +02:00
|
|
|
|
2012-11-23 17:15:29 +01:00
|
|
|
QElapsedTimer timeElapsed;
|
2014-07-14 14:45:51 +02:00
|
|
|
|
|
|
|
|
bool printTime = qmlInspectorLog().isDebugEnabled();
|
|
|
|
|
if (printTime)
|
2012-10-11 16:49:45 +02:00
|
|
|
timeElapsed.start();
|
2015-03-18 17:23:35 +01:00
|
|
|
addWatchData(object, m_debugIdToIname.value(parentId), true);
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Build Watch Data took "
|
|
|
|
|
<< timeElapsed.elapsed() << " ms";
|
|
|
|
|
if (printTime)
|
2012-10-11 16:49:45 +02:00
|
|
|
timeElapsed.start();
|
|
|
|
|
buildDebugIdHashRecursive(object);
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Build Debug Id Hash took "
|
|
|
|
|
<< timeElapsed.elapsed() << " ms";
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2014-07-14 14:45:51 +02:00
|
|
|
if (printTime)
|
2012-05-29 22:21:04 +02:00
|
|
|
timeElapsed.start();
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took "
|
|
|
|
|
<< timeElapsed.elapsed() << " ms";
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2018-11-15 16:42:25 +01:00
|
|
|
for (auto it = m_objectsToSelect.begin(); it != m_objectsToSelect.end();) {
|
|
|
|
|
if (m_debugIdToIname.contains(*it)) {
|
|
|
|
|
// select item in view
|
|
|
|
|
QString iname = m_debugIdToIname.value(*it);
|
|
|
|
|
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
|
|
|
|
|
m_qmlEngine->watchHandler()->setCurrentItem(iname);
|
|
|
|
|
it = m_objectsToSelect.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
2017-10-26 16:32:48 +02:00
|
|
|
m_qmlEngine->watchHandler()->updateLocalsWindow();
|
2015-08-26 11:51:56 +02:00
|
|
|
m_qmlEngine->watchHandler()->reexpandItems();
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << ref << ')';
|
2012-04-18 14:20:54 +02:00
|
|
|
|
|
|
|
|
QUrl fileUrl = ref.source().url();
|
|
|
|
|
int lineNum = ref.source().lineNumber();
|
|
|
|
|
int colNum = ref.source().columnNumber();
|
|
|
|
|
|
|
|
|
|
// handle the case where the url contains the revision number encoded.
|
2018-11-15 13:33:45 +01:00
|
|
|
// (for object created by the debugger)
|
2018-10-07 22:38:47 +03:00
|
|
|
static QRegExp rx("(.*)_(\\d+):(\\d+)$");
|
2012-04-18 14:20:54 +02:00
|
|
|
if (rx.exactMatch(fileUrl.path())) {
|
|
|
|
|
fileUrl.setPath(rx.cap(1));
|
|
|
|
|
lineNum += rx.cap(3).toInt() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 13:33:45 +01:00
|
|
|
const QString filePath = m_qmlEngine->toFileInProject(fileUrl);
|
2012-05-14 23:26:23 +02:00
|
|
|
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
|
2012-05-29 22:21:04 +02:00
|
|
|
|
2018-11-15 16:42:25 +01:00
|
|
|
const auto children = ref.children();
|
|
|
|
|
for (const ObjectReference &it : children)
|
2012-04-18 14:20:54 +02:00
|
|
|
buildDebugIdHashRecursive(it);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QString buildIName(const QString &parentIname, int debugId)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2012-05-14 23:26:23 +02:00
|
|
|
if (parentIname.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
return "inspect." + QString::number(debugId);
|
|
|
|
|
return parentIname + "." + QString::number(debugId);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QString buildIName(const QString &parentIname, const QString &name)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
return parentIname + "." + name;
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-18 17:23:35 +01:00
|
|
|
void QmlInspectorAgent::addWatchData(const ObjectReference &obj,
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString &parentIname,
|
2015-03-18 17:23:35 +01:00
|
|
|
bool append)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2014-07-14 14:45:51 +02:00
|
|
|
qCDebug(qmlInspectorLog) << '(' << obj << parentIname << ')';
|
2015-09-01 12:57:51 +02:00
|
|
|
QTC_ASSERT(m_qmlEngine, return);
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2012-05-29 22:21:04 +02:00
|
|
|
int objDebugId = obj.debugId();
|
2016-06-07 17:04:53 +02:00
|
|
|
QString objIname = buildIName(parentIname, objDebugId);
|
2012-05-29 22:21:04 +02:00
|
|
|
|
|
|
|
|
if (append) {
|
|
|
|
|
QString name = obj.idString();
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = obj.className();
|
|
|
|
|
|
|
|
|
|
if (name.isEmpty())
|
2017-03-14 19:00:36 +01:00
|
|
|
name = obj.name();
|
|
|
|
|
|
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
|
FileReference file = obj.source();
|
|
|
|
|
name = file.url().fileName() + ':' + QString::number(file.lineNumber());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = tr("<anonymous>");
|
2012-05-29 22:21:04 +02:00
|
|
|
|
|
|
|
|
// object
|
2015-12-16 17:17:38 +01:00
|
|
|
auto objWatch = new WatchItem;
|
|
|
|
|
objWatch->iname = objIname;
|
|
|
|
|
objWatch->name = name;
|
2015-03-19 12:42:53 +01:00
|
|
|
objWatch->id = objDebugId;
|
2016-06-07 17:04:53 +02:00
|
|
|
objWatch->exp = name;
|
|
|
|
|
objWatch->type = obj.className();
|
|
|
|
|
objWatch->value = "object";
|
2015-03-19 12:42:53 +01:00
|
|
|
objWatch->wantsChildren = true;
|
|
|
|
|
|
2015-08-26 11:51:56 +02:00
|
|
|
m_qmlEngine->watchHandler()->insertItem(objWatch);
|
2015-03-19 12:42:53 +01:00
|
|
|
addObjectWatch(objWatch->id);
|
2012-10-11 16:49:45 +02:00
|
|
|
if (m_debugIdToIname.contains(objDebugId)) {
|
|
|
|
|
// The data needs to be removed since we now know the parent and
|
|
|
|
|
// hence we can insert the data in the correct position
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString oldIname = m_debugIdToIname.value(objDebugId);
|
2012-10-11 16:49:45 +02:00
|
|
|
if (oldIname != objIname)
|
2015-08-26 11:51:56 +02:00
|
|
|
m_qmlEngine->watchHandler()->removeItemByIName(oldIname);
|
2012-10-11 16:49:45 +02:00
|
|
|
}
|
2012-10-05 12:46:30 +02:00
|
|
|
m_debugIdToIname.insert(objDebugId, objIname);
|
2012-05-14 23:26:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-26 11:51:56 +02:00
|
|
|
if (!m_qmlEngine->watchHandler()->isExpandedIName(objIname)) {
|
2012-05-11 14:00:17 +02:00
|
|
|
// we don't know the children yet. Not adding the 'properties'
|
|
|
|
|
// element makes sure we're queried on expansion.
|
2012-05-31 15:50:06 +02:00
|
|
|
if (obj.needsMoreData())
|
2015-03-18 17:23:35 +01:00
|
|
|
return;
|
2012-05-11 14:00:17 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
// properties
|
2012-05-29 22:21:04 +02:00
|
|
|
if (append && obj.properties().count()) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString iname = objIname + ".[properties]";
|
2015-12-16 17:17:38 +01:00
|
|
|
auto propertiesWatch = new WatchItem;
|
|
|
|
|
propertiesWatch->iname = iname;
|
|
|
|
|
propertiesWatch->name = tr("Properties");
|
2015-03-19 12:42:53 +01:00
|
|
|
propertiesWatch->id = objDebugId;
|
2016-06-07 17:04:53 +02:00
|
|
|
propertiesWatch->value = "list";
|
2015-03-19 12:42:53 +01:00
|
|
|
propertiesWatch->wantsChildren = true;
|
2012-05-14 23:26:23 +02:00
|
|
|
|
|
|
|
|
foreach (const PropertyReference &property, obj.properties()) {
|
2013-04-25 10:50:35 +02:00
|
|
|
const QString propertyName = property.name();
|
|
|
|
|
if (propertyName.isEmpty())
|
|
|
|
|
continue;
|
2015-12-16 17:17:38 +01:00
|
|
|
auto propertyWatch = new WatchItem;
|
|
|
|
|
propertyWatch->iname = buildIName(iname, propertyName);
|
|
|
|
|
propertyWatch->name = propertyName;
|
2015-03-19 12:42:53 +01:00
|
|
|
propertyWatch->id = objDebugId;
|
2016-06-07 17:04:53 +02:00
|
|
|
propertyWatch->exp = propertyName;
|
|
|
|
|
propertyWatch->type = property.valueTypeName();
|
2015-03-19 12:42:53 +01:00
|
|
|
propertyWatch->value = property.value().toString();
|
2018-05-25 17:09:46 +02:00
|
|
|
propertyWatch->wantsChildren = insertChildren(propertyWatch, property.value());
|
2015-03-19 10:30:50 +01:00
|
|
|
propertiesWatch->appendChild(propertyWatch);
|
2012-05-14 23:26:23 +02:00
|
|
|
}
|
2015-03-19 10:30:50 +01:00
|
|
|
|
2018-05-25 17:09:46 +02:00
|
|
|
sortChildrenIfNecessary(propertiesWatch);
|
2015-08-26 11:51:56 +02:00
|
|
|
m_qmlEngine->watchHandler()->insertItem(propertiesWatch);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// recurse
|
2012-05-10 10:29:11 +02:00
|
|
|
foreach (const ObjectReference &child, obj.children())
|
2015-03-18 17:23:35 +01:00
|
|
|
addWatchData(child, objIname, append);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::log(QmlInspectorAgent::LogDirection direction,
|
|
|
|
|
const QString &message)
|
|
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
QString msg = "Inspector";
|
2012-04-18 14:20:54 +02:00
|
|
|
if (direction == LogSend)
|
2016-06-07 17:04:53 +02:00
|
|
|
msg += " sending ";
|
2012-04-18 14:20:54 +02:00
|
|
|
else
|
2016-06-07 17:04:53 +02:00
|
|
|
msg += " receiving ";
|
2012-04-18 14:20:54 +02:00
|
|
|
msg += message;
|
|
|
|
|
|
2015-08-26 11:51:56 +02:00
|
|
|
if (m_qmlEngine)
|
|
|
|
|
m_qmlEngine->showMessage(msg, LogDebug);
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-14 23:26:23 +02:00
|
|
|
bool QmlInspectorAgent::isConnected() const
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2018-11-15 13:33:45 +01:00
|
|
|
return m_engineClient->state() == QmlDebugClient::Enabled;
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-14 23:26:23 +02:00
|
|
|
void QmlInspectorAgent::clearObjectTree()
|
|
|
|
|
{
|
2015-09-01 12:57:51 +02:00
|
|
|
if (m_qmlEngine)
|
|
|
|
|
m_qmlEngine->watchHandler()->removeAllData(true);
|
2012-05-14 23:26:23 +02:00
|
|
|
m_objectTreeQueryIds.clear();
|
2012-10-01 17:13:21 +02:00
|
|
|
m_fetchDataIds.clear();
|
2012-05-14 23:26:23 +02:00
|
|
|
m_debugIdToIname.clear();
|
2016-06-07 17:04:53 +02:00
|
|
|
m_debugIdToIname.insert(WatchItem::InvalidId, "inspect");
|
2012-05-14 23:26:23 +02:00
|
|
|
m_objectStack.clear();
|
2015-08-26 11:51:56 +02:00
|
|
|
m_objectWatches.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::toolsClientStateChanged(QmlDebugClient::State state)
|
|
|
|
|
{
|
2018-11-15 13:33:45 +01:00
|
|
|
QTC_ASSERT(m_toolsClient, return);
|
|
|
|
|
m_qmlEngine->logServiceStateChange(m_toolsClient->name(), m_toolsClient->serviceVersion(),
|
|
|
|
|
state);
|
2015-08-26 11:51:56 +02:00
|
|
|
if (state == QmlDebugClient::Enabled) {
|
2018-11-15 13:33:45 +01:00
|
|
|
Core::ICore::addAdditionalContext(m_inspectorToolsContext);
|
2015-08-26 11:51:56 +02:00
|
|
|
Core::ActionManager::registerAction(m_selectAction,
|
|
|
|
|
Core::Id(Constants::QML_SELECTTOOL),
|
|
|
|
|
m_inspectorToolsContext);
|
|
|
|
|
Core::ActionManager::registerAction(m_showAppOnTopAction,
|
|
|
|
|
Core::Id(Constants::QML_SHOW_APP_ON_TOP),
|
|
|
|
|
m_inspectorToolsContext);
|
|
|
|
|
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
enableTools(m_qmlEngine->state() == InferiorRunOk);
|
2015-08-26 11:51:56 +02:00
|
|
|
if (m_showAppOnTopAction->isChecked())
|
|
|
|
|
m_toolsClient->showAppOnTop(true);
|
2018-11-15 13:33:45 +01:00
|
|
|
} else {
|
|
|
|
|
enableTools(false);
|
2015-08-26 11:51:56 +02:00
|
|
|
|
|
|
|
|
Core::ActionManager::unregisterAction(m_selectAction, Core::Id(Constants::QML_SELECTTOOL));
|
|
|
|
|
Core::ActionManager::unregisterAction(m_showAppOnTopAction,
|
|
|
|
|
Core::Id(Constants::QML_SHOW_APP_ON_TOP));
|
|
|
|
|
Core::ICore::removeAdditionalContext(m_inspectorToolsContext);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::selectObjectsFromToolsClient(const QList<int> &debugIds)
|
|
|
|
|
{
|
2018-11-15 16:42:25 +01:00
|
|
|
if (!debugIds.isEmpty())
|
|
|
|
|
selectObjects(debugIds, m_debugIdLocations.value(debugIds.first()));
|
2015-08-26 11:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::onSelectActionTriggered(bool checked)
|
|
|
|
|
{
|
2016-08-04 00:19:05 +02:00
|
|
|
QTC_ASSERT(m_toolsClient, return);
|
2015-08-26 11:51:56 +02:00
|
|
|
if (checked) {
|
2016-08-04 00:19:05 +02:00
|
|
|
m_toolsClient->setDesignModeBehavior(true);
|
|
|
|
|
m_toolsClient->changeToSelectTool();
|
2015-08-26 11:51:56 +02:00
|
|
|
} else {
|
2016-08-04 00:19:05 +02:00
|
|
|
m_toolsClient->setDesignModeBehavior(false);
|
2015-08-26 11:51:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::onShowAppOnTopChanged(bool checked)
|
|
|
|
|
{
|
2016-08-04 00:19:05 +02:00
|
|
|
QTC_ASSERT(m_toolsClient, return);
|
|
|
|
|
m_toolsClient->showAppOnTop(checked);
|
2015-08-26 11:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 13:33:45 +01:00
|
|
|
void QmlInspectorAgent::jumpToObjectDefinitionInEditor(const FileReference &objSource)
|
2015-08-26 11:51:56 +02:00
|
|
|
{
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
const QString fileName = m_qmlEngine->toFileInProject(objSource.url());
|
2015-08-26 11:51:56 +02:00
|
|
|
Core::EditorManager::openEditorAt(fileName, objSource.lineNumber());
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 16:42:25 +01:00
|
|
|
void QmlInspectorAgent::selectObjects(const QList<int> &debugIds,
|
|
|
|
|
const QmlDebug::FileReference &source)
|
2015-08-26 11:51:56 +02:00
|
|
|
{
|
2018-11-15 16:42:25 +01:00
|
|
|
jumpToObjectDefinitionInEditor(source);
|
|
|
|
|
selectObjectsInTree(debugIds);
|
2015-08-26 11:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::enableTools(const bool enable)
|
|
|
|
|
{
|
|
|
|
|
m_selectAction->setEnabled(enable);
|
|
|
|
|
m_showAppOnTopAction->setEnabled(enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlInspectorAgent::onReloaded()
|
|
|
|
|
{
|
|
|
|
|
reloadEngines();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|