qmlengine.h 6.92 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12
** 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
** a written agreement between you and Digia.  For licensing terms and
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** 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 25 26
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt 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>
hjk's avatar
hjk committed
43

Kai Koehne's avatar
Kai Koehne committed
44
#include <QTextDocument>
45

46
namespace Core { class IDocument; }
47

48
namespace Debugger {
49
namespace Internal {
50

51
class QmlAdapter;
52
class WatchTreeView;
53

54
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
55 56 57 58
{
    Q_OBJECT

public:
Aurindam Jana's avatar
Aurindam Jana committed
59 60
    explicit QmlEngine(const DebuggerStartParameters &startParameters,
                       DebuggerEngine *masterEngine = 0);
61
    ~QmlEngine();
62

Aurindam Jana's avatar
Aurindam Jana committed
63
    void notifyEngineRemoteServerRunning(const QByteArray &, int pid);
64
    void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
65

66
    bool canDisplayTooltip() const;
67

68 69
    void showMessage(const QString &msg, int channel = LogDebug,
                     int timeout = -1) const;
70 71
    void gotoLocation(const Internal::Location &location);

72
    void filterApplicationMessage(const QString &msg, int channel);
73 74
    void inferiorSpontaneousStop();

Kai Koehne's avatar
Kai Koehne committed
75 76 77 78 79 80 81
    enum LogDirection {
        LogSend,
        LogReceive
    };

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

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

87 88
    void insertBreakpoint(BreakpointModelId id);

Kai Koehne's avatar
Kai Koehne committed
89 90
signals:
    void tooltipRequested(const QPoint &mousePos,
91
        TextEditor::TextEditorWidget *editorWidget, int cursorPos);
Kai Koehne's avatar
Kai Koehne committed
92 93

private slots:
94
    void disconnected();
95
    void documentUpdated(QmlJS::Document::Ptr doc);
96
    void expressionEvaluated(quint32 queryId, const QVariant &result);
97

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

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

    void synchronizeWatchers();

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

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

129
    bool setToolTipExpression(TextEditor::TextEditorWidget *editorWidget,
hjk's avatar
hjk committed
130
        const DebuggerToolTipContext &);
131 132 133 134

    void continueInferior();
    void interruptInferior();

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

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

    void attemptBreakpointSynchronization();
143 144
    void removeBreakpoint(BreakpointModelId id);
    void changeBreakpoint(BreakpointModelId id);
145
    bool acceptsBreakpoint(BreakpointModelId id) const;
146

147
    void assignValueInDebugger(const WatchData *data,
hjk's avatar
hjk committed
148
        const QString &expr, const QVariant &value);
149 150


151 152 153 154 155
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();
    void requestModuleSymbols(const QString &moduleName);
    void reloadModules();
    void reloadRegisters() {}
156
    void reloadSourceFiles();
157 158
    void reloadFullStack() {}

Olivier Goffart's avatar
Olivier Goffart committed
159
    bool supportsThreads() const { return false; }
160 161
    void updateWatchData(const WatchData &data,
        const WatchUpdateFlags &flags);
162
    void watchDataSelected(const QByteArray &iname);
163
    void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
164
    bool evaluateScript(const QString &expression);
165

166
    bool hasCapability(unsigned) const;
167
    void quitDebugger();
168

169
private:
170 171 172 173
    void closeConnection();
    void startApplicationLauncher();
    void stopApplicationLauncher();

174 175
    bool isShadowBuildProject() const;
    QString fromShadowBuildFilename(const QString &filename) const;
hjk's avatar
hjk committed
176 177
    QString mangleFilenamePaths(const QString &filename,
        const QString &oldBasePath, const QString &newBasePath) const;
178 179
    QString qmlImportPath() const;

180
    void updateDocument(Core::IDocument *document, const QTextDocument *textDocument);
181
    bool canEvaluateScript(const QString &script);
182 183
    bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
                                       quint32 *column, bool *valid);
184

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

198
    friend class QmlCppEngine;
199 200
};

201
} // namespace Internal
202 203
} // namespace Debugger

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