Debugger: Merge QmlInspectorAdapter into QmlInspectorAgent

There's a 1:1 relation, and the abstraction is not needed anymore.

Also remove some unused code.

Change-Id: I09a2522deb5d522f46ec7518d19978a038032fbb
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
This commit is contained in:
hjk
2015-08-26 11:51:56 +02:00
parent 5c815dea19
commit 156320ff6c
8 changed files with 406 additions and 819 deletions

View File

@@ -149,7 +149,6 @@ QtcPlugin {
"qmlcppengine.cpp", "qmlcppengine.h", "qmlcppengine.cpp", "qmlcppengine.h",
"qmlengine.cpp", "qmlengine.h", "qmlengine.cpp", "qmlengine.h",
"qmlengineutils.cpp", "qmlengineutils.h", "qmlengineutils.cpp", "qmlengineutils.h",
"qmlinspectoradapter.cpp", "qmlinspectoradapter.h",
"qmlinspectoragent.cpp", "qmlinspectoragent.h", "qmlinspectoragent.cpp", "qmlinspectoragent.h",
"qmlv8debuggerclientconstants.h" "qmlv8debuggerclientconstants.h"
] ]

View File

@@ -4,13 +4,11 @@ HEADERS += \
$$PWD/qmlcppengine.h \ $$PWD/qmlcppengine.h \
$$PWD/interactiveinterpreter.h \ $$PWD/interactiveinterpreter.h \
$$PWD/qmlv8debuggerclientconstants.h \ $$PWD/qmlv8debuggerclientconstants.h \
$$PWD/qmlinspectoragent.h \ $$PWD/qmlinspectoragent.h
$$PWD/qmlinspectoradapter.h
SOURCES += \ SOURCES += \
$$PWD/qmlengine.cpp \ $$PWD/qmlengine.cpp \
$$PWD/qmlengineutils.cpp \ $$PWD/qmlengineutils.cpp \
$$PWD/qmlcppengine.cpp \ $$PWD/qmlcppengine.cpp \
$$PWD/interactiveinterpreter.cpp \ $$PWD/interactiveinterpreter.cpp \
$$PWD/qmlinspectoragent.cpp \ $$PWD/qmlinspectoragent.cpp
$$PWD/qmlinspectoradapter.cpp

View File

