2011-04-13 08:42:33 +02:00
|
|
|
/**************************************************************************
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file is part of Qt Creator
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-04-13 08:42:33 +02:00
|
|
|
**
|
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-07-08 11:34:51 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-07-08 11:34:51 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
**************************************************************************/
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
#include "qmltoolsclient.h"
|
2012-04-18 14:20:54 +02:00
|
|
|
#include <QStringList>
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
//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";
|
2011-02-24 17:26:36 +01:00
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
namespace QmlDebug {
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
QmlToolsClient::QmlToolsClient(QmlDebugConnection *client)
|
2012-04-18 14:20:54 +02:00
|
|
|
: BaseToolsClient(client, QLatin1String("QmlInspector")),
|
2012-04-24 12:23:54 +02:00
|
|
|
m_connection(client),
|
|
|
|
|
m_requestId(0),
|
2012-05-11 16:25:53 +02:00
|
|
|
m_slowDownFactor(1),
|
|
|
|
|
m_reloadQueryId(-1)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2011-09-20 12:29:03 +02:00
|
|
|
setObjectName(name());
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::messageReceived(const QByteArray &message)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
|
|
|
|
QDataStream ds(message);
|
|
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
QByteArray type;
|
|
|
|
|
int requestId;
|
|
|
|
|
ds >> type >> requestId;
|
|
|
|
|
|
|
|
|
|
if (type == QByteArray(RESPONSE)) {
|
|
|
|
|
bool success = false;
|
|
|
|
|
ds >> success;
|
2012-05-11 16:25:53 +02:00
|
|
|
|
|
|
|
|
if ((m_reloadQueryId != -1) && (m_reloadQueryId == requestId) && success)
|
|
|
|
|
emit reloaded();
|
|
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
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);
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
2012-04-24 12:23:54 +02:00
|
|
|
} else {
|
2012-03-23 12:39:19 +01:00
|
|
|
log(LogReceive, type, QLatin1String("Warning: Not handling message"));
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QList<int> QmlToolsClient::currentObjects() const
|
2010-07-14 17:22:22 +02:00
|
|
|
{
|
2010-10-25 08:56:25 +02:00
|
|
|
return m_currentDebugIds;
|
2010-07-14 17:22:22 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::setCurrentObjects(const QList<int> &debugIds)
|
2011-02-24 17:52:35 +01:00
|
|
|
{
|
2010-07-08 11:34:51 +02:00
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
2010-10-25 09:38:54 +02:00
|
|
|
if (debugIds == m_currentDebugIds)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_currentDebugIds = debugIds;
|
|
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(SELECT) << m_currentDebugIds;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, SELECT, QString("%1 [list of ids]").arg(debugIds.length()));
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::setObjectIdList(
|
2012-05-10 10:29:11 +02:00
|
|
|
const QList<ObjectReference> &/*objectRoots*/)
|
2010-07-26 15:31:59 +02:00
|
|
|
{
|
2012-04-24 12:23:54 +02:00
|
|
|
//NOT IMPLEMENTED
|
2010-07-26 15:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::clearComponentCache()
|
2010-08-03 14:07:30 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(CLEAR_CACHE);
|
2010-08-03 14:07:30 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, CLEAR_CACHE);
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-08-03 14:07:30 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-11 16:25:53 +02:00
|
|
|
void QmlToolsClient::reload(const QHash<QString, QByteArray> &changesHash)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
2012-05-11 16:25:53 +02:00
|
|
|
m_reloadQueryId = m_requestId;
|
|
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
2012-05-11 16:25:53 +02:00
|
|
|
<< QByteArray(RELOAD) << changesHash;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, RELOAD);
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::setDesignModeBehavior(bool inDesignMode)
|
2010-07-12 12:02:35 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++;
|
|
|
|
|
if (inDesignMode)
|
|
|
|
|
ds << QByteArray(ENABLE);
|
|
|
|
|
else
|
|
|
|
|
ds << QByteArray(DISABLE);
|
2010-07-12 12:02:35 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, ENABLE, QLatin1String(inDesignMode ? "true" : "false"));
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-07-12 12:02:35 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::setAnimationSpeed(qreal slowDownFactor)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(SET_ANIMATION_SPEED) << slowDownFactor;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, SET_ANIMATION_SPEED, QString::number(slowDownFactor));
|
2011-03-18 20:45:23 +01:00
|
|
|
|
|
|
|
|
sendMessage(message);
|
2012-04-24 12:23:54 +02:00
|
|
|
//Cache non-zero values
|
|
|
|
|
if (slowDownFactor)
|
|
|
|
|
m_slowDownFactor = slowDownFactor;
|
2011-03-18 20:45:23 +01:00
|
|
|
}
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::setAnimationPaused(bool paused)
|
2011-03-18 20:45:23 +01:00
|
|
|
{
|
2012-04-24 12:23:54 +02:00
|
|
|
if (paused)
|
|
|
|
|
setAnimationSpeed(0);
|
|
|
|
|
else
|
|
|
|
|
setAnimationSpeed(m_slowDownFactor);
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::changeToSelectTool()
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2012-04-24 12:23:54 +02:00
|
|
|
// NOT IMPLEMENTED
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::changeToSelectMarqueeTool()
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2012-04-24 12:23:54 +02:00
|
|
|
// NOT IMPLEMENTED
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::changeToZoomTool()
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2012-04-24 12:23:54 +02:00
|
|
|
// NOT IMPLEMENTED
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::showAppOnTop(bool showOnTop)
|
2010-11-23 10:07:09 +01:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(SHOW_APP_ON_TOP) << showOnTop;
|
2010-11-23 10:07:09 +01:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, SHOW_APP_ON_TOP, QLatin1String(showOnTop ? "true" : "false"));
|
2010-11-23 10:07:09 +01:00
|
|
|
|
|
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::createQmlObject(const QString &qmlText,
|
2012-04-17 08:43:27 +02:00
|
|
|
int parentDebugId,
|
|
|
|
|
const QStringList &imports,
|
|
|
|
|
const QString &filename, int order)
|
2010-07-16 09:41:56 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(CREATE_OBJECT)
|
2010-07-16 09:41:56 +02:00
|
|
|
<< qmlText
|
2010-07-21 14:26:25 +02:00
|
|
|
<< parentDebugId
|
2010-07-16 09:41:56 +02:00
|
|
|
<< imports
|
2011-05-24 11:40:17 +02:00
|
|
|
<< filename
|
|
|
|
|
<< order;
|
2010-07-16 09:41:56 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, CREATE_OBJECT, QString("%1 %2 [%3] %4").arg(qmlText,
|
2012-04-17 08:43:27 +02:00
|
|
|
QString::number(parentDebugId),
|
2011-02-24 17:26:36 +01:00
|
|
|
imports.join(","), filename));
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-07-16 09:41:56 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::destroyQmlObject(int debugId)
|
2010-07-19 10:42:39 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(DESTROY_OBJECT) << debugId;
|
2010-07-19 10:42:39 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, DESTROY_OBJECT, QString::number(debugId));
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-07-19 10:42:39 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::reparentQmlObject(int debugId, int newParent)
|
2010-08-26 17:38:31 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
QByteArray message;
|
|
|
|
|
QDataStream ds(&message, QIODevice::WriteOnly);
|
2012-04-24 12:23:54 +02:00
|
|
|
ds << QByteArray(REQUEST) << m_requestId++
|
|
|
|
|
<< QByteArray(MOVE_OBJECT) << debugId << newParent;
|
2010-08-26 17:38:31 +02:00
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
log(LogSend, MOVE_OBJECT, QString("%1 %2").arg(QString::number(debugId),
|
2011-02-24 17:26:36 +01:00
|
|
|
QString::number(newParent)));
|
2010-10-07 10:56:36 +02:00
|
|
|
|
2010-08-26 17:38:31 +02:00
|
|
|
sendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 10:42:39 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::applyChangesToQmlFile()
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::applyChangesFromQmlFile()
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
|
|
|
|
if (!m_connection || !m_connection->isConnected())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlToolsClient::log(LogDirection direction,
|
2012-04-24 12:23:54 +02:00
|
|
|
const QByteArray &message,
|
2012-04-16 17:09:27 +02:00
|
|
|
const QString &extra)
|
2010-12-16 17:26:25 +01:00
|
|
|
{
|
|
|
|
|
QString msg;
|
2011-02-24 17:26:36 +01:00
|
|
|
if (direction == LogSend)
|
|
|
|
|
msg += QLatin1String(" sending ");
|
|
|
|
|
else
|
|
|
|
|
msg += QLatin1String(" receiving ");
|
|
|
|
|
|
2012-04-24 12:23:54 +02:00
|
|
|
msg += message;
|
2011-02-24 17:26:36 +01:00
|
|
|
msg += QLatin1Char(' ');
|
|
|
|
|
msg += extra;
|
2010-12-16 17:26:25 +01:00
|
|
|
emit logActivity(name(), msg);
|
|
|
|
|
}
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
} // namespace QmlDebug
|