qmljsinspector.h 5.52 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
30 31 32 33 34 35
**
**************************************************************************/

#ifndef QMLJSINSPECTOR_H
#define QMLJSINSPECTOR_H

36
#include <coreplugin/editormanager/ieditor.h>
37
#include <utils/fileinprojectfinder.h>
38

39 40
#include <qmldebug/baseenginedebugclient.h>

41 42 43
#include <qmljs/qmljsdocument.h>
#include <qmljs/parser/qmljsastfwd_p.h>

44 45
#include <debugger/debuggerconstants.h>

46 47
#include <QAction>
#include <QObject>
48 49

namespace ProjectExplorer {
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
50 51
class Project;
class Environment;
52 53
}

54
namespace TextEditor {
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
55
class ITextEditor;
56 57
}

58
namespace Core {
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
59
class IContext;
60 61
}

62
namespace QmlJS {
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
63
class ModelManagerInterface;
64 65
}

66 67 68
namespace QmlJSInspector {
namespace Internal {

69
class QmlJsInspectorToolBar;
70
class QmlJSPropertyInspector;
71
class ClientProxy;
72
class InspectorSettings;
73
class ContextCrumblePath;
74
class QmlJSLiveTextPreview;
75

76 77
using namespace QmlDebug;

Lasse Holmstedt's avatar
Lasse Holmstedt committed
78
class InspectorUi : public QObject
79 80 81 82
{
    Q_OBJECT

public:
83 84 85 86 87
    enum DebugMode {
        StandaloneMode,
        CppProjectWithQmlEngines,
        QmlProjectWithCppPlugins
    };
88

Lasse Holmstedt's avatar
Lasse Holmstedt committed
89 90
    InspectorUi(QObject *parent = 0);
    virtual ~InspectorUi();
91

92 93 94 95 96 97
    void saveSettings() const;
    void restoreSettings();

    bool showExperimentalWarning();
    void setShowExperimentalWarning(bool value);

Lasse Holmstedt's avatar
Lasse Holmstedt committed
98
    static InspectorUi *instance();
99

100
    QString findFileInProject(const QUrl &fileUrl) const;
101

Lasse Holmstedt's avatar
Lasse Holmstedt committed
102
    void setupUi();
103
    bool isConnected() const;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
104 105
    void connected(ClientProxy *clientProxy);
    void disconnected();
106
    void setDebuggerEngine(QObject *qmlEngine);
107

108 109
signals:
    void statusMessage(const QString &text);
110
    void livePreviewActivated(bool isActivated);
111 112 113

public slots:
    void reloadQmlViewer();
114
    void serverReloaded();
115
    void setApplyChangesToQmlInspector(bool applyChanges);
116
    void onResult(quint32 queryId, const QVariant &result);
117 118

private slots:
119 120
    void enable();
    void disable();
121 122
    void gotoObjectReferenceDefinition(const QmlDebugObjectReference &obj);
    void selectItems(const QList<QmlDebugObjectReference> &objectReferences);
123
    void selectItems(const QList<int> &objectIds);
124
    void changeSelectedItems(const QList<QmlDebugObjectReference> &objects);
125 126
    void changePropertyValue(int debugId,const QString &propertyName,
                             const QString &valueExpression, bool isLiteral);
127
    void objectTreeReady();
128
    void onRootContext(const QVariant &value);
129 130 131

    void updateEngineList();

132
    void removePreviewForEditor(Core::IEditor *newEditor);
133
    QmlJSLiveTextPreview *createPreviewForEditor(Core::IEditor *newEditor);
134

135
    void disableLivePreview();
136
    void crumblePathElementClicked(const QVariant &data);
137

138
    void updatePendingPreviewDocuments(QmlJS::Document::Ptr doc);
Kai Koehne's avatar
Kai Koehne committed
139 140
    void showDebuggerTooltip(const QPoint &mousePos,
                             TextEditor::ITextEditor *editor, int cursorPos);
141
    void onEngineStateChanged(Debugger::DebuggerState state);
142

143
private:
144
    void showRoot();
145 146
    void resetViews();

147
    void initializeDocuments();
148
    void applyChangesToQmlInspectorHelper(bool applyChanges);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
149
    void setupDockWidgets();
150
    QString filenameForShadowBuildFile(const QString &filename) const;
151 152
    void populateCrumblePath(const QmlDebugObjectReference &objRef);
    bool isRoot(const QmlDebugObjectReference &obj) const;
Kai Koehne's avatar
Kai Koehne committed
153 154
    QmlDebugObjectReference objectReferenceForLocation(
            const QString &fileName, int cursorPosition = -1) const;
155

156 157 158
    void connectSignals();
    void disconnectSignals();

159 160
    void showObject(const QmlDebugObjectReference &obj);

161
    QmlDebugObjectReference findParentRecursive(
Kai Koehne's avatar
Kai Koehne committed
162 163
            int goalDebugId,
            const QList<QmlDebugObjectReference > &objectsToSearch);
164
private:
165
    bool m_listeningToEditorManager;
166
    QmlJsInspectorToolBar *m_toolBar;
167
    ContextCrumblePath *m_crumblePath;
168
    QmlJSPropertyInspector *m_propertyInspector;
169

170
    InspectorSettings *m_settings;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
171
    ClientProxy *m_clientProxy;
172
    quint32 m_debugQuery;
173
    quint32 m_showObjectQueryId;
174
    QList<quint32> m_updateObjectQueryIds;
175

176
    // Qml/JS integration
177
    QHash<QString, QmlJSLiveTextPreview *> m_textPreviews;
178
    QmlJS::Snapshot m_loadedSnapshot; //the snapshot loaded by the viewer
179 180

    QStringList m_pendingPreviewDocumentNames;
181
    Utils::FileInProjectFinder m_projectFinder;
182

Lasse Holmstedt's avatar
Lasse Holmstedt committed
183
    static InspectorUi *m_instance;
184
    bool m_selectionCallbackExpected;
185
    bool m_cursorPositionChangedExternally;
186
    bool m_onCrumblePathClicked;
187 188
};

189 190
} // Internal
} // QmlJSInspector
191

Kai Koehne's avatar
Kai Koehne committed
192
#endif // QMLJSINSPECTOR_H