Commit 4cd2e326 authored by Aurindam Jana's avatar Aurindam Jana
Browse files

QmlEngineDebugClient: Simplify the client and utility classes



Change-Id: I86033bdbdef94c6f17e706f8e13ce390969171c6
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 8966d82a
...@@ -40,256 +40,157 @@ ...@@ -40,256 +40,157 @@
namespace QmlJsDebugClient { namespace QmlJsDebugClient {
class QDeclarativeDebugConnection; class QDeclarativeDebugConnection;
class QDeclarativeDebugWatch; class QmlDebugPropertyReference;
class QDeclarativeDebugPropertyWatch; class QmlDebugContextReference;
class QDeclarativeDebugObjectExpressionWatch; class QmlDebugObjectReference;
class QDeclarativeDebugEnginesQuery; class QmlDebugFileReference;
class QDeclarativeDebugRootContextQuery; class QmlDebugEngineReference;
class QDeclarativeDebugObjectQuery;
class QDeclarativeDebugExpressionQuery;
class QDeclarativeDebugPropertyReference;
class QDeclarativeDebugContextReference;
class QDeclarativeDebugObjectReference;
class QDeclarativeDebugFileReference;
class QDeclarativeDebugEngineReference;
class QmlEngineDebugClientPrivate;
class QMLJSDEBUGCLIENT_EXPORT QmlEngineDebugClient : public QDeclarativeDebugClient class QMLJSDEBUGCLIENT_EXPORT QmlEngineDebugClient : public QDeclarativeDebugClient
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QmlEngineDebugClient(QDeclarativeDebugConnection *); QmlEngineDebugClient(QDeclarativeDebugConnection *conn);
~QmlEngineDebugClient();
quint32 addWatch(const QmlDebugPropertyReference &property);
QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &, quint32 addWatch(const QmlDebugContextReference &context, const QString &id);
QObject *parent = 0); quint32 addWatch(const QmlDebugObjectReference &object, const QString &expr);
QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &, quint32 addWatch(const QmlDebugObjectReference &object);
QObject *parent = 0); quint32 addWatch(const QmlDebugFileReference &file);
QDeclarativeDebugObjectExpressionWatch *addWatch(const QDeclarativeDebugObjectReference &, const QString &,
QObject *parent = 0); void removeWatch(quint32 watch);
QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugObjectReference &,
QObject *parent = 0); quint32 queryAvailableEngines();
QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugFileReference &, quint32 queryRootContexts(const QmlDebugEngineReference &context);
QObject *parent = 0); quint32 queryObject(const QmlDebugObjectReference &object);
quint32 queryObjectRecursive(const QmlDebugObjectReference &object);
void removeWatch(QDeclarativeDebugWatch *watch); quint32 queryExpressionResult(int objectDebugId,
const QString &expr);
QDeclarativeDebugEnginesQuery *queryAvailableEngines(QObject *parent = 0); quint32 setBindingForObject(int objectDebugId, const QString &propertyName,
QDeclarativeDebugRootContextQuery *queryRootContexts(const QDeclarativeDebugEngineReference &, const QVariant &bindingExpression,
QObject *parent = 0); bool isLiteralValue,
QDeclarativeDebugObjectQuery *queryObject(const QDeclarativeDebugObjectReference &, QString source, int line);
QObject *parent = 0); quint32 resetBindingForObject(int objectDebugId,
QDeclarativeDebugObjectQuery *queryObjectRecursive(const QDeclarativeDebugObjectReference &, const QString &propertyName);
QObject *parent = 0); quint32 setMethodBody(int objectDebugId, const QString &methodName,
QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, const QString &methodBody);
const QString &expr,
QObject *parent = 0); signals:
bool setBindingForObject(int objectDebugId, const QString &propertyName,
const QVariant &bindingExpression, bool isLiteralValue,
QString source = QString(), int line = -1);
bool resetBindingForObject(int objectDebugId, const QString &propertyName);
bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody);
QmlEngineDebugClientPrivate *priv() const { return d; }
Q_SIGNALS:
void newObjects();
void newStatus(QDeclarativeDebugClient::Status status); void newStatus(QDeclarativeDebugClient::Status status);
void newObjects();
void valueChanged(int debugId, const QByteArray &name,
const QVariant &value);
void result(quint32 queryId, const QVariant &result);
protected: protected:
virtual void statusChanged(Status status); virtual void statusChanged(Status status);
virtual void messageReceived(const QByteArray &); virtual void messageReceived(const QByteArray &);
private: private:
friend class QmlEngineDebugClientPrivate; quint32 getId() { return m_nextId++; }
QmlEngineDebugClientPrivate *d;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugWatch : public QObject
{
Q_OBJECT
public:
enum State { Waiting, Active, Inactive, Dead };
QDeclarativeDebugWatch(QObject *);
~QDeclarativeDebugWatch();
int queryId() const;
int objectDebugId() const;
State state() const;
Q_SIGNALS:
void stateChanged(QDeclarativeDebugWatch::State);
//void objectChanged(int, const QDeclarativeDebugObjectReference &);
//void valueChanged(int, const QVariant &);
// Server sends value as string if it is a user-type variant void decode(QDataStream &d, QmlDebugContextReference &context);
void valueChanged(const QByteArray &name, const QVariant &value); void decode(QDataStream &d, QmlDebugObjectReference &object, bool simple);
private: private:
friend class QmlEngineDebugClient; quint32 m_nextId;
friend class QmlEngineDebugClientPrivate;
void setState(State);
State m_state;
int m_queryId;
QmlEngineDebugClient *m_client;
int m_objectDebugId;
}; };
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugPropertyWatch : public QDeclarativeDebugWatch class QmlDebugFileReference
{ {
Q_OBJECT
public: public:
QDeclarativeDebugPropertyWatch(QObject *parent); QmlDebugFileReference() : m_lineNumber(-1), m_columnNumber(-1) {}
QString name() const; QUrl url() const { return m_url; }
int lineNumber() const { return m_lineNumber; }
int columnNumber() const { return m_columnNumber; }
private: private:
friend class QmlEngineDebugClient; friend class QmlEngineDebugClient;
QString m_name;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugObjectExpressionWatch : public QDeclarativeDebugWatch
{
Q_OBJECT
public:
QDeclarativeDebugObjectExpressionWatch(QObject *parent);
QString expression() const;
private:
friend class QmlEngineDebugClient;
QString m_expr;
int m_debugId;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugQuery : public QObject
{
Q_OBJECT
public:
enum State { Waiting, Error, Completed };
State state() const;
bool isWaiting() const;
Q_SIGNALS:
void stateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State);
protected:
QDeclarativeDebugQuery(QObject *);
private:
friend class QmlEngineDebugClient;
friend class QmlEngineDebugClientPrivate;
void setState(State);
State m_state;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugFileReference
{
public:
QDeclarativeDebugFileReference();
QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &);
QDeclarativeDebugFileReference &operator=(const QDeclarativeDebugFileReference &);
QUrl url() const;
void setUrl(const QUrl &);
int lineNumber() const;
void setLineNumber(int);
int columnNumber() const;
void setColumnNumber(int);
private:
friend class QmlEngineDebugClientPrivate;
QUrl m_url; QUrl m_url;
int m_lineNumber; int m_lineNumber;
int m_columnNumber; int m_columnNumber;
}; };
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugEngineReference class QmlDebugEngineReference
{ {
public: public:
QDeclarativeDebugEngineReference(); QmlDebugEngineReference() : m_debugId(-1) {}
QDeclarativeDebugEngineReference(int); QmlDebugEngineReference(int id) : m_debugId(id) {}
QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &);
QDeclarativeDebugEngineReference &operator=(const QDeclarativeDebugEngineReference &);
int debugId() const; int debugId() const { return m_debugId; }
QString name() const; QString name() const { return m_name; }
private: private:
friend class QmlEngineDebugClientPrivate; friend class QmlEngineDebugClient;
int m_debugId; int m_debugId;
QString m_name; QString m_name;
}; };
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugObjectReference typedef QList<QmlDebugEngineReference> QmlDebugEngineReferenceList;
class QmlDebugObjectReference
{ {
public: public:
QDeclarativeDebugObjectReference(); QmlDebugObjectReference() : m_debugId(-1), m_contextDebugId(-1) {}
QDeclarativeDebugObjectReference(int); QmlDebugObjectReference(int id) : m_debugId(id), m_contextDebugId(-1) {}
QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &);
QDeclarativeDebugObjectReference &operator=(const QDeclarativeDebugObjectReference &);
int debugId() const; int debugId() const { return m_debugId; }
QString className() const; QString className() const { return m_className; }
QString idString() const; QString idString() const { return m_idString; }
QString name() const; QString name() const { return m_name; }
QDeclarativeDebugFileReference source() const; QmlDebugFileReference source() const { return m_source; }
int contextDebugId() const; int contextDebugId() const { return m_contextDebugId; }
QList<QDeclarativeDebugPropertyReference> properties() const; QList<QmlDebugPropertyReference> properties() const { return m_properties; }
QList<QDeclarativeDebugObjectReference> children() const; QList<QmlDebugObjectReference> children() const { return m_children; }
private: private:
friend class QmlEngineDebugClientPrivate; friend class QmlEngineDebugClient;
int m_debugId; int m_debugId;
QString m_class; QString m_className;
QString m_idString; QString m_idString;
QString m_name; QString m_name;
QDeclarativeDebugFileReference m_source; QmlDebugFileReference m_source;
int m_contextDebugId; int m_contextDebugId;
QList<QDeclarativeDebugPropertyReference> m_properties; QList<QmlDebugPropertyReference> m_properties;
QList<QDeclarativeDebugObjectReference> m_children; QList<QmlDebugObjectReference> m_children;
}; };
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugContextReference class QmlDebugContextReference
{ {
public: public:
QDeclarativeDebugContextReference(); QmlDebugContextReference() : m_debugId(-1) {}
QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &);
QDeclarativeDebugContextReference &operator=(const QDeclarativeDebugContextReference &);
int debugId() const; int debugId() const { return m_debugId; }
QString name() const; QString name() const { return m_name; }
QList<QDeclarativeDebugObjectReference> objects() const; QList<QmlDebugObjectReference> objects() const { return m_objects; }
QList<QDeclarativeDebugContextReference> contexts() const; QList<QmlDebugContextReference> contexts() const { return m_contexts; }
private: private:
friend class QmlEngineDebugClientPrivate; friend class QmlEngineDebugClient;
int m_debugId; int m_debugId;
QString m_name; QString m_name;
QList<QDeclarativeDebugObjectReference> m_objects; QList<QmlDebugObjectReference> m_objects;
QList<QDeclarativeDebugContextReference> m_contexts; QList<QmlDebugContextReference> m_contexts;
}; };
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugPropertyReference class QmlDebugPropertyReference
{ {
public: public:
QDeclarativeDebugPropertyReference(); QmlDebugPropertyReference() : m_objectDebugId(-1), m_hasNotifySignal(false) {}
QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &);
QDeclarativeDebugPropertyReference &operator=(const QDeclarativeDebugPropertyReference &);
int objectDebugId() const; int debugId() const { return m_objectDebugId; }
QString name() const; QString name() const { return m_name; }
QVariant value() const; QVariant value() const { return m_value; }
QString valueTypeName() const; QString valueTypeName() const { return m_valueTypeName; }
QString binding() const; QString binding() const { return m_binding; }
bool hasNotifySignal() const; bool hasNotifySignal() const { return m_hasNotifySignal; }
private: private:
friend class QmlEngineDebugClientPrivate; friend class QmlEngineDebugClient;
int m_objectDebugId; int m_objectDebugId;
QString m_name; QString m_name;
QVariant m_value; QVariant m_value;
...@@ -298,75 +199,11 @@ private: ...@@ -298,75 +199,11 @@ private:
bool m_hasNotifySignal; bool m_hasNotifySignal;
}; };
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugEnginesQuery : public QDeclarativeDebugQuery
{
Q_OBJECT
public:
virtual ~QDeclarativeDebugEnginesQuery();
QList<QDeclarativeDebugEngineReference> engines() const;
private:
friend class QmlEngineDebugClient;
friend class QmlEngineDebugClientPrivate;
QDeclarativeDebugEnginesQuery(QObject *);
QmlEngineDebugClient *m_client;
int m_queryId;
QList<QDeclarativeDebugEngineReference> m_engines;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugRootContextQuery : public QDeclarativeDebugQuery
{
Q_OBJECT
public:
virtual ~QDeclarativeDebugRootContextQuery();
QDeclarativeDebugContextReference rootContext() const;
private:
friend class QmlEngineDebugClient;
friend class QmlEngineDebugClientPrivate;
QDeclarativeDebugRootContextQuery(QObject *);
QmlEngineDebugClient *m_client;
int m_queryId;
QDeclarativeDebugContextReference m_context;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugObjectQuery : public QDeclarativeDebugQuery
{
Q_OBJECT
public:
virtual ~QDeclarativeDebugObjectQuery();
QDeclarativeDebugObjectReference object() const;
private:
friend class QmlEngineDebugClient;
friend class QmlEngineDebugClientPrivate;
QDeclarativeDebugObjectQuery(QObject *);
QmlEngineDebugClient *m_client;
int m_queryId;
QDeclarativeDebugObjectReference m_object;
};
class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativeDebugQuery
{
Q_OBJECT
public:
virtual ~QDeclarativeDebugExpressionQuery();
QVariant expression() const;
QVariant result() const;
private:
friend class QmlEngineDebugClient;
friend class QmlEngineDebugClientPrivate;
QDeclarativeDebugExpressionQuery(QObject *);
QmlEngineDebugClient *m_client;
int m_queryId;
QVariant m_expr;
QVariant m_result;
};
} // namespace QmlJsDebugClient } // namespace QmlJsDebugClient
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugEngineReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QmlDebugObjectReference)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugObjectReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QmlDebugEngineReference)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugContextReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QmlDebugEngineReferenceList)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugPropertyReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QmlDebugContextReference)
#endif // QMLENGINEDEBUGCLIENT_H #endif // QMLENGINEDEBUGCLIENT_H
...@@ -311,7 +311,17 @@ QmlJsDebugClient::QmlEngineDebugClient *QmlAdapter::engineDebugClient() const ...@@ -311,7 +311,17 @@ QmlJsDebugClient::QmlEngineDebugClient *QmlAdapter::engineDebugClient() const
void QmlAdapter::setEngineDebugClient(QmlJsDebugClient::QmlEngineDebugClient *client) void QmlAdapter::setEngineDebugClient(QmlJsDebugClient::QmlEngineDebugClient *client)
{ {
Internal::QmlEngine *engine =
qobject_cast<Internal::QmlEngine *>(d->m_engine.data());
if (engine && d->m_engineDebugClient)
disconnect(d->m_engineDebugClient, SIGNAL(result(quint32,QVariant)),
engine,
SLOT(expressionEvaluated(quint32,QVariant)));
d->m_engineDebugClient = client; d->m_engineDebugClient = client;
if (engine && d->m_engineDebugClient)
connect(d->m_engineDebugClient, SIGNAL(result(quint32,QVariant)),
engine,
SLOT(expressionEvaluated(quint32,QVariant)));
} }
QmlJsDebugClient::QDebugMessageClient *QmlAdapter::messageClient() const QmlJsDebugClient::QDebugMessageClient *QmlAdapter::messageClient() const
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <projectexplorer/applicationlauncher.h> #include <projectexplorer/applicationlauncher.h>
#include <qmljsdebugclient/qdeclarativeoutputparser.h> #include <qmljsdebugclient/qdeclarativeoutputparser.h>
#include <qmljsdebugclient/qmlenginedebugclient.h>
#include <qmljseditor/qmljseditorconstants.h> #include <qmljseditor/qmljseditorconstants.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
...@@ -120,6 +121,7 @@ private: ...@@ -120,6 +121,7 @@ private:
bool m_validContext; bool m_validContext;
QHash<QString,BreakpointModelId> pendingBreakpoints; QHash<QString,BreakpointModelId> pendingBreakpoints;
bool m_retryOnConnectFail; bool m_retryOnConnectFail;
QList<quint32> queryIds;
}; };
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *q) QmlEnginePrivate::QmlEnginePrivate(QmlEngine *q)
...@@ -1038,21 +1040,14 @@ void QmlEngine::synchronizeWatchers() ...@@ -1038,21 +1040,14 @@ void QmlEngine::synchronizeWatchers()
} }
} }
void QmlEngine::onDebugQueryStateChanged( void QmlEngine::expressionEvaluated(quint32 queryId, const QVariant &result)
QmlJsDebugClient::QDeclarativeDebugQuery::State state)
{ {
QmlJsDebugClient::QDeclarativeDebugExpressionQuery *query = if (d->queryIds.contains(queryId)) {
qobject_cast<QmlJsDebugClient::QDeclarativeDebugExpressionQuery *>( d->queryIds.removeOne(queryId);
sender()); QtMessageLogItem *item = constructLogItemTree(result);
if (query && state != QmlJsDebugClient::QDeclarativeDebugQuery::Error) {
QtMessageLogItem *item = constructLogItemTree(query->result());
if (item) if (item)
qtMessageLogHandler()->appendItem(item); qtMessageLogHandler()->appendItem(item);
} else }
qtMessageLogHandler()->
appendItem(new QtMessageLogItem(QtMessageLogHandler::ErrorType,
_("Error evaluating expression.")));
delete query;
} }
bool QmlEngine::hasCapability(unsigned cap) const bool QmlEngine::hasCapability(unsigned cap) const
...@@ -1154,16 +1149,19 @@ bool QmlEngine::evaluateScriptExpression(const QString& expression) ...@@ -1154,16 +1149,19 @@ bool QmlEngine::evaluateScriptExpression(const QString& expression)
int id = d->m_adapter.currentSelectedDebugId(); int id = d->m_adapter.currentSelectedDebugId();
if (engineDebug && id != -1) { if (engineDebug && id != -1) {
QDeclarativeDebugExpressionQuery *query = quint32 queryId =
engineDebug->queryExpressionResult(id, expression); engineDebug->queryExpressionResult(
connect(query, id, expression);
SIGNAL(stateChanged( if (queryId) {
QmlJsDebugClient::QDeclarativeDebugQuery d->queryIds << queryId;
::State)), } else {
this, didEvaluate = false;
SLOT(onDebugQueryStateChanged( qtMessageLogHandler()->
QmlJsDebugClient::QDeclarativeDebugQuery appendItem(
::State))); new QtMessageLogItem(
QtMessageLogHandler::ErrorType,
_("Error evaluating expression.")));
}
} }
} else { } else {
executeDebuggerCommand(expression); executeDebuggerCommand(expression);
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#define DEBUGGER_QMLENGINE_H #define DEBUGGER_QMLENGINE_H