QmlProfiler: Move event handling into model manager

This is the logical place to do it. Adding the event first to the QML
model and then passing it back to the manager in order to have it
dispatched to the other models is somewhat backwards.

Change-Id: I64b1cb38f97331b62d83fa5ae49b9b2690810d40
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Ulf Hermann
2016-12-28 16:39:57 +01:00
parent 00d424eadb
commit 5dd25c42cb
14 changed files with 142 additions and 92 deletions

View File

@@ -153,6 +153,8 @@ public:
QHash<ProfileFeature, QVector<EventLoader> > eventLoaders;
QVector<Finalizer> finalizers;
void dispatch(const QmlEvent &event, const QmlEventType &type);
};
@@ -204,6 +206,11 @@ uint QmlProfilerModelManager::numLoadedEvents() const
return d->numLoadedEvents;
}
uint QmlProfilerModelManager::numLoadedEventTypes() const
{
return d->model->eventTypes().count();
}
int QmlProfilerModelManager::registerModelProxy()
{
return d->numRegisteredModels++;
@@ -219,11 +226,36 @@ int QmlProfilerModelManager::numRegisteredFinalizers() const
return d->finalizers.count();
}
void QmlProfilerModelManager::dispatch(const QmlEvent &event, const QmlEventType &type)
void QmlProfilerModelManager::addEvents(const QVector<QmlEvent> &events)
{
foreach (const EventLoader &loader, d->eventLoaders[type.feature()])
d->model->addEvents(events);
const QVector<QmlEventType> &types = d->model->eventTypes();
for (const QmlEvent &event : events)
d->dispatch(event, types[event.typeIndex()]);
}
void QmlProfilerModelManager::addEvent(const QmlEvent &event)
{
d->model->addEvent(event);
d->dispatch(event, d->model->eventType(event.typeIndex()));
}
void QmlProfilerModelManager::addEventTypes(const QVector<QmlEventType> &types)
{
d->model->addEventTypes(types);
}
void QmlProfilerModelManager::addEventType(const QmlEventType &type)
{
d->model->addEventType(type);
}
void QmlProfilerModelManager::QmlProfilerModelManagerPrivate::dispatch(const QmlEvent &event,
const QmlEventType &type)
{
foreach (const EventLoader &loader, eventLoaders[type.feature()])
loader(event, type);
++d->numLoadedEvents;
++numLoadedEvents;
}
void QmlProfilerModelManager::announceFeatures(quint64 features, EventLoader eventLoader,
@@ -373,13 +405,13 @@ void QmlProfilerModelManager::load(const QString &filename)
}, Qt::QueuedConnection);
connect(reader, &QmlProfilerFileReader::typesLoaded,
d->model, &QmlProfilerDataModel::setEventTypes);
this, &QmlProfilerModelManager::addEventTypes);
connect(reader, &QmlProfilerFileReader::notesLoaded,
d->notesModel, &QmlProfilerNotesModel::setNotes);
connect(reader, &QmlProfilerFileReader::qmlEventsLoaded,
d->model, &QmlProfilerDataModel::addEvents);
this, &QmlProfilerModelManager::addEvents);
connect(reader, &QmlProfilerFileReader::success, this, [this, reader]() {
d->traceTime->setTime(reader->traceStart(), reader->traceEnd());
@@ -464,7 +496,7 @@ void QmlProfilerModelManager::restrictToRange(qint64 startTime, qint64 endTime)
startAcquiring();
d->model->replayEvents(startTime, endTime,
std::bind(&QmlProfilerModelManager::dispatch, this,
std::bind(&QmlProfilerModelManagerPrivate::dispatch, d,
std::placeholders::_1, std::placeholders::_2));
d->notesModel->setNotes(notes);
d->traceTime->restrictToRange(startTime, endTime);