From b2487e1683b82eef7f3d62297af843b4b5babc8b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 2 Sep 2014 12:45:18 +0200 Subject: [PATCH] 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 --- .../qmlprofiler/abstracttimelinemodel.cpp | 4 ++++ .../qmlprofiler/abstracttimelinemodel.h | 2 ++ src/plugins/qmlprofiler/qml/CategoryLabel.qml | 2 +- src/plugins/qmlprofiler/qml/TimeMarks.qml | 2 +- .../qmlprofiler/timelinemodelaggregator.cpp | 21 ++++++++++++++----- .../qmlprofiler/timelinemodelaggregator.h | 5 ++++- src/plugins/qmlprofiler/timelinerenderer.cpp | 10 ++++----- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel.cpp b/src/plugins/qmlprofiler/abstracttimelinemodel.cpp index b2d95979a71..14a9422229a 100644 --- a/src/plugins/qmlprofiler/abstracttimelinemodel.cpp +++ b/src/plugins/qmlprofiler/abstracttimelinemodel.cpp @@ -38,6 +38,10 @@ AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd, SortedTimelineModel(parent), d_ptr(dd) { 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->modelId = 0; d->modelManager = 0; diff --git a/src/plugins/qmlprofiler/abstracttimelinemodel.h b/src/plugins/qmlprofiler/abstracttimelinemodel.h index 3bd8812520b..89ea3627625 100644 --- a/src/plugins/qmlprofiler/abstracttimelinemodel.h +++ b/src/plugins/qmlprofiler/abstracttimelinemodel.h @@ -46,6 +46,7 @@ class QMLPROFILER_EXPORT AbstractTimelineModel : public SortedTimelineModel Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged) Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged) + Q_PROPERTY(int height READ height NOTIFY heightChanged) public: class AbstractTimelineModelPrivate; @@ -96,6 +97,7 @@ signals: void hiddenChanged(); void rowHeightChanged(); void emptyChanged(); + void heightChanged(); protected: static const int DefaultRowHeight = 30; diff --git a/src/plugins/qmlprofiler/qml/CategoryLabel.qml b/src/plugins/qmlprofiler/qml/CategoryLabel.qml index 317e6653547..c7dd854ee5f 100644 --- a/src/plugins/qmlprofiler/qml/CategoryLabel.qml +++ b/src/plugins/qmlprofiler/qml/CategoryLabel.qml @@ -56,7 +56,7 @@ Item { visible: trigger(qmlProfilerModelProxy.rowCount(modelIndex)) > 0 - height: trigger(qmlProfilerModelProxy.height(modelIndex)) + height: trigger(qmlProfilerModelProxy.models[modelIndex].height) width: 150 function updateDescriptions() { diff --git a/src/plugins/qmlprofiler/qml/TimeMarks.qml b/src/plugins/qmlprofiler/qml/TimeMarks.qml index 5ebab18697f..a884e207fa9 100644 --- a/src/plugins/qmlprofiler/qml/TimeMarks.qml +++ b/src/plugins/qmlprofiler/qml/TimeMarks.qml @@ -123,7 +123,7 @@ Canvas { // separators var cumulatedHeight = y < 0 ? -y : 0; for (var modelIndex = 0; modelIndex < qmlProfilerModelProxy.modelCount(); ++modelIndex) { - var modelHeight = qmlProfilerModelProxy.height(modelIndex); + var modelHeight = qmlProfilerModelProxy.models[modelIndex].height; if (cumulatedHeight + modelHeight < y) { cumulatedHeight += modelHeight; if (qmlProfilerModelProxy.rowCount(modelIndex) % 2 !== 0) diff --git a/src/plugins/qmlprofiler/timelinemodelaggregator.cpp b/src/plugins/qmlprofiler/timelinemodelaggregator.cpp index 30c28736a15..7184558e373 100644 --- a/src/plugins/qmlprofiler/timelinemodelaggregator.cpp +++ b/src/plugins/qmlprofiler/timelinemodelaggregator.cpp @@ -54,6 +54,8 @@ public: TimelineModelAggregator::TimelineModelAggregator(QObject *parent) : QObject(parent), d(new TimelineModelAggregatorPrivate(this)) { + connect(this,SIGNAL(modelsChanged(int,int)),this,SIGNAL(heightChanged())); + connect(this,SIGNAL(stateChanged()),this,SIGNAL(heightChanged())); } TimelineModelAggregator::~TimelineModelAggregator() @@ -61,6 +63,14 @@ TimelineModelAggregator::~TimelineModelAggregator() 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) { d->modelManager = modelManager; @@ -93,9 +103,15 @@ void TimelineModelAggregator::addModel(AbstractTimelineModel *m) connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged())); connect(m,SIGNAL(hiddenChanged()),this,SIGNAL(hiddenChanged())); connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged())); + connect(m,SIGNAL(heightChanged()),this,SIGNAL(heightChanged())); emit modelsChanged(d->modelList.length(), d->modelList.length()); } +const AbstractTimelineModel *TimelineModelAggregator::model(int modelIndex) const +{ + return d->modelList[modelIndex]; +} + QVariantList TimelineModelAggregator::models() const { QVariantList ret; @@ -125,11 +141,6 @@ bool TimelineModelAggregator::isEmpty() const return true; } -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); diff --git a/src/plugins/qmlprofiler/timelinemodelaggregator.h b/src/plugins/qmlprofiler/timelinemodelaggregator.h index 2367170102d..8c99e021175 100644 --- a/src/plugins/qmlprofiler/timelinemodelaggregator.h +++ b/src/plugins/qmlprofiler/timelinemodelaggregator.h @@ -39,13 +39,16 @@ namespace Internal { class TimelineModelAggregator : public QObject { Q_OBJECT + Q_PROPERTY(int height READ height NOTIFY heightChanged) Q_PROPERTY(QVariantList models READ models NOTIFY modelsChanged) public: TimelineModelAggregator(QObject *parent = 0); ~TimelineModelAggregator(); + int height() const; void setModelManager(QmlProfilerModelManager *modelManager); void addModel(AbstractTimelineModel *m); + const AbstractTimelineModel *model(int modelIndex) const; QVariantList models() const; Q_INVOKABLE int count(int modelIndex = -1) const; @@ -58,7 +61,6 @@ public: bool isEmpty() 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; @@ -105,6 +107,7 @@ signals: void hiddenChanged(); void rowHeightChanged(); void modelsChanged(int modelIndex1, int modelIndex2); + void heightChanged(); protected slots: void dataChanged(); diff --git a/src/plugins/qmlprofiler/timelinerenderer.cpp b/src/plugins/qmlprofiler/timelinerenderer.cpp index b692747df7a..497228b76d0 100644 --- a/src/plugins/qmlprofiler/timelinerenderer.cpp +++ b/src/plugins/qmlprofiler/timelinerenderer.cpp @@ -167,7 +167,7 @@ void TimelineRenderer::drawItemsToPainter(QPainter *p, int modelIndex, int fromI p->setPen(Qt::transparent); int modelRowStart = 0; 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++) { int currentX, currentY, itemWidth, itemHeight; @@ -203,7 +203,7 @@ void TimelineRenderer::drawSelectionBoxes(QPainter *p, int modelIndex, int fromI int modelRowStart = 0; for (int mi = 0; mi < modelIndex; mi++) - modelRowStart += m_profilerModelProxy->height(mi); + modelRowStart += m_profilerModelProxy->model(mi)->height(); p->save(); @@ -310,7 +310,7 @@ int TimelineRenderer::rowFromPosition(int y) { int ret = 0; 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) { for (int row = 0; row < m_profilerModelProxy->rowCount(modelIndex); ++row) { y -= m_profilerModelProxy->rowHeight(modelIndex, row); @@ -328,7 +328,7 @@ int TimelineRenderer::rowFromPosition(int y) int TimelineRenderer::modelFromPosition(int y) { for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) { - y -= m_profilerModelProxy->height(modelIndex); + y -= m_profilerModelProxy->model(modelIndex)->height(); if (y < 0) return modelIndex; } @@ -469,7 +469,7 @@ int TimelineRenderer::getYPosition(int modelIndex, int index) const int modelRowStart = 0; for (int mi = 0; mi < modelIndex; mi++) - modelRowStart += m_profilerModelProxy->height(mi); + modelRowStart += m_profilerModelProxy->model(mi)->height(); return modelRowStart + m_profilerModelProxy->rowOffset(modelIndex, m_profilerModelProxy->row(modelIndex, index));