QmlProfiler: Put height of rows in the timeline into the model

Like that we can provide functionality to interactively resize rows in
the model so that one can zoom in to more interesting parts.

Change-Id: I31f14cd8aa37703240ebec744ca2e77188fb0f27
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-06-18 11:20:41 +02:00
parent d1cd1a490c
commit 63ca524069
10 changed files with 180 additions and 65 deletions

View File

@@ -32,6 +32,7 @@
namespace QmlProfiler { namespace QmlProfiler {
static const int DefaultRowHeight = 30;
AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd, AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd,
const QString &name, const QString &label, QmlDebug::Message message, const QString &name, const QString &label, QmlDebug::Message message,
@@ -122,6 +123,63 @@ bool AbstractTimelineModel::isEmpty() const
return count() == 0; return count() == 0;
} }
int AbstractTimelineModel::rowHeight(int rowNumber) const
{
Q_D(const AbstractTimelineModel);
if (!expanded())
return DefaultRowHeight;
if (d->rowOffsets.length() > rowNumber)
return d->rowOffsets[rowNumber] - (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
return DefaultRowHeight;
}
int AbstractTimelineModel::rowOffset(int rowNumber) const
{
Q_D(const AbstractTimelineModel);
if (rowNumber == 0)
return 0;
if (!expanded())
return DefaultRowHeight * rowNumber;
if (d->rowOffsets.length() >= rowNumber)
return d->rowOffsets[rowNumber - 1];
if (!d->rowOffsets.empty())
return d->rowOffsets.last() + (rowNumber - 1 - d->rowOffsets.length()) * DefaultRowHeight;
return rowNumber * DefaultRowHeight;
}
void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
{
Q_D(AbstractTimelineModel);
if (!expanded())
return;
if (height < DefaultRowHeight)
height = DefaultRowHeight;
int nextOffset = d->rowOffsets.empty() ? 0 : d->rowOffsets.last();
while (d->rowOffsets.length() <= rowNumber)
d->rowOffsets << (nextOffset += DefaultRowHeight);
int difference = height - d->rowOffsets[rowNumber] +
(rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
if (difference != 0) {
for (; rowNumber < d->rowOffsets.length(); ++rowNumber) {
d->rowOffsets[rowNumber] += difference;
}
emit rowHeightChanged();
}
}
int AbstractTimelineModel::height() const
{
Q_D(const AbstractTimelineModel);
int depth = rowCount();
if (!expanded() || d->rowOffsets.empty())
return depth * DefaultRowHeight;
return d->rowOffsets.last() + (depth - d->rowOffsets.length()) * DefaultRowHeight;
}
qint64 AbstractTimelineModel::traceStartTime() const qint64 AbstractTimelineModel::traceStartTime() const
{ {
Q_D(const AbstractTimelineModel); Q_D(const AbstractTimelineModel);
@@ -192,6 +250,8 @@ void AbstractTimelineModel::dataChanged()
default: default:
break; break;
} }
d->rowOffsets.clear();
} }
bool AbstractTimelineModel::eventAccepted(const QmlProfilerDataModel::QmlEventTypeData &event) const bool AbstractTimelineModel::eventAccepted(const QmlProfilerDataModel::QmlEventTypeData &event) const

View File

@@ -54,6 +54,11 @@ public:
bool isEmpty() const; bool isEmpty() const;
// Methods are directly passed on to the private model and relying on its virtual methods. // Methods are directly passed on to the private model and relying on its virtual methods.
int rowHeight(int rowNumber) const;
int rowOffset(int rowNumber) const;
void setRowHeight(int rowNumber, int height);
int height() const;
Q_INVOKABLE qint64 lastTimeMark() const; Q_INVOKABLE qint64 lastTimeMark() const;
Q_INVOKABLE qint64 traceStartTime() const; Q_INVOKABLE qint64 traceStartTime() const;
Q_INVOKABLE qint64 traceEndTime() const; Q_INVOKABLE qint64 traceEndTime() const;
@@ -91,6 +96,7 @@ public:
signals: signals:
void expandedChanged(); void expandedChanged();
void rowHeightChanged();
protected: protected:
enum BoxColorProperties { enum BoxColorProperties {

View File

@@ -47,6 +47,7 @@ public:
virtual int findFirstIndexNoParents(qint64 startTime) const = 0; virtual int findFirstIndexNoParents(qint64 startTime) const = 0;
virtual int findLastIndex(qint64 endTime) const = 0; virtual int findLastIndex(qint64 endTime) const = 0;
QVector<int> rowOffsets;
QString name; QString name;
QmlProfilerModelManager *modelManager; QmlProfilerModelManager *modelManager;
int modelId; int modelId;

View File

@@ -32,30 +32,25 @@ import QtQuick 2.1
Item { Item {
id: labelContainer id: labelContainer
property string text: qmlProfilerModelProxy.title(modelIndex) property string text: qmlProfilerModelProxy.title(modelIndex)
property bool expanded: false property bool expanded: trigger(qmlProfilerModelProxy.expanded(modelIndex))
property int modelIndex: index; property int modelIndex: index
property int bindingTrigger: 1
property var descriptions: [] property var descriptions: []
property var extdescriptions: [] property var extdescriptions: []
property var eventIds: [] property var eventIds: []
visible: qmlProfilerModelProxy.rowCount(modelIndex) > 0; function trigger(i) {
return i * bindingTrigger * bindingTrigger;
}
height: root.singleRowHeight visible: trigger(qmlProfilerModelProxy.rowCount(modelIndex)) > 0
height: trigger(qmlProfilerModelProxy.height(modelIndex))
width: 150 width: 150
Component.onCompleted: {
updateHeight();
}
function updateHeight() {
height = root.singleRowHeight * qmlProfilerModelProxy.rowCount(modelIndex);
}
function getDescriptions() { function getDescriptions() {
expanded = qmlProfilerModelProxy.expanded(modelIndex); bindingTrigger = -bindingTrigger;
backgroundMarks.requestPaint(); backgroundMarks.requestPaint();
visible = qmlProfilerModelProxy.rowCount(modelIndex) > 0;
if (!visible) if (!visible)
return; return;
@@ -71,18 +66,13 @@ Item {
descriptions = desc; descriptions = desc;
eventIds = ids; eventIds = ids;
extdescriptions = extdesc; extdescriptions = extdesc;
updateHeight();
} }
Connections { Connections {
target: qmlProfilerModelProxy target: qmlProfilerModelProxy
onExpandedChanged: { onExpandedChanged: getDescriptions();
getDescriptions(); onStateChanged: getDescriptions()
} onRowHeightChanged: getDescriptions()
onStateChanged: {
getDescriptions();
}
} }
Text { Text {
@@ -91,7 +81,7 @@ Item {
font.pixelSize: 12 font.pixelSize: 12
text: labelContainer.text text: labelContainer.text
color: "#232323" color: "#232323"
height: root.singleRowHeight height: trigger(qmlProfilerModelProxy.rowHeight(modelIndex, 0))
width: 140 width: 140
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
@@ -105,20 +95,21 @@ Item {
} }
Column { Column {
y: root.singleRowHeight anchors.top: txt.bottom
visible: expanded visible: expanded
Repeater { Repeater {
model: descriptions.length model: descriptions.length
Rectangle { Rectangle {
width: labelContainer.width width: labelContainer.width
height: root.singleRowHeight height: trigger(qmlProfilerModelProxy.rowHeight(modelIndex, index + 1))
color: "#eaeaea" color: "#eaeaea"
border.width: 1 border.width: 1
border.color:"#c8c8c8" border.color:"#c8c8c8"
Text { Text {
height: root.singleRowHeight anchors.fill: parent
x: 5 anchors.leftMargin: 5
width: 140 anchors.rightMargin: 5
text: descriptions[index] text: descriptions[index]
textFormat: Text.PlainText textFormat: Text.PlainText
elide: Text.ElideRight elide: Text.ElideRight
@@ -143,7 +134,7 @@ Item {
Image { Image {
source: expanded ? "arrow_down.png" : "arrow_right.png" source: expanded ? "arrow_down.png" : "arrow_right.png"
x: parent.width - 12 x: parent.width - 12
y: Math.floor((root.singleRowHeight - height) / 2) y: 9
smooth: false smooth: false
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent

View File

@@ -36,8 +36,6 @@ Rectangle {
// ***** properties // ***** properties
property int singleRowHeight: 30
property alias selectionLocked : view.selectionLocked property alias selectionLocked : view.selectionLocked
property bool lockItemSelection : false property bool lockItemSelection : false

View File

@@ -102,21 +102,30 @@ Canvas {
function drawBackgroundBars( context, region ) { function drawBackgroundBars( context, region ) {
var colorIndex = true; var colorIndex = true;
// row background
var backgroundOffset = y < 0 ? -y : -(y % (2 * root.singleRowHeight));
for (var currentY= backgroundOffset; currentY < Math.min(height, labels.height - y); currentY += root.singleRowHeight) {
context.fillStyle = colorIndex ? "#f0f0f0" : "white";
context.strokeStyle = colorIndex ? "#f0f0f0" : "white";
context.fillRect(0, currentY, width, root.singleRowHeight);
colorIndex = !colorIndex;
}
// separators // separators
var cumulatedHeight = 0; var cumulatedHeight = y < 0 ? -y : 0;
for (var modelIndex = 0; modelIndex < qmlProfilerModelProxy.modelCount() && cumulatedHeight < y + height; modelIndex++) { for (var modelIndex = 0; modelIndex < qmlProfilerModelProxy.modelCount(); ++modelIndex) {
cumulatedHeight += root.singleRowHeight * qmlProfilerModelProxy.rowCount(modelIndex); var modelHeight = qmlProfilerModelProxy.height(modelIndex);
if (cumulatedHeight < y) if (cumulatedHeight + modelHeight < y) {
cumulatedHeight += modelHeight;
if (qmlProfilerModelProxy.rowCount(modelIndex) % 2 !== 0)
colorIndex = !colorIndex;
continue; continue;
}
for (var row = 0; row < qmlProfilerModelProxy.rowCount(modelIndex); ++row) {
// row background
var rowHeight = qmlProfilerModelProxy.rowHeight(modelIndex, row)
cumulatedHeight += rowHeight;
colorIndex = !colorIndex;
if (cumulatedHeight < y - rowHeight)
continue;
context.strokeStyle = context.fillStyle = colorIndex ? "#f0f0f0" : "white";
context.fillRect(0, cumulatedHeight - rowHeight - y, width, rowHeight);
if (cumulatedHeight > y + height)
return;
}
context.strokeStyle = "#B0B0B0"; context.strokeStyle = "#B0B0B0";
context.beginPath(); context.beginPath();

View File

@@ -91,6 +91,7 @@ void TimelineModelAggregator::addModel(AbstractTimelineModel *m)
{ {
d->modelList << m; d->modelList << m;
connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged())); connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged()));
connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged()));
} }
QStringList TimelineModelAggregator::categoryTitles() const QStringList TimelineModelAggregator::categoryTitles() const
@@ -141,6 +142,26 @@ qint64 TimelineModelAggregator::lastTimeMark() const
return mark; return mark;
} }
int TimelineModelAggregator::height(int modelIndex) const
{
return d->modelList[modelIndex]->height();
}
int TimelineModelAggregator::rowHeight(int modelIndex, int row) const
{
return d->modelList[modelIndex]->rowHeight(row);
}
int TimelineModelAggregator::rowOffset(int modelIndex, int row) const
{
return d->modelList[modelIndex]->rowOffset(row);
}
void TimelineModelAggregator::setRowHeight(int modelIndex, int row, int height)
{
d->modelList[modelIndex]->setRowHeight(row, height);
}
bool TimelineModelAggregator::expanded(int modelIndex) const bool TimelineModelAggregator::expanded(int modelIndex) const
{ {
return d->modelList[modelIndex]->expanded(); return d->modelList[modelIndex]->expanded();

View File

@@ -62,6 +62,10 @@ public:
Q_INVOKABLE qint64 lastTimeMark() const; Q_INVOKABLE qint64 lastTimeMark() const;
Q_INVOKABLE int height(int modelIndex) const;
Q_INVOKABLE int rowHeight(int modelIndex, int row) const;
Q_INVOKABLE void setRowHeight(int modelIndex, int row, int height);
Q_INVOKABLE int rowOffset(int modelIndex, int row) const;
Q_INVOKABLE bool expanded(int modelIndex) const; Q_INVOKABLE bool expanded(int modelIndex) const;
Q_INVOKABLE void setExpanded(int modelIndex, bool expanded); Q_INVOKABLE void setExpanded(int modelIndex, bool expanded);
Q_INVOKABLE int rowCount(int modelIndex) const; Q_INVOKABLE int rowCount(int modelIndex) const;
@@ -93,6 +97,7 @@ signals:
void dataAvailable(); void dataAvailable();
void stateChanged(); void stateChanged();
void expandedChanged(); void expandedChanged();
void rowHeightChanged();
protected slots: protected slots:
void dataChanged(); void dataChanged();

View File

@@ -41,8 +41,6 @@
using namespace QmlProfiler::Internal; using namespace QmlProfiler::Internal;
const int DefaultRowHeight = 30;
TimelineRenderer::TimelineRenderer(QQuickPaintedItem *parent) : TimelineRenderer::TimelineRenderer(QQuickPaintedItem *parent) :
QQuickPaintedItem(parent), m_startTime(0), m_endTime(0), m_spacing(0), m_spacedDuration(0), QQuickPaintedItem(parent), m_startTime(0), m_endTime(0), m_spacing(0), m_spacedDuration(0),
m_lastStartTime(0), m_lastEndTime(0) m_lastStartTime(0), m_lastEndTime(0)
@@ -130,18 +128,20 @@ void TimelineRenderer::drawItemsToPainter(QPainter *p, int modelIndex, int fromI
p->setPen(Qt::transparent); p->setPen(Qt::transparent);
int modelRowStart = 0; int modelRowStart = 0;
for (int mi = 0; mi < modelIndex; mi++) for (int mi = 0; mi < modelIndex; mi++)
modelRowStart += m_profilerModelProxy->rowCount(mi); modelRowStart += m_profilerModelProxy->height(mi);
for (int i = fromIndex; i <= toIndex; i++) { for (int i = fromIndex; i <= toIndex; i++) {
int currentX, currentY, itemWidth, itemHeight; int currentX, currentY, itemWidth, itemHeight;
int rowNumber = m_profilerModelProxy->getEventRow(modelIndex, i); int rowNumber = m_profilerModelProxy->getEventRow(modelIndex, i);
currentY = (modelRowStart + rowNumber) * DefaultRowHeight - y(); currentY = modelRowStart + m_profilerModelProxy->rowOffset(modelIndex, rowNumber) - y();
if (currentY >= height()) if (currentY >= height())
continue; continue;
itemHeight = DefaultRowHeight * m_profilerModelProxy->getHeight(modelIndex, i); itemHeight = m_profilerModelProxy->rowHeight(modelIndex, rowNumber) *
currentY += DefaultRowHeight - itemHeight; m_profilerModelProxy->getHeight(modelIndex, i);
currentY += m_profilerModelProxy->rowHeight(modelIndex, rowNumber) - itemHeight;
if (currentY + itemHeight < 0) if (currentY + itemHeight < 0)
continue; continue;
@@ -164,7 +164,7 @@ void TimelineRenderer::drawSelectionBoxes(QPainter *p, int modelIndex, int fromI
int modelRowStart = 0; int modelRowStart = 0;
for (int mi = 0; mi < modelIndex; mi++) for (int mi = 0; mi < modelIndex; mi++)
modelRowStart += m_profilerModelProxy->rowCount(mi); modelRowStart += m_profilerModelProxy->height(mi);
p->save(); p->save();
@@ -183,16 +183,19 @@ void TimelineRenderer::drawSelectionBoxes(QPainter *p, int modelIndex, int fromI
if (m_profilerModelProxy->getEventId(modelIndex, i) != id) if (m_profilerModelProxy->getEventId(modelIndex, i) != id)
continue; continue;
currentY = (modelRowStart + m_profilerModelProxy->getEventRow(modelIndex, i)) * DefaultRowHeight - y(); int row = m_profilerModelProxy->getEventRow(modelIndex, i);
if (currentY + DefaultRowHeight < 0 || height() < currentY) int rowHeight = m_profilerModelProxy->rowHeight(modelIndex, row);
currentY = modelRowStart + m_profilerModelProxy->rowOffset(modelIndex, row) - y();
if (currentY + rowHeight < 0 || height() < currentY)
continue; continue;
getItemXExtent(modelIndex, i, currentX, itemWidth); getItemXExtent(modelIndex, i, currentX, itemWidth);
if (i == m_selectedItem) if (i == m_selectedItem)
selectedItemRect = QRect(currentX, currentY - 1, itemWidth, DefaultRowHeight + 1); selectedItemRect = QRect(currentX, currentY - 1, itemWidth, rowHeight + 1);
else else
p->drawRect(currentX, currentY, itemWidth, DefaultRowHeight); p->drawRect(currentX, currentY, itemWidth, rowHeight);
} }
// draw the selected item rectangle the last, so that it's overlayed // draw the selected item rectangle the last, so that it's overlayed
@@ -209,7 +212,7 @@ void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int modelIndex, int f
int destindex; int destindex;
int xfrom, xto, width; int xfrom, xto, width;
int yfrom, yto; int yfrom, yto;
int radius = DefaultRowHeight / 3; int radius = 10;
QPen shadowPen = QPen(QColor("grey"),2); QPen shadowPen = QPen(QColor("grey"),2);
QPen markerPen = QPen(QColor("orange"),2); QPen markerPen = QPen(QColor("orange"),2);
QBrush shadowBrush = QBrush(QColor("grey")); QBrush shadowBrush = QBrush(QColor("grey"));
@@ -222,12 +225,14 @@ void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int modelIndex, int f
// to // to
getItemXExtent(modelIndex, destindex, xto, width); getItemXExtent(modelIndex, destindex, xto, width);
xto += width / 2; xto += width / 2;
yto = getYPosition(modelIndex, destindex) + DefaultRowHeight / 2 - y(); yto = getYPosition(modelIndex, destindex) +
m_profilerModelProxy->rowHeight(modelIndex, destindex) / 2 - y();
// from // from
getItemXExtent(modelIndex, i, xfrom, width); getItemXExtent(modelIndex, i, xfrom, width);
xfrom += width / 2; xfrom += width / 2;
yfrom = getYPosition(modelIndex, i) + DefaultRowHeight / 2 - y(); yfrom = getYPosition(modelIndex, i) +
m_profilerModelProxy->rowHeight(modelIndex, i) / 2 - y();
// radius (derived from width of origin event) // radius (derived from width of origin event)
radius = 5; radius = 5;
@@ -260,11 +265,29 @@ void TimelineRenderer::drawBindingLoopMarkers(QPainter *p, int modelIndex, int f
p->restore(); p->restore();
} }
int TimelineRenderer::rowFromPosition(int y)
{
int ret = 0;
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
int modelHeight = m_profilerModelProxy->height(modelIndex);
if (y < modelHeight) {
for (int row = 0; row < m_profilerModelProxy->rowCount(modelIndex); ++row) {
y -= m_profilerModelProxy->rowHeight(modelIndex, row);
if (y < 0) return ret;
++ret;
}
} else {
y -= modelHeight;
ret += m_profilerModelProxy->rowCount(modelIndex);
}
}
return ret;
}
int TimelineRenderer::modelFromPosition(int y) int TimelineRenderer::modelFromPosition(int y)
{ {
y = y / DefaultRowHeight;
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) { for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
y -= m_profilerModelProxy->rowCount(modelIndex); y -= m_profilerModelProxy->height(modelIndex);
if (y < 0) if (y < 0)
return modelIndex; return modelIndex;
} }
@@ -328,7 +351,7 @@ void TimelineRenderer::manageHovered(int mouseX, int mouseY)
// Make the "selected" area 3 pixels wide by adding/subtracting 1 to catch very narrow events. // Make the "selected" area 3 pixels wide by adding/subtracting 1 to catch very narrow events.
qint64 startTime = (mouseX - 1) * (m_endTime - m_startTime) / width() + m_startTime; qint64 startTime = (mouseX - 1) * (m_endTime - m_startTime) / width() + m_startTime;
qint64 endTime = (mouseX + 1) * (m_endTime - m_startTime) / width() + m_startTime; qint64 endTime = (mouseX + 1) * (m_endTime - m_startTime) / width() + m_startTime;
int row = (mouseY + y()) / DefaultRowHeight; int row = rowFromPosition(mouseY + y());
int modelIndex = modelFromPosition(mouseY + y()); int modelIndex = modelFromPosition(mouseY + y());
// already covered? nothing to do // already covered? nothing to do
@@ -404,10 +427,10 @@ int TimelineRenderer::getYPosition(int modelIndex, int index) const
int modelRowStart = 0; int modelRowStart = 0;
for (int mi = 0; mi < modelIndex; mi++) for (int mi = 0; mi < modelIndex; mi++)
modelRowStart += m_profilerModelProxy->rowCount(mi); modelRowStart += m_profilerModelProxy->height(mi);
int y = DefaultRowHeight * (modelRowStart + m_profilerModelProxy->getEventRow(modelIndex, index)); return modelRowStart + m_profilerModelProxy->rowOffset(modelIndex,
return y; m_profilerModelProxy->getEventRow(modelIndex, index));
} }
void TimelineRenderer::selectNext() void TimelineRenderer::selectNext()

View File

@@ -172,6 +172,7 @@ private:
void drawSelectionBoxes(QPainter *p, int modelIndex, int fromIndex, int toIndex); void drawSelectionBoxes(QPainter *p, int modelIndex, int fromIndex, int toIndex);
void drawBindingLoopMarkers(QPainter *p, int modelIndex, int fromIndex, int toIndex); void drawBindingLoopMarkers(QPainter *p, int modelIndex, int fromIndex, int toIndex);
int modelFromPosition(int y); int modelFromPosition(int y);
int rowFromPosition(int y);
void manageClicked(); void manageClicked();
void manageHovered(int mouseX, int mouseY); void manageHovered(int mouseX, int mouseY);