tracewindow.h 5.83 KB
Newer Older
Christiaan Janssen's avatar
Christiaan Janssen committed
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).
Christiaan Janssen's avatar
Christiaan Janssen committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
Christiaan Janssen's avatar
Christiaan Janssen committed
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
Thomas Murach's avatar
Thomas Murach 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.
Christiaan Janssen's avatar
Christiaan Janssen committed
18
**
Kai Koehne's avatar
Kai Koehne committed
19
** In addition, as a special exception, Nokia gives you certain additional
Thomas Murach's avatar
Thomas Murach committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
Kai Koehne's avatar
Kai Koehne committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
Thomas Murach's avatar
Thomas Murach 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.
**
Kai Koehne's avatar
Kai Koehne committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
Christiaan Janssen's avatar
Christiaan Janssen committed
30 31
**
**************************************************************************/
Kai Koehne's avatar
Kai Koehne committed
32 33 34

#ifndef TRACEWINDOW_H
#define TRACEWINDOW_H
Christiaan Janssen's avatar
Christiaan Janssen committed
35

36
#include <qmljsdebugclient/qmlprofilertraceclient.h>
37
#include <qmljsdebugclient/qmlprofilereventlist.h>
38
#include "qmlprofilerdetailsrewriter.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
39 40
#include <qmljsdebugclient/qv8profilerclient.h>

41 42 43
#include <QPointer>
#include <QWidget>
#include <QToolButton>
Kai Koehne's avatar
Kai Koehne committed
44

45 46
#include <QEvent>
#include <QDeclarativeView>
Christiaan Janssen's avatar
Christiaan Janssen committed
47

Kai Koehne's avatar
Kai Koehne committed
48 49 50
namespace QmlProfiler {
namespace Internal {

51 52 53 54 55 56 57 58 59 60
class MouseWheelResizer : public QObject {
    Q_OBJECT
public:
    MouseWheelResizer(QObject *parent=0):QObject(parent){}
protected:
    bool eventFilter(QObject *obj, QEvent *event);
signals:
    void mouseWheelMoved(int x, int y, int delta);
};

61 62 63 64 65 66 67
// centralized zoom control
class ZoomControl : public QObject {
    Q_OBJECT
public:
    ZoomControl(QObject *parent=0):QObject(parent),m_startTime(0),m_endTime(0) {}
    ~ZoomControl(){}

68
    Q_INVOKABLE void setRange(qint64 startTime, qint64 endTime);
69 70 71 72 73 74 75 76 77 78 79
    Q_INVOKABLE qint64 startTime() { return m_startTime; }
    Q_INVOKABLE qint64 endTime() { return m_endTime; }

signals:
    void rangeChanged();

private:
    qint64 m_startTime;
    qint64 m_endTime;
};

80 81 82 83 84 85 86 87 88 89
class ScrollableDeclarativeView : public QDeclarativeView
{
    Q_OBJECT
public:
    explicit ScrollableDeclarativeView(QWidget *parent = 0);
    ~ScrollableDeclarativeView();
protected:
    void scrollContentsBy(int dx, int dy);
};

Christiaan Janssen's avatar
Christiaan Janssen committed
90 91 92
class TraceWindow : public QWidget
{
    Q_OBJECT
hjk's avatar
hjk committed
93

Christiaan Janssen's avatar
Christiaan Janssen committed
94 95 96 97
public:
    TraceWindow(QWidget *parent = 0);
    ~TraceWindow();

98
    void reset(QmlJsDebugClient::QDeclarativeDebugConnection *conn);
Christiaan Janssen's avatar
Christiaan Janssen committed
99

100
    QmlJsDebugClient::QmlProfilerEventList *getEventList() const;
101
    ZoomControl *rangeTimes() const;
102

Christiaan Janssen's avatar
Christiaan Janssen committed
103
    void setRecording(bool recording);
104
    bool isRecording() const;
105
    void viewAll();
Christiaan Janssen's avatar
Christiaan Janssen committed
106

107 108 109
    bool hasValidSelection() const;
    qint64 selectionStart() const;
    qint64 selectionEnd() const;
110
    double profiledTime() const;
111

Christiaan Janssen's avatar
Christiaan Janssen committed
112
public slots:
113 114 115 116
    void clearDisplay();
    void selectNextEvent(int eventId);

private slots:
Christiaan Janssen's avatar
Christiaan Janssen committed
117
    void updateCursorPosition();
Christiaan Janssen's avatar
Christiaan Janssen committed
118
    void updateTimer();
119
    void updateToolbar();
120
    void toggleRangeMode(bool);
121
    void toggleLockMode(bool);
122
    void updateRangeButton();
123
    void updateLockButton();
124 125 126
    void setZoomLevel(int zoomLevel);
    void updateRange();
    void mouseWheelMoved(int x, int y, int delta);
Christiaan Janssen's avatar
Christiaan Janssen committed
127

Christiaan Janssen's avatar
Christiaan Janssen committed
128 129
    void qmlComplete();
    void v8Complete();
130
    void updateProfilerState();
Kai Koehne's avatar
Kai Koehne committed
131
    void updateToolTip(const QString &text);
132
    void updateVerticalScroll(int newPosition);
133 134 135
    void eventListStateChanged();
    void manageTraceStart(qint64 traceStart);
    void firstDataReceived();
136
    void applicationDied();
137
    void correctTimer();
Christiaan Janssen's avatar
Christiaan Janssen committed
138

Christiaan Janssen's avatar
Christiaan Janssen committed
139 140
signals:
    void viewUpdated();
141
    void profilerStateChanged(bool qmlActive, bool v8active);
142 143
    void gotoSourceLocation(const QString &fileUrl, int lineNumber, int columNumber);
    void range(int type, qint64 startTime, qint64 length, const QStringList &data, const QmlJsDebugClient::QmlEventLocation &location);
Christiaan Janssen's avatar
Christiaan Janssen committed
144 145
    void v8range(int depth,const QString &function,const QString &filename,
               int lineNumber, double totalTime, double selfTime);
146
    void traceFinished(qint64);
147
    void traceStarted(qint64);
148
    void frameEvent(qint64, int, int);
149
    void recordingChanged(bool);
Christiaan Janssen's avatar
Christiaan Janssen committed
150

151
    void internalClearDisplay();
152
    void clearViewsFromTool();
153 154
    void jumpToPrev();
    void jumpToNext();
155
    void rangeModeChanged(bool);
156
    void lockModeChanged(bool);
157
    void enableToolbar(bool);
158 159 160 161
    void zoomLevelChanged(int);
    void updateViewZoom(QVariant zoomLevel);
    void wheelZoom(QVariant wheelCenter, QVariant wheelDelta);
    void globalZoom();
162

163
    void contextMenuRequested(const QPoint& position);
164 165
    void selectNextEventInDisplay(QVariant eventId);
    void selectedEventIdChanged(int eventId);
166 167 168

private:
    void contextMenuEvent(QContextMenuEvent *);
169
    QWidget *createToolbar();
170
    QWidget *createZoomToolbar();
171 172
    void connectClientSignals();
    void disconnectClientSignals();
173 174 175

protected:
    virtual void resizeEvent(QResizeEvent *event);
176

Christiaan Janssen's avatar
Christiaan Janssen committed
177
private:
178
    QWeakPointer<QmlJsDebugClient::QmlProfilerTraceClient> m_plugin;
Christiaan Janssen's avatar
Christiaan Janssen committed
179
    QWeakPointer<QmlJsDebugClient::QV8ProfilerClient> m_v8plugin;
Christiaan Janssen's avatar
Christiaan Janssen committed
180 181
    QSize m_sizeHint;

182
    ScrollableDeclarativeView *m_mainView;
183 184
    QDeclarativeView *m_timebar;
    QDeclarativeView *m_overview;
185
    QmlJsDebugClient::QmlProfilerEventList *m_eventList;
186
    QmlProfilerDetailsRewriter *m_rewriter;
Christiaan Janssen's avatar
Christiaan Janssen committed
187 188
    bool m_qmlDataReady;
    bool m_v8DataReady;
189
    double m_profiledTime;
190 191

    QWeakPointer<ZoomControl> m_zoomControl;
192 193

    QToolButton *m_buttonRange;
194
    QToolButton *m_buttonLock;
195 196
    QWidget *m_zoomToolbar;
    int m_currentZoomLevel;
Christiaan Janssen's avatar
Christiaan Janssen committed
197 198
};

Kai Koehne's avatar
Kai Koehne committed
199 200 201
} // namespace Internal
} // namespace QmlProfiler

Kai Koehne's avatar
Kai Koehne committed
202
#endif // TRACEWINDOW_H
Christiaan Janssen's avatar
Christiaan Janssen committed
203