forked from qt-creator/qt-creator
QmlJSInspector: Add QmlToolsClient for QmlInspector Service
QmlInspector Service replaces the QDeclarativeObserverMode service in Qt5. This patch adds a new client for the service. Change-Id: Id79c378cfd88042fdf264cd7416a213a139e618c Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
@@ -33,108 +33,75 @@
|
||||
#include "qmljsclientproxy.h"
|
||||
#include "qmljsinspectorconstants.h"
|
||||
|
||||
using namespace QmlJSDebugger;
|
||||
//INSPECTOR SERVICE PROTOCOL
|
||||
// <HEADER><COMMAND><DATA>
|
||||
// <HEADER> : <type{request, response, event}><requestId/eventId>[<response_success_bool>]
|
||||
// <COMMAND> : {"enable", "disable", "select", "setAnimationSpeed",
|
||||
// "showAppOnTop", "createObject", "destroyObject", "moveObject",
|
||||
// "clearCache"}
|
||||
// <DATA> : select: <debugIds_int_list>
|
||||
// setAnimationSpeed: <speed_real>
|
||||
// showAppOnTop: <set_bool>
|
||||
// createObject: <qml_string><parentId_int><imports_string_list><filename_string>
|
||||
// destroyObject: <debugId_int>
|
||||
// moveObject: <debugId_int><newParentId_int>
|
||||
// clearCache: void
|
||||
|
||||
const char REQUEST[] = "request";
|
||||
const char RESPONSE[] = "response";
|
||||
const char EVENT[] = "event";
|
||||
const char ENABLE[] = "enable";
|
||||
const char DISABLE[] = "disable";
|
||||
const char SELECT[] = "select";
|
||||
const char RELOAD[] = "reload";
|
||||
const char SET_ANIMATION_SPEED[] = "setAnimationSpeed";
|
||||
const char SHOW_APP_ON_TOP[] = "showAppOnTop";
|
||||
const char CREATE_OBJECT[] = "createObject";
|
||||
const char DESTROY_OBJECT[] = "destroyObject";
|
||||
const char MOVE_OBJECT[] = "moveObject";
|
||||
const char CLEAR_CACHE[] = "clearCache";
|
||||
|
||||
namespace QmlJSInspector {
|
||||
namespace Internal {
|
||||
|
||||
QmlToolsClient::QmlToolsClient(QmlDebugConnection *client,
|
||||
QObject * /*parent*/)
|
||||
: QmlDebugClient(QLatin1String("QDeclarativeObserverMode"), client),
|
||||
m_connection(client)
|
||||
QmlToolsClient::QmlToolsClient(QmlDebugConnection *client)
|
||||
: BaseToolsClient(client, QLatin1String(Constants::QML_INSPECTOR)),
|
||||
m_connection(client),
|
||||
m_requestId(0),
|
||||
m_slowDownFactor(1)
|
||||
{
|
||||
setObjectName(name());
|
||||
}
|
||||
|
||||
void QmlToolsClient::statusChanged(Status status)
|
||||
{
|
||||
emit connectedStatusChanged(status);
|
||||
}
|
||||
|
||||
void QmlToolsClient::messageReceived(const QByteArray &message)
|
||||
{
|
||||
QDataStream ds(message);
|
||||
|
||||
InspectorProtocol::Message type;
|
||||
ds >> type;
|
||||
QByteArray type;
|
||||
int requestId;
|
||||
ds >> type >> requestId;
|
||||
|
||||
switch (type) {
|
||||
case InspectorProtocol::CurrentObjectsChanged: {
|
||||
int objectCount;
|
||||
ds >> objectCount;
|
||||
|
||||
log(LogReceive, type, QString("%1 [list of debug ids]").arg(objectCount));
|
||||
|
||||
m_currentDebugIds.clear();
|
||||
|
||||
for (int i = 0; i < objectCount; ++i) {
|
||||
int debugId;
|
||||
ds >> debugId;
|
||||
if (debugId != -1)
|
||||
m_currentDebugIds << debugId;
|
||||
if (type == QByteArray(RESPONSE)) {
|
||||
bool success = false;
|
||||
ds >> success;
|
||||
log(LogReceive, type, QString(QLatin1String("requestId: %1 success: %2"))
|
||||
.arg(QString::number(requestId)).arg(QString::number(success)));
|
||||
} else if (type == QByteArray(EVENT)) {
|
||||
QByteArray event;
|
||||
ds >> event;
|
||||
if (event == QByteArray(SELECT)) {
|
||||
m_currentDebugIds.clear();
|
||||
QList<int> debugIds;
|
||||
ds >> debugIds;
|
||||
log(LogReceive, type + ':' + event,
|
||||
QString("%1 [list of debug ids]").arg(debugIds.count()));
|
||||
foreach (int debugId, debugIds) {
|
||||
if (debugId != -1)
|
||||
m_currentDebugIds << debugId;
|
||||
}
|
||||
emit currentObjectsChanged(m_currentDebugIds);
|
||||
}
|
||||
|
||||
emit currentObjectsChanged(m_currentDebugIds);
|
||||
break;
|
||||
}
|
||||
case InspectorProtocol::ToolChanged: {
|
||||
int toolId;
|
||||
ds >> toolId;
|
||||
|
||||
log(LogReceive, type, QString::number(toolId));
|
||||
|
||||
if (toolId == Constants::ZoomMode) {
|
||||
emit zoomToolActivated();
|
||||
} else if (toolId == Constants::SelectionToolMode) {
|
||||
emit selectToolActivated();
|
||||
} else if (toolId == Constants::MarqueeSelectionToolMode) {
|
||||
emit selectMarqueeToolActivated();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InspectorProtocol::AnimationSpeedChanged: {
|
||||
qreal slowDownFactor;
|
||||
ds >> slowDownFactor;
|
||||
|
||||
log(LogReceive, type, QString::number(slowDownFactor));
|
||||
|
||||
emit animationSpeedChanged(slowDownFactor);
|
||||
break;
|
||||
}
|
||||
case InspectorProtocol::AnimationPausedChanged: {
|
||||
bool paused;
|
||||
ds >> paused;
|
||||
|
||||
log(LogReceive, type, paused ? QLatin1String("true")
|
||||
: QLatin1String("false"));
|
||||
|
||||
emit animationPausedChanged(paused);
|
||||
break;
|
||||
}
|
||||
case InspectorProtocol::SetDesignMode: {
|
||||
bool inDesignMode;
|
||||
ds >> inDesignMode;
|
||||
|
||||
log(LogReceive, type, QLatin1String(inDesignMode ? "true" : "false"));
|
||||
|
||||
emit designModeBehaviorChanged(inDesignMode);
|
||||
break;
|
||||
}
|
||||
case InspectorProtocol::ShowAppOnTop: {
|
||||
bool showAppOnTop;
|
||||
ds >> showAppOnTop;
|
||||
|
||||
log(LogReceive, type, QLatin1String(showAppOnTop ? "true" : "false"));
|
||||
|
||||
emit showAppOnTopChanged(showAppOnTop);
|
||||
break;
|
||||
}
|
||||
case InspectorProtocol::Reloaded: {
|
||||
log(LogReceive, type);
|
||||
emit reloaded();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
} else {
|
||||
log(LogReceive, type, QLatin1String("Warning: Not handling message"));
|
||||
}
|
||||
}
|
||||
@@ -156,55 +123,18 @@ void QmlToolsClient::setCurrentObjects(const QList<int> &debugIds)
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(SELECT) << m_currentDebugIds;
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::SetCurrentObjects;
|
||||
ds << cmd
|
||||
<< debugIds.length();
|
||||
|
||||
foreach (int id, debugIds) {
|
||||
ds << id;
|
||||
}
|
||||
|
||||
log(LogSend, cmd, QString("%1 [list of ids]").arg(debugIds.length()));
|
||||
log(LogSend, SELECT, QString("%1 [list of ids]").arg(debugIds.length()));
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
void recurseObjectIdList(const QmlDebugObjectReference &ref,
|
||||
QList<int> &debugIds, QList<QString> &objectIds)
|
||||
{
|
||||
debugIds << ref.debugId();
|
||||
objectIds << ref.idString();
|
||||
foreach (const QmlDebugObjectReference &child, ref.children())
|
||||
recurseObjectIdList(child, debugIds, objectIds);
|
||||
}
|
||||
|
||||
void QmlToolsClient::setObjectIdList(
|
||||
const QList<QmlDebugObjectReference> &objectRoots)
|
||||
const QList<QmlDebugObjectReference> &/*objectRoots*/)
|
||||
{
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
QList<int> debugIds;
|
||||
QList<QString> objectIds;
|
||||
|
||||
foreach (const QmlDebugObjectReference &ref, objectRoots)
|
||||
recurseObjectIdList(ref, debugIds, objectIds);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::ObjectIdList;
|
||||
ds << cmd
|
||||
<< debugIds.length();
|
||||
|
||||
Q_ASSERT(debugIds.length() == objectIds.length());
|
||||
|
||||
for(int i = 0; i < debugIds.length(); ++i) {
|
||||
ds << debugIds[i] << objectIds[i];
|
||||
}
|
||||
|
||||
log(LogSend, cmd,
|
||||
QString("%1 %2 [list of debug / object ids]").arg(debugIds.length()));
|
||||
|
||||
sendMessage(message);
|
||||
//NOT IMPLEMENTED
|
||||
}
|
||||
|
||||
void QmlToolsClient::clearComponentCache()
|
||||
@@ -214,11 +144,10 @@ void QmlToolsClient::clearComponentCache()
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(CLEAR_CACHE);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::ClearComponentCache;
|
||||
ds << cmd;
|
||||
|
||||
log(LogSend, cmd);
|
||||
log(LogSend, CLEAR_CACHE);
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
@@ -230,11 +159,10 @@ void QmlToolsClient::reloadViewer()
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(RELOAD);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::Reload;
|
||||
ds << cmd;
|
||||
|
||||
log(LogSend, cmd);
|
||||
log(LogSend, RELOAD);
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
@@ -246,12 +174,13 @@ void QmlToolsClient::setDesignModeBehavior(bool inDesignMode)
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++;
|
||||
if (inDesignMode)
|
||||
ds << QByteArray(ENABLE);
|
||||
else
|
||||
ds << QByteArray(DISABLE);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::SetDesignMode;
|
||||
ds << cmd
|
||||
<< inDesignMode;
|
||||
|
||||
log(LogSend, cmd, QLatin1String(inDesignMode ? "true" : "false"));
|
||||
log(LogSend, ENABLE, QLatin1String(inDesignMode ? "true" : "false"));
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
@@ -263,86 +192,38 @@ void QmlToolsClient::setAnimationSpeed(qreal slowDownFactor)
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(SET_ANIMATION_SPEED) << slowDownFactor;
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::SetAnimationSpeed;
|
||||
ds << cmd
|
||||
<< slowDownFactor;
|
||||
|
||||
|
||||
log(LogSend, cmd, QString::number(slowDownFactor));
|
||||
log(LogSend, SET_ANIMATION_SPEED, QString::number(slowDownFactor));
|
||||
|
||||
sendMessage(message);
|
||||
//Cache non-zero values
|
||||
if (slowDownFactor)
|
||||
m_slowDownFactor = slowDownFactor;
|
||||
}
|
||||
|
||||
void QmlToolsClient::setAnimationPaused(bool paused)
|
||||
{
|
||||
if (!m_connection || !m_connection->isConnected())
|
||||
return;
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::SetAnimationPaused;
|
||||
ds << cmd
|
||||
<< paused;
|
||||
|
||||
log(LogSend, cmd, paused ? QLatin1String("true") : QLatin1String("false"));
|
||||
|
||||
sendMessage(message);
|
||||
if (paused)
|
||||
setAnimationSpeed(0);
|
||||
else
|
||||
setAnimationSpeed(m_slowDownFactor);
|
||||
}
|
||||
|
||||
void QmlToolsClient::changeToSelectTool()
|
||||
{
|
||||
if (!m_connection || !m_connection->isConnected())
|
||||
return;
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool;
|
||||
InspectorProtocol::Tool tool = InspectorProtocol::SelectTool;
|
||||
ds << cmd
|
||||
<< tool;
|
||||
|
||||
log(LogSend, cmd, InspectorProtocol::toString(tool));
|
||||
|
||||
sendMessage(message);
|
||||
// NOT IMPLEMENTED
|
||||
}
|
||||
|
||||
void QmlToolsClient::changeToSelectMarqueeTool()
|
||||
{
|
||||
if (!m_connection || !m_connection->isConnected())
|
||||
return;
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool;
|
||||
InspectorProtocol::Tool tool = InspectorProtocol::SelectMarqueeTool;
|
||||
ds << cmd
|
||||
<< tool;
|
||||
|
||||
log(LogSend, cmd, InspectorProtocol::toString(tool));
|
||||
|
||||
sendMessage(message);
|
||||
// NOT IMPLEMENTED
|
||||
}
|
||||
|
||||
void QmlToolsClient::changeToZoomTool()
|
||||
{
|
||||
if (!m_connection || !m_connection->isConnected())
|
||||
return;
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool;
|
||||
InspectorProtocol::Tool tool = InspectorProtocol::ZoomTool;
|
||||
ds << cmd
|
||||
<< tool;
|
||||
|
||||
log(LogSend, cmd, InspectorProtocol::toString(tool));
|
||||
|
||||
sendMessage(message);
|
||||
// NOT IMPLEMENTED
|
||||
}
|
||||
|
||||
void QmlToolsClient::showAppOnTop(bool showOnTop)
|
||||
@@ -352,11 +233,10 @@ void QmlToolsClient::showAppOnTop(bool showOnTop)
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(SHOW_APP_ON_TOP) << showOnTop;
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::ShowAppOnTop;
|
||||
ds << cmd << showOnTop;
|
||||
|
||||
log(LogSend, cmd, QLatin1String(showOnTop ? "true" : "false"));
|
||||
log(LogSend, SHOW_APP_ON_TOP, QLatin1String(showOnTop ? "true" : "false"));
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
@@ -371,16 +251,15 @@ void QmlToolsClient::createQmlObject(const QString &qmlText,
|
||||
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::CreateObject;
|
||||
ds << cmd
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(CREATE_OBJECT)
|
||||
<< qmlText
|
||||
<< parentDebugId
|
||||
<< imports
|
||||
<< filename
|
||||
<< order;
|
||||
|
||||
log(LogSend, cmd, QString("%1 %2 [%3] %4").arg(qmlText,
|
||||
log(LogSend, CREATE_OBJECT, QString("%1 %2 [%3] %4").arg(qmlText,
|
||||
QString::number(parentDebugId),
|
||||
imports.join(","), filename));
|
||||
|
||||
@@ -393,11 +272,10 @@ void QmlToolsClient::destroyQmlObject(int debugId)
|
||||
return;
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(DESTROY_OBJECT) << debugId;
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::DestroyObject;
|
||||
ds << cmd << debugId;
|
||||
|
||||
log(LogSend, cmd, QString::number(debugId));
|
||||
log(LogSend, DESTROY_OBJECT, QString::number(debugId));
|
||||
|
||||
sendMessage(message);
|
||||
}
|
||||
@@ -408,13 +286,10 @@ void QmlToolsClient::reparentQmlObject(int debugId, int newParent)
|
||||
return;
|
||||
QByteArray message;
|
||||
QDataStream ds(&message, QIODevice::WriteOnly);
|
||||
ds << QByteArray(REQUEST) << m_requestId++
|
||||
<< QByteArray(MOVE_OBJECT) << debugId << newParent;
|
||||
|
||||
InspectorProtocol::Message cmd = InspectorProtocol::MoveObject;
|
||||
ds << cmd
|
||||
<< debugId
|
||||
<< newParent;
|
||||
|
||||
log(LogSend, cmd, QString("%1 %2").arg(QString::number(debugId),
|
||||
log(LogSend, MOVE_OBJECT, QString("%1 %2").arg(QString::number(debugId),
|
||||
QString::number(newParent)));
|
||||
|
||||
sendMessage(message);
|
||||
@@ -438,7 +313,7 @@ void QmlToolsClient::applyChangesFromQmlFile()
|
||||
}
|
||||
|
||||
void QmlToolsClient::log(LogDirection direction,
|
||||
InspectorProtocol::Message message,
|
||||
const QByteArray &message,
|
||||
const QString &extra)
|
||||
{
|
||||
QString msg;
|
||||
@@ -447,7 +322,7 @@ void QmlToolsClient::log(LogDirection direction,
|
||||
else
|
||||
msg += QLatin1String(" receiving ");
|
||||
|
||||
msg += InspectorProtocol::toString(message);
|
||||
msg += message;
|
||||
msg += QLatin1Char(' ');
|
||||
msg += extra;
|
||||
emit logActivity(name(), msg);
|
||||
|
||||
Reference in New Issue
Block a user