qmlprofilertraceview.cpp 18.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Christiaan Janssen's avatar
Christiaan Janssen committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Christiaan Janssen's avatar
Christiaan Janssen committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Christiaan Janssen's avatar
Christiaan Janssen committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Christiaan Janssen's avatar
Christiaan Janssen committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
Christiaan Janssen's avatar
Christiaan Janssen committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Christiaan Janssen's avatar
Christiaan Janssen committed
29 30 31 32

#include "qmlprofilertraceview.h"
#include "qmlprofilertool.h"
#include "qmlprofilerstatemanager.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
33 34 35
#include "qmlprofilermodelmanager.h"
#include "qmlprofilertimelinemodelproxy.h"
#include "timelinemodelaggregator.h"
Christiaan Janssen's avatar
Christiaan Janssen committed
36 37 38 39

// Needed for the load&save actions in the context menu
#include <analyzerbase/ianalyzertool.h>

Christiaan Janssen's avatar
Christiaan Janssen committed
40
// Communication with the other views (limit events to range)
Christiaan Janssen's avatar
Christiaan Janssen committed
41 42 43 44
#include "qmlprofilerviewmanager.h"

#include <utils/styledbar.h>

45
#include <QQmlContext>
Christiaan Janssen's avatar
Christiaan Janssen committed
46 47 48 49 50 51 52
#include <QToolButton>
#include <QEvent>
#include <QVBoxLayout>
#include <QGraphicsObject>
#include <QScrollBar>
#include <QSlider>
#include <QMenu>
53
#include <QQuickItem>
Christiaan Janssen's avatar
Christiaan Janssen committed
54 55 56

#include <math.h>

57
using namespace QmlDebug;
Christiaan Janssen's avatar
Christiaan Janssen committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

namespace QmlProfiler {
namespace Internal {

/////////////////////////////////////////////////////////
void ZoomControl::setRange(qint64 startTime, qint64 endTime)
{
    if (m_startTime != startTime || m_endTime != endTime) {
        m_startTime = startTime;
        m_endTime = endTime;
        emit rangeChanged();
    }
}

/////////////////////////////////////////////////////////
class QmlProfilerTraceView::QmlProfilerTraceViewPrivate
{
public:
    QmlProfilerTraceViewPrivate(QmlProfilerTraceView *qq) : q(qq) {}
77 78 79 80 81 82 83
    ~QmlProfilerTraceViewPrivate()
    {
        delete m_mainView;
        delete m_timebar;
        delete m_overview;
    }

Christiaan Janssen's avatar
Christiaan Janssen committed
84 85 86 87 88 89 90 91
    QmlProfilerTraceView *q;

    QmlProfilerStateManager *m_profilerState;
    Analyzer::IAnalyzerTool *m_profilerTool;
    QmlProfilerViewManager *m_viewContainer;

    QSize m_sizeHint;

92
    QQuickView *m_mainView;
93 94
    QQuickView *m_timebar;
    QQuickView *m_overview;
Christiaan Janssen's avatar
Christiaan Janssen committed
95 96 97
    QmlProfilerModelManager *m_modelManager;
    TimelineModelAggregator *m_modelProxy;

Christiaan Janssen's avatar
Christiaan Janssen committed
98 99 100 101 102 103 104

    ZoomControl *m_zoomControl;

