OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmljsinspector / qmljsclientproxy.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32 #ifndef QMLJSCLIENTPROXY_H
33 #define QMLJSCLIENTPROXY_H
34
35 #include "qmljsinspectorplugin.h"
36 #include "qmljsprivateapi.h"
37 #include <QtCore/QObject>
38
39 QT_FORWARD_DECLARE_CLASS(QUrl)
40
41 namespace Debugger {
42 class QmlAdapter;
43 }
44
45 namespace QmlJSInspector {
46
47 //map <filename, editorRevision> -> <lineNumber, columnNumber> -> debugIds
48 typedef QHash<QPair<QString, int>, QHash<QPair<int, int>, QList<int> > > DebugIdHash;
49
50 namespace Internal {
51
52 class InspectorPlugin;
53 class QmlJSObserverClient;
54
55 class ClientProxy : public QObject
56 {
57     Q_OBJECT
58
59 public:
60     explicit ClientProxy(Debugger::QmlAdapter *adapter, QObject *parent = 0);
61
62     bool setBindingForObject(int objectDebugId,
63                              const QString &propertyName,
64                              const QVariant &value,
65                              bool isLiteralValue);
66
67     bool setMethodBodyForObject(int objectDebugId, const QString &methodName, const QString &methodBody);
68     bool resetBindingForObject(int objectDebugId, const QString &propertyName);
69     QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, const QString &expr);
70     void clearComponentCache();
71
72     bool addObjectWatch(int objectDebugId);
73     bool removeObjectWatch(int objectDebugId);
74     void removeAllObjectWatches();
75
76     // returns the object references
77     QList<QDeclarativeDebugObjectReference> objectReferences() const;
78     QDeclarativeDebugObjectReference objectReferenceForId(int debugId) const;
79     QDeclarativeDebugObjectReference objectReferenceForId(const QString &objectId) const;
80     QDeclarativeDebugObjectReference objectReferenceForLocation(const int line, const int column) const;
81     QList<QDeclarativeDebugObjectReference> rootObjectReference() const;
82     DebugIdHash debugIdHash() const { return m_debugIdHash; }
83
84     bool isConnected() const;
85
86     void setSelectedItemsByObjectId(const QList<QDeclarativeDebugObjectReference> &objectRefs);
87
88     QList<QDeclarativeDebugEngineReference> engines() const;
89
90     Debugger::QmlAdapter *qmlAdapter() const;
91
92 signals:
93     void objectTreeUpdated();
94     void connectionStatusMessage(const QString &text);
95
96     void aboutToReloadEngines();
97     void enginesChanged();
98
99     void selectedItemsChanged(const QList<QDeclarativeDebugObjectReference> &selectedItems);
100
101     void connected();
102     void disconnected();
103
104     void colorPickerActivated();
105     void selectToolActivated();
106     void selectMarqueeToolActivated();
107     void zoomToolActivated();
108     void animationSpeedChanged(qreal slowDownFactor);
109     void animationPausedChanged(bool paused);
110     void designModeBehaviorChanged(bool inDesignMode);
111     void showAppOnTopChanged(bool showAppOnTop);
112     void serverReloaded();
113     void selectedColorChanged(const QColor &color);
114     void contextPathUpdated(const QStringList &contextPath);
115     void propertyChanged(int debugId, const QByteArray &propertyName, const QVariant &propertyValue);
116
117 public slots:
118     void refreshObjectTree();
119     void queryEngineContext(int id);
120     void reloadQmlViewer();
121
122     void setDesignModeBehavior(bool inDesignMode);
123     void setAnimationSpeed(qreal slowDownFactor);
124     void setAnimationPaused(bool paused);
125     void changeToColorPickerTool();
126     void changeToZoomTool();
127     void changeToSelectTool();
128     void changeToSelectMarqueeTool();
129     void showAppOnTop(bool showOnTop);
130     void createQmlObject(const QString &qmlText, int parentDebugId,
131                          const QStringList &imports, const QString &filename = QString());
132     void destroyQmlObject(int debugId);
133     void reparentQmlObject(int debugId, int newParent);
134     void setContextPathIndex(int contextIndex);
135
136 private slots:
137     void connectToServer();
138     void clientStatusChanged(QDeclarativeDebugClient::Status status);
139
140     void contextChanged();
141
142     void onCurrentObjectsChanged(const QList<int> &debugIds, bool requestIfNeeded = true);
143     void updateEngineList();
144     void objectTreeFetched(QDeclarativeDebugQuery::State state = QDeclarativeDebugQuery::Completed);
145     void fetchContextObjectRecursive(const QmlJsDebugClient::QDeclarativeDebugContextReference& context);
146     void newObjects();
147     void objectWatchTriggered(const QByteArray &propertyName, const QVariant &propertyValue);
148
149 private:
150     void updateConnected();
151     void reloadEngines();
152
153     QList<QDeclarativeDebugObjectReference> objectReferences(const QDeclarativeDebugObjectReference &objectRef) const;
154     QDeclarativeDebugObjectReference objectReferenceForId(int debugId, const QDeclarativeDebugObjectReference &ref) const;
155
156     enum LogDirection {
157         LogSend,
158         LogReceive
159     };
160     void log(LogDirection direction, const QString &message);
161
162
163 private:
164     Q_DISABLE_COPY(ClientProxy)
165     void buildDebugIdHashRecursive(const QDeclarativeDebugObjectReference &ref);
166
167     Debugger::QmlAdapter *m_adapter;
168     QDeclarativeEngineDebug *m_engineClient;
169     QmlJSObserverClient *m_observerClient;
170
171     QDeclarativeDebugEnginesQuery *m_engineQuery;
172     QDeclarativeDebugRootContextQuery *m_contextQuery;
173     QList<QDeclarativeDebugObjectQuery *> m_objectTreeQuery;
174
175     QList<QDeclarativeDebugObjectReference> m_rootObjects;
176     QList<QDeclarativeDebugEngineReference> m_engines;
177     QTimer m_requestObjectsTimer;
178     DebugIdHash m_debugIdHash;
179
180     QHash<int, QDeclarativeDebugWatch *> m_objectWatches;
181
182     bool m_isConnected;
183 };
184
185 } // namespace Internal
186 } // namespace QmlJSInspector
187
188 #endif // QMLJSCLIENTPROXY_H