@@ -31,7 +31,6 @@
#include "qmlengine.h" #include "qmlengine.h"
#include "interactiveinterpreter.h" #include "interactiveinterpreter.h"
#include "qmlinspectoradapter.h"
#include "qmlinspectoragent.h" #include "qmlinspectoragent.h"
#include "qmlv8debuggerclientconstants.h" #include "qmlv8debuggerclientconstants.h"
#include "qmlengineutils.h" #include "qmlengineutils.h"
@@ -136,7 +135,7 @@ public:
QmlEnginePrivate(QmlEngine *engine_, QmlDebugConnection *connection_) QmlEnginePrivate(QmlEngine *engine_, QmlDebugConnection *connection_)
: QmlDebugClient(QLatin1String("V8Debugger"), connection_), : QmlDebugClient(QLatin1String("V8Debugger"), connection_),
engine(engine_), engine(engine_),
inspectorAdapter(engine, connection_), inspectorAgent(engine, connection_),
connection(connection_) connection(connection_)
{} {}
@@ -206,7 +205,7 @@ public:
QHash<QString, QWeakPointer<BaseTextEditor> > sourceEditors; QHash<QString, QWeakPointer<BaseTextEditor> > sourceEditors;
InteractiveInterpreter interpreter; InteractiveInterpreter interpreter;
ApplicationLauncher applicationLauncher; ApplicationLauncher applicationLauncher;
QmlInspectorAdapter inspectorAdapter; QmlInspectorAgent inspectorAgent;
QmlOutputParser outputParser; QmlOutputParser outputParser;
QTimer noDebugOutputTimer; QTimer noDebugOutputTimer;
@@ -254,8 +253,6 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
this, &QmlEngine::updateCurrentContext); this, &QmlEngine::updateCurrentContext);
connect(inspectorView(), SIGNAL(currentIndexChanged(QModelIndex)), connect(inspectorView(), SIGNAL(currentIndexChanged(QModelIndex)),
SLOT(updateCurrentContext())); SLOT(updateCurrentContext()));
connect(d->inspectorAdapter.agent(), &QmlInspectorAgent::expressionResult,
this, &QmlEngine::expressionEvaluated);
connect(&d->applicationLauncher, &ApplicationLauncher::processExited, connect(&d->applicationLauncher, &ApplicationLauncher::processExited,
this, &QmlEngine::disconnected); this, &QmlEngine::disconnected);
@@ -965,8 +962,8 @@ void QmlEngine::assignValueInDebugger(WatchItem *item,
const QString &expression, const QVariant &value) const QString &expression, const QVariant &value)
{ {
if (!expression.isEmpty()) { if (!expression.isEmpty()) {
if (item->isInspect() && d->inspectorAdapter.agent()) { if (item->isInspect()) {
d->inspectorAdapter.agent()->assignValue(item, expression, value); d->inspectorAgent.assignValue(item, expression, value);
} else { } else {
StackHandler *handler = stackHandler(); StackHandler *handler = stackHandler();
QString exp = QString(_("%1 = %2;")).arg(expression).arg(value.toString()); QString exp = QString(_("%1 = %2;")).arg(expression).arg(value.toString());
@@ -986,7 +983,7 @@ void QmlEngine::expandItem(const QByteArray &iname)
QTC_ASSERT(item, return); QTC_ASSERT(item, return);
if (item->isInspect()) { if (item->isInspect()) {
d->inspectorAdapter.agent()->updateWatchData(*item); d->inspectorAgent.updateWatchData(*item);
} else { } else {
LookupItems items; LookupItems items;
items.insert(int(item->id), {item->iname, item->name}); items.insert(int(item->id), {item->iname, item->name});
@@ -1013,7 +1010,7 @@ void QmlEngine::selectWatchData(const QByteArray &iname)
{ {
const WatchItem *item = watchHandler()->findItem(iname); const WatchItem *item = watchHandler()->findItem(iname);
if (item && item->isInspect()) if (item && item->isInspect())
d->inspectorAdapter.agent()->watchDataSelected(item->id); d->inspectorAgent.watchDataSelected(item->id);
} }
bool compareConsoleItems(const ConsoleItem *a, const ConsoleItem *b) bool compareConsoleItems(const ConsoleItem *a, const ConsoleItem *b)
@@ -1186,9 +1183,8 @@ bool QmlEngine::evaluateScript(const QString &expression)
// When engine->state() == InferiorStopOk, the expression is sent to debuggerClient. // When engine->state() == InferiorStopOk, the expression is sent to debuggerClient.
if (state() != InferiorStopOk) { if (state() != InferiorStopOk) {
QModelIndex currentIndex = inspectorView()->currentIndex(); QModelIndex currentIndex = inspectorView()->currentIndex();
QmlInspectorAgent *agent = d->inspectorAdapter.agent(); quint32 queryId = d->inspectorAgent.queryExpressionResult
quint32 queryId = agent->queryExpressionResult(watchHandler()->watchItem(currentIndex)->id, (watchHandler()->watchItem(currentIndex)->id, expression);
expression);
if (queryId) { if (queryId) {
d->queryIds.append(queryId); d->queryIds.append(queryId);
} else { } else {

View File

@@ -45,7 +45,7 @@ namespace Internal {
class WatchData; class WatchData;
class WatchItem; class WatchItem;
class QmlEnginePrivate; class QmlEnginePrivate;
class QmlAdapter; class QmlInspectorAgent;
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
{ {
@@ -62,10 +62,11 @@ public:
QmlDebug::QmlDebugClient::State newState); QmlDebug::QmlDebugClient::State newState);
void logServiceActivity(const QString &service, const QString &logMessage); void logServiceActivity(const QString &service, const QString &logMessage);
void expressionEvaluated(quint32 queryId, const QVariant &result);
private slots: private slots:
void disconnected(); void disconnected();
void documentUpdated(QmlJS::Document::Ptr doc); void documentUpdated(QmlJS::Document::Ptr doc);
void expressionEvaluated(quint32 queryId, const QVariant &result);
void errorMessageBoxFinished(int result); void errorMessageBoxFinished(int result);
void updateCurrentContext(); void updateCurrentContext();
@@ -153,6 +154,7 @@ private:
private: private:
friend class QmlCppEngine; friend class QmlCppEngine;
friend class QmlEnginePrivate; friend class QmlEnginePrivate;
friend class QmlInspectorAgent;
QmlEnginePrivate *d; QmlEnginePrivate *d;
}; };

View File

@@ -1,367 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qmlinspectoradapter.h"
#include "qmlengine.h"
#include "qmlinspectoragent.h"
#include <debugger/debuggeractions.h>
#include <debugger/debuggercore.h>
#include <debugger/debuggerstringutils.h>
#include <debugger/debuggerengine.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <qmldebug/declarativeenginedebugclient.h>
#include <qmldebug/declarativeenginedebugclientv2.h>
#include <qmldebug/declarativetoolsclient.h>
#include <qmldebug/qmlenginedebugclient.h>
#include <qmldebug/qmltoolsclient.h>
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <QFileInfo>
using namespace QmlDebug;
namespace Debugger {
namespace Internal {
/*!
* QmlInspectorAdapter manages the clients for the inspector, and the
* integration with the text editor.
*/
QmlInspectorAdapter::QmlInspectorAdapter(QmlEngine *engine, QmlDebugConnection *connection)
: m_qmlEngine(engine)
, m_masterEngine(engine)
, m_engineClient(0)
, m_toolsClient(0)
, m_agent(new QmlInspectorAgent(engine))
, m_targetToSync(NoTarget)
, m_debugIdToSelect(-1)
, m_currentSelectedDebugId(-1)
, m_toolsClientConnected(false)
, m_inspectorToolsContext("Debugger.QmlInspector")
, m_selectAction(new QAction(this))
, m_zoomAction(new QAction(this))
, m_showAppOnTopAction(action(ShowAppOnTop))
, m_engineClientConnected(false)
{
if (!m_masterEngine->isMasterEngine())
m_masterEngine = m_masterEngine->masterEngine();
connect(m_masterEngine, &DebuggerEngine::stateChanged,
this, &QmlInspectorAdapter::onEngineStateChanged);
connect(m_agent, &QmlInspectorAgent::objectFetched,
this, &QmlInspectorAdapter::onObjectFetched);
connect(m_agent, &QmlInspectorAgent::jumpToObjectDefinition,
this, &QmlInspectorAdapter::jumpToObjectDefinitionInEditor);
auto engineClient1 = new DeclarativeEngineDebugClient(connection);
connect(engineClient1, &BaseEngineDebugClient::newState,
this, &QmlInspectorAdapter::clientStateChanged);
connect(engineClient1, &BaseEngineDebugClient::newState,
this, &QmlInspectorAdapter::engineClientStateChanged);
auto engineClient2 = new QmlEngineDebugClient(connection);
connect(engineClient2, &BaseEngineDebugClient::newState,
this, &QmlInspectorAdapter::clientStateChanged);
connect(engineClient2, &BaseEngineDebugClient::newState,
this, &QmlInspectorAdapter::engineClientStateChanged);
auto engineClient3 = new DeclarativeEngineDebugClientV2(connection);
connect(engineClient3, &BaseEngineDebugClient::newState,
this, &QmlInspectorAdapter::clientStateChanged);
connect(engineClient3, &BaseEngineDebugClient::newState,
this, &QmlInspectorAdapter::engineClientStateChanged);
m_engineClients.insert(engineClient1->name(), engineClient1);
m_engineClients.insert(engineClient2->name(), engineClient2);
m_engineClients.insert(engineClient3->name(), engineClient3);
if (engineClient1->state() == QmlDebugClient::Enabled)
setActiveEngineClient(engineClient1);
if (engineClient2->state() == QmlDebugClient::Enabled)
setActiveEngineClient(engineClient2);
if (engineClient3->state() == QmlDebugClient::Enabled)
setActiveEngineClient(engineClient3);
auto toolsClient1 = new DeclarativeToolsClient(connection);
connect(toolsClient1, &BaseToolsClient::newState,
this, &QmlInspectorAdapter::clientStateChanged);
connect(toolsClient1, &BaseToolsClient::newState,
this, &QmlInspectorAdapter::toolsClientStateChanged);
auto toolsClient2 = new QmlToolsClient(connection);
connect(toolsClient2, &BaseToolsClient::newState,
this, &QmlInspectorAdapter::clientStateChanged);
connect(toolsClient2, &BaseToolsClient::newState,
this, &QmlInspectorAdapter::toolsClientStateChanged);
// toolbar
m_selectAction->setObjectName(QLatin1String("QML Select Action"));
m_zoomAction->setObjectName(QLatin1String("QML Zoom Action"));
m_selectAction->setCheckable(true);
m_zoomAction->setCheckable(true);
m_showAppOnTopAction->setCheckable(true);
m_selectAction->setEnabled(false);
m_zoomAction->setEnabled(false);
m_showAppOnTopAction->setEnabled(false);
connect(m_selectAction, &QAction::triggered,
this, &QmlInspectorAdapter::onSelectActionTriggered);
connect(m_zoomAction, &QAction::triggered,
this, &QmlInspectorAdapter::onZoomActionTriggered);
connect(m_showAppOnTopAction, &QAction::triggered,
this, &QmlInspectorAdapter::onShowAppOnTopChanged);
}
QmlInspectorAdapter::~QmlInspectorAdapter()
{
}
BaseEngineDebugClient *QmlInspectorAdapter::engineClient() const
{
return m_engineClient;
}
BaseToolsClient *QmlInspectorAdapter::toolsClient() const
{
return m_toolsClient;
}
QmlInspectorAgent *QmlInspectorAdapter::agent() const
{
return m_agent;
}
int QmlInspectorAdapter::currentSelectedDebugId() const
{
return m_currentSelectedDebugId;
}
QString QmlInspectorAdapter::currentSelectedDisplayName() const
{
return m_currentSelectedDebugName;
}
void QmlInspectorAdapter::clientStateChanged(QmlDebugClient::State state)
{
QString serviceName;
float version = 0;
if (QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender())) {
serviceName = client->name();
version = client->remoteVersion();
}
m_qmlEngine->logServiceStateChange(serviceName, version, state);
}
void QmlInspectorAdapter::toolsClientStateChanged(QmlDebugClient::State state)
{
BaseToolsClient *client = qobject_cast<BaseToolsClient*>(sender());
QTC_ASSERT(client, return);
if (state == QmlDebugClient::Enabled) {
m_toolsClient = client;
connect(client, &BaseToolsClient::currentObjectsChanged,
this, &QmlInspectorAdapter::selectObjectsFromToolsClient);
connect(client, &BaseToolsClient::logActivity,
m_qmlEngine, &QmlEngine::logServiceActivity);
connect(client, &BaseToolsClient::reloaded, this, &QmlInspectorAdapter::onReloaded);
// register actions here
// because there can be multiple QmlEngines
// at the same time (but hopefully one one is connected)
Core::ActionManager::registerAction(m_selectAction,
Core::Id(Constants::QML_SELECTTOOL),
m_inspectorToolsContext);
Core::ActionManager::registerAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL),
m_inspectorToolsContext);
Core::ActionManager::registerAction(m_showAppOnTopAction,
Core::Id(Constants::QML_SHOW_APP_ON_TOP),
m_inspectorToolsContext);
Core::ICore::addAdditionalContext(m_inspectorToolsContext);
m_toolsClientConnected = true;
onEngineStateChanged(m_masterEngine->state());
if (m_showAppOnTopAction->isChecked())
m_toolsClient->showAppOnTop(true);
} else if (m_toolsClientConnected && client == m_toolsClient) {
disconnect(client, &BaseToolsClient::currentObjectsChanged,
this, &QmlInspectorAdapter::selectObjectsFromToolsClient);
disconnect(client, &BaseToolsClient::logActivity,
m_qmlEngine, &QmlEngine::logServiceActivity);
Core::ActionManager::unregisterAction(m_selectAction, Core::Id(Constants::QML_SELECTTOOL));
Core::ActionManager::unregisterAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL));
Core::ActionManager::unregisterAction(m_showAppOnTopAction,
Core::Id(Constants::QML_SHOW_APP_ON_TOP));
Core::ICore::removeAdditionalContext(m_inspectorToolsContext);
enableTools(false);
m_toolsClientConnected = false;
m_selectAction->setCheckable(false);
m_zoomAction->setCheckable(false);
m_showAppOnTopAction->setCheckable(false);
}
}
void QmlInspectorAdapter::engineClientStateChanged(QmlDebugClient::State state)
{
BaseEngineDebugClient *client
= qobject_cast<BaseEngineDebugClient*>(sender());
if (state == QmlDebugClient::Enabled && !m_engineClientConnected) {
// We accept the first client that is enabled and reject the others.
QTC_ASSERT(client, return);
setActiveEngineClient(client);
} else if (m_engineClientConnected && client == m_engineClient) {
m_engineClientConnected = false;
}
}
void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList<int> &debugIds)
{
if (debugIds.isEmpty())
return;
m_targetToSync = EditorTarget;
m_debugIdToSelect = debugIds.first();
selectObject(agent()->objectForId(m_debugIdToSelect), EditorTarget);
}
void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref)
{
if (ref.debugId() == m_debugIdToSelect) {
m_debugIdToSelect = -1;
selectObject(ref, m_targetToSync);
}
}
void QmlInspectorAdapter::onSelectActionTriggered(bool checked)
{
QTC_ASSERT(toolsClient(), return);
if (checked) {
toolsClient()->setDesignModeBehavior(true);
toolsClient()->changeToSelectTool();
m_zoomAction->setChecked(false);
} else {
toolsClient()->setDesignModeBehavior(false);
}
}
void QmlInspectorAdapter::onZoomActionTriggered(bool checked)
{
QTC_ASSERT(toolsClient(), return);
if (checked) {
toolsClient()->setDesignModeBehavior(true);
toolsClient()->changeToZoomTool();
m_selectAction->setChecked(false);
} else {
toolsClient()->setDesignModeBehavior(false);
}
}
void QmlInspectorAdapter::onShowAppOnTopChanged(bool checked)
{
QTC_ASSERT(toolsClient(), return);
toolsClient()->showAppOnTop(checked);
}
void QmlInspectorAdapter::setActiveEngineClient(BaseEngineDebugClient *client)
{
if (m_engineClient == client)
return;
m_engineClient = client;
m_agent->setEngineClient(m_engineClient);
m_engineClientConnected = true;
}
void QmlInspectorAdapter::showConnectionStateMessage(const QString &message)
{
m_masterEngine->showMessage(_("QML Inspector: ") + message, LogStatus);
}
void QmlInspectorAdapter::jumpToObjectDefinitionInEditor(
const FileReference &objSource, int debugId)
{
const QString fileName = m_masterEngine->toFileInProject(objSource.url());
Core::EditorManager::openEditorAt(fileName, objSource.lineNumber());
if (debugId != -1 && debugId != m_currentSelectedDebugId) {
m_currentSelectedDebugId = debugId;
m_currentSelectedDebugName = agent()->displayName(debugId);
}
}
void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
SelectionTarget target)
{
if (m_toolsClient && target == ToolTarget)
m_toolsClient->setObjectIdList(
QList<ObjectReference>() << obj);
if (target == EditorTarget)
jumpToObjectDefinitionInEditor(obj.source());
agent()->selectObjectInTree(obj.debugId());
}
void QmlInspectorAdapter::enableTools(const bool enable)
{
if (!m_toolsClientConnected)
return;
m_selectAction->setEnabled(enable);
m_showAppOnTopAction->setEnabled(enable);
// only enable zoom action for Qt 4.x/old client
// (zooming is integrated into selection tool in Qt 5).
if (!qobject_cast<QmlToolsClient*>(m_toolsClient))
m_zoomAction->setEnabled(enable);
}
void QmlInspectorAdapter::onReloaded()
{
m_agent->reloadEngines();
}
void QmlInspectorAdapter::onEngineStateChanged(const DebuggerState state)
{
enableTools(state == InferiorRunOk);
}
} // namespace Internal
} // namespace Debugger

View File

@@ -1,125 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMLINSPECTORADAPTER_H
#define QMLINSPECTORADAPTER_H
#include <debugger/debuggerconstants.h>
#include <coreplugin/icontext.h>
#include <qmldebug/qmldebugclient.h>
namespace QmlDebug {
class BaseEngineDebugClient;
class BaseToolsClient;
class ObjectReference;
class FileReference;
class QmlDebugConnection;
}
namespace Debugger {
namespace Internal {
class DebuggerEngine;
class QmlEngine;
class QmlInspectorAgent;
class QmlInspectorAdapter : public QObject
{
Q_OBJECT
public:
QmlInspectorAdapter(QmlEngine *engine, QmlDebug::QmlDebugConnection *connection);
~QmlInspectorAdapter();
QmlDebug::BaseEngineDebugClient *engineClient() const;
QmlDebug::BaseToolsClient *toolsClient() const;
QmlInspectorAgent *agent() const;
int currentSelectedDebugId() const;
QString currentSelectedDisplayName() const;
signals:
void expressionResult();
private:
void onEngineStateChanged(const Debugger::DebuggerState);
void clientStateChanged(QmlDebug::QmlDebugClient::State state);
void toolsClientStateChanged(QmlDebug::QmlDebugClient::State state);
void engineClientStateChanged(QmlDebug::QmlDebugClient::State state);
void selectObjectsFromToolsClient(const QList<int> &debugIds);
void onObjectFetched(const QmlDebug::ObjectReference &ref);
void onSelectActionTriggered(bool checked);
void onZoomActionTriggered(bool checked);
void onShowAppOnTopChanged(bool checked);
void onReloaded();
void jumpToObjectDefinitionInEditor(const QmlDebug::FileReference &objSource, int debugId = -1);
void setActiveEngineClient(QmlDebug::BaseEngineDebugClient *client);
void showConnectionStateMessage(const QString &message);
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
void selectObject(
const QmlDebug::ObjectReference &objectReference,
SelectionTarget target);
void enableTools(const bool enable);
QmlEngine *m_qmlEngine;
DebuggerEngine *m_masterEngine;
QmlDebug::BaseEngineDebugClient *m_engineClient;
QHash<QString, QmlDebug::BaseEngineDebugClient*> m_engineClients;
QmlDebug::BaseToolsClient *m_toolsClient;
QmlInspectorAgent *m_agent;
SelectionTarget m_targetToSync;
int m_debugIdToSelect;
int m_currentSelectedDebugId;
QString m_currentSelectedDebugName;
// toolbar
bool m_toolsClientConnected;
Core::Context m_inspectorToolsContext;
QAction *m_selectAction;
QAction *m_zoomAction;
QAction *m_showAppOnTopAction;
bool m_engineClientConnected;
};
} // namespace Internal
} // namespace Debugger
#endif // QMLINSPECTORADAPTER_H

View File

@@ -29,6 +29,7 @@
****************************************************************************/ ****************************************************************************/
#include "qmlinspectoragent.h" #include "qmlinspectoragent.h"
#include "qmlengine.h"
#include <debugger/debuggeractions.h> #include <debugger/debuggeractions.h>
#include <debugger/debuggercore.h> #include <debugger/debuggercore.h>
@@ -36,12 +37,25 @@
#include <debugger/debuggerstringutils.h> #include <debugger/debuggerstringutils.h>
#include <debugger/watchhandler.h> #include <debugger/watchhandler.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <qmldebug/declarativeenginedebugclient.h>
#include <qmldebug/declarativeenginedebugclientv2.h>
#include <qmldebug/declarativetoolsclient.h>
#include <qmldebug/qmldebugconstants.h> #include <qmldebug/qmldebugconstants.h>
#include <qmldebug/qmlenginedebugclient.h>
#include <qmldebug/qmltoolsclient.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/savedaction.h> #include <utils/savedaction.h>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QFileInfo>
#include <QLoggingCategory> #include <QLoggingCategory>
using namespace QmlDebug; using namespace QmlDebug;
@@ -55,21 +69,94 @@ Q_LOGGING_CATEGORY(qmlInspectorLog, "qtc.dbg.qmlinspector")
/*! /*!
* DebuggerAgent updates the watchhandler with the object tree data. * DebuggerAgent updates the watchhandler with the object tree data.
*/ */
QmlInspectorAgent::QmlInspectorAgent(DebuggerEngine *engine, QObject *parent) QmlInspectorAgent::QmlInspectorAgent(QmlEngine *engine, QmlDebugConnection *connection)
: QObject(parent) : m_qmlEngine(engine)
, m_debuggerEngine(engine)
, m_engineClient(0) , m_engineClient(0)
, m_engineQueryId(0) , m_engineQueryId(0)
, m_rootContextQueryId(0) , m_rootContextQueryId(0)
, m_objectToSelect(-1) , m_objectToSelect(-1)
, m_masterEngine(engine)
, m_toolsClient(0)
, m_targetToSync(NoTarget)
, m_debugIdToSelect(-1)
, m_currentSelectedDebugId(-1)
, m_toolsClientConnected(false)
, m_inspectorToolsContext("Debugger.QmlInspector")
, m_selectAction(new QAction(this))
, m_zoomAction(new QAction(this))
, m_showAppOnTopAction(action(ShowAppOnTop))
, m_engineClientConnected(false)
{ {
m_debugIdToIname.insert(-1, QByteArray("inspect")); m_debugIdToIname.insert(-1, QByteArray("inspect"));
connect(action(ShowQmlObjectTree), connect(action(ShowQmlObjectTree),
SIGNAL(valueChanged(QVariant)), SLOT(updateState())); &Utils::SavedAction::valueChanged, this, &QmlInspectorAgent::updateState);
m_delayQueryTimer.setSingleShot(true); m_delayQueryTimer.setSingleShot(true);
m_delayQueryTimer.setInterval(100); m_delayQueryTimer.setInterval(100);
connect(&m_delayQueryTimer, &QTimer::timeout, connect(&m_delayQueryTimer, &QTimer::timeout,
this, &QmlInspectorAgent::queryEngineContext); this, &QmlInspectorAgent::queryEngineContext);
if (!m_masterEngine->isMasterEngine())
m_masterEngine = m_masterEngine->masterEngine();
connect(m_masterEngine, &DebuggerEngine::stateChanged,
this, &QmlInspectorAgent::onEngineStateChanged);
auto engineClient1 = new DeclarativeEngineDebugClient(connection);
connect(engineClient1, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::clientStateChanged);
connect(engineClient1, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::engineClientStateChanged);
auto engineClient2 = new QmlEngineDebugClient(connection);
connect(engineClient2, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::clientStateChanged);
connect(engineClient2, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::engineClientStateChanged);
auto engineClient3 = new DeclarativeEngineDebugClientV2(connection);
connect(engineClient3, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::clientStateChanged);
connect(engineClient3, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::engineClientStateChanged);
m_engineClients.insert(engineClient1->name(), engineClient1);
m_engineClients.insert(engineClient2->name(), engineClient2);
m_engineClients.insert(engineClient3->name(), engineClient3);
if (engineClient1->state() == QmlDebugClient::Enabled)
setActiveEngineClient(engineClient1);
if (engineClient2->state() == QmlDebugClient::Enabled)
setActiveEngineClient(engineClient2);
if (engineClient3->state() == QmlDebugClient::Enabled)
setActiveEngineClient(engineClient3);
auto toolsClient1 = new DeclarativeToolsClient(connection);
connect(toolsClient1, &BaseToolsClient::newState,
this, &QmlInspectorAgent::clientStateChanged);
connect(toolsClient1, &BaseToolsClient::newState,
this, &QmlInspectorAgent::toolsClientStateChanged);
auto toolsClient2 = new QmlToolsClient(connection);
connect(toolsClient2, &BaseToolsClient::newState,
this, &QmlInspectorAgent::clientStateChanged);
connect(toolsClient2, &BaseToolsClient::newState,
this, &QmlInspectorAgent::toolsClientStateChanged);
// toolbar
m_selectAction->setObjectName(QLatin1String("QML Select Action"));
m_zoomAction->setObjectName(QLatin1String("QML Zoom Action"));
m_selectAction->setCheckable(true);
m_zoomAction->setCheckable(true);
m_showAppOnTopAction->setCheckable(true);
m_selectAction->setEnabled(false);
m_zoomAction->setEnabled(false);
m_showAppOnTopAction->setEnabled(false);
connect(m_selectAction, &QAction::triggered,
this, &QmlInspectorAgent::onSelectActionTriggered);
connect(m_zoomAction, &QAction::triggered,
this, &QmlInspectorAgent::onZoomActionTriggered);
connect(m_showAppOnTopAction, &QAction::triggered,
this, &QmlInspectorAgent::onShowAppOnTopChanged);
} }
quint32 QmlInspectorAgent::queryExpressionResult(int debugId, quint32 QmlInspectorAgent::queryExpressionResult(int debugId,
@@ -103,7 +190,7 @@ void QmlInspectorAgent::assignValue(const WatchData *data,
} }
} }
int parentIdForIname(const QByteArray &iname) static int parentIdForIname(const QByteArray &iname)
{ {
// Extract the parent id // Extract the parent id
int lastIndex = iname.lastIndexOf('.'); int lastIndex = iname.lastIndexOf('.');
@@ -131,7 +218,7 @@ void QmlInspectorAgent::watchDataSelected(quint64 id)
if (id) { if (id) {
QTC_ASSERT(m_debugIdLocations.keys().contains(id), return); QTC_ASSERT(m_debugIdLocations.keys().contains(id), return);
emit jumpToObjectDefinition(m_debugIdLocations.value(id), id); jumpToObjectDefinitionInEditor(m_debugIdLocations.value(id), id);
} }
} }
@@ -145,7 +232,7 @@ bool QmlInspectorAgent::selectObjectInTree(int debugId)
QByteArray iname = m_debugIdToIname.value(debugId); QByteArray iname = m_debugIdToIname.value(debugId);
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname); QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree"; qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
m_debuggerEngine->watchHandler()->setCurrentItem(iname); m_qmlEngine->watchHandler()->setCurrentItem(iname);
m_objectToSelect = 0; m_objectToSelect = 0;
return true; return true;
} else { } else {
@@ -154,8 +241,8 @@ bool QmlInspectorAgent::selectObjectInTree(int debugId)
using namespace QmlDebug::Constants; using namespace QmlDebug::Constants;
if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) { if (m_engineClient->objectName() == QLatin1String(QDECLARATIVE_ENGINE)) {
// reset current Selection // reset current Selection
QByteArray root = m_debuggerEngine->watchHandler()->watchItem(QModelIndex())->iname; QByteArray root = m_qmlEngine->watchHandler()->watchItem(QModelIndex())->iname;
m_debuggerEngine->watchHandler()->setCurrentItem(root); m_qmlEngine->watchHandler()->setCurrentItem(root);
} else { } else {
fetchObject(debugId); fetchObject(debugId);
} }
@@ -163,107 +250,6 @@ bool QmlInspectorAgent::selectObjectInTree(int debugId)
} }
} }
quint32 QmlInspectorAgent::setBindingForObject(int objectDebugId,
const QString &propertyName,
const QVariant &value,
bool isLiteralValue,
QString source,
int line)
{
qCDebug(qmlInspectorLog)
<< __FUNCTION__ << '(' << objectDebugId << propertyName
<< value.toString() << isLiteralValue << source << line << ')';
if (objectDebugId == -1)
return 0;
if (propertyName == QLatin1String("id"))
return 0; // Crashes the QMLViewer.
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
return 0;
log(LogSend, QString::fromLatin1("SET_BINDING %1 %2 %3 %4").arg(
QString::number(objectDebugId), propertyName, value.toString(),
QString(isLiteralValue ? QLatin1String("true") : QLatin1String("false"))));
quint32 queryId = m_engineClient->setBindingForObject(
objectDebugId, propertyName, value.toString(), isLiteralValue,
source, line);
if (!queryId)
log(LogSend, QLatin1String("SET_BINDING failed!"));
return queryId;
}
quint32 QmlInspectorAgent::setMethodBodyForObject(int objectDebugId,
const QString &methodName,
const QString &methodBody)
{
qCDebug(qmlInspectorLog)
<< __FUNCTION__ << '(' << objectDebugId << methodName << methodBody
<< ')';
if (objectDebugId == -1)
return 0;
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
return 0;
log(LogSend, QString::fromLatin1("SET_METHOD_BODY %1 %2 %3").arg(
QString::number(objectDebugId), methodName, methodBody));
quint32 queryId = m_engineClient->setMethodBody(
objectDebugId, methodName, methodBody);
if (!queryId)
log(LogSend, QLatin1String("failed!"));
return queryId;
}
quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId,
const QString &propertyName)
{
qCDebug(qmlInspectorLog)
<< __FUNCTION__ << '(' << objectDebugId
<< propertyName << ')';
if (objectDebugId == -1)
return 0;
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
return 0;
log(LogSend, QString::fromLatin1("RESET_BINDING %1 %2").arg(
QString::number(objectDebugId), propertyName));
quint32 queryId = m_engineClient->resetBindingForObject(
objectDebugId, propertyName);
if (!queryId)
log(LogSend, QLatin1String("failed!"));
return queryId;
}
ObjectReference QmlInspectorAgent::objectForName(
const QString &objectId) const
{
if (!objectId.isEmpty() && objectId[0].isLower()) {
QHashIterator<int, QByteArray> iter(m_debugIdToIname);
const WatchHandler *watchHandler = m_debuggerEngine->watchHandler();
while (iter.hasNext()) {
iter.next();
const WatchItem *item = watchHandler->findItem(iter.value());
if (item && item->name == objectId)
return ObjectReference(iter.key());
}
}
return ObjectReference();
}
ObjectReference QmlInspectorAgent::objectForId(int objectDebugId) const ObjectReference QmlInspectorAgent::objectForId(int objectDebugId) const
{ {
if (!m_debugIdToIname.contains(objectDebugId)) if (!m_debugIdToIname.contains(objectDebugId))
@@ -294,117 +280,25 @@ ObjectReference QmlInspectorAgent::objectForId(int objectDebugId) const
FileReference(QUrl::fromLocalFile(file), line, column)); FileReference(QUrl::fromLocalFile(file), line, column));
} }
int QmlInspectorAgent::objectIdForLocation( void QmlInspectorAgent::addObjectWatch(int objectDebugId)
int line, int column) const
{
QHashIterator<int, FileReference> iter(m_debugIdLocations);
while (iter.hasNext()) {
iter.next();
const FileReference &ref = iter.value();
if (ref.lineNumber() == line
&& ref.columnNumber() == column)
return iter.key();
}
return -1;
}
QHash<int,QString> QmlInspectorAgent::rootObjectIds() const
{
QHash<int,QString> rIds;
const WatchHandler *watchHandler = m_debuggerEngine->watchHandler();
foreach (const QByteArray &iname, m_debugIdToIname) {
if (const WatchItem *item = watchHandler->findItem(iname)) {
int debugId = item->id;
rIds.insert(debugId, QLatin1String(item->type));
}
}
return rIds;
}
bool QmlInspectorAgent::addObjectWatch(int objectDebugId)
{ {
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << objectDebugId << ')'; qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << objectDebugId << ')';
if (objectDebugId == -1) if (objectDebugId == -1)
return false; return;
if (!isConnected() || !boolSetting(ShowQmlObjectTree)) if (!isConnected() || !boolSetting(ShowQmlObjectTree))
return false; return;
// already set // already set
if (m_objectWatches.contains(objectDebugId)) if (m_objectWatches.contains(objectDebugId))
return true; return;
// is flooding the debugging output log! // is flooding the debugging output log!
// log(LogSend, QString::fromLatin1("WATCH_PROPERTY %1").arg(objectDebugId)); // log(LogSend, QString::fromLatin1("WATCH_PROPERTY %1").arg(objectDebugId));
if (m_engineClient->addWatch(objectDebugId)) if (m_engineClient->addWatch(objectDebugId))
m_objectWatches.append(objectDebugId); m_objectWatches.append(objectDebugId);
return true;
}
bool QmlInspectorAgent::isObjectBeingWatched(int objectDebugId)
{
return m_objectWatches.contains(objectDebugId);
}
bool QmlInspectorAgent::removeObjectWatch(int objectDebugId)
{
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << objectDebugId << ')';
if (objectDebugId == -1)
return false;
if (!m_objectWatches.contains(objectDebugId))
return false;
if (!isConnected())
return false;
m_objectWatches.removeOne(objectDebugId);
return true;
}
void QmlInspectorAgent::removeAllObjectWatches()
{
qCDebug(qmlInspectorLog) << __FUNCTION__ << "()";
foreach (int watchedObject, m_objectWatches)
removeObjectWatch(watchedObject);
}
void QmlInspectorAgent::setEngineClient(BaseEngineDebugClient *client)
{
if (m_engineClient == client)
return;
if (m_engineClient) {
disconnect(m_engineClient, SIGNAL(newState(QmlDebug::QmlDebugClient::State)),
this, SLOT(updateState()));
disconnect(m_engineClient, SIGNAL(result(quint32,QVariant,QByteArray)),
this, SLOT(onResult(quint32,QVariant,QByteArray)));
disconnect(m_engineClient, SIGNAL(newObject(int,int,int)),
this, SLOT(newObject(int,int,int)));
disconnect(m_engineClient, SIGNAL(valueChanged(int,QByteArray,QVariant)),
this, SLOT(onValueChanged(int,QByteArray,QVariant)));
}
m_engineClient = client;
if (m_engineClient) {
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();
} }
QString QmlInspectorAgent::displayName(int objectDebugId) const QString QmlInspectorAgent::displayName(int objectDebugId) const
@@ -413,7 +307,7 @@ QString QmlInspectorAgent::displayName(int objectDebugId) const
return QString(); return QString();
if (m_debugIdToIname.contains(objectDebugId)) { if (m_debugIdToIname.contains(objectDebugId)) {
const WatchItem *item = m_debuggerEngine->watchHandler()->findItem( const WatchItem *item = m_qmlEngine->watchHandler()->findItem(
m_debugIdToIname.value(objectDebugId)); m_debugIdToIname.value(objectDebugId));
QTC_ASSERT(item, return QString()); QTC_ASSERT(item, return QString());
return item->name; return item->name;
@@ -443,11 +337,12 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
} else if (type == "SET_BINDING_R" } else if (type == "SET_BINDING_R"
|| type == "RESET_BINDING_R" || type == "RESET_BINDING_R"
|| type == "SET_METHOD_BODY_R") { || type == "SET_METHOD_BODY_R") {
// FIXME: This is not supported anymore.
QString msg = QLatin1String(type) + tr("Success:"); QString msg = QLatin1String(type) + tr("Success:");
msg += QLatin1Char(' '); msg += QLatin1Char(' ');
msg += value.toBool() ? QLatin1Char('1') : QLatin1Char('0'); msg += value.toBool() ? QLatin1Char('1') : QLatin1Char('0');
if (!value.toBool()) // if (!value.toBool())
emit automaticUpdateFailed(); // emit automaticUpdateFailed();
log(LogReceive, msg); log(LogReceive, msg);
} else { } else {
log(LogReceive, QLatin1String(type)); log(LogReceive, QLatin1String(type));
@@ -477,11 +372,10 @@ void QmlInspectorAgent::onResult(quint32 queryId, const QVariant &value,
clearObjectTree(); clearObjectTree();
updateObjectTree(qvariant_cast<ContextReference>(value)); updateObjectTree(qvariant_cast<ContextReference>(value));
} else { } else {
emit expressionResult(queryId, value); m_qmlEngine->expressionEvaluated(queryId, value);
} }
qCDebug(qmlInspectorLog) << __FUNCTION__ << "done"; qCDebug(qmlInspectorLog) << __FUNCTION__ << "done";
} }
void QmlInspectorAgent::newObject(int engineId, int /*objectId*/, int /*parentId*/) void QmlInspectorAgent::newObject(int engineId, int /*objectId*/, int /*parentId*/)
@@ -502,7 +396,7 @@ void QmlInspectorAgent::onValueChanged(int debugId, const QByteArray &propertyNa
{ {
const QByteArray iname = m_debugIdToIname.value(debugId) + const QByteArray iname = m_debugIdToIname.value(debugId) +
".[properties]." + propertyName; ".[properties]." + propertyName;
WatchHandler *watchHandler = m_debuggerEngine->watchHandler(); WatchHandler *watchHandler = m_qmlEngine->watchHandler();
qCDebug(qmlInspectorLog) qCDebug(qmlInspectorLog)
<< __FUNCTION__ << '(' << debugId << ')' << iname << __FUNCTION__ << '(' << debugId << ')' << iname
<< value.toString(); << value.toString();
@@ -524,22 +418,6 @@ void QmlInspectorAgent::reloadEngines()
m_engineQueryId = m_engineClient->queryAvailableEngines(); m_engineQueryId = m_engineClient->queryAvailableEngines();
} }
int QmlInspectorAgent::parentIdForObject(int objectDebugId)
{
int pid = -1;
if (m_debugIdToIname.contains(objectDebugId)) {
QByteArray iname = m_debugIdToIname.value(objectDebugId);
if (iname.count('.') > 1) {
int offset = iname.lastIndexOf('.');
QTC_ASSERT(offset > 0, return pid);
iname = iname.left(offset);
pid = m_debugIdToIname.key(iname);
}
}
return pid;
}
void QmlInspectorAgent::queryEngineContext() void QmlInspectorAgent::queryEngineContext()
{ {
qCDebug(qmlInspectorLog) << __FUNCTION__; qCDebug(qmlInspectorLog) << __FUNCTION__;
@@ -567,27 +445,6 @@ void QmlInspectorAgent::fetchObject(int debugId)
m_objectTreeQueryIds << queryId; m_objectTreeQueryIds << queryId;
} }
void QmlInspectorAgent::fetchContextObjectsForLocation(const QString &file,
int lineNumber, int columnNumber)
{
// This can be an expensive operation as it may return multiple
// objects. Use fetchContextObject() where possible.
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << file << ':' << lineNumber
<< ':' << columnNumber << ')';
if (!isConnected() || !boolSetting(ShowQmlObjectTree))
return;
log(LogSend, QString::fromLatin1("FETCH_OBJECTS_FOR_LOCATION %1:%2:%3").arg(file)
.arg(QString::number(lineNumber)).arg(QString::number(columnNumber)));
quint32 queryId = m_engineClient->queryObjectsForLocation(Utils::FileName::fromString(file).fileName(),
lineNumber, columnNumber);
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << file << ':' << lineNumber
<< ':' << columnNumber << ')' << " - query id" << queryId;
m_objectTreeQueryIds << queryId;
}
void QmlInspectorAgent::updateObjectTree(const ContextReference &context) void QmlInspectorAgent::updateObjectTree(const ContextReference &context)
{ {
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << context << ')'; qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << context << ')';
@@ -616,7 +473,7 @@ void QmlInspectorAgent::verifyAndInsertObjectInTree(const ObjectReference &objec
// If the two conditions are not met then we push the object to a stack and recursively // 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. // fetch parents till we find a previously expanded parent.
WatchHandler *handler = m_debuggerEngine->watchHandler(); WatchHandler *handler = m_qmlEngine->watchHandler();
const int parentId = object.parentId(); const int parentId = object.parentId();
const int objectDebugId = object.debugId(); const int objectDebugId = object.debugId();
if (m_debugIdToIname.contains(parentId)) { if (m_debugIdToIname.contains(parentId)) {
@@ -675,18 +532,20 @@ void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took " qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took "
<< timeElapsed.elapsed() << " ms"; << timeElapsed.elapsed() << " ms";
emit objectTreeUpdated(); if (object.debugId() == m_debugIdToSelect) {
emit objectFetched(object); m_debugIdToSelect = -1;
selectObject(object, m_targetToSync);
}
if (m_debugIdToIname.contains(m_objectToSelect)) { if (m_debugIdToIname.contains(m_objectToSelect)) {
// select item in view // select item in view
QByteArray iname = m_debugIdToIname.value(m_objectToSelect); QByteArray iname = m_debugIdToIname.value(m_objectToSelect);
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree"; qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
m_debuggerEngine->watchHandler()->setCurrentItem(iname); m_qmlEngine->watchHandler()->setCurrentItem(iname);
m_objectToSelect = -1; m_objectToSelect = -1;
} }
m_debuggerEngine->watchHandler()->updateWatchersWindow(); m_qmlEngine->watchHandler()->updateWatchersWindow();
m_debuggerEngine->watchHandler()->reexpandItems(); m_qmlEngine->watchHandler()->reexpandItems();
} }
void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref) void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
@@ -708,7 +567,7 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
} }
const QString filePath const QString filePath
= m_debuggerEngine->toFileInProject(fileUrl); = m_qmlEngine->toFileInProject(fileUrl);
// append the debug ids in the hash // append the debug ids in the hash
QPair<QString, int> file = qMakePair<QString, int>(filePath, rev); QPair<QString, int> file = qMakePair<QString, int>(filePath, rev);
@@ -759,19 +618,19 @@ void QmlInspectorAgent::addWatchData(const ObjectReference &obj,
objWatch->wantsChildren = true; objWatch->wantsChildren = true;
objWatch->setAllUnneeded(); objWatch->setAllUnneeded();
m_debuggerEngine->watchHandler()->insertItem(objWatch); m_qmlEngine->watchHandler()->insertItem(objWatch);
addObjectWatch(objWatch->id); addObjectWatch(objWatch->id);
if (m_debugIdToIname.contains(objDebugId)) { if (m_debugIdToIname.contains(objDebugId)) {
// The data needs to be removed since we now know the parent and // The data needs to be removed since we now know the parent and
// hence we can insert the data in the correct position // hence we can insert the data in the correct position
const QByteArray oldIname = m_debugIdToIname.value(objDebugId); const QByteArray oldIname = m_debugIdToIname.value(objDebugId);
if (oldIname != objIname) if (oldIname != objIname)
m_debuggerEngine->watchHandler()->removeItemByIName(oldIname); m_qmlEngine->watchHandler()->removeItemByIName(oldIname);
} }
m_debugIdToIname.insert(objDebugId, objIname); m_debugIdToIname.insert(objDebugId, objIname);
} }
if (!m_debuggerEngine->watchHandler()->isExpandedIName(objIname)) { if (!m_qmlEngine->watchHandler()->isExpandedIName(objIname)) {
// we don't know the children yet. Not adding the 'properties' // we don't know the children yet. Not adding the 'properties'
// element makes sure we're queried on expansion. // element makes sure we're queried on expansion.
if (obj.needsMoreData()) if (obj.needsMoreData())
@@ -801,7 +660,7 @@ void QmlInspectorAgent::addWatchData(const ObjectReference &obj,
propertiesWatch->appendChild(propertyWatch); propertiesWatch->appendChild(propertyWatch);
} }
m_debuggerEngine->watchHandler()->insertItem(propertiesWatch); m_qmlEngine->watchHandler()->insertItem(propertiesWatch);
} }
// recurse // recurse
@@ -819,19 +678,18 @@ void QmlInspectorAgent::log(QmlInspectorAgent::LogDirection direction,
msg += _(" receiving "); msg += _(" receiving ");
msg += message; msg += message;
if (m_debuggerEngine) if (m_qmlEngine)
m_debuggerEngine->showMessage(msg, LogDebug); m_qmlEngine->showMessage(msg, LogDebug);
} }
bool QmlInspectorAgent::isConnected() const bool QmlInspectorAgent::isConnected() const
{ {
return m_engineClient return m_engineClient && m_engineClient->state() == QmlDebugClient::Enabled;
&& (m_engineClient->state() == QmlDebugClient::Enabled);
} }
void QmlInspectorAgent::clearObjectTree() void QmlInspectorAgent::clearObjectTree()
{ {
m_debuggerEngine->watchHandler()->removeAllData(true); m_qmlEngine->watchHandler()->removeAllData(true);
m_objectTreeQueryIds.clear(); m_objectTreeQueryIds.clear();
m_fetchDataIds.clear(); m_fetchDataIds.clear();
int old_count = m_debugIdHash.count(); int old_count = m_debugIdHash.count();
@@ -840,8 +698,214 @@ void QmlInspectorAgent::clearObjectTree()
m_debugIdToIname.clear(); m_debugIdToIname.clear();
m_debugIdToIname.insert(-1, QByteArray("inspect")); m_debugIdToIname.insert(-1, QByteArray("inspect"));
m_objectStack.clear(); m_objectStack.clear();
removeAllObjectWatches(); m_objectWatches.clear();
} }
} // Internal
} // Debugger
BaseToolsClient *QmlInspectorAgent::toolsClient() const
{
return m_toolsClient;
}
void QmlInspectorAgent::clientStateChanged(QmlDebugClient::State state)
{
QString serviceName;
float version = 0;
if (QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender())) {
serviceName = client->name();
version = client->remoteVersion();
}
m_qmlEngine->logServiceStateChange(serviceName, version, state);
}
void QmlInspectorAgent::toolsClientStateChanged(QmlDebugClient::State state)
{
BaseToolsClient *client = qobject_cast<BaseToolsClient*>(sender());
QTC_ASSERT(client, return);
if (state == QmlDebugClient::Enabled) {
m_toolsClient = client;
connect(client, &BaseToolsClient::currentObjectsChanged,
this, &QmlInspectorAgent::selectObjectsFromToolsClient);
connect(client, &BaseToolsClient::logActivity,
m_qmlEngine, &QmlEngine::logServiceActivity);
connect(client, &BaseToolsClient::reloaded,
this, &QmlInspectorAgent::onReloaded);
// register actions here
// because there can be multiple QmlEngines
// at the same time (but hopefully one one is connected)
Core::ActionManager::registerAction(m_selectAction,
Core::Id(Constants::QML_SELECTTOOL),
m_inspectorToolsContext);
Core::ActionManager::registerAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL),
m_inspectorToolsContext);
Core::ActionManager::registerAction(m_showAppOnTopAction,
Core::Id(Constants::QML_SHOW_APP_ON_TOP),
m_inspectorToolsContext);
Core::ICore::addAdditionalContext(m_inspectorToolsContext);
m_toolsClientConnected = true;
onEngineStateChanged(m_masterEngine->state());
if (m_showAppOnTopAction->isChecked())
m_toolsClient->showAppOnTop(true);
} else if (m_toolsClientConnected && client == m_toolsClient) {
disconnect(client, &BaseToolsClient::currentObjectsChanged,
this, &QmlInspectorAgent::selectObjectsFromToolsClient);
disconnect(client, &BaseToolsClient::logActivity,
m_qmlEngine, &QmlEngine::logServiceActivity);
Core::ActionManager::unregisterAction(m_selectAction, Core::Id(Constants::QML_SELECTTOOL));
Core::ActionManager::unregisterAction(m_zoomAction, Core::Id(Constants::QML_ZOOMTOOL));
Core::ActionManager::unregisterAction(m_showAppOnTopAction,
Core::Id(Constants::QML_SHOW_APP_ON_TOP));
Core::ICore::removeAdditionalContext(m_inspectorToolsContext);
enableTools(false);
m_toolsClientConnected = false;
m_selectAction->setCheckable(false);
m_zoomAction->setCheckable(false);
m_showAppOnTopAction->setCheckable(false);
}
}
void QmlInspectorAgent::engineClientStateChanged(QmlDebugClient::State state)
{
BaseEngineDebugClient *client
= qobject_cast<BaseEngineDebugClient*>(sender());
if (state == QmlDebugClient::Enabled && !m_engineClientConnected) {
// We accept the first client that is enabled and reject the others.
QTC_ASSERT(client, return);
setActiveEngineClient(client);
} else if (m_engineClientConnected && client == m_engineClient) {
m_engineClientConnected = false;
}
}
void QmlInspectorAgent::selectObjectsFromToolsClient(const QList<int> &debugIds)
{
if (debugIds.isEmpty())
return;
m_targetToSync = EditorTarget;
m_debugIdToSelect = debugIds.first();
selectObject(objectForId(m_debugIdToSelect), EditorTarget);
}
void QmlInspectorAgent::onSelectActionTriggered(bool checked)
{
QTC_ASSERT(toolsClient(), return);
if (checked) {
toolsClient()->setDesignModeBehavior(true);
toolsClient()->changeToSelectTool();
m_zoomAction->setChecked(false);
} else {
toolsClient()->setDesignModeBehavior(false);
}
}
void QmlInspectorAgent::onZoomActionTriggered(bool checked)
{
QTC_ASSERT(toolsClient(), return);
if (checked) {
toolsClient()->setDesignModeBehavior(true);
toolsClient()->changeToZoomTool();
m_selectAction->setChecked(false);
} else {
toolsClient()->setDesignModeBehavior(false);
}
}
void QmlInspectorAgent::onShowAppOnTopChanged(bool checked)
{
QTC_ASSERT(toolsClient(), return);
toolsClient()->showAppOnTop(checked);
}
void QmlInspectorAgent::setActiveEngineClient(BaseEngineDebugClient *client)
{
if (m_engineClient == client)
return;
if (m_engineClient) {
disconnect(m_engineClient, &BaseEngineDebugClient::newState,
this, &QmlInspectorAgent::updateState);
disconnect(m_engineClient, &BaseEngineDebugClient::result,
this, &QmlInspectorAgent::onResult);
disconnect(m_engineClient, &BaseEngineDebugClient::newObject,
this, &QmlInspectorAgent::newObject);
disconnect(m_engineClient, &BaseEngineDebugClient::valueChanged,
this, &QmlInspectorAgent::onValueChanged);
}
m_engineClient = client;
if (m_engineClient) {
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();
m_engineClientConnected = true;
}
void QmlInspectorAgent::jumpToObjectDefinitionInEditor(
const FileReference &objSource, int debugId)
{
const QString fileName = m_masterEngine->toFileInProject(objSource.url());
Core::EditorManager::openEditorAt(fileName, objSource.lineNumber());
if (debugId != -1 && debugId != m_currentSelectedDebugId) {
m_currentSelectedDebugId = debugId;
m_currentSelectedDebugName = displayName(debugId);
}
}
void QmlInspectorAgent::selectObject(const ObjectReference &obj,
SelectionTarget target)
{
if (m_toolsClient && target == ToolTarget)
m_toolsClient->setObjectIdList(
QList<ObjectReference>() << obj);
if (target == EditorTarget)
jumpToObjectDefinitionInEditor(obj.source());
selectObjectInTree(obj.debugId());
}
void QmlInspectorAgent::enableTools(const bool enable)
{
if (!m_toolsClientConnected)
return;
m_selectAction->setEnabled(enable);
m_showAppOnTopAction->setEnabled(enable);
// only enable zoom action for Qt 4.x/old client
// (zooming is integrated into selection tool in Qt 5).
if (!qobject_cast<QmlToolsClient*>(m_toolsClient))
m_zoomAction->setEnabled(enable);
}
void QmlInspectorAgent::onReloaded()
{
reloadEngines();
}
void QmlInspectorAgent::onEngineStateChanged(const DebuggerState state)
{
enableTools(state == InferiorRunOk);
}
} // namespace Internal
} // namespace Debugger