    QToolButton *m_buttonRange;
    QToolButton *m_buttonLock;
};

Christiaan Janssen's avatar
Christiaan Janssen committed
105
QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, Analyzer::IAnalyzerTool *profilerTool, QmlProfilerViewManager *container, QmlProfilerModelManager *modelManager, QmlProfilerStateManager *profilerState)
Christiaan Janssen's avatar
Christiaan Janssen committed
106 107
    : QWidget(parent), d(new QmlProfilerTraceViewPrivate(this))
{
108
    setObjectName(QLatin1String("QML Profiler"));
Christiaan Janssen's avatar
Christiaan Janssen committed
109 110 111 112 113 114 115 116

    d->m_zoomControl = new ZoomControl(this);
    connect(d->m_zoomControl, SIGNAL(rangeChanged()), this, SLOT(updateRange()));

    QVBoxLayout *groupLayout = new QVBoxLayout;
    groupLayout->setContentsMargins(0, 0, 0, 0);
    groupLayout->setSpacing(0);

117
    d->m_mainView = new QQuickView();
118
    d->m_mainView->setResizeMode(QQuickView::SizeRootObjectToView);
119
    QWidget *mainViewContainer = QWidget::createWindowContainer(d->m_mainView);
Christiaan Janssen's avatar
Christiaan Janssen committed
120 121 122

    QHBoxLayout *toolsLayout = new QHBoxLayout;

123 124 125 126 127
    d->m_timebar = new QQuickView();
    d->m_timebar->setResizeMode(QQuickView::SizeRootObjectToView);
    QWidget *timeBarContainer = QWidget::createWindowContainer(d->m_timebar);
    timeBarContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    timeBarContainer->setFixedHeight(24);
Christiaan Janssen's avatar
Christiaan Janssen committed
128

129 130 131 132 133
    d->m_overview = new QQuickView();
    d->m_overview->setResizeMode(QQuickView::SizeRootObjectToView);
    QWidget *overviewContainer = QWidget::createWindowContainer(d->m_overview);
    overviewContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    overviewContainer->setMaximumHeight(50);
Christiaan Janssen's avatar
Christiaan Janssen committed
134 135

    toolsLayout->addWidget(createToolbar());
136
    toolsLayout->addWidget(timeBarContainer);
Christiaan Janssen's avatar
Christiaan Janssen committed
137 138 139
    emit enableToolbar(false);

    groupLayout->addLayout(toolsLayout);
140 141
    groupLayout->addWidget(mainViewContainer);
    groupLayout->addWidget(overviewContainer);
Christiaan Janssen's avatar
Christiaan Janssen committed
142 143 144 145 146

    setLayout(groupLayout);

    d->m_profilerTool = profilerTool;
    d->m_viewContainer = container;
Christiaan Janssen's avatar
Christiaan Janssen committed
147 148 149 150
    d->m_modelManager = modelManager;
    d->m_modelProxy = new TimelineModelAggregator(this);
    d->m_modelProxy->setModelManager(modelManager);
    connect(d->m_modelManager, SIGNAL(stateChanged()),
Christiaan Janssen's avatar
Christiaan Janssen committed
151
            this, SLOT(profilerDataModelStateChanged()));
Christiaan Janssen's avatar
Christiaan Janssen committed
152 153 154 155
    d->m_mainView->rootContext()->setContextProperty(QLatin1String("qmlProfilerModelProxy"),
                                                     d->m_modelProxy);
    d->m_overview->rootContext()->setContextProperty(QLatin1String("qmlProfilerModelProxy"),
                                                     d->m_modelProxy);
Christiaan Janssen's avatar
Christiaan Janssen committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

    d->m_profilerState = profilerState;
    connect(d->m_profilerState, SIGNAL(stateChanged()),
            this, SLOT(profilerStateChanged()));
    connect(d->m_profilerState, SIGNAL(clientRecordingChanged()),
            this, SLOT(clientRecordingChanged()));
    connect(d->m_profilerState, SIGNAL(serverRecordingChanged()),
            this, SLOT(serverRecordingChanged()));

    // Minimum height: 5 rows of 20 pixels + scrollbar of 50 pixels + 20 pixels margin
    setMinimumHeight(170);
}

QmlProfilerTraceView::~QmlProfilerTraceView()
{
    delete d;
}

/////////////////////////////////////////////////////////
// Initialize widgets
void QmlProfilerTraceView::reset()
{
178 179 180
    d->m_mainView->rootContext()->setContextProperty(QLatin1String("zoomControl"), d->m_zoomControl);
    d->m_timebar->rootContext()->setContextProperty(QLatin1String("zoomControl"), d->m_zoomControl);
    d->m_overview->rootContext()->setContextProperty(QLatin1String("zoomControl"), d->m_zoomControl);
Christiaan Janssen's avatar
Christiaan Janssen committed
181

182 183
    d->m_timebar->setSource(QUrl(QLatin1String("qrc:/qmlprofiler/TimeDisplay.qml")));
    d->m_overview->setSource(QUrl(QLatin1String("qrc:/qmlprofiler/Overview.qml")));
Christiaan Janssen's avatar
Christiaan Janssen committed
184

185
    d->m_mainView->setSource(QUrl(QLatin1String("qrc:/qmlprofiler/MainView.qml")));
186

187
    QQuickItem *rootObject = d->m_mainView->rootObject();
188 189 190 191 192 193 194
    connect(rootObject, SIGNAL(updateCursorPosition()), this, SLOT(updateCursorPosition()));
    connect(rootObject, SIGNAL(updateRangeButton()), this, SLOT(updateRangeButton()));
    connect(rootObject, SIGNAL(updateLockButton()), this, SLOT(updateLockButton()));
    connect(this, SIGNAL(jumpToPrev()), rootObject, SLOT(prevEvent()));
    connect(this, SIGNAL(jumpToNext()), rootObject, SLOT(nextEvent()));
    connect(rootObject, SIGNAL(selectedEventChanged(int)), this, SIGNAL(selectedEventChanged(int)));
    connect(rootObject, SIGNAL(changeToolTip(QString)), this, SLOT(updateToolTip(QString)));
195 196 197
    connect(this, SIGNAL(enableToolbar(bool)), this, SLOT(setZoomSliderEnabled(bool)));
    connect(this, SIGNAL(showZoomSlider(bool)), this, SLOT(setZoomSliderVisible(bool)));
}
198

199 200 201 202 203 204 205 206 207 208 209 210
void QmlProfilerTraceView::setZoomSliderEnabled(bool enabled)
{
    QQuickItem *zoomSlider = d->m_mainView->rootObject()->findChild<QQuickItem*>(QLatin1String("zoomSliderToolBar"));
    if (zoomSlider->isEnabled() != enabled)
        zoomSlider->setEnabled(enabled);
}

void QmlProfilerTraceView::setZoomSliderVisible(bool visible)
{
    QQuickItem *zoomSlider = d->m_mainView->rootObject()->findChild<QQuickItem*>(QLatin1String("zoomSliderToolBar"));
    if (zoomSlider->isVisible() != visible)
        zoomSlider->setVisible(visible);
Christiaan Janssen's avatar
Christiaan Janssen committed
211 212 213 214 215
}

QWidget *QmlProfilerTraceView::createToolbar()
{
    Utils::StyledBar *bar = new Utils::StyledBar(this);
216
    bar->setStyleSheet(QLatin1String("background: #9B9B9B"));
Christiaan Janssen's avatar
Christiaan Janssen committed
217 218 219 220 221 222 223 224 225
    bar->setSingleRow(true);
    bar->setFixedWidth(150);
    bar->setFixedHeight(24);

    QHBoxLayout *toolBarLayout = new QHBoxLayout(bar);
    toolBarLayout->setMargin(0);
    toolBarLayout->setSpacing(0);

    QToolButton *buttonPrev= new QToolButton;
226
    buttonPrev->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_prev.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
227 228 229 230 231
    buttonPrev->setToolTip(tr("Jump to previous event"));
    connect(buttonPrev, SIGNAL(clicked()), this, SIGNAL(jumpToPrev()));
    connect(this, SIGNAL(enableToolbar(bool)), buttonPrev, SLOT(setEnabled(bool)));

    QToolButton *buttonNext= new QToolButton;
232
    buttonNext->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_next.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
233 234 235 236 237
    buttonNext->setToolTip(tr("Jump to next event"));
    connect(buttonNext, SIGNAL(clicked()), this, SIGNAL(jumpToNext()));
    connect(this, SIGNAL(enableToolbar(bool)), buttonNext, SLOT(setEnabled(bool)));

    QToolButton *buttonZoomControls = new QToolButton;
238
    buttonZoomControls->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_zoom.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
239 240 241
    buttonZoomControls->setToolTip(tr("Show zoom slider"));
    buttonZoomControls->setCheckable(true);
    buttonZoomControls->setChecked(false);
242
    connect(buttonZoomControls, SIGNAL(toggled(bool)), this, SIGNAL(showZoomSlider(bool)));
Christiaan Janssen's avatar
Christiaan Janssen committed
243 244 245
    connect(this, SIGNAL(enableToolbar(bool)), buttonZoomControls, SLOT(setEnabled(bool)));

    d->m_buttonRange = new QToolButton;
246
    d->m_buttonRange->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_rangeselection.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
247 248 249 250 251 252 253 254
    d->m_buttonRange->setToolTip(tr("Select range"));
    d->m_buttonRange->setCheckable(true);
    d->m_buttonRange->setChecked(false);
    connect(d->m_buttonRange, SIGNAL(clicked(bool)), this, SLOT(toggleRangeMode(bool)));
    connect(this, SIGNAL(enableToolbar(bool)), d->m_buttonRange, SLOT(setEnabled(bool)));
    connect(this, SIGNAL(rangeModeChanged(bool)), d->m_buttonRange, SLOT(setChecked(bool)));

    d->m_buttonLock = new QToolButton;
255
    d->m_buttonLock->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_selectionmode.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    d->m_buttonLock->setToolTip(tr("View event information on mouseover"));
    d->m_buttonLock->setCheckable(true);
    d->m_buttonLock->setChecked(false);
    connect(d->m_buttonLock, SIGNAL(clicked(bool)), this, SLOT(toggleLockMode(bool)));
    connect(this, SIGNAL(enableToolbar(bool)), d->m_buttonLock, SLOT(setEnabled(bool)));
    connect(this, SIGNAL(lockModeChanged(bool)), d->m_buttonLock, SLOT(setChecked(bool)));

    toolBarLayout->addWidget(buttonPrev);
    toolBarLayout->addWidget(buttonNext);
    toolBarLayout->addWidget(new Utils::StyledSeparator());
    toolBarLayout->addWidget(buttonZoomControls);
    toolBarLayout->addWidget(new Utils::StyledSeparator());
    toolBarLayout->addWidget(d->m_buttonRange);
    toolBarLayout->addWidget(d->m_buttonLock);

    return bar;
}

/////////////////////////////////////////////////////////
bool QmlProfilerTraceView::hasValidSelection() const
{
277
    QQuickItem *rootObject = d->m_mainView->rootObject();
278 279
    if (rootObject)
        return rootObject->property("selectionRangeReady").toBool();
Christiaan Janssen's avatar
Christiaan Janssen committed
280 281 282 283 284
    return false;
}

qint64 QmlProfilerTraceView::selectionStart() const
{
285
    QQuickItem *rootObject = d->m_mainView->rootObject();
286 287
    if (rootObject)
        return rootObject->property("selectionRangeStart").toLongLong();
Christiaan Janssen's avatar
Christiaan Janssen committed
288 289 290 291 292
    return 0;
}

qint64 QmlProfilerTraceView::selectionEnd() const
{
293
    QQuickItem *rootObject = d->m_mainView->rootObject();
294 295
    if (rootObject)
        return rootObject->property("selectionRangeEnd").toLongLong();
Christiaan Janssen's avatar
Christiaan Janssen committed
296 297 298 299 300 301 302 303 304 305 306 307
    return 0;
}

void QmlProfilerTraceView::clearDisplay()
{
    d->m_zoomControl->setRange(0,0);
    d->m_mainView->rootObject()->setProperty("scrollY", QVariant(0));

    QMetaObject::invokeMethod(d->m_mainView->rootObject(), "clearAll");
    QMetaObject::invokeMethod(d->m_overview->rootObject(), "clearDisplay");
}

Christiaan Janssen's avatar
Christiaan Janssen committed
308
void QmlProfilerTraceView::selectNextEventByHash(const QString &hash)
Christiaan Janssen's avatar
Christiaan Janssen committed
309
{
310
    QQuickItem *rootObject = d->m_mainView->rootObject();
Christiaan Janssen's avatar
Christiaan Janssen committed
311

312
    if (rootObject)
Christiaan Janssen's avatar
Christiaan Janssen committed
313 314 315 316 317 318 319 320 321
        QMetaObject::invokeMethod(rootObject, "selectNextByHash",
                                  Q_ARG(QVariant,QVariant(hash)));
}

void QmlProfilerTraceView::selectNextEventByLocation(const QString &filename, const int line, const int column)
{
    int eventId = d->m_modelProxy->getEventIdForLocation(filename, line, column);

    if (eventId != -1) {
322
        QQuickItem *rootObject = d->m_mainView->rootObject();
Christiaan Janssen's avatar
Christiaan Janssen committed
323 324 325 326
        if (rootObject)
            QMetaObject::invokeMethod(rootObject, "selectNextById",
                                      Q_ARG(QVariant,QVariant(eventId)));
    }
Christiaan Janssen's avatar
Christiaan Janssen committed
327 328 329 330 331 332
}

/////////////////////////////////////////////////////////
// Goto source location
void QmlProfilerTraceView::updateCursorPosition()
{
333
    QQuickItem *rootObject = d->m_mainView->rootObject();
334 335 336
    emit gotoSourceLocation(rootObject->property("fileName").toString(),
                            rootObject->property("lineNumber").toInt(),
                            rootObject->property("columnNumber").toInt());
Christiaan Janssen's avatar
Christiaan Janssen committed
337 338 339 340 341 342
}

/////////////////////////////////////////////////////////
// Toolbar buttons
void QmlProfilerTraceView::toggleRangeMode(bool active)
{
343
    QQuickItem *rootObject = d->m_mainView->rootObject();
344
    bool rangeMode = rootObject->property("selectionRangeMode").toBool();
Christiaan Janssen's avatar
Christiaan Janssen committed
345 346
    if (active != rangeMode) {
        if (active)
347
            d->m_buttonRange->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_rangeselected.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
348
        else
349
            d->m_buttonRange->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_rangeselection.png")));
350
        rootObject->setProperty("selectionRangeMode", QVariant(active));
Christiaan Janssen's avatar
Christiaan Janssen committed
351 352 353 354 355 356 357
    }
}

void QmlProfilerTraceView::updateRangeButton()
{
    bool rangeMode = d->m_mainView->rootObject()->property("selectionRangeMode").toBool();
    if (rangeMode)
358
        d->m_buttonRange->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_rangeselected.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
359
    else
360
        d->m_buttonRange->setIcon(QIcon(QLatin1String(":/qmlprofiler/ico_rangeselection.png")));
Christiaan Janssen's avatar
Christiaan Janssen committed
361 362 363 364 365
    emit rangeModeChanged(rangeMode);
}

void QmlProfilerTraceView::toggleLockMode(bool active)
{
366
    QQuickItem *rootObject = d->m_mainView->rootObject();
367
    bool lockMode = !rootObject->property("selectionLocked").toBool();
Christiaan Janssen's avatar
Christiaan Janssen committed
368
    if (active != lockMode) {
369 370
        rootObject->setProperty("selectionLocked", QVariant(!active));
        rootObject->setProperty("selectedItem", QVariant(-1));
Christiaan Janssen's avatar
Christiaan Janssen committed
371 372 373 374 375 376 377 378 379 380 381 382 383
    }
}

void QmlProfilerTraceView::updateLockButton()
{
    bool lockMode = !d->m_mainView->rootObject()->property("selectionLocked").toBool();
    emit lockModeChanged(lockMode);
}

////////////////////////////////////////////////////////
// Zoom control
void QmlProfilerTraceView::updateRange()
{
Christiaan Janssen's avatar
Christiaan Janssen committed
384
    if (!d->m_modelManager)
Christiaan Janssen's avatar
Christiaan Janssen committed
385 386 387 388
        return;
    qreal duration = d->m_zoomControl->endTime() - d->m_zoomControl->startTime();
    if (duration <= 0)
        return;
Christiaan Janssen's avatar
Christiaan Janssen committed
389
    if (d->m_modelManager->traceTime()->duration() <= 0)
Christiaan Janssen's avatar
Christiaan Janssen committed
390
        return;
391
    QMetaObject::invokeMethod(d->m_mainView->rootObject()->findChild<QObject*>(QLatin1String("zoomSliderToolBar")), "updateZoomLevel");
Christiaan Janssen's avatar
Christiaan Janssen committed
392 393 394 395 396 397 398 399 400 401
}

////////////////////////////////////////////////////////
void QmlProfilerTraceView::updateToolTip(const QString &text)
{
    setToolTip(text);
}

void QmlProfilerTraceView::resizeEvent(QResizeEvent *event)
{
402
    QWidget::resizeEvent(event);
403
    QQuickItem *rootObject = d->m_mainView->rootObject();
404 405
    if (rootObject) {
        rootObject->setProperty("width", QVariant(event->size().width()));
Christiaan Janssen's avatar
Christiaan Janssen committed
406
        int newHeight = event->size().height() - d->m_timebar->height() - d->m_overview->height();
407
        rootObject->setProperty("candidateHeight", QVariant(newHeight));
Christiaan Janssen's avatar
Christiaan Janssen committed
408
    }
409
    emit resized();
Christiaan Janssen's avatar
Christiaan Janssen committed
410 411 412 413 414 415 416 417 418 419 420
}

////////////////////////////////////////////////////////////////
// Context menu
void QmlProfilerTraceView::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    QAction *viewAllAction = 0;

