Timeline: Use the same type for setting and getting a model list

We want to use QVariantList here because that is the only list type we
can pass to QML without special registration.

Change-Id: Ia57f8f0c578388da7603ddb6d62288e9cf61e381
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2016-11-23 16:47:04 +01:00
parent 2ed5d7998a
commit 824f5f443a
3 changed files with 26 additions and 15 deletions

View File

@@ -28,6 +28,8 @@
#include "timelinemodel.h"
#include "timelinenotesmodel.h"
#include <utils/algorithm.h>
#include <QStringList>
#include <QVariant>
@@ -70,10 +72,15 @@ void TimelineModelAggregator::addModel(TimelineModel *m)
emit heightChanged();
}
void TimelineModelAggregator::setModels(const QList<TimelineModel *> &models)
void TimelineModelAggregator::setModels(const QVariantList &models)
{
Q_D(TimelineModelAggregator);
if (d->modelList == models)
QList<TimelineModel *> timelineModels = Utils::transform(models, [](const QVariant &model) {
return qvariant_cast<TimelineModel *>(model);
});
if (d->modelList == timelineModels)
return;
int prevHeight = height();
@@ -83,8 +90,8 @@ void TimelineModelAggregator::setModels(const QList<TimelineModel *> &models)
d->notesModel->removeTimelineModel(m);
}
d->modelList = models;
foreach (TimelineModel *m, models) {
d->modelList = timelineModels;
foreach (TimelineModel *m, timelineModels) {
connect(m, &TimelineModel::heightChanged, this, &TimelineModelAggregator::heightChanged);
if (d->notesModel)
d->notesModel->addTimelineModel(m);

View File

@@ -34,7 +34,7 @@ class TIMELINE_EXPORT TimelineModelAggregator : public QObject
{
Q_OBJECT
Q_PROPERTY(int height READ height NOTIFY heightChanged)
Q_PROPERTY(QVariantList models READ models NOTIFY modelsChanged)
Q_PROPERTY(QVariantList models READ models WRITE setModels NOTIFY modelsChanged)
Q_PROPERTY(Timeline::TimelineNotesModel *notes READ notes CONSTANT)
public:
TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent = 0);
@@ -43,9 +43,10 @@ public:
int height() const;
void addModel(TimelineModel *m);
void setModels(const QList<TimelineModel *> &models);
const TimelineModel *model(int modelIndex) const;
QVariantList models() const;
void setModels(const QVariantList &models);
TimelineNotesModel *notes() const;
void clear();

View File

@@ -130,15 +130,18 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag
d->m_modelProxy = new Timeline::TimelineModelAggregator(modelManager->notesModel(), this);
d->m_modelManager = modelManager;
QList<Timeline::TimelineModel *> models;
models.append(new PixmapCacheModel(modelManager, d->m_modelProxy));
models.append(new SceneGraphTimelineModel(modelManager, d->m_modelProxy));
models.append(new MemoryUsageModel(modelManager, d->m_modelProxy));
models.append(new InputEventsModel(modelManager, d->m_modelProxy));
models.append(new DebugMessagesModel(modelManager, d->m_modelProxy));
models.append(new QmlProfilerAnimationsModel(modelManager, d->m_modelProxy));
for (int i = 0; i < MaximumRangeType; ++i)
models.append(new QmlProfilerRangeModel(modelManager, (RangeType)i, d->m_modelProxy));
QVariantList models;
models.append(QVariant::fromValue(new PixmapCacheModel(modelManager, d->m_modelProxy)));
models.append(QVariant::fromValue(new SceneGraphTimelineModel(modelManager, d->m_modelProxy)));
models.append(QVariant::fromValue(new MemoryUsageModel(modelManager, d->m_modelProxy)));
models.append(QVariant::fromValue(new InputEventsModel(modelManager, d->m_modelProxy)));
models.append(QVariant::fromValue(new DebugMessagesModel(modelManager, d->m_modelProxy)));
models.append(QVariant::fromValue(new QmlProfilerAnimationsModel(modelManager,
d->m_modelProxy)));
for (int i = 0; i < MaximumRangeType; ++i) {
models.append(QVariant::fromValue(new QmlProfilerRangeModel(modelManager, (RangeType)i,
d->m_modelProxy)));
}
d->m_modelProxy->setModels(models);
// Minimum height: 5 rows of 20 pixels + scrollbar of 50 pixels + 20 pixels margin