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

#ifndef QMLINSPECTORAGENT_H
#define QMLINSPECTORAGENT_H

34 35
#include <QStack>
#include <QTimer>
36

37 38
#include <coreplugin/icontext.h>
#include <debugger/debuggerconstants.h>
39
#include <qmldebug/baseenginedebugclient.h>
40 41 42 43 44 45 46 47 48
#include <qmldebug/qmldebugclient.h>

namespace QmlDebug {
class BaseEngineDebugClient;
class BaseToolsClient;
class ObjectReference;
class FileReference;
class QmlDebugConnection;
}
49 50 51 52

namespace Debugger {
namespace Internal {

hjk's avatar
hjk committed
53
class DebuggerEngine;
54
class QmlEngine;
55 56 57 58 59 60 61 62 63 64
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:
65
    QmlInspectorAgent(QmlEngine *engine, QmlDebug::QmlDebugConnection *connection);
66 67 68 69

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

70
    void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
71
    void updateWatchData(const WatchData &data);
72
    void watchDataSelected(quint64 id);
73
    bool selectObjectInTree(int debugId);
74
    void addObjectWatch(int objectDebugId);
75

76
    QmlDebug::ObjectReference objectForId(int objectDebugId) const;
77
    QString displayName(int objectDebugId) const;
78
    void reloadEngines();
79

80
    QmlDebug::BaseToolsClient *toolsClient() const;
81

82
private:
83
    void updateState();
84
    void onResult(quint32 queryId, const QVariant &value, const QByteArray &type);
85
    void newObject(int engineId, int objectId, int parentId);
86
    void onValueChanged(int debugId, const QByteArray &propertyName, const QVariant &value);
87

88
    void queryEngineContext();
89
    void updateObjectTree(const QmlDebug::ContextReference &context);
90
    void verifyAndInsertObjectInTree(const QmlDebug::ObjectReference &object);
91
    void insertObjectInTree(const QmlDebug::ObjectReference &result);
92

Kai Koehne's avatar
Kai Koehne committed
93
    void buildDebugIdHashRecursive(const QmlDebug::ObjectReference &ref);
94 95
    void addWatchData(const QmlDebug::ObjectReference &obj,
                      const QByteArray &parentIname, bool append);
96 97 98 99 100 101 102

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

103 104
    bool isConnected() const;
    void clearObjectTree();
105

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    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 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);

    enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
    void selectObject(
            const QmlDebug::ObjectReference &objectReference,
            SelectionTarget target);

    void enableTools(const bool enable);

129
private:
130
    QmlEngine *m_qmlEngine;
131 132 133 134 135 136
    QmlDebug::BaseEngineDebugClient *m_engineClient;

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

    QList<int> m_objectWatches;
hjk's avatar
hjk committed
144
    QList<int> m_fetchDataIds;
145
    QTimer m_delayQueryTimer;
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

    DebuggerEngine *m_masterEngine;
    QHash<QString, QmlDebug::BaseEngineDebugClient*> m_engineClients;
    QmlDebug::BaseToolsClient *m_toolsClient;

    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;
165 166 167 168 169 170
};

} // Internal
} // Debugger

#endif // QMLINSPECTORAGENT_H