    QmlProfilerTool *profilerTool = qobject_cast<QmlProfilerTool *>(d->m_profilerTool);

421 422
    if (profilerTool)
        menu.addActions(profilerTool->profilerContextMenuActions());
Christiaan Janssen's avatar
Christiaan Janssen committed
423 424

    menu.addSeparator();
425 426

    QAction *getLocalStatsAction = menu.addAction(tr("Limit Events Pane to Current Range"));
Christiaan Janssen's avatar
Christiaan Janssen committed
427 428
    if (!d->m_viewContainer->hasValidSelection())
        getLocalStatsAction->setEnabled(false);
429 430

    QAction *getGlobalStatsAction = menu.addAction(tr("Reset Events Pane"));
Christiaan Janssen's avatar
Christiaan Janssen committed
431 432 433
    if (d->m_viewContainer->hasGlobalStats())
        getGlobalStatsAction->setEnabled(false);

Christiaan Janssen's avatar
Christiaan Janssen committed
434
    if (!d->m_modelProxy->isEmpty()) {
Christiaan Janssen's avatar
Christiaan Janssen committed
435 436 437 438
        menu.addSeparator();
        viewAllAction = menu.addAction(tr("Reset Zoom"));
    }

439
    QAction *selectedAction = menu.exec(ev->globalPos());
Christiaan Janssen's avatar
Christiaan Janssen committed
440 441 442 443

