2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-25 09:25:17 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
#include <QQmlContext>
|
|
|
|
|
#include <QQmlProperty>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <QVarLengthArray>
|
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
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
TimelineRenderer::TimelineRenderer(QQuickPaintedItem *parent) :
|
|
|
|
|
QQuickPaintedItem(parent), m_startTime(0), m_endTime(0), m_spacing(0),
|
2013-08-08 13:28:08 +02:00
|
|
|
m_lastStartTime(0), m_lastEndTime(0)
|
|
|
|
|
, m_profilerModelProxy(0)
|
2011-03-11 12:22:57 +01:00
|
|
|
{
|
2011-10-26 11:32:01 +02:00
|
|
|
clearData();
|
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
|
setAcceptHoverEvents(true);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimelineRenderer::setProfilerModelProxy(QObject *profilerModelProxy)
|
|
|
|
|
{
|
|
|
|
|
if (m_profilerModelProxy) {
|
|
|
|
|
disconnect(m_profilerModelProxy, SIGNAL(expandedChanged()), this, SLOT(requestPaint()));
|
|
|
|
|
}
|
|
|
|
|
m_profilerModelProxy = qobject_cast<TimelineModelAggregator *>(profilerModelProxy);
|
|
|
|
|
|
|
|
|
|
if (m_profilerModelProxy) {
|
|
|
|
|
connect(m_profilerModelProxy, SIGNAL(expandedChanged()), this, SLOT(requestPaint()));
|
|
|
|
|
}
|
|
|
|
|
emit profilerModelProxyChanged(m_profilerModelProxy);
|
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);
|
|
|
|
|
}
|
2013-09-16 14:33:07 +02:00
|
|
|
QQuickItem::componentComplete();
|
2011-03-11 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
void TimelineRenderer::paint(QPainter *p)
|
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
|
|
|
p->setPen(Qt::transparent);
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
|
|
|
|
|
int lastIndex = m_profilerModelProxy->findLastIndex(modelIndex, m_endTime);
|
|
|
|
|
if (lastIndex >= 0 && lastIndex < m_profilerModelProxy->count(modelIndex)) {
|
|
|
|
|
int firstIndex = m_profilerModelProxy->findFirstIndex(modelIndex, m_startTime);
|
|
|
|
|
if (firstIndex >= 0) {
|
|
|
|
|
drawItemsToPainter(p, modelIndex, firstIndex, lastIndex);
|
|
|
|
|
if (m_selectedModel == modelIndex)
|
|
|
|
|
drawSelectionBoxes(p, modelIndex, firstIndex, lastIndex);
|
|
|
|
|
drawBindingLoopMarkers(p, modelIndex, firstIndex, lastIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-11 16:45:47 +02: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
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void TimelineRenderer::drawItemsToPainter(QPainter *p, int modelIndex, int fromIndex, int toIndex)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
p->save();
|
|
|
|
|
p->setPen(Qt::transparent);
|
|
|
|
|
int modelRowStart = 0;
|
|
|
|
|
for (int mi = 0; mi < modelIndex; mi++)
|
|
|
|
|
modelRowStart += m_profilerModelProxy->rowCount(mi);
|
2013-11-05 17:16:43 +01:00
|
|
|
QRect window = p->window();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2013-08-08 13:28:08 +02:00
|
|
|
int x, y, width, height;
|
|
|
|
|
x = (m_profilerModelProxy->getStartTime(modelIndex, i) - m_startTime) * m_spacing;
|
2011-12-14 16:44:33 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int rowNumber = m_profilerModelProxy->getEventRow(modelIndex, i);
|
|
|
|
|
y = (modelRowStart + rowNumber) * DefaultRowHeight;
|
2013-11-05 17:16:43 +01:00
|
|
|
if (y >= window.bottom())
|
|
|
|
|
continue;
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
width = m_profilerModelProxy->getDuration(modelIndex, i) * m_spacing;
|
|
|
|
|
if (width < 1)
|
2011-10-26 11:32:01 +02:00
|
|
|
width = 1;
|
2011-03-11 12:22:57 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
height = DefaultRowHeight * m_profilerModelProxy->getHeight(modelIndex, i);
|
|
|
|
|
y += DefaultRowHeight - height;
|
2013-11-05 17:16:43 +01:00
|
|
|
if (y + height < window.top())
|
|
|
|
|
continue;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// normal events
|
|
|
|
|
p->setBrush(m_profilerModelProxy->getColor(modelIndex, i));
|
|
|
|
|
p->drawRect(x, y, width, height);
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
p->restore();
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void TimelineRenderer::drawSelectionBoxes(QPainter *p, int modelIndex, 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
|
|
|
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int id = m_profilerModelProxy->getEventId(modelIndex, m_selectedItem);
|
|
|
|
|
|
|
|
|
|
int modelRowStart = 0;
|
|
|
|
|
for (int mi = 0; mi < modelIndex; mi++)
|
|
|
|
|
modelRowStart += m_profilerModelProxy->rowCount(mi);
|
|
|
|
|
|
|
|
|
|
p->save();
|
|
|
|
|
|
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);
|
2013-08-08 13:28:08 +02:00
|
|
|
p->setBrush(Qt::transparent);
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int x, y, width;
|
2011-11-23 16:17:33 +01:00
|
|
|
QRect selectedItemRect(0,0,0,0);
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2013-08-08 13:28:08 +02:00
|
|
|
if (m_profilerModelProxy->getEventId(modelIndex, i) != id)
|
2011-10-26 11:32:01 +02:00
|
|
|
continue;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
x = (m_profilerModelProxy->getStartTime(modelIndex, i) - m_startTime) * m_spacing;
|
|
|
|
|
y = (modelRowStart + m_profilerModelProxy->getEventRow(modelIndex, i)) * DefaultRowHeight;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
width = m_profilerModelProxy->getDuration(modelIndex, 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
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
p->restore();
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int modelIndex, int fromIndex, int toIndex)
|
2012-02-06 16:08:56 +01:00
|
|
|
{
|
|
|
|
|
int destindex;
|
2013-08-08 13:28:08 +02:00
|
|
|
int xfrom, xto;
|
2012-02-06 16:08:56 +01:00
|
|
|
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"));
|
2013-11-05 17:16:43 +01:00
|
|
|
QRect window = p->window();
|
2012-02-06 16:08:56 +01:00
|
|
|
|
|
|
|
|
p->save();
|
|
|
|
|
for (int i = fromIndex; i <= toIndex; i++) {
|
2013-08-08 13:28:08 +02:00
|
|
|
destindex = m_profilerModelProxy->getBindingLoopDest(modelIndex, i);
|
2012-02-06 16:08:56 +01:00
|
|
|
if (destindex >= 0) {
|
|
|
|
|
// from
|
2013-08-08 13:28:08 +02:00
|
|
|
xfrom = (m_profilerModelProxy->getStartTime(modelIndex, i) +
|
|
|
|
|
m_profilerModelProxy->getDuration(modelIndex, i)/2 -
|
2012-02-06 16:08:56 +01:00
|
|
|
m_startTime) * m_spacing;
|
2013-08-08 13:28:08 +02:00
|
|
|
yfrom = getYPosition(modelIndex, i);
|
2012-02-06 16:08:56 +01:00
|
|
|
yfrom += DefaultRowHeight / 2;
|
|
|
|
|
|
|
|
|
|
// to
|
2013-08-08 13:28:08 +02:00
|
|
|
xto = (m_profilerModelProxy->getStartTime(modelIndex, destindex) +
|
|
|
|
|
m_profilerModelProxy->getDuration(modelIndex, destindex)/2 -
|
2012-02-06 16:08:56 +01:00
|
|
|
m_startTime) * m_spacing;
|
2013-08-08 13:28:08 +02:00
|
|
|
yto = getYPosition(modelIndex, destindex);
|
2012-02-06 16:08:56 +01:00
|
|
|
yto += DefaultRowHeight / 2;
|
|
|
|
|
|
|
|
|
|
// radius
|
2013-08-08 13:28:08 +02:00
|
|
|
int eventWidth = m_profilerModelProxy->getDuration(modelIndex, 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;
|
|
|
|
|
|
|
|
|
|
int shadowoffset = 2;
|
2013-11-05 17:16:43 +01:00
|
|
|
if ((yfrom + radius + shadowoffset < window.top() && yto + radius + shadowoffset < window.top()) ||
|
|
|
|
|
(yfrom - radius >= window.bottom() && yto - radius >= window.bottom()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// shadow
|
2012-02-06 16:08:56 +01:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int TimelineRenderer::modelFromPosition(int y)
|
|
|
|
|
{
|
|
|
|
|
y = y / DefaultRowHeight;
|
|
|
|
|
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
|
|
|
|
|
y -= m_profilerModelProxy->rowCount(modelIndex);
|
|
|
|
|
if (y < 0)
|
|
|
|
|
return modelIndex;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
void TimelineRenderer::mousePressEvent(QMouseEvent *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
|
|
|
}
|
|
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
void TimelineRenderer::mouseReleaseEvent(QMouseEvent *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
|
|
|
}
|
|
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
void TimelineRenderer::mouseMoveEvent(QMouseEvent *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
|
|
|
|
2013-09-16 14:33:07 +02:00
|
|
|
void TimelineRenderer::hoverMoveEvent(QHoverEvent *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) {
|
2013-08-08 13:28:08 +02:00
|
|
|
if (m_currentSelection.eventIndex == m_selectedItem && m_currentSelection.modelIndex == m_selectedModel)
|
2011-10-26 11:32:01 +02:00
|
|
|
setSelectionLocked(!m_selectionLocked);
|
|
|
|
|
else
|
|
|
|
|
setSelectionLocked(true);
|
2013-08-08 13:28:08 +02:00
|
|
|
emit itemPressed(m_currentSelection.modelIndex, m_currentSelection.eventIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
} else {
|
2013-08-08 13:28:08 +02:00
|
|
|
setSelectionLocked(false);
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
setSelectedModel(m_currentSelection.modelIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
setSelectedItem(m_currentSelection.eventIndex);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
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::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;
|
2013-08-08 13:28:08 +02:00
|
|
|
int modelIndex = modelFromPosition(y);
|
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
|
2013-08-08 13:28:08 +02:00
|
|
|
int eventFrom = m_profilerModelProxy->findFirstIndex(modelIndex, time);
|
|
|
|
|
int eventTo = m_profilerModelProxy->findLastIndex(modelIndex, time);
|
|
|
|
|
if (eventFrom == -1 ||
|
|
|
|
|
eventTo < eventFrom || eventTo >= m_profilerModelProxy->count()) {
|
2011-10-26 11:32:01 +02:00
|
|
|
m_currentSelection.eventIndex = -1;
|
2011-07-26 13:56:14 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int modelRowStart = 0;
|
|
|
|
|
for (int mi = 0; mi < modelIndex; mi++)
|
|
|
|
|
modelRowStart += m_profilerModelProxy->rowCount(mi);
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
// find if we are in the right column
|
2013-08-08 13:28:08 +02:00
|
|
|
int itemRow;
|
2011-10-26 11:32:01 +02:00
|
|
|
for (int i=eventTo; i>=eventFrom; --i) {
|
2013-08-08 13:28:08 +02:00
|
|
|
if (ceil(m_profilerModelProxy->getEndTime(modelIndex, i)*m_spacing) < floor(time*m_spacing))
|
2011-10-26 11:32:01 +02:00
|
|
|
continue;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
itemRow = modelRowStart + m_profilerModelProxy->getEventRow(modelIndex, i);
|
|
|
|
|
|
2011-10-26 11:32:01 +02:00
|
|
|
if (itemRow == row) {
|
|
|
|
|
// match
|
|
|
|
|
m_currentSelection.eventIndex = i;
|
2013-08-08 13:28:08 +02:00
|
|
|
m_currentSelection.startTime = m_profilerModelProxy->getStartTime(modelIndex, i);
|
|
|
|
|
m_currentSelection.endTime = m_profilerModelProxy->getEndTime(modelIndex, i);
|
2011-10-26 11:32:01 +02:00
|
|
|
m_currentSelection.row = row;
|
2013-08-08 13:28:08 +02:00
|
|
|
m_currentSelection.modelIndex = modelIndex;
|
|
|
|
|
if (!m_selectionLocked) {
|
|
|
|
|
setSelectedModel(modelIndex);
|
2011-10-26 11:32:01 +02:00
|
|
|
setSelectedItem(i);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
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
|
|
|
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;
|
2013-08-08 13:28:08 +02:00
|
|
|
m_currentSelection.modelIndex = -1;
|
2011-10-26 11:32:01 +02:00
|
|
|
m_selectedItem = -1;
|
2013-08-08 13:28:08 +02:00
|
|
|
m_selectedModel = -1;
|
2011-10-26 11:32:01 +02:00
|
|
|
m_selectionLocked = true;
|
2011-07-26 13:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int TimelineRenderer::getYPosition(int modelIndex, int index) const
|
2011-07-26 13:56:14 +02:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
Q_ASSERT(m_profilerModelProxy);
|
|
|
|
|
if (index >= m_profilerModelProxy->count())
|
|
|
|
|
return 0;
|
2011-07-26 13:56:14 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int modelRowStart = 0;
|
|
|
|
|
for (int mi = 0; mi < modelIndex; mi++)
|
|
|
|
|
modelRowStart += m_profilerModelProxy->rowCount(mi);
|
2011-10-26 11:32:01 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int y = DefaultRowHeight * (modelRowStart + m_profilerModelProxy->getEventRow(modelIndex, index));
|
2012-02-03 16:33:51 +01:00
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::selectNext()
|
2011-11-23 16:17:33 +01:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
if (m_profilerModelProxy->count() == 0)
|
2011-11-23 16:17:33 +01:00
|
|
|
return;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
qint64 searchTime = m_startTime;
|
|
|
|
|
if (m_selectedItem != -1)
|
|
|
|
|
searchTime = m_profilerModelProxy->getStartTime(m_selectedModel, m_selectedItem);
|
|
|
|
|
|
|
|
|
|
QVarLengthArray<int> itemIndexes(m_profilerModelProxy->modelCount());
|
|
|
|
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
|
|
|
|
|
if (m_profilerModelProxy->count(i) > 0) {
|
|
|
|
|
if (m_selectedModel == i) {
|
|
|
|
|
itemIndexes[i] = (m_selectedItem + 1) % m_profilerModelProxy->count(i);
|
|
|
|
|
} else {
|
|
|
|
|
if (m_profilerModelProxy->getStartTime(i, 0) > searchTime)
|
|
|
|
|
itemIndexes[i] = 0;
|
|
|
|
|
else
|
|
|
|
|
itemIndexes[i] = (m_profilerModelProxy->findLastIndex(i, searchTime) + 1) % m_profilerModelProxy->count(i);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
itemIndexes[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int candidateModelIndex = -1;
|
|
|
|
|
qint64 candidateStartTime = m_profilerModelProxy->traceEndTime();
|
|
|
|
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
|
|
|
|
|
if (itemIndexes[i] == -1)
|
|
|
|
|
continue;
|
|
|
|
|
qint64 newStartTime = m_profilerModelProxy->getStartTime(i, itemIndexes[i]);
|
|
|
|
|
if (newStartTime > searchTime && newStartTime < candidateStartTime) {
|
|
|
|
|
candidateStartTime = newStartTime;
|
|
|
|
|
candidateModelIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int itemIndex;
|
|
|
|
|
if (candidateModelIndex != -1) {
|
|
|
|
|
itemIndex = itemIndexes[candidateModelIndex];
|
|
|
|
|
} else {
|
|
|
|
|
// find the first index of them all (todo: the modelproxy should do this)
|
|
|
|
|
itemIndex = -1;
|
|
|
|
|
candidateStartTime = m_profilerModelProxy->traceEndTime();
|
|
|
|
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++)
|
|
|
|
|
if (m_profilerModelProxy->count(i) > 0 &&
|
|
|
|
|
m_profilerModelProxy->getStartTime(i,0) < candidateStartTime) {
|
|
|
|
|
candidateModelIndex = i;
|
|
|
|
|
itemIndex = 0;
|
|
|
|
|
candidateStartTime = m_profilerModelProxy->getStartTime(i,0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSelectedModel(candidateModelIndex);
|
|
|
|
|
setSelectedItem(itemIndex);
|
2011-11-23 16:17:33 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 10:47:17 +01:00
|
|
|
void TimelineRenderer::selectPrev()
|
2011-11-23 16:17:33 +01:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
if (m_profilerModelProxy->count() == 0)
|
2011-11-23 16:17:33 +01:00
|
|
|
return;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
qint64 searchTime = m_endTime;
|
|
|
|
|
if (m_selectedItem != -1)
|
|
|
|
|
searchTime = m_profilerModelProxy->getEndTime(m_selectedModel, m_selectedItem);
|
|
|
|
|
|
|
|
|
|
QVarLengthArray<int> itemIndexes(m_profilerModelProxy->modelCount());
|
|
|
|
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
|
|
|
|
|
if (m_selectedModel == i) {
|
|
|
|
|
itemIndexes[i] = m_selectedItem - 1;
|
|
|
|
|
if (itemIndexes[i] < 0)
|
|
|
|
|
itemIndexes[i] = m_profilerModelProxy->count(m_selectedModel) -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
itemIndexes[i] = m_profilerModelProxy->findLastIndex(i, searchTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int candidateModelIndex = -1;
|
|
|
|
|
qint64 candidateStartTime = m_profilerModelProxy->traceStartTime();
|
|
|
|
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
|
|
|
|
|
if (itemIndexes[i] == -1
|
|
|
|
|
|| itemIndexes[i] >= m_profilerModelProxy->count(i))
|
|
|
|
|
continue;
|
|
|
|
|
qint64 newStartTime = m_profilerModelProxy->getStartTime(i, itemIndexes[i]);
|
|
|
|
|
if (newStartTime < searchTime && newStartTime > candidateStartTime) {
|
|
|
|
|
candidateStartTime = newStartTime;
|
|
|
|
|
candidateModelIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int itemIndex = -1;
|
|
|
|
|
if (candidateModelIndex != -1) {
|
|
|
|
|
itemIndex = itemIndexes[candidateModelIndex];
|
|
|
|
|
} else {
|
|
|
|
|
// find the last index of them all (todo: the modelproxy should do this)
|
|
|
|
|
candidateModelIndex = 0;
|
|
|
|
|
candidateStartTime = m_profilerModelProxy->traceStartTime();
|
|
|
|
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++)
|
|
|
|
|
if (m_profilerModelProxy->count(i) > 0 &&
|
|
|
|
|
m_profilerModelProxy->getStartTime(i,m_profilerModelProxy->count(i)-1) > candidateStartTime) {
|
|
|
|
|
candidateModelIndex = i;
|
|
|
|
|
itemIndex = m_profilerModelProxy->count(candidateModelIndex) - 1;
|
|
|
|
|
candidateStartTime = m_profilerModelProxy->getStartTime(i,m_profilerModelProxy->count(i)-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSelectedModel(candidateModelIndex);
|
|
|
|
|
setSelectedItem(itemIndex);
|
2011-11-23 16:17:33 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int TimelineRenderer::nextItemFromId(int modelIndex, int eventId) const
|
2011-11-09 12:57:41 +01:00
|
|
|
{
|
|
|
|
|
int ndx = -1;
|
|
|
|
|
if (m_selectedItem == -1)
|
2013-08-08 13:28:08 +02:00
|
|
|
ndx = m_profilerModelProxy->findFirstIndexNoParents(modelIndex, m_startTime);
|
2011-11-09 12:57:41 +01:00
|
|
|
else
|
|
|
|
|
ndx = m_selectedItem + 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
if (ndx < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
if (ndx >= m_profilerModelProxy->count(modelIndex))
|
2011-11-09 12:57:41 +01:00
|
|
|
ndx = 0;
|
|
|
|
|
int startIndex = ndx;
|
|
|
|
|
do {
|
2013-08-08 13:28:08 +02:00
|
|
|
if (m_profilerModelProxy->getEventId(modelIndex, ndx) == eventId)
|
2011-11-09 12:57:41 +01:00
|
|
|
return ndx;
|
2013-08-08 13:28:08 +02:00
|
|
|
ndx = (ndx + 1) % m_profilerModelProxy->count(modelIndex);
|
2011-11-09 12:57:41 +01:00
|
|
|
} while (ndx != startIndex);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int TimelineRenderer::prevItemFromId(int modelIndex, 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)
|
2013-08-08 13:28:08 +02:00
|
|
|
ndx = m_profilerModelProxy->findFirstIndexNoParents(modelIndex, m_startTime);
|
2011-11-23 16:17:33 +01:00
|
|
|
else
|
|
|
|
|
ndx = m_selectedItem - 1;
|
|
|
|
|
if (ndx < 0)
|
2013-08-08 13:28:08 +02:00
|
|
|
ndx = m_profilerModelProxy->count(modelIndex) - 1;
|
2011-11-23 16:17:33 +01:00
|
|
|
int startIndex = ndx;
|
|
|
|
|
do {
|
2013-08-08 13:28:08 +02:00
|
|
|
if (m_profilerModelProxy->getEventId(modelIndex, ndx) == eventId)
|
2011-11-23 16:17:33 +01:00
|
|
|
return ndx;
|
|
|
|
|
if (--ndx < 0)
|
2013-08-08 13:28:08 +02:00
|
|
|
ndx = m_profilerModelProxy->count(modelIndex)-1;
|
2011-11-23 16:17:33 +01:00
|
|
|
} while (ndx != startIndex);
|
|
|
|
|
return -1;
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void TimelineRenderer::selectNextFromId(int modelIndex, int eventId)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
int eventIndex = nextItemFromId(modelIndex, eventId);
|
|
|
|
|
if (eventIndex != -1) {
|
|
|
|
|
setSelectedModel(modelIndex);
|
2011-11-23 16:17:33 +01:00
|
|
|
setSelectedItem(eventIndex);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void TimelineRenderer::selectPrevFromId(int modelIndex, int eventId)
|
2011-10-26 11:32:01 +02:00
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
int eventIndex = prevItemFromId(modelIndex, eventId);
|
|
|
|
|
if (eventIndex != -1) {
|
|
|
|
|
setSelectedModel(modelIndex);
|
2011-11-23 16:17:33 +01:00
|
|
|
setSelectedItem(eventIndex);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2011-10-26 11:32:01 +02:00
|
|
|
}
|