QmlProfiler: Introduce properties for timeline category heights

Like this we can easily refer to them from QML and it makes it simpler
to see if we mean the overall height or the height of a single category.

Change-Id: Ia2b79d99b5c46c3d9563cfc2ed0715bc352ce9b4
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-09-02 12:45:18 +02:00
parent 2919dc617f
commit b2487e1683
7 changed files with 33 additions and 13 deletions

View File

@@ -38,6 +38,10 @@ AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd,
SortedTimelineModel(parent), d_ptr(dd) SortedTimelineModel(parent), d_ptr(dd)
{ {
Q_D(AbstractTimelineModel); Q_D(AbstractTimelineModel);
connect(this,SIGNAL(rowHeightChanged()),this,SIGNAL(heightChanged()));
connect(this,SIGNAL(expandedChanged()),this,SIGNAL(heightChanged()));
connect(this,SIGNAL(hiddenChanged()),this,SIGNAL(heightChanged()));
d->q_ptr = this; d->q_ptr = this;
d->modelId = 0; d->modelId = 0;
d->modelManager = 0; d->modelManager = 0;

View File

@@ -46,6 +46,7 @@ class QMLPROFILER_EXPORT AbstractTimelineModel : public SortedTimelineModel
Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(QString displayName READ displayName CONSTANT)
Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged) Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged) Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
Q_PROPERTY(int height READ height NOTIFY heightChanged)
public: public:
class AbstractTimelineModelPrivate; class AbstractTimelineModelPrivate;
@@ -96,6 +97,7 @@ signals:
void hiddenChanged(); void hiddenChanged();
void rowHeightChanged(); void rowHeightChanged();
void emptyChanged(); void emptyChanged();
void heightChanged();
protected: protected:
static const int DefaultRowHeight = 30; static const int DefaultRowHeight = 30;

View File