    if (selectedAction) {
        if (selectedAction == viewAllAction) {
            d->m_zoomControl->setRange(
Christiaan Janssen's avatar
Christiaan Janssen committed
444 445
                        d->m_modelManager->traceTime()->startTime(),
                        d->m_modelManager->traceTime()->endTime());
Christiaan Janssen's avatar
Christiaan Janssen committed
446 447 448 449 450 451
        }
        if (selectedAction == getLocalStatsAction) {
            d->m_viewContainer->getStatisticsInRange(
                        d->m_viewContainer->selectionStart(),
                        d->m_viewContainer->selectionEnd());
        }
Orgad Shaneh's avatar
Orgad Shaneh committed
452
        if (selectedAction == getGlobalStatsAction)
Christiaan Janssen's avatar
Christiaan Janssen committed
453
            d->m_viewContainer->getStatisticsInRange(-1, -1);
Christiaan Janssen's avatar
Christiaan Janssen committed
454 455 456 457 458 459 460
    }
}

/////////////////////////////////////////////////
// Tell QML the state of the profiler
void QmlProfilerTraceView::setRecording(bool recording)
{
461
    QQuickItem *rootObject = d->m_mainView->rootObject();
462 463
    if (rootObject)
        rootObject->setProperty("recordingEnabled", QVariant(recording));
Christiaan Janssen's avatar
Christiaan Janssen committed
464 465 466 467
}

