From eef83495ea53c0c65ddbf7bfca15bb43957f2939 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 12 Jun 2014 13:08:08 +0200 Subject: [PATCH] QmlProfiler: Pass model index to QML when selecting in trace view This allows more precise specification of which event is supposed to be selected. Task-number: QTCREATORBUG-11945 Change-Id: Iff2e9bb8569711cc5df72a5ca55956e0091d6163 Reviewed-by: Kai Koehne --- src/plugins/qmlprofiler/qml/MainView.qml | 7 ++--- .../qmlprofiler/qmlprofilertraceview.cpp | 30 ++++++++++++++----- .../qmlprofiler/qmlprofilertraceview.h | 1 + .../qmlprofiler/timelinemodelaggregator.cpp | 28 ++++------------- .../qmlprofiler/timelinemodelaggregator.h | 7 ++--- 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/plugins/qmlprofiler/qml/MainView.qml b/src/plugins/qmlprofiler/qml/MainView.qml index b861b2efb0e..d79deec25e3 100644 --- a/src/plugins/qmlprofiler/qml/MainView.qml +++ b/src/plugins/qmlprofiler/qml/MainView.qml @@ -158,17 +158,16 @@ Rectangle { rangeDetails.isBindingLoop = false; } - function selectById(eventId) + function selectById(modelIndex, eventId) { - if (eventId === -1 || - eventId === qmlProfilerModelProxy.getEventId(view.selectedModel, view.selectedItem)) + if (eventId === -1 || (modelIndex === view.selectedModel && + eventId === qmlProfilerModelProxy.getEventId(modelIndex, view.selectedItem))) return; // this is a slot responding to events from the other pane // which tracks only events from the basic model if (!lockItemSelection) { lockItemSelection = true; - var modelIndex = qmlProfilerModelProxy.basicModelIndex(); var itemIndex = view.nextItemFromId(modelIndex, eventId); // select an item, lock to it, and recenter if necessary view.selectFromId(modelIndex, itemIndex); // triggers recentering diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp index 5405f0ad0e7..a78d275506b 100644 --- a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp @@ -262,20 +262,34 @@ void QmlProfilerTraceView::clear() void QmlProfilerTraceView::selectByHash(const QString &hash) { QQuickItem *rootObject = d->m_mainView->rootObject(); + if (!rootObject) + return; - if (rootObject) - QMetaObject::invokeMethod(rootObject, "selectById", - Q_ARG(QVariant,QVariant(d->m_modelProxy->getEventIdForHash(hash)))); + for (int modelIndex = 0; modelIndex < d->m_modelProxy->modelCount(); ++modelIndex) { + int eventId = d->m_modelProxy->getEventIdForHash(modelIndex, hash); + if (eventId != -1) { + QMetaObject::invokeMethod(rootObject, "selectById", + Q_ARG(QVariant,QVariant(modelIndex)), + Q_ARG(QVariant,QVariant(eventId))); + return; + } + } } void QmlProfilerTraceView::selectBySourceLocation(const QString &filename, int line, int column) { - int eventId = d->m_modelProxy->getEventIdForLocation(filename, line, column); + QQuickItem *rootObject = d->m_mainView->rootObject(); + if (!rootObject) + return; - if (eventId != -1) { - QQuickItem *rootObject = d->m_mainView->rootObject(); - if (rootObject) - QMetaObject::invokeMethod(rootObject, "selectById", Q_ARG(QVariant,QVariant(eventId))); + for (int modelIndex = 0; modelIndex < d->m_modelProxy->modelCount(); ++modelIndex) { + int eventId = d->m_modelProxy->getEventIdForLocation(modelIndex, filename, line, column); + if (eventId != -1) { + QMetaObject::invokeMethod(rootObject, "selectById", + Q_ARG(QVariant,QVariant(modelIndex)), + Q_ARG(QVariant,QVariant(eventId))); + return; + } } } diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.h b/src/plugins/qmlprofiler/qmlprofilertraceview.h index 409f8eb38c5..b00dd497d30 100644 --- a/src/plugins/qmlprofiler/qmlprofilertraceview.h +++ b/src/plugins/qmlprofiler/qmlprofilertraceview.h @@ -119,6 +119,7 @@ protected: signals: void gotoSourceLocation(const QString &fileUrl, int lineNumber, int columNumber); + void eventSelectedByHash(const QString &hash); void resized(); private: diff --git a/src/plugins/qmlprofiler/timelinemodelaggregator.cpp b/src/plugins/qmlprofiler/timelinemodelaggregator.cpp index 80c0a87bf02..10e2cc3ae1f 100644 --- a/src/plugins/qmlprofiler/timelinemodelaggregator.cpp +++ b/src/plugins/qmlprofiler/timelinemodelaggregator.cpp @@ -47,7 +47,6 @@ public: TimelineModelAggregator *q; - int basicModelIndex; QList modelList; QmlProfilerModelManager *modelManager; }; @@ -81,9 +80,6 @@ void TimelineModelAggregator::setModelManager(QmlProfilerModelManager *modelMana BasicTimelineModel *basicTimelineModel = new BasicTimelineModel(this); basicTimelineModel->setModelManager(modelManager); addModel(basicTimelineModel); - // the basic model is the last one here - d->basicModelIndex = d->modelList.count() - 1; - } void TimelineModelAggregator::addModel(AbstractTimelineModel *m) @@ -149,11 +145,6 @@ bool TimelineModelAggregator::eventAccepted(const QmlProfilerDataModel::QmlEvent return true; } -int TimelineModelAggregator::basicModelIndex() const -{ - return d->basicModelIndex; -} - qint64 TimelineModelAggregator::lastTimeMark() const { qint64 mark = -1; @@ -297,24 +288,15 @@ const QVariantMap TimelineModelAggregator::getEventLocation(int modelIndex, int return d->modelList[modelIndex]->getEventLocation(index); } -int TimelineModelAggregator::getEventIdForHash(const QString &hash) const +int TimelineModelAggregator::getEventIdForHash(int modelIndex, const QString &hash) const { - foreach (const AbstractTimelineModel *model, d->modelList) { - int eventId = model->getEventIdForHash(hash); - if (eventId != -1) - return eventId; - } - return -1; + return d->modelList[modelIndex]->getEventIdForHash(hash); } -int TimelineModelAggregator::getEventIdForLocation(const QString &filename, int line, int column) const +int TimelineModelAggregator::getEventIdForLocation(int modelIndex, const QString &filename, + int line, int column) const { - foreach (const AbstractTimelineModel *model, d->modelList) { - int eventId = model->getEventIdForLocation(filename, line, column); - if (eventId != -1) - return eventId; - } - return -1; + return d->modelList[modelIndex]->getEventIdForLocation(filename, line, column); } void TimelineModelAggregator::dataChanged() diff --git a/src/plugins/qmlprofiler/timelinemodelaggregator.h b/src/plugins/qmlprofiler/timelinemodelaggregator.h index cd8ced50117..95e2d77169a 100644 --- a/src/plugins/qmlprofiler/timelinemodelaggregator.h +++ b/src/plugins/qmlprofiler/timelinemodelaggregator.h @@ -63,8 +63,6 @@ public: bool eventAccepted(const QmlProfilerDataModel::QmlEventData &event) const; - Q_INVOKABLE int basicModelIndex() const; - Q_INVOKABLE qint64 lastTimeMark() const; Q_INVOKABLE bool expanded(int modelIndex, int category) const; @@ -94,8 +92,9 @@ public: Q_INVOKABLE const QVariantList getEventDetails(int modelIndex, int index) const; Q_INVOKABLE const QVariantMap getEventLocation(int modelIndex, int index) const; - Q_INVOKABLE int getEventIdForHash(const QString &hash) const; - Q_INVOKABLE int getEventIdForLocation(const QString &filename, int line, int column) const; + Q_INVOKABLE int getEventIdForHash(int modelIndex, const QString &hash) const; + Q_INVOKABLE int getEventIdForLocation(int modelIndex, const QString &filename, int line, + int column) const; Q_INVOKABLE int modelIndexForCategory(int absoluteCategoryIndex) const; Q_INVOKABLE int correctedCategoryIndexForModel(int modelIndex, int absoluteCategoryIndex) const;