@@ -56,7 +56,7 @@ Item {
visible: trigger(qmlProfilerModelProxy.rowCount(modelIndex)) > 0 visible: trigger(qmlProfilerModelProxy.rowCount(modelIndex)) > 0
height: trigger(qmlProfilerModelProxy.height(modelIndex)) height: trigger(qmlProfilerModelProxy.models[modelIndex].height)
width: 150 width: 150
function updateDescriptions() { function updateDescriptions() {

View File

@@ -123,7 +123,7 @@ Canvas {
// separators // separators
var cumulatedHeight = y < 0 ? -y : 0; var cumulatedHeight = y < 0 ? -y : 0;
for (var modelIndex = 0; modelIndex < qmlProfilerModelProxy.modelCount(); ++modelIndex) { for (var modelIndex = 0; modelIndex < qmlProfilerModelProxy.modelCount(); ++modelIndex) {
var modelHeight = qmlProfilerModelProxy.height(modelIndex); var modelHeight = qmlProfilerModelProxy.models[modelIndex].height;
if (cumulatedHeight + modelHeight < y) { if (cumulatedHeight + modelHeight < y) {
cumulatedHeight += modelHeight; cumulatedHeight += modelHeight;
if (qmlProfilerModelProxy.rowCount(modelIndex) % 2 !== 0) if (qmlProfilerModelProxy.rowCount(modelIndex) % 2 !== 0)

View File

@@ -54,6 +54,8 @@ public:
TimelineModelAggregator::TimelineModelAggregator(QObject *parent) TimelineModelAggregator::TimelineModelAggregator(QObject *parent)
: QObject(parent), d(new TimelineModelAggregatorPrivate(this)) : QObject(parent), d(new TimelineModelAggregatorPrivate(this))
{ {
connect(this,SIGNAL(modelsChanged(int,int)),this,SIGNAL(heightChanged()));
connect(this,SIGNAL(stateChanged()),this,SIGNAL(heightChanged()));
} }
TimelineModelAggregator::~TimelineModelAggregator() TimelineModelAggregator::~TimelineModelAggregator()
@@ -61,6 +63,14 @@ TimelineModelAggregator::~TimelineModelAggregator()
delete d; delete d;
} }
int TimelineModelAggregator::height() const
{
int ret = 0;
for (int i = 0; i < d->modelList.length(); ++i)
ret += d->modelList[i]->height();
return ret;
}
void TimelineModelAggregator::setModelManager(QmlProfilerModelManager *modelManager) void TimelineModelAggregator::setModelManager(QmlProfilerModelManager *modelManager)
{ {
d->modelManager = modelManager; d->modelManager = modelManager;
@@ -93,9 +103,15 @@ void TimelineModelAggregator::addModel(AbstractTimelineModel *m)
connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged())); connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged()));
connect(m,SIGNAL(hiddenChanged()),this,SIGNAL(hiddenChanged())); connect(m,SIGNAL(hiddenChanged()),this,SIGNAL(hiddenChanged()));
connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged())); connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged()));
connect(m,SIGNAL(heightChanged()),this,SIGNAL(heightChanged()));
emit modelsChanged(d->modelList.length(), d->modelList.length()); emit modelsChanged(d->modelList.length(), d->modelList.length());
} }
const AbstractTimelineModel *TimelineModelAggregator::model(int modelIndex) const
{
return d->modelList[modelIndex];
}
QVariantList TimelineModelAggregator::models() const QVariantList TimelineModelAggregator::models() const
{ {
QVariantList ret; QVariantList ret;
@@ -125,11 +141,6 @@ bool TimelineModelAggregator::isEmpty() const
return true; return true;
} }
int TimelineModelAggregator::height(int modelIndex) const
{
return d->modelList[modelIndex]->height();
}
int TimelineModelAggregator::rowHeight(int modelIndex, int row) const int TimelineModelAggregator::rowHeight(int modelIndex, int row) const
{ {
return d->modelList[modelIndex]->rowHeight(row); return d->modelList[modelIndex]->rowHeight(row);

View File

@@ -39,13 +39,16 @@ namespace Internal {
class TimelineModelAggregator : public QObject class TimelineModelAggregator : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int height READ height NOTIFY heightChanged)
Q_PROPERTY(QVariantList models READ models NOTIFY modelsChanged) Q_PROPERTY(QVariantList models READ models NOTIFY modelsChanged)
public: public:
TimelineModelAggregator(QObject *parent = 0); TimelineModelAggregator(QObject *parent = 0);
~TimelineModelAggregator(); ~TimelineModelAggregator();
int height() const;
void setModelManager(QmlProfilerModelManager *modelManager); void setModelManager(QmlProfilerModelManager *modelManager);
void addModel(AbstractTimelineModel *m); void addModel(AbstractTimelineModel *m);
const AbstractTimelineModel *model(int modelIndex) const;
QVariantList models() const; QVariantList models() const;
Q_INVOKABLE int count(int modelIndex = -1) const; Q_INVOKABLE int count(int modelIndex = -1) const;
@@ -58,7 +61,6 @@ public:
bool isEmpty() const; bool isEmpty() const;
Q_INVOKABLE int height(int modelIndex) const;
Q_INVOKABLE int rowHeight(int modelIndex, int row) const; Q_INVOKABLE int rowHeight(int modelIndex, int row) const;
Q_INVOKABLE void setRowHeight(int modelIndex, int row, int height); Q_INVOKABLE void setRowHeight(int modelIndex, int row, int height);
Q_INVOKABLE int rowOffset(int modelIndex, int row) const; Q_INVOKABLE int rowOffset(int modelIndex, int row) const;
@@ -105,6 +107,7 @@ signals:
void hiddenChanged(); void hiddenChanged();
void rowHeightChanged(); void rowHeightChanged();
void modelsChanged(int modelIndex1, int modelIndex2); void modelsChanged(int modelIndex1, int modelIndex2);
void heightChanged();
protected slots: protected slots:
void dataChanged(); void dataChanged();

View File

@@ -167,7 +167,7 @@ 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->height(mi); modelRowStart += m_profilerModelProxy->model(mi)->height();
for (int i = fromIndex; i <= toIndex; i++) { for (int i = fromIndex; i <= toIndex; i++) {
int currentX, currentY, itemWidth, itemHeight; int currentX, currentY, itemWidth, itemHeight;
@@ -203,7 +203,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->height(mi); modelRowStart += m_profilerModelProxy->model(mi)->height();
p->save(); p->save();
@@ -310,7 +310,7 @@ int TimelineRenderer::rowFromPosition(int y)
{ {
int ret = 0; int ret = 0;
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) { for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
int modelHeight = m_profilerModelProxy->height(modelIndex); int modelHeight = m_profilerModelProxy->model(modelIndex)->height();
if (y < modelHeight) { if (y < modelHeight) {
for (int row = 0; row < m_profilerModelProxy->rowCount(modelIndex); ++row) { for (int row = 0; row < m_profilerModelProxy->rowCount(modelIndex); ++row) {
y -= m_profilerModelProxy->rowHeight(modelIndex, row); y -= m_profilerModelProxy->rowHeight(modelIndex, row);
@@ -328,7 +328,7 @@ int TimelineRenderer::rowFromPosition(int y)
int TimelineRenderer::modelFromPosition(int y) int TimelineRenderer::modelFromPosition(int y)
{ {
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) { for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
y -= m_profilerModelProxy->height(modelIndex); y -= m_profilerModelProxy->model(modelIndex)->height();
if (y < 0) if (y < 0)
return modelIndex; return modelIndex;
} }
@@ -469,7 +469,7 @@ 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->height(mi); modelRowStart += m_profilerModelProxy->model(mi)->height();
return modelRowStart + m_profilerModelProxy->rowOffset(modelIndex, return modelRowStart + m_profilerModelProxy->rowOffset(modelIndex,
m_profilerModelProxy->row(modelIndex, index)); m_profilerModelProxy->row(modelIndex, index));