View File

@@ -34,12 +34,24 @@
#include <QStack> #include <QStack>
#include <QTimer> #include <QTimer>
#include <coreplugin/icontext.h>
#include <debugger/debuggerconstants.h>
#include <qmldebug/baseenginedebugclient.h> #include <qmldebug/baseenginedebugclient.h>
#include <qmldebug/qmldebugclient.h>
namespace QmlDebug {
class BaseEngineDebugClient;
class BaseToolsClient;
class ObjectReference;
class FileReference;
class QmlDebugConnection;
}
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
class DebuggerEngine; class DebuggerEngine;
class QmlEngine;
class WatchData; class WatchData;
//map <filename, editorRevision> -> <lineNumber, columnNumber> -> debugId //map <filename, editorRevision> -> <lineNumber, columnNumber> -> debugId
@@ -50,7 +62,7 @@ class QmlInspectorAgent : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QmlInspectorAgent(DebuggerEngine *engine, QObject *parent = 0); QmlInspectorAgent(QmlEngine *engine, QmlDebug::QmlDebugConnection *connection);
void fetchObject(int debugId); void fetchObject(int debugId);
quint32 queryExpressionResult(int debugId, const QString &expression); quint32 queryExpressionResult(int debugId, const QString &expression);
@@ -59,55 +71,21 @@ public:
void updateWatchData(const WatchData &data); void updateWatchData(const WatchData &data);
void watchDataSelected(quint64 id); void watchDataSelected(quint64 id);
bool selectObjectInTree(int debugId); bool selectObjectInTree(int debugId);
void addObjectWatch(int objectDebugId);
quint32 setBindingForObject(int objectDebugId,
const QString &propertyName,
const QVariant &value,
bool isLiteralValue,
QString source,
int line);
quint32 setMethodBodyForObject(int objectDebugId, const QString &methodName,
const QString &methodBody);
quint32 resetBindingForObject(int objectDebugId,
const QString &propertyName);
QmlDebug::ObjectReference objectForName(const QString &objectId) const;
QmlDebug::ObjectReference objectForId(int objectDebugId) const; QmlDebug::ObjectReference objectForId(int objectDebugId) const;
int objectIdForLocation(int line, int column) const;
QHash<int, QString> rootObjectIds() const;
DebugIdHash debugIdHash() const { return m_debugIdHash; }
bool addObjectWatch(int objectDebugId);
bool isObjectBeingWatched(int objectDebugId);
bool removeObjectWatch(int objectDebugId);
void removeAllObjectWatches();
void setEngineClient(QmlDebug::BaseEngineDebugClient *client);
QString displayName(int objectDebugId) const; QString displayName(int objectDebugId) const;
int parentIdForObject(int objectDebugId);
void reloadEngines(); void reloadEngines();
public slots: QmlDebug::BaseToolsClient *toolsClient() const;
void fetchContextObjectsForLocation(const QString &file,
int lineNumber, int columnNumber);
void queryEngineContext();
signals: private:
void objectTreeUpdated();
void objectFetched(const QmlDebug::ObjectReference &ref);
void expressionResult(quint32 queryId, const QVariant &value);
void propertyChanged(int debugId, const QByteArray &propertyName,
const QVariant &propertyValue);
void automaticUpdateFailed();
void jumpToObjectDefinition(const QmlDebug::FileReference &objSource, int debugId);
private slots:
void updateState(); void updateState();
void onResult(quint32 queryId, const QVariant &value, const QByteArray &type); void onResult(quint32 queryId, const QVariant &value, const QByteArray &type);
void newObject(int engineId, int objectId, int parentId); void newObject(int engineId, int objectId, int parentId);
void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value); void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value);
private: void queryEngineContext();
void updateObjectTree(const QmlDebug::ContextReference &context); void updateObjectTree(const QmlDebug::ContextReference &context);
void verifyAndInsertObjectInTree(const QmlDebug::ObjectReference &object); void verifyAndInsertObjectInTree(const QmlDebug::ObjectReference &object);
void insertObjectInTree(const QmlDebug::ObjectReference &result); void insertObjectInTree(const QmlDebug::ObjectReference &result);
@@ -125,8 +103,31 @@ private:
bool isConnected() const; bool isConnected() const;
void clearObjectTree(); void clearObjectTree();
void onEngineStateChanged(const Debugger::DebuggerState);
void clientStateChanged(QmlDebug::QmlDebugClient::State state);
void toolsClientStateChanged(QmlDebug::QmlDebugClient::State state);
void engineClientStateChanged(QmlDebug::QmlDebugClient::State state);
void selectObjectsFromToolsClient(const QList<int> &debugIds);
void onSelectActionTriggered(bool checked);
void onZoomActionTriggered(bool checked);
void onShowAppOnTopChanged(bool checked);
void onReloaded();
void jumpToObjectDefinitionInEditor(const QmlDebug::FileReference &objSource, int debugId = -1);
void setActiveEngineClient(QmlDebug::BaseEngineDebugClient *client);
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
void selectObject(
const QmlDebug::ObjectReference &objectReference,
SelectionTarget target);
void enableTools(const bool enable);
private: private:
DebuggerEngine *m_debuggerEngine; QmlEngine *m_qmlEngine;
QmlDebug::BaseEngineDebugClient *m_engineClient; QmlDebug::BaseEngineDebugClient *m_engineClient;
quint32 m_engineQueryId; quint32 m_engineQueryId;
@@ -142,6 +143,25 @@ private:
QList<int> m_objectWatches; QList<int> m_objectWatches;
QList<int> m_fetchDataIds; QList<int> m_fetchDataIds;
QTimer m_delayQueryTimer; QTimer m_delayQueryTimer;
DebuggerEngine *m_masterEngine;
QHash<QString, QmlDebug::BaseEngineDebugClient*> m_engineClients;
QmlDebug::BaseToolsClient *m_toolsClient;
SelectionTarget m_targetToSync;
int m_debugIdToSelect;
int m_currentSelectedDebugId;
QString m_currentSelectedDebugName;
// toolbar
bool m_toolsClientConnected;
Core::Context m_inspectorToolsContext;
QAction *m_selectAction;
QAction *m_zoomAction;
QAction *m_showAppOnTopAction;
bool m_engineClientConnected;
}; };
} // Internal } // Internal