qmljsinspector.h 5.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef QMLJSINSPECTOR_H
#define QMLJSINSPECTOR_H

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "qmljsprivateapi.h"

#include <coreplugin/basemode.h>
#include <qmlprojectmanager/qmlprojectrunconfiguration.h>

#include <qmljs/qmljsdocument.h>
#include <qmljs/parser/qmljsastfwd_p.h>

#include <QtGui/QAction>
#include <QtCore/QObject>

namespace ProjectExplorer {
    class Project;
    class Environment;
}

namespace Core {
    class IContext;
}

namespace Debugger {
    class DebuggerRunControl;
}
56

57 58 59 60
namespace QmlJS {
    class ModelManagerInterface;
}

61 62
QT_FORWARD_DECLARE_CLASS(QDockWidget)

63 64 65
namespace QmlJSInspector {
namespace Internal {

66 67
class ClientProxy;
class InspectorContext;
68
class ContextCrumblePath;
69
class QmlJSLiveTextPreview;
70

71 72 73 74 75
class Inspector : public QObject
{
    Q_OBJECT

public:
76 77 78 79 80
    enum DebugMode {
        StandaloneMode,
        CppProjectWithQmlEngines,
        QmlProjectWithCppPlugins
    };
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
81
public:
82
    Inspector(QObject *parent = 0);
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
83
    virtual ~Inspector();
84 85

    bool connectToViewer(); // using host, port from widgets
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
86
    void shutdown();
87 88 89 90 91 92 93 94 95

    // returns false if project is not debuggable.
    bool setDebugConfigurationDataFromProject(ProjectExplorer::Project *projectToDebug);
    void startQmlProjectDebugger();

    QDeclarativeDebugExpressionQuery *executeExpression(int objectDebugId, const QString &objectId,
                                                        const QString &propertyName, const QVariant &value);

    QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, const QString &objectId,
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
96 97
                                                          const QString &propertyName, const QVariant &value,
                                                          bool isLiteralValue);
98 99
    static bool showExperimentalWarning();
    static void setShowExperimentalWarning(bool value);
100
    static Inspector *instance();
101

102 103
    // returns the project being currently debugged, or 0 if not debugging anything
    ProjectExplorer::Project *debugProject() const;
104
    void createDockWidgets();
105

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

public slots:
    void setSimpleDockWidgetArrangement();
    void reloadQmlViewer();
113
    void serverReloaded();
114
    void setApplyChangesToQmlObserver(bool applyChanges);
115 116 117 118 119 120 121 122 123

private slots:
    void gotoObjectReferenceDefinition(const QDeclarativeDebugObjectReference &obj);
    void simultaneouslyDebugQmlCppApplication();

    void debuggerStateChanged(int newState);
    void pollInspector();

    void setSelectedItemsByObjectReference(QList<QDeclarativeDebugObjectReference> objectReferences);
124
    void changeSelectedItems(const QList<QDeclarativeDebugObjectReference> &objects);
125 126 127 128 129 130 131 132 133

    void updateMenuActions();
    void connected(QDeclarativeEngineDebug *client);
    void aboutToReloadEngines();
    void updateEngineList();

    void disconnectWidgets();
    void disconnected();

134 135 136
    void removePreviewForEditor(Core::IEditor *newEditor);
    void createPreviewForEditor(Core::IEditor *newEditor);

137
    void disableLivePreview();
138
    void crumblePathElementClicked(int);
139 140 141

    void currentDebugProjectRemoved();

142 143 144 145 146 147 148 149 150 151
private:
    QString executeDebuggerRunControl(Debugger::DebuggerRunControl *debuggableRunControl,
                                      ProjectExplorer::Environment *environment);

    QString attachToQmlViewerAsExternalApp(ProjectExplorer::Project *project);
    QString attachToExternalCppAppWithQml(ProjectExplorer::Project *project);

    bool addQuotesForData(const QVariant &value) const;
    void resetViews();

152

153 154
    QmlJS::ModelManagerInterface *modelManager();
    void initializeDocuments();
155
    void applyChangesToQmlObserverHelper(bool applyChanges);
156

157 158
private:
    QWeakPointer<QDeclarativeEngineDebug> m_client;
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
159
    QmlProjectManager::QmlProjectRunConfigurationDebugData m_runConfigurationDebugData;
160 161 162 163 164 165 166 167
    InspectorContext *m_context;
    QTimer *m_connectionTimer;
    int m_connectionAttempts;
    int m_cppDebuggerState;
    bool m_connectionInitialized;
    bool m_simultaneousCppAndQmlDebugMode;
    DebugMode m_debugMode;
    ClientProxy *m_clientProxy;
168

169
    static bool m_showExperimentalWarning;
170
    bool m_listeningToEditorManager;
171

172 173 174
    ContextCrumblePath *m_crumblePath;
    QDockWidget *m_crumblePathDock;

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

    static Inspector *m_instance;
181 182
};

183 184
} // Internal
} // QmlJSInspector
185

186
#endif