2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-10-11 17:52:39 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-10-11 17:52:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-11 17:52:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-10-11 17:52:39 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** 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.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-10-11 17:52:39 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-11 17:52:39 +02:00
|
|
|
|
2013-09-03 12:53:48 +02:00
|
|
|
import QtQuick 2.1
|
2011-10-11 17:52:39 +02:00
|
|
|
import Monitor 1.0
|
|
|
|
|
import "Overview.js" as Plotter
|
|
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
Canvas {
|
2011-10-11 17:52:39 +02:00
|
|
|
id: canvas
|
2013-10-30 13:39:29 +01:00
|
|
|
objectName: "Overview"
|
2013-11-28 15:29:29 +01:00
|
|
|
contextType: "2d"
|
2011-10-11 17:52:39 +02:00
|
|
|
|
2014-09-02 17:10:23 +02:00
|
|
|
readonly property int eventsPerPass: 512
|
2014-05-28 05:34:16 +02:00
|
|
|
property int increment: -1
|
|
|
|
|
property int offset: -1
|
2014-09-02 17:09:27 +02:00
|
|
|
readonly property int bump: 10;
|
|
|
|
|
readonly property int blockHeight: (height - bump) / qmlProfilerModelProxy.models.length;
|
2014-05-28 05:34:16 +02:00
|
|
|
|
2011-10-11 17:52:39 +02:00
|
|
|
// ***** properties
|
|
|
|
|
height: 50
|
2013-08-08 13:28:08 +02:00
|
|
|
property bool dataReady: false
|
2014-03-28 10:23:39 +01:00
|
|
|
property double startTime : 0
|
|
|
|
|
property double endTime : 0
|
2014-03-28 16:14:21 +01:00
|
|
|
property bool recursionGuard: false
|
2011-10-11 17:52:39 +02:00
|
|
|
|
2014-05-28 05:34:16 +02:00
|
|
|
onWidthChanged: offset = -1
|
|
|
|
|
|
2011-10-11 17:52:39 +02:00
|
|
|
// ***** functions
|
2014-03-25 17:10:25 +01:00
|
|
|
function clear()
|
2011-10-11 17:52:39 +02:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
dataReady = false;
|
2014-05-28 05:34:16 +02:00
|
|
|
increment = -1;
|
|
|
|
|
offset = -1;
|
2013-11-28 15:29:29 +01:00
|
|
|
requestPaint();
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateRange() {
|
2014-03-28 16:14:21 +01:00
|
|
|
if (recursionGuard)
|
|
|
|
|
return;
|
2014-07-08 14:46:17 +02:00
|
|
|
var newStartTime = Math.round(rangeMover.rangeLeft * qmlProfilerModelProxy.traceDuration() / width) + qmlProfilerModelProxy.traceStartTime();
|
|
|
|
|
var newEndTime = Math.round(rangeMover.rangeRight * qmlProfilerModelProxy.traceDuration() / width) + qmlProfilerModelProxy.traceStartTime();
|
2014-03-28 17:13:55 +01:00
|
|
|
if (startTime !== newStartTime || endTime !== newEndTime)
|
|
|
|
|
zoomControl.setRange(newStartTime, Math.max(newEndTime, newStartTime + 500));
|
2013-11-13 12:10:48 +01:00
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2013-11-13 12:10:48 +01:00
|
|
|
function clamp(val, min, max) {
|
|
|
|
|
return Math.min(Math.max(val, min), max);
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***** connections to external objects
|
|
|
|
|
Connections {
|
|
|
|
|
target: zoomControl
|
|
|
|
|
onRangeChanged: {
|
2013-08-08 13:28:08 +02:00
|
|
|
if (qmlProfilerModelProxy) {
|
2014-03-28 16:14:21 +01:00
|
|
|
recursionGuard = true;
|
2013-11-13 12:10:48 +01:00
|
|
|
startTime = clamp(zoomControl.startTime(), qmlProfilerModelProxy.traceStartTime(), qmlProfilerModelProxy.traceEndTime());
|
|
|
|
|
endTime = clamp(zoomControl.endTime(), startTime, qmlProfilerModelProxy.traceEndTime());
|
2013-08-08 13:28:08 +02:00
|
|
|
var newRangeX = (startTime - qmlProfilerModelProxy.traceStartTime()) * width / qmlProfilerModelProxy.traceDuration();
|
2013-11-13 12:10:48 +01:00
|
|
|
var newWidth = (endTime - startTime) * width / qmlProfilerModelProxy.traceDuration();
|
2014-07-08 14:46:17 +02:00
|
|
|
var widthChanged = Math.abs(newWidth - rangeMover.rangeWidth) > 1;
|
|
|
|
|
var leftChanged = Math.abs(newRangeX - rangeMover.rangeLeft) > 1;
|
2013-11-13 12:10:48 +01:00
|
|
|
if (leftChanged)
|
2014-07-08 14:46:17 +02:00
|
|
|
rangeMover.rangeLeft = newRangeX;
|
2013-11-13 12:10:48 +01:00
|
|
|
|
|
|
|
|
if (leftChanged || widthChanged)
|
2014-07-08 14:46:17 +02:00
|
|
|
rangeMover.rangeRight = newRangeX + newWidth;
|
2014-03-28 16:14:21 +01:00
|
|
|
recursionGuard = false;
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
2013-08-08 13:28:08 +02:00
|
|
|
target: qmlProfilerModelProxy
|
|
|
|
|
onDataAvailable: {
|
2014-05-28 05:34:16 +02:00
|
|
|
dataReady = true;
|
2014-09-29 12:36:29 +02:00
|
|
|
increment = 0;
|
|
|
|
|
for (var i = 0; i < qmlProfilerModelProxy.modelCount(); ++i)
|
|
|
|
|
increment += qmlProfilerModelProxy.count(i);
|
|
|
|
|
increment = Math.ceil(increment / eventsPerPass);
|
2014-05-28 05:34:16 +02:00
|
|
|
offset = -1;
|
|
|
|
|
requestPaint();
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 05:34:16 +02:00
|
|
|
Timer {
|
|
|
|
|
id: paintTimer
|
2014-09-02 17:10:23 +02:00
|
|
|
repeat: true
|
|
|
|
|
running: offset >= 0
|
|
|
|
|
interval: offset == 0 ? 1000 : 14 // Larger initial delay to avoid flickering on resize
|
|
|
|
|
onTriggered: canvas.requestPaint()
|
2014-05-28 05:34:16 +02:00
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2011-10-11 17:52:39 +02:00
|
|
|
// ***** slots
|
2013-11-28 15:29:29 +01:00
|
|
|
onPaint: {
|
2014-09-09 17:42:35 +02:00
|
|
|
var context = (canvas.context === null) ? getContext("2d") : canvas.context;
|
2014-04-11 17:15:10 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
Plotter.qmlProfilerModelProxy = qmlProfilerModelProxy;
|
2014-05-28 05:34:16 +02:00
|
|
|
|
|
|
|
|
if (offset < 0) {
|
|
|
|
|
context.reset();
|
|
|
|
|
Plotter.drawGraph(canvas, context);
|
|
|
|
|
if (dataReady) {
|
|
|
|
|
Plotter.drawTimeBar(canvas, context);
|
|
|
|
|
offset = 0;
|
|
|
|
|
}
|
|
|
|
|
} else if (offset < increment) {
|
|
|
|
|
Plotter.drawData(canvas, context);
|
|
|
|
|
++offset;
|
2014-09-02 17:09:27 +02:00
|
|
|
} else if (offset < 2 * increment) {
|
|
|
|
|
Plotter.drawBindingLoops(canvas, context);
|
|
|
|
|
++offset;
|
2014-09-02 17:10:23 +02:00
|
|
|
} else {
|
|
|
|
|
offset = -1;
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***** child items
|
|
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: canvas
|
|
|
|
|
function jumpTo(posX) {
|
2014-07-08 14:46:17 +02:00
|
|
|
var newX = posX - rangeMover.rangeWidth / 2;
|
2011-10-11 17:52:39 +02:00
|
|
|
if (newX < 0)
|
|
|
|
|
newX = 0;
|
2014-07-08 14:46:17 +02:00
|
|
|
if (newX + rangeMover.rangeWidth > canvas.width)
|
|
|
|
|
newX = canvas.width - rangeMover.rangeWidth;
|
|
|
|
|
|
|
|
|
|
if (newX < rangeMover.rangeLeft) {
|
2014-09-19 17:33:49 +02:00
|
|
|
// Changing left border will change width, so precompute right border here.
|
|
|
|
|
var right = newX + rangeMover.rangeWidth;
|
2014-07-08 14:46:17 +02:00
|
|
|
rangeMover.rangeLeft = newX;
|
2014-09-19 17:33:49 +02:00
|
|
|
rangeMover.rangeRight = right;
|
2014-07-08 14:46:17 +02:00
|
|
|
} else if (newX > rangeMover.rangeLeft) {
|
|
|
|
|
rangeMover.rangeRight = newX + rangeMover.rangeWidth;
|
|
|
|
|
rangeMover.rangeLeft = newX;
|
2013-11-13 12:10:48 +01:00
|
|
|
}
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onPressed: {
|
|
|
|
|
jumpTo(mouse.x);
|
|
|
|
|
}
|
2013-09-16 14:33:07 +02:00
|
|
|
onPositionChanged: {
|
2011-10-11 17:52:39 +02:00
|
|
|
jumpTo(mouse.x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RangeMover {
|
|
|
|
|
id: rangeMover
|
2013-08-08 13:28:08 +02:00
|
|
|
visible: dataReady
|
2014-07-08 14:46:17 +02:00
|
|
|
onRangeLeftChanged: canvas.updateRange()
|
|
|
|
|
onRangeRightChanged: canvas.updateRange()
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
height: 1
|
|
|
|
|
width: parent.width
|
2011-11-16 16:08:05 +01:00
|
|
|
color: "#858585"
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
}
|