qmlinspectoragent.h 5.64 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
31
32
33

#ifndef QMLINSPECTORAGENT_H
#define QMLINSPECTORAGENT_H

#include <QObject>
34
35
#include <QStack>
#include <QTimer>
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include <qmldebug/baseenginedebugclient.h>
#include <watchdata.h>

namespace Debugger {

class DebuggerEngine;

namespace Internal {

class WatchData;

//map <filename, editorRevision> -> <lineNumber, columnNumber> -> debugId
typedef
QHash<QPair<QString, int>, QHash<QPair<int, int>, QList<int> > > DebugIdHash;

class QmlInspectorAgent : public QObject
{
    Q_OBJECT
public:
    explicit QmlInspectorAgent(DebuggerEngine *engine, QObject *parent = 0);

    void fetchObject(int debugId);
    quint32 queryExpressionResult(int debugId, const QString &expression);

61
    void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
62
    void updateWatchData(const WatchData &data);
63
    void watchDataSelected(const WatchData *data);
64
    bool selectObjectInTree(int debugId);
65
66
67
68
69
70
71
72
73
74
75
76

    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);

77
78
    QmlDebug::ObjectReference objectForName(const QString &objectId) const;
    QmlDebug::ObjectReference objectForId(int objectDebugId) const;
79
80
    int objectIdForLocation(int line, int column) const;
    QHash<int, QString> rootObjectIds() const;
81
82
83
84
85
86
87
    DebugIdHash debugIdHash() const { return m_debugIdHash; }

    bool addObjectWatch(int objectDebugId);
    bool isObjectBeingWatched(int objectDebugId);
    bool removeObjectWatch(int objectDebugId);
    void removeAllObjectWatches();

Kai Koehne's avatar
Kai Koehne committed
88
    void setEngineClient(QmlDebug::BaseEngineDebugClient *client);
89
    QString displayName(int objectDebugId) const;
90
    int parentIdForObject(int objectDebugId);
91
    void reloadEngines();
92

93
94
95
public slots:
    void fetchContextObjectsForLocation(const QString &file,
                                         int lineNumber, int columnNumber);
96
97
    void queryEngineContext();

98
99
signals:
    void objectTreeUpdated();
Kai Koehne's avatar
Kai Koehne committed
100
    void objectFetched(const QmlDebug::ObjectReference &ref);
101
102
103
    void expressionResult(quint32 queryId, const QVariant &value);
    void propertyChanged(int debugId, const QByteArray &propertyName,
                         const QVariant &propertyValue);
104
    void automaticUpdateFailed();
Aurindam Jana's avatar
Aurindam Jana committed
105
    void jumpToObjectDefinition(const QmlDebug::FileReference &objSource, int debugId);
106
107
108
109

private slots:
    void updateStatus();
    void onResult(quint32 queryId, const QVariant &value, const QByteArray &type);
110
    void newObject(int engineId, int objectId, int parentId);
111
    void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value);
112
113

private:
114
    void updateObjectTree(const QmlDebug::ContextReference &context);
115
    void verifyAndInsertObjectInTree(const QmlDebug::ObjectReference &object);
116
    void insertObjectInTree(const QmlDebug::ObjectReference &result);
117

Kai Koehne's avatar
Kai Koehne committed
118
119
    void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
    QList<WatchData> buildWatchData(const QmlDebug::ObjectReference &obj,
120
                                           const QByteArray &parentIname, bool append);
121
122
123
124
125
126
127

    enum LogDirection {
        LogSend,
        LogReceive
    };
    void log(LogDirection direction, const QString &message);

128
129
    bool isConnected() const;
    void clearObjectTree();
130
131

private:
132
    DebuggerEngine *m_debuggerEngine;
133
134
135
136
137
138
    QmlDebug::BaseEngineDebugClient *m_engineClient;

    quint32 m_engineQueryId;
    quint32 m_rootContextQueryId;
    int m_objectToSelect;
    QList<quint32> m_objectTreeQueryIds;
139
140
    QStack<QmlDebug::ObjectReference> m_objectStack;
    QmlDebug::EngineReference m_engine;
141
    QHash<int, QByteArray> m_debugIdToIname;
142
    QHash<int, QmlDebug::FileReference> m_debugIdLocations;
143
144
145
    DebugIdHash m_debugIdHash;

    QList<int> m_objectWatches;
hjk's avatar
hjk committed
146
    QList<int> m_fetchDataIds;
147
    QTimer m_delayQueryTimer;
148
149
150
151
152
153
};

} // Internal
} // Debugger

#endif // QMLINSPECTORAGENT_H