void QmlProfilerTraceView::setAppKilled()
{
468
    QQuickItem *rootObject = d->m_mainView->rootObject();
469 470
    if (rootObject)
        rootObject->setProperty("appKilled",QVariant(true));
Christiaan Janssen's avatar
Christiaan Janssen committed
471 472 473 474 475
}
////////////////////////////////////////////////////////////////
// Profiler State
void QmlProfilerTraceView::profilerDataModelStateChanged()
{
Christiaan Janssen's avatar
Christiaan Janssen committed
476
    switch (d->m_modelManager->state()) {
477 478
        case QmlProfilerDataState::Empty: break;
        case QmlProfilerDataState::ClearingData:
Christiaan Janssen's avatar
Christiaan Janssen committed
479
            emit enableToolbar(false);
Christiaan Janssen's avatar
Christiaan Janssen committed
480
        break;
Christiaan Janssen's avatar
Christiaan Janssen committed
481 482 483 484
        case QmlProfilerDataState::AcquiringData: break;
        case QmlProfilerDataState::ProcessingData: break;
        case QmlProfilerDataState::Done:
            emit enableToolbar(true);
Christiaan Janssen's avatar
Christiaan Janssen committed
485 486 487 488 489 490 491 492 493 494
        break;
    default:
        break;
    }
}

void QmlProfilerTraceView::profilerStateChanged()
{
    switch (d->m_profilerState->currentState()) {
    case QmlProfilerStateManager::AppKilled : {
Christiaan Janssen's avatar
Christiaan Janssen committed
495
        if (d->m_modelManager->state() == QmlProfilerDataState::AcquiringData)
Christiaan Janssen's avatar
Christiaan Janssen committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
            setAppKilled();
        break;
    }
    default:
        // no special action needed for other states
        break;
    }
}

void QmlProfilerTraceView::clientRecordingChanged()
{
    // nothing yet
}

void QmlProfilerTraceView::serverRecordingChanged()
{
    setRecording(d->m_profilerState->serverRecording());
}

} // namespace Internal
} // namespace QmlProfiler