qmlengine.h 6.76 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
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30

Kai Koehne's avatar
Kai Koehne committed
31 32
#ifndef QMLENGINE_H
#define QMLENGINE_H
33

Kai Koehne's avatar
Kai Koehne committed
34 35 36
#include "interactiveinterpreter.h"
#include "qmladapter.h"
#include "qmlinspectoradapter.h"
37
#include <debugger/debuggerengine.h>
Kai Koehne's avatar
Kai Koehne committed
38 39

#include <projectexplorer/applicationlauncher.h>
40
#include <qmldebug/qdebugmessageclient.h>
Kai Koehne's avatar
Kai Koehne committed
41
#include <qmldebug/qmloutputparser.h>
42
#include <qmljs/iscriptevaluator.h>
43
#include <qmljs/qmljsdocument.h>
hjk's avatar
hjk committed
44

45
QT_FORWARD_DECLARE_CLASS(QTextDocument)
46

47
namespace Core { class IDocument; }
48

49 50
namespace TextEditor { class BaseTextEditor; }

51
namespace Debugger {
52
namespace Internal {
53

54
class QmlAdapter;
55
class WatchTreeView;
56

57
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
58 59 60 61
{
    Q_OBJECT

public:
62
    explicit QmlEngine(const DebuggerRunParameters &runParameters,
Aurindam Jana's avatar
Aurindam Jana committed
63
                       DebuggerEngine *masterEngine = 0);
64
    ~QmlEngine();
65

Aurindam Jana's avatar
Aurindam Jana committed
66
    void notifyEngineRemoteServerRunning(const QByteArray &, int pid);
67
    void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
68

69
    bool canDisplayTooltip() const;
70

71 72
    void showMessage(const QString &msg, int channel = LogDebug,
                     int timeout = -1) const;
73 74
    void gotoLocation(const Internal::Location &location);

75
    void filterApplicationMessage(const QString &msg, int channel);
76 77
    void inferiorSpontaneousStop();

Kai Koehne's avatar
Kai Koehne committed
78 79 80 81 82 83 84
    enum LogDirection {
        LogSend,
        LogReceive
    };

    void logMessage(const QString &service, LogDirection direction,
                    const QString &str);
85

86
    void setSourceFiles(const QStringList &fileNames);
Kai Koehne's avatar
Kai Koehne committed
87 88
    void updateScriptSource(const QString &fileName, int lineOffset,
                            int columnOffset, const QString &source);
89

90
    void insertBreakpoint(Breakpoint bp);
91

Kai Koehne's avatar
Kai Koehne committed
92
private slots:
93
    void disconnected();
94
    void documentUpdated(QmlJS::Document::Ptr doc);
95
    void expressionEvaluated(quint32 queryId, const QVariant &result);
96

97
    void errorMessageBoxFinished(int result);
98
    void updateCurrentContext();
99
    void appendDebugOutput(QtMsgType type, const QString &message,
100
                           const QmlDebug::QDebugContextInfo &info);
101

Kai Koehne's avatar
Kai Koehne committed
102 103 104 105 106
    void tryToConnect(quint16 port = 0);
    void beginConnection(quint16 port = 0);
    void connectionEstablished();
    void connectionStartupFailed();
    void appStartupFailed(const QString &errorMessage);
107
    void connectionError(QDebugSupport::Error error);
Kai Koehne's avatar
Kai Koehne committed
108 109 110 111 112
    void serviceConnectionError(const QString &service);
    void appendMessage(const QString &msg, Utils::OutputFormat);

    void synchronizeWatchers();

113
private:
114
    // DebuggerEngine implementation.
hjk's avatar
hjk committed
115
    bool isSynchronous() const { return false; }
116 117 118 119 120 121
    void executeStep();
    void executeStepOut();
    void executeNext();
    void executeStepI();
    void executeNextI();

hjk's avatar
hjk committed
122
    void setupEngine();
hjk's avatar
hjk committed
123 124 125 126 127
    void setupInferior();
    void runEngine();
    void shutdownInferior();
    void shutdownEngine();

128
    bool canHandleToolTip(const DebuggerToolTipContext &) const;
129 130 131 132

    void continueInferior();
    void interruptInferior();

133
    void executeRunToLine(const ContextData &data);
134
    void executeRunToFunction(const QString &functionName);
135
    void executeJumpToLine(const ContextData &data);
136 137

    void activateFrame(int index);
hjk's avatar
hjk committed
138
    void selectThread(ThreadId threadId);
139 140

    void attemptBreakpointSynchronization();
141 142 143
    void removeBreakpoint(Breakpoint bp);
    void changeBreakpoint(Breakpoint bp);
    bool acceptsBreakpoint(Breakpoint bp) const;
144

145
    void assignValueInDebugger(WatchItem *item,
hjk's avatar
hjk committed
146
        const QString &expr, const QVariant &value);
147

148 149 150 151 152
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();
    void requestModuleSymbols(const QString &moduleName);
    void reloadModules();
    void reloadRegisters() {}
153
    void reloadSourceFiles();
154 155
    void reloadFullStack() {}

Olivier Goffart's avatar
Olivier Goffart committed
156
    bool supportsThreads() const { return false; }
157 158
    void updateWatchData(const QByteArray &iname);
    void selectWatchData(const QByteArray &iname);
159
    void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
160
    bool evaluateScript(const QString &expression);
161

162
    bool hasCapability(unsigned) const;
163
    void quitDebugger();
164

165
private:
166 167 168 169
    void closeConnection();
    void startApplicationLauncher();
    void stopApplicationLauncher();

170 171
    bool isShadowBuildProject() const;
    QString fromShadowBuildFilename(const QString &filename) const;
hjk's avatar
hjk committed
172 173
    QString mangleFilenamePaths(const QString &filename,
        const QString &oldBasePath, const QString &newBasePath) const;
174 175
    QString qmlImportPath() const;

176
    void updateDocument(Core::IDocument *document, const QTextDocument *textDocument);
177
    bool canEvaluateScript(const QString &script);
178 179
    bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
                                       quint32 *column, bool *valid);
180

Kai Koehne's avatar
Kai Koehne committed
181 182 183 184
    QmlAdapter m_adapter;
    QmlInspectorAdapter m_inspectorAdapter;
    ProjectExplorer::ApplicationLauncher m_applicationLauncher;
    QTimer m_noDebugOutputTimer;
Kai Koehne's avatar
Kai Koehne committed
185
    QmlDebug::QmlOutputParser m_outputParser;
Kai Koehne's avatar
Kai Koehne committed
186
    QHash<QString, QTextDocument*> m_sourceDocuments;
187
    QHash<QString, QWeakPointer<TextEditor::BaseTextEditor> > m_sourceEditors;
Kai Koehne's avatar
Kai Koehne committed
188
    InteractiveInterpreter m_interpreter;
189
    QHash<QString,Breakpoint> pendingBreakpoints;
Kai Koehne's avatar
Kai Koehne committed
190 191 192 193
    QList<quint32> queryIds;
    bool m_retryOnConnectFail;
    bool m_automaticConnect;

194
    friend class QmlCppEngine;
195 196
};

197
} // namespace Internal
198 199
} // namespace Debugger

Kai Koehne's avatar
Kai Koehne committed
200
#endif // QMLENGINE_H