QmlProfiler: Center trace view vertically around newly selected items

It's rather unintuitive if it only centers horizontally.

Change-Id: I9245da0b26fccc14a100804715d09aaa82059413
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-09-29 16:49:31 +02:00
parent 95a13d57c8
commit 0f3f3df36c
3 changed files with 17 additions and 4 deletions

View File

@@ -141,6 +141,13 @@ Rectangle {
recenter((qmlProfilerModelProxy.startTime(modelIndex, itemIndex) +
qmlProfilerModelProxy.endTime(modelIndex, itemIndex)) / 2);
}
var row = qmlProfilerModelProxy.row(modelIndex, itemIndex);
var totalRowOffset = qmlProfilerModelProxy.modelOffset(modelIndex) +
qmlProfilerModelProxy.rowOffset(modelIndex, row);
if (totalRowOffset > flick.contentY + flick.height ||
totalRowOffset + qmlProfilerModelProxy.rowHeight(modelIndex, row) < flick.contentY)
flick.contentY = Math.min(flick.contentHeight - flick.height,
Math.max(0, totalRowOffset - flick.height / 2));
}
function hideRangeDetails() {

View File

@@ -65,10 +65,7 @@ TimelineModelAggregator::~TimelineModelAggregator()
int TimelineModelAggregator::height() const
{
int ret = 0;
for (int i = 0; i < d->modelList.length(); ++i)
ret += d->modelList[i]->height();
return ret;
return modelOffset(d->modelList.length());
}
void TimelineModelAggregator::setModelManager(QmlProfilerModelManager *modelManager)
@@ -133,6 +130,14 @@ bool TimelineModelAggregator::isEmpty() const
return true;
}
int TimelineModelAggregator::modelOffset(int modelIndex) const
{
int ret = 0;
for (int i = 0; i < modelIndex; ++i)
ret += d->modelList[i]->height();
return ret;
}
int TimelineModelAggregator::rowHeight(int modelIndex, int row) const
{
return d->modelList[modelIndex]->rowHeight(row);

View File

@@ -61,6 +61,7 @@ public:
Q_INVOKABLE bool isEmpty() const;
Q_INVOKABLE int modelOffset(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;