2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-25 09:25:17 +01: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
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-03-25 09:25:17 +01: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
|
|
|
|
|
** 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
|
2011-03-25 09:25:17 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-25 09:25:17 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
#include "timelinerenderer.h"
|
2011-03-11 12:22:57 +01:00
|
|
|
|
|
|
|
|
#include <qdeclarativecontext.h>
|
|
|
|
|
#include <qdeclarativeproperty.h>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2011-10-26 11:32:01 +02:00
|
|
|
|
|
|
|
|
#include <math.h>
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-03-25 09:21:00 +01:00
|
|
|
using namespace QmlProfiler::Internal;
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
const int DefaultRowHeight = 30;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
TimelineRenderer::TimelineRenderer(QDeclarativeItem *parent) :
|
2011-10-26 11:32:01 +02:00
|
|
|
QDeclarativeItem(parent), m_startTime(0), m_endTime(0), m_spacing(0),
|
2012-02-24 10:47:17 +01:00
|
|
|
m_lastStartTime(0), m_lastEndTime(0), m_profilerDataModel(0)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
clearData();
|
|
|
|
|
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
|
setAcceptHoverEvents(true);
|
2012-04-18 12:06:10 +02:00
|
|
|
for (int i=0; i<QmlDebug::MaximumQmlEventType; i++)
|
2011-10-26 11:32:01 +02:00
|
|
|
m_rowsExpanded << false;
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::componentComplete()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
const QMetaObject *metaObject = this->metaObject();
|
|
|
|
|
int propertyCount = metaObject->propertyCount();
|
|
|
|
|
int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
|
2012-02-24 10:47:17 +01:00
|
|
|
for (int ii = TimelineRenderer::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
|
2011-10-26 11:32:01 +02:00
|
|
|
QMetaProperty p = metaObject->property(ii);
|
|
|
|
|
if (p.hasNotifySignal())
|
|
|
|
|
QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
QDeclarativeItem::componentComplete();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::requestPaint()
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
update();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
qint64 windowDuration = m_endTime - m_startTime;
|
|
|
|
|
if (windowDuration <= 0)
|
2011-03-11 12:22:57 +01:00
|
|
|
return;
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_spacing = qreal(width()) / windowDuration;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_rowWidths.clear();
|
2011-11-16 16:08:05 +01:00
|
|
|
// The "1+" is because the reference screenshot features an empty row per type, in order to leave space for the title
|
2012-04-18 12:06:10 +02:00
|
|
|
for (int i=0; i<QmlDebug::MaximumQmlEventType; i++) {
|
2012-02-24 10:47:17 +01:00
|
|
|
m_rowWidths << 1 + (m_rowsExpanded[i] ? m_profilerDataModel->uniqueEventsOfType(i) :
|
|
|
|
|
m_profilerDataModel->maxNestingForType(i));
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// event rows
|
|
|
|
|
m_rowStarts.clear();
|
|
|
|
|
int pos = 0;
|
2012-04-18 12:06:10 +02:00
|
|
|
for (int i=0; i<QmlDebug::MaximumQmlEventType; i++) {
|
2011-10-26 11:32:01 +02:00
|
|
|
m_rowStarts << pos;
|
|
|
|
|
pos += DefaultRowHeight * m_rowWidths[i];
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
p->setPen(Qt::transparent);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// speedup: don't draw overlapping events, just skip them
|
|
|
|
|
m_rowLastX.clear();
|
2012-04-18 12:06:10 +02:00
|
|
|
for (int i=0; i<QmlDebug::MaximumQmlEventType; i++)
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int j=0; j<m_rowWidths[i]; j++)
|
|
|
|
|
m_rowLastX << -m_startTime * m_spacing;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
int firstIndex = m_profilerDataModel->findFirstIndex(m_startTime);
|
|
|
|
|
int lastIndex = m_profilerDataModel->findLastIndex(m_endTime);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2012-05-11 16:45:47 +02:00
|
|
|
if (lastIndex < m_profilerDataModel->count()) {
|
|
|
|
|
drawItemsToPainter(p, firstIndex, lastIndex);
|
|
|
|
|
drawSelectionBoxes(p, firstIndex, lastIndex);
|
|
|
|
|
drawBindingLoopMarkers(p, firstIndex, lastIndex);
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_lastStartTime = m_startTime;
|
|
|
|
|
m_lastEndTime = m_endTime;
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
QColor TimelineRenderer::colorForItem(int itemIndex)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
int ndx = m_profilerDataModel->getEventId(itemIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
return QColor::fromHsl((ndx*25)%360, 76, 166);
|
|
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::drawItemsToPainter(QPainter *p, int fromIndex, int toIndex)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-12-14 16:44:33 +01:00
|
|
|
int x, y, width, height, rowNumber, eventType;
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2012-02-24 10:47:17 +01:00
|
|
|
x = (m_profilerDataModel->getStartTime(i) - m_startTime) * m_spacing;
|
2011-12-14 16:44:33 +01:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
eventType = m_profilerDataModel->getType(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_rowsExpanded[eventType])
|
2012-02-24 10:47:17 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
(m_profilerDataModel->eventPosInType(i) + 1);
|
2011-07-26 13:56:14 +02:00
|
|
|
else
|
2012-02-24 10:47:17 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
m_profilerDataModel->getNestingLevel(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
width = m_profilerDataModel->getDuration(i)*m_spacing;
|
2011-10-26 11:32:01 +02:00
|
|
|
if (width<1)
|
|
|
|
|
width = 1;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
rowNumber = y/DefaultRowHeight;
|
|
|
|
|
if (m_rowLastX[rowNumber] > x+width)
|
|
|
|
|
continue;
|
|
|
|
|
m_rowLastX[rowNumber] = x+width;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-12-14 16:44:33 +01:00
|
|
|
// special: animations
|
2012-02-24 10:47:17 +01:00
|
|
|
if (eventType == 0 && m_profilerDataModel->getAnimationCount(i) >= 0) {
|
|
|
|
|
double scale = m_profilerDataModel->getMaximumAnimationCount() -
|
|
|
|
|
m_profilerDataModel->getMinimumAnimationCount();
|
2012-01-10 17:31:04 +01:00
|
|
|
double fraction;
|
|
|
|
|
if (scale > 1)
|
2012-02-24 10:47:17 +01:00
|
|
|
fraction = (double)(m_profilerDataModel->getAnimationCount(i) -
|
|
|
|
|
m_profilerDataModel->getMinimumAnimationCount()) / scale;
|
2012-01-10 17:31:04 +01:00
|
|
|
else
|
|
|
|
|
fraction = 1.0;
|
2011-12-14 16:44:33 +01:00
|
|
|
height = DefaultRowHeight * (fraction * 0.85 + 0.15);
|
|
|
|
|
y += DefaultRowHeight - height;
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
double fpsFraction = m_profilerDataModel->getFramerate(i) / 60.0;
|
2011-12-14 16:44:33 +01:00
|
|
|
if (fpsFraction > 1.0)
|
|
|
|
|
fpsFraction = 1.0;
|
|
|
|
|
p->setBrush(QColor::fromHsl((fpsFraction*96)+10, 76, 166));
|
|
|
|
|
p->drawRect(x, y, width, height);
|
|
|
|
|
} else {
|
|
|
|
|
// normal events
|
|
|
|
|
p->setBrush(colorForItem(i));
|
|
|
|
|
p->drawRect(x, y, width, DefaultRowHeight);
|
|
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::drawSelectionBoxes(QPainter *p, int fromIndex, int toIndex)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_selectedItem == -1)
|
|
|
|
|
return;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
int id = m_profilerDataModel->getEventId(m_selectedItem);
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
p->setBrush(Qt::transparent);
|
2011-11-16 16:08:05 +01:00
|
|
|
QColor selectionColor = Qt::blue;
|
|
|
|
|
if (m_selectionLocked)
|
|
|
|
|
selectionColor = QColor(96,0,255);
|
|
|
|
|
QPen strongPen(selectionColor, 3);
|
|
|
|
|
QPen lightPen(QBrush(selectionColor.lighter(130)), 2);
|
2011-11-29 12:32:35 +01:00
|
|
|
lightPen.setJoinStyle(Qt::MiterJoin);
|
2011-10-26 11:32:01 +02:00
|
|
|
p->setPen(lightPen);
|
|
|
|
|
|
2011-11-08 11:05:07 +01:00
|
|
|
int x, y, width, eventType;
|
2011-11-23 16:17:33 +01:00
|
|
|
p->setPen(lightPen);
|
|
|
|
|
|
|
|
|
|
QRect selectedItemRect(0,0,0,0);
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_profilerDataModel->getEventId(i) != id)
|
2011-10-26 11:32:01 +02:00
|
|
|
continue;
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
x = (m_profilerDataModel->getStartTime(i) - m_startTime) * m_spacing;
|
|
|
|
|
eventType = m_profilerDataModel->getType(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_rowsExpanded[eventType])
|
2012-02-24 10:47:17 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
(m_profilerDataModel->eventPosInType(i) + 1);
|
2011-10-26 11:32:01 +02:00
|
|
|
else
|
2012-02-24 10:47:17 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
m_profilerDataModel->getNestingLevel(i);
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
width = m_profilerDataModel->getDuration(i)*m_spacing;
|
2011-10-26 11:32:01 +02:00
|
|
|
if (width<1)
|
|
|
|
|
width = 1;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-11-23 16:17:33 +01:00
|
|
|
if (i == m_selectedItem)
|
2011-11-29 12:32:35 +01:00
|
|
|
selectedItemRect = QRect(x, y-1, width, DefaultRowHeight+1);
|
2011-11-23 16:17:33 +01:00
|
|
|
else
|
|
|
|
|
p->drawRect(x,y,width,DefaultRowHeight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// draw the selected item rectangle the last, so that it's overlayed
|
|
|
|
|
if (selectedItemRect.width() != 0) {
|
|
|
|
|
p->setPen(strongPen);
|
|
|
|
|
p->drawRect(selectedItemRect);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int fromIndex, int toIndex)
|
2012-02-06 16:08:56 +01:00
|
|
|
{
|
|
|
|
|
int destindex;
|
|
|
|
|
int xfrom, xto, eventType;
|
|
|
|
|
int yfrom, yto;
|
|
|
|
|
int radius = DefaultRowHeight / 3;
|
|
|
|
|
QPen shadowPen = QPen(QColor("grey"),2);
|
|
|
|
|
QPen markerPen = QPen(QColor("orange"),2);
|
|
|
|
|
QBrush shadowBrush = QBrush(QColor("grey"));
|
|
|
|
|
QBrush markerBrush = QBrush(QColor("orange"));
|
|
|
|
|
|
|
|
|
|
p->save();
|
|
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2012-02-24 10:47:17 +01:00
|
|
|
destindex = m_profilerDataModel->getBindingLoopDest(i);
|
2012-02-06 16:08:56 +01:00
|
|
|
if (destindex >= 0) {
|
|
|
|
|
// from
|
2012-02-24 10:47:17 +01:00
|
|
|
xfrom = (m_profilerDataModel->getStartTime(i) +
|
|
|
|
|
m_profilerDataModel->getDuration(i)/2 -
|
2012-02-06 16:08:56 +01:00
|
|
|
m_startTime) * m_spacing;
|
2012-02-24 10:47:17 +01:00
|
|
|
eventType = m_profilerDataModel->getType(i);
|
2012-02-06 16:08:56 +01:00
|
|
|
if (m_rowsExpanded[eventType])
|
|
|
|
|
yfrom = m_rowStarts[eventType] + DefaultRowHeight*
|
2012-02-24 10:47:17 +01:00
|
|
|
(m_profilerDataModel->eventPosInType(i) + 1);
|
2012-02-06 16:08:56 +01:00
|
|
|
else
|
2012-02-24 10:47:17 +01:00
|
|
|
yfrom = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
m_profilerDataModel->getNestingLevel(i);
|
2012-02-06 16:08:56 +01:00
|
|
|
|
|
|
|
|
yfrom += DefaultRowHeight / 2;
|
|
|
|
|
|
|
|
|
|
// to
|
2012-02-24 10:47:17 +01:00
|
|
|
xto = (m_profilerDataModel->getStartTime(destindex) +
|
|
|
|
|
m_profilerDataModel->getDuration(destindex)/2 -
|
2012-02-06 16:08:56 +01:00
|
|
|
m_startTime) * m_spacing;
|
2012-02-24 10:47:17 +01:00
|
|
|
eventType = m_profilerDataModel->getType(destindex);
|
2012-02-06 16:08:56 +01:00
|
|
|
if (m_rowsExpanded[eventType])
|
2012-02-24 10:47:17 +01:00
|
|
|
yto = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
(m_profilerDataModel->eventPosInType(destindex) + 1);
|
2012-02-06 16:08:56 +01:00
|
|
|
else
|
|
|
|
|
yto = m_rowStarts[eventType] + DefaultRowHeight *
|
2012-02-24 10:47:17 +01:00
|
|
|
m_profilerDataModel->getNestingLevel(destindex);
|
2012-02-06 16:08:56 +01:00
|
|
|
|
|
|
|
|
yto += DefaultRowHeight / 2;
|
|
|
|
|
|
|
|
|
|
// radius
|
2012-02-24 10:47:17 +01:00
|
|
|
int eventWidth = m_profilerDataModel->getDuration(i) * m_spacing;
|
2012-02-06 16:08:56 +01:00
|
|
|
radius = 5;
|
|
|
|
|
if (radius * 2 > eventWidth)
|
|
|
|
|
radius = eventWidth / 2;
|
|
|
|
|
if (radius < 2)
|
|
|
|
|
radius = 2;
|
|
|
|
|
|
|
|
|
|
// shadow
|
|
|
|
|
int shadowoffset = 2;
|
|
|
|
|
p->setPen(shadowPen);
|
|
|
|
|
p->setBrush(shadowBrush);
|
|
|
|
|
p->drawEllipse(QPoint(xfrom, yfrom + shadowoffset), radius, radius);
|
|
|
|
|
p->drawEllipse(QPoint(xto, yto + shadowoffset), radius, radius);
|
|
|
|
|
p->drawLine(QPoint(xfrom, yfrom + shadowoffset), QPoint(xto, yto + shadowoffset));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// marker
|
|
|
|
|
p->setPen(markerPen);
|
|
|
|
|
p->setBrush(markerBrush);
|
|
|
|
|
p->drawEllipse(QPoint(xfrom, yfrom), radius, radius);
|
|
|
|
|
p->drawEllipse(QPoint(xto, yto), radius, radius);
|
|
|
|
|
p->drawLine(QPoint(xfrom, yfrom), QPoint(xto, yto));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
p->restore();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
// special case: if there is a drag area below me, don't accept the
|
|
|
|
|
// events unless I'm actually clicking inside an item
|
|
|
|
|
if (m_currentSelection.eventIndex == -1 &&
|
|
|
|
|
event->pos().x()+x() >= m_startDragArea &&
|
|
|
|
|
event->pos().x()+x() <= m_endDragArea)
|
|
|
|
|
event->setAccepted(false);
|
|
|
|
|
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
Q_UNUSED(event);
|
|
|
|
|
manageClicked();
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
event->setAccepted(false);
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
manageHovered(event->pos().x(), event->pos().y());
|
|
|
|
|
if (m_currentSelection.eventIndex == -1)
|
|
|
|
|
event->setAccepted(false);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::manageClicked()
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_currentSelection.eventIndex != -1) {
|
|
|
|
|
if (m_currentSelection.eventIndex == m_selectedItem)
|
|
|
|
|
setSelectionLocked(!m_selectionLocked);
|
|
|
|
|
else
|
|
|
|
|
setSelectionLocked(true);
|
|
|
|
|
emit itemPressed(m_currentSelection.eventIndex);
|
|
|
|
|
} else {
|
|
|
|
|
// setSelectionLocked(false);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
setSelectedItem(m_currentSelection.eventIndex);
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::manageHovered(int x, int y)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-09 17:35:12 +01:00
|
|
|
if (m_endTime - m_startTime <=0 || m_lastEndTime - m_lastStartTime <= 0)
|
2011-10-26 11:32:01 +02:00
|
|
|
return;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
qint64 time = x * (m_endTime - m_startTime) / width() + m_startTime;
|
|
|
|
|
int row = y / DefaultRowHeight;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// already covered? nothing to do
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_currentSelection.eventIndex != -1 &&
|
|
|
|
|
time >= m_currentSelection.startTime &&
|
|
|
|
|
time <= m_currentSelection.endTime &&
|
|
|
|
|
row == m_currentSelection.row) {
|
2011-10-26 11:32:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// find if there's items in the time range
|
2012-02-24 10:47:17 +01:00
|
|
|
int eventFrom = m_profilerDataModel->findFirstIndex(time);
|
|
|
|
|
int eventTo = m_profilerDataModel->findLastIndex(time);
|
2012-05-11 16:45:47 +02:00
|
|
|
if (eventTo < eventFrom || eventTo >= m_profilerDataModel->count()) {
|
2011-10-26 11:32:01 +02:00
|
|
|
m_currentSelection.eventIndex = -1;
|
2011-07-26 13:56:14 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// find if we are in the right column
|
|
|
|
|
int itemRow, eventType;
|
|
|
|
|
for (int i=eventTo; i>=eventFrom; --i) {
|
2012-02-24 10:47:17 +01:00
|
|
|
if (ceil(m_profilerDataModel->getEndTime(i)*m_spacing) < floor(time*m_spacing))
|
2011-10-26 11:32:01 +02:00
|
|
|
continue;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
eventType = m_profilerDataModel->getType(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
if (m_rowsExpanded[eventType])
|
2012-02-24 10:47:17 +01:00
|
|
|
itemRow = m_rowStarts[eventType]/DefaultRowHeight +
|
|
|
|
|
m_profilerDataModel->eventPosInType(i) + 1;
|
2011-10-26 11:32:01 +02:00
|
|
|
else
|
2012-02-24 10:47:17 +01:00
|
|
|
itemRow = m_rowStarts[eventType]/DefaultRowHeight +
|
|
|
|
|
m_profilerDataModel->getNestingLevel(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
if (itemRow == row) {
|
|
|
|
|
// match
|
|
|
|
|
m_currentSelection.eventIndex = i;
|
2012-02-24 10:47:17 +01:00
|
|
|
m_currentSelection.startTime = m_profilerDataModel->getStartTime(i);
|
|
|
|
|
m_currentSelection.endTime = m_profilerDataModel->getEndTime(i);
|
2011-10-26 11:32:01 +02:00
|
|
|
m_currentSelection.row = row;
|
|
|
|
|
if (!m_selectionLocked)
|
|
|
|
|
setSelectedItem(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
m_currentSelection.eventIndex = -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::clearData()
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
|
|
|
|
m_startTime = 0;
|
|
|
|
|
m_endTime = 0;
|
|
|
|
|
m_lastStartTime = 0;
|
|
|
|
|
m_lastEndTime = 0;
|
|
|
|
|
m_currentSelection.startTime = -1;
|
|
|
|
|
m_currentSelection.endTime = -1;
|
|
|
|
|
m_currentSelection.row = -1;
|
|
|
|
|
m_currentSelection.eventIndex = -1;
|
|
|
|
|
m_selectedItem = -1;
|
|
|
|
|
m_selectionLocked = true;
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
qint64 TimelineRenderer::getDuration(int index) const
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
Q_ASSERT(m_profilerDataModel);
|
|
|
|
|
return m_profilerDataModel->getEndTime(index) -
|
|
|
|
|
m_profilerDataModel->getStartTime(index);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
QString TimelineRenderer::getFilename(int index) const
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
Q_ASSERT(m_profilerDataModel);
|
|
|
|
|
return m_profilerDataModel->getFilename(index);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
int TimelineRenderer::getLine(int index) const
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
Q_ASSERT(m_profilerDataModel);
|
|
|
|
|
return m_profilerDataModel->getLine(index);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
QString TimelineRenderer::getDetails(int index) const
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
Q_ASSERT(m_profilerDataModel);
|
|
|
|
|
return m_profilerDataModel->getDetails(index);
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
int TimelineRenderer::getYPosition(int index) const
|
2012-02-03 16:33:51 +01:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
Q_ASSERT(m_profilerDataModel);
|
|
|
|
|
if (index >= m_profilerDataModel->count() || m_rowStarts.isEmpty())
|
2012-02-03 16:33:51 +01:00
|
|
|
return 0;
|
2012-02-24 10:47:17 +01:00
|
|
|
int y, eventType = m_profilerDataModel->getType(index);
|
2012-02-03 16:33:51 +01:00
|
|
|
if (m_rowsExpanded[eventType])
|
2012-02-24 10:47:17 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
(m_profilerDataModel->eventPosInType(index) + 1);
|
2012-02-03 16:33:51 +01:00
|
|
|
else
|
2012-02-24 10:47:17 +01:00
|
|
|
y = m_rowStarts[eventType] + DefaultRowHeight *
|
|
|
|
|
m_profilerDataModel->getNestingLevel(index);
|
2012-02-03 16:33:51 +01:00
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::setRowExpanded(int rowIndex, bool expanded)
|
2011-11-23 16:17:33 +01:00
|
|
|
{
|
|
|
|
|
m_rowsExpanded[rowIndex] = expanded;
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::selectNext()
|
2011-11-23 16:17:33 +01:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_profilerDataModel->count() == 0)
|
2011-11-23 16:17:33 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// select next in view or after
|
|
|
|
|
int newIndex = m_selectedItem+1;
|
2012-02-24 10:47:17 +01:00
|
|
|
if (newIndex >= m_profilerDataModel->count())
|
2011-11-23 16:17:33 +01:00
|
|
|
newIndex = 0;
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_profilerDataModel->getEndTime(newIndex) < m_startTime)
|
|
|
|
|
newIndex = m_profilerDataModel->findFirstIndexNoParents(m_startTime);
|
2011-11-23 16:17:33 +01:00
|
|
|
setSelectedItem(newIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::selectPrev()
|
2011-11-23 16:17:33 +01:00
|
|
|
{
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_profilerDataModel->count() == 0)
|
2011-11-23 16:17:33 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// select last in view or before
|
|
|
|
|
int newIndex = m_selectedItem-1;
|
|
|
|
|
if (newIndex < 0)
|
2012-02-24 10:47:17 +01:00
|
|
|
newIndex = m_profilerDataModel->count()-1;
|
|
|
|
|
if (m_profilerDataModel->getStartTime(newIndex) > m_endTime)
|
|
|
|
|
newIndex = m_profilerDataModel->findLastIndex(m_endTime);
|
2011-11-23 16:17:33 +01:00
|
|
|
setSelectedItem(newIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
int TimelineRenderer::nextItemFromId(int eventId) const
|
2011-11-09 12:57:41 +01:00
|
|
|
{
|
|
|
|
|
int ndx = -1;
|
|
|
|
|
if (m_selectedItem == -1)
|
2012-02-24 10:47:17 +01:00
|
|
|
ndx = m_profilerDataModel->findFirstIndexNoParents(m_startTime);
|
2011-11-09 12:57:41 +01:00
|
|
|
else
|
|
|
|
|
ndx = m_selectedItem + 1;
|
2012-02-24 10:47:17 +01:00
|
|
|
if (ndx >= m_profilerDataModel->count())
|
2011-11-09 12:57:41 +01:00
|
|
|
ndx = 0;
|
|
|
|
|
int startIndex = ndx;
|
|
|
|
|
do {
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_profilerDataModel->getEventId(ndx) == eventId)
|
2011-11-09 12:57:41 +01:00
|
|
|
return ndx;
|
2012-02-24 10:47:17 +01:00
|
|
|
ndx = (ndx + 1) % m_profilerDataModel->count();
|
2011-11-09 12:57:41 +01:00
|
|
|
} while (ndx != startIndex);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
int TimelineRenderer::prevItemFromId(int eventId) const
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-23 16:17:33 +01:00
|
|
|
int ndx = -1;
|
|
|
|
|
if (m_selectedItem == -1)
|
2012-02-24 10:47:17 +01:00
|
|
|
ndx = m_profilerDataModel->findFirstIndexNoParents(m_startTime);
|
2011-11-23 16:17:33 +01:00
|
|
|
else
|
|
|
|
|
ndx = m_selectedItem - 1;
|
|
|
|
|
if (ndx < 0)
|
2012-02-24 10:47:17 +01:00
|
|
|
ndx = m_profilerDataModel->count() - 1;
|
2011-11-23 16:17:33 +01:00
|
|
|
int startIndex = ndx;
|
|
|
|
|
do {
|
2012-02-24 10:47:17 +01:00
|
|
|
if (m_profilerDataModel->getEventId(ndx) == eventId)
|
2011-11-23 16:17:33 +01:00
|
|
|
return ndx;
|
|
|
|
|
if (--ndx < 0)
|
2012-02-24 10:47:17 +01:00
|
|
|
ndx = m_profilerDataModel->count()-1;
|
2011-11-23 16:17:33 +01:00
|
|
|
} while (ndx != startIndex);
|
|
|
|
|
return -1;
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::selectNextFromId(int eventId)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-23 16:17:33 +01:00
|
|
|
int eventIndex = nextItemFromId(eventId);
|
|
|
|
|
if (eventIndex != -1)
|
|
|
|
|
setSelectedItem(eventIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::selectPrevFromId(int eventId)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2011-11-23 16:17:33 +01:00
|
|
|
int eventIndex = prevItemFromId(eventId);
|
|
|
|
|
if (eventIndex != -1)
|
|
|
|
|
setSelectedItem(eventIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|