Commit 156320ff authored by hjk's avatar hjk

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: default avatarUlf Hermann <ulf.hermann@theqtcompany.com>
parent 5c815dea
......@@ -149,7 +149,6 @@ QtcPlugin {
"qmlcppengine.cpp", "qmlcppengine.h",
"qmlengine.cpp", "qmlengine.h",
"qmlengineutils.cpp", "qmlengineutils.h",
"qmlinspectoradapter.cpp", "qmlinspectoradapter.h",
"qmlinspectoragent.cpp", "qmlinspectoragent.h",
"qmlv8debuggerclientconstants.h"
]
......
......@@ -4,13 +4,11 @@ HEADERS += \
$$PWD/qmlcppengine.h \
$$PWD/interactiveinterpreter.h \
$$PWD/qmlv8debuggerclientconstants.h \
$$PWD/qmlinspectoragent.h \
$$PWD/qmlinspectoradapter.h
$$PWD/qmlinspectoragent.h
SOURCES += \
$$PWD/qmlengine.cpp \
$$PWD/qmlengineutils.cpp \
$$PWD/qmlcppengine.cpp \
$$PWD/interactiveinterpreter.cpp \
$$PWD/qmlinspectoragent.cpp \
$$PWD/qmlinspectoradapter.cpp
$$PWD/qmlinspectoragent.cpp
......@@ -31,7 +31,6 @@
#include "qmlengine.h"
#include "interactiveinterpreter.h"
#include "qmlinspectoradapter.h"
#include "qmlinspectoragent.h"
#include "qmlv8debuggerclientconstants.h"
#include "qmlengineutils.h"
......@@ -136,7 +135,7 @@ public:
QmlEnginePrivate(QmlEngine *engine_, QmlDebugConnection *connection_)
: QmlDebugClient(QLatin1String("V8Debugger"), connection_),
engine(engine_),
inspectorAdapter(engine, connection_),
inspectorAgent(engine, connection_),
connection(connection_)
{}
......@@ -206,7 +205,7 @@ public:
QHash<QString, QWeakPointer<BaseTextEditor> > sourceEditors;
InteractiveInterpreter interpreter;
ApplicationLauncher applicationLauncher;
QmlInspectorAdapter inspectorAdapter;
QmlInspectorAgent inspectorAgent;
QmlOutputParser outputParser;
QTimer noDebugOutputTimer;
......@@ -254,8 +253,6 @@ QmlEngine::QmlEngine(const DebuggerRunParameters &startParameters, DebuggerEngin
this, &QmlEngine::updateCurrentContext);
connect(inspectorView(), SIGNAL(currentIndexChanged(QModelIndex)),
SLOT(updateCurrentContext()));
connect(d->inspectorAdapter.agent(), &QmlInspectorAgent::expressionResult,
this, &QmlEngine::expressionEvaluated);
connect(&d->applicationLauncher, &ApplicationLauncher::processExited,
this, &QmlEngine::disconnected);
......@@ -965,8 +962,8 @@ void QmlEngine::assignValueInDebugger(WatchItem *item,
const QString &expression, const QVariant &value)
{
if (!expression.isEmpty()) {
if (item->isInspect() && d->inspectorAdapter.agent()) {
d->inspectorAdapter.agent()->assignValue(item, expression, value);
if (item->isInspect()) {
d->inspectorAgent.assignValue(item, expression, value);
} else {
StackHandler *handler = stackHandler();
QString exp = QString(_("%1 = %2;")).arg(expression).arg(value.toString());
......@@ -986,7 +983,7 @@ void QmlEngine::expandItem(const QByteArray &iname)
QTC_ASSERT(item, return);
if (item->isInspect()) {
d->inspectorAdapter.agent()->updateWatchData(*item);
d->inspectorAgent.updateWatchData(*item);
} else {
LookupItems items;
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);
if (item && item->isInspect())
d->inspectorAdapter.agent()->watchDataSelected(item->id);
d->inspectorAgent.watchDataSelected(item->id);
}
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.
if (state() != InferiorStopOk) {
QModelIndex currentIndex = inspectorView()->currentIndex();
QmlInspectorAgent *agent = d->inspectorAdapter.agent();
quint32 queryId = agent->queryExpressionResult(watchHandler()->watchItem(currentIndex)->id,
expression);
quint32 queryId = d->inspectorAgent.queryExpressionResult
(watchHandler()->watchItem(currentIndex)->id, expression);
if (queryId) {
d->queryIds.append(queryId);
} else {
......
......@@ -45,7 +45,7 @@ namespace Internal {
class WatchData;
class WatchItem;
class QmlEnginePrivate;
class QmlAdapter;
class QmlInspectorAgent;
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
{
......@@ -62,10 +62,11 @@ public:
QmlDebug::QmlDebugClient::State newState);
void logServiceActivity(const QString &service, const QString &logMessage);
void expressionEvaluated(quint32 queryId, const QVariant &result);
private slots:
void disconnected();
void documentUpdated(QmlJS::Document::Ptr doc);
void expressionEvaluated(quint32 queryId, const QVariant &result);
void errorMessageBoxFinished(int result);
void updateCurrentContext();
......@@ -153,6 +154,7 @@ private:
private:
friend class QmlCppEngine;
friend class QmlEnginePrivate;
friend class QmlInspectorAgent;
QmlEnginePrivate *d;
};
......
/****************************************************************************
**
** 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
/****************************************************************************
**
** 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
......@@ -29,6 +29,7 @@
****************************************************************************/
#include "qmlinspectoragent.h"
#include "qmlengine.h"