From ffa0c86617c2877b8efc9a9d652f35550c8c288a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 4 Dec 2015 16:54:58 +0100 Subject: [PATCH] QmlProfiler: Allow multiple events views loaded from plugins Change-Id: Ifaf4e63f4a843a42a1a22f005e87d8c1a4604686 Reviewed-by: Joerg Bornemann --- doc/src/analyze/qtquick-profiler.qdoc | 2 +- .../qmlprofiler/qmlprofilereventsview.h | 10 +++ .../qmlprofiler/qmlprofilerstatisticsview.cpp | 3 +- .../qmlprofiler/qmlprofilertraceview.cpp | 4 +- .../qmlprofiler/qmlprofilerviewmanager.cpp | 81 ++++++++++++------- .../qmlprofiler/qmlprofilerviewmanager.h | 1 + 6 files changed, 69 insertions(+), 32 deletions(-) diff --git a/doc/src/analyze/qtquick-profiler.qdoc b/doc/src/analyze/qtquick-profiler.qdoc index 41efbca00f2..1194be7f043 100644 --- a/doc/src/analyze/qtquick-profiler.qdoc +++ b/doc/src/analyze/qtquick-profiler.qdoc @@ -546,7 +546,7 @@ When you select an event in the \uicontrol Timeline view, information about it is displayed in the \uicontrol Statistics view. To view an event range in the - \uicontrol Statistics view, select \uicontrol {Limit Statistics Pane to Current Range} + \uicontrol Statistics view, select \uicontrol {Analyze Current Range} in the context menu in the \uicontrol Timeline view. To copy the contents of one view or row to the clipboard, select diff --git a/src/plugins/qmlprofiler/qmlprofilereventsview.h b/src/plugins/qmlprofiler/qmlprofilereventsview.h index d121e864a69..e07b399366c 100644 --- a/src/plugins/qmlprofiler/qmlprofilereventsview.h +++ b/src/plugins/qmlprofiler/qmlprofilereventsview.h @@ -32,6 +32,7 @@ #define QMLPROFILEREVENTSVIEW_H #include "qmlprofiler_global.h" +#include "qmlprofilermodelmanager.h" #include #include @@ -51,12 +52,21 @@ public: signals: void gotoSourceLocation(const QString &fileName, int lineNumber, int columnNumber); void typeSelected(int typeIndex); + void showFullRange(); public slots: virtual void selectByTypeId(int typeIndex) = 0; virtual void onVisibleFeaturesChanged(quint64 features) = 0; }; +class QMLPROFILER_EXPORT QmlProfilerEventsViewFactory : public QObject +{ + Q_OBJECT +public: + virtual QList create(QWidget *parent, + QmlProfilerModelManager *manager) = 0; +}; + } #endif // QMLPROFILEREVENTSVIEW_H diff --git a/src/plugins/qmlprofiler/qmlprofilerstatisticsview.cpp b/src/plugins/qmlprofiler/qmlprofilerstatisticsview.cpp index 2da486dc934..b115ead64c7 100644 --- a/src/plugins/qmlprofiler/qmlprofilerstatisticsview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerstatisticsview.cpp @@ -192,6 +192,7 @@ QmlProfilerStatisticsView::QmlProfilerStatisticsView(QWidget *parent, : QmlProfilerEventsView(parent), d(new QmlProfilerStatisticsViewPrivate(this)) { setObjectName(QLatin1String("QmlProfilerStatisticsView")); + setWindowTitle(tr("Statistics")); d->model = new QmlProfilerStatisticsModel(profilerModelManager, this); @@ -304,7 +305,7 @@ void QmlProfilerStatisticsView::contextMenuEvent(QContextMenuEvent *ev) if (selectedAction == copyTableAction) copyTableToClipboard(); if (selectedAction == getGlobalStatsAction) - restrictToRange(-1, -1); + emit showFullRange(); if (selectedAction == showExtendedStatsAction) setShowExtendedStatistics(!showExtendedStatistics()); } diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp index 2d62faab8ee..73a88f106fc 100644 --- a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp @@ -242,11 +242,11 @@ void QmlProfilerTraceView::showContextMenu(QPoint position) menu.addActions(QmlProfilerTool::profilerContextMenuActions()); menu.addSeparator(); - QAction *getLocalStatsAction = menu.addAction(tr("Limit Statistics Pane to Current Range")); + QAction *getLocalStatsAction = menu.addAction(tr("Analyze Current Range")); if (!d->m_viewContainer->hasValidSelection()) getLocalStatsAction->setEnabled(false); - QAction *getGlobalStatsAction = menu.addAction(tr("Show Full Range in Statistics Pane")); + QAction *getGlobalStatsAction = menu.addAction(tr("Analyze Full Range")); if (!d->m_viewContainer->isEventsRestrictedToRange()) getGlobalStatsAction->setEnabled(false); diff --git a/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp b/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp index 1dbc109f0df..d2196da4a92 100644 --- a/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerviewmanager.cpp @@ -37,9 +37,11 @@ #include "qmlprofilermodelmanager.h" #include "qmlprofilerstatewidget.h" +#include #include #include #include +#include #include @@ -54,9 +56,10 @@ public: QDockWidget *timelineDock; QmlProfilerTraceView *traceView; - QmlProfilerStatisticsView *eventsView; + QList eventsViews; QmlProfilerStateManager *profilerState; QmlProfilerModelManager *profilerModelManager; + QmlProfilerEventsViewFactory *eventsViewFactory; }; QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, @@ -66,9 +69,10 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, { setObjectName(QLatin1String("QML Profiler View Manager")); d->traceView = 0; - d->eventsView = 0; d->profilerState = profilerState; d->profilerModelManager = modelManager; + d->eventsViewFactory = + ExtensionSystem::PluginManager::getObject(); createViews(); } @@ -79,7 +83,6 @@ QmlProfilerViewManager::~QmlProfilerViewManager() void QmlProfilerViewManager::createViews() { - QTC_ASSERT(d->profilerModelManager, return); QTC_ASSERT(d->profilerState, return); @@ -89,32 +92,48 @@ void QmlProfilerViewManager::createViews() d->traceView->setWindowTitle(tr("Timeline")); connect(d->traceView, &QmlProfilerTraceView::gotoSourceLocation, this, &QmlProfilerViewManager::gotoSourceLocation); - - d->eventsView = new QmlProfilerStatisticsView(mw, d->profilerModelManager); - d->eventsView->setWindowTitle(tr("Statistics")); - connect(d->eventsView, &QmlProfilerStatisticsView::gotoSourceLocation, - this, &QmlProfilerViewManager::gotoSourceLocation); - connect(d->eventsView, &QmlProfilerStatisticsView::typeSelected, - d->traceView, &QmlProfilerTraceView::selectByTypeId); connect(d->traceView, &QmlProfilerTraceView::typeSelected, - d->eventsView, &QmlProfilerStatisticsView::selectByTypeId); - connect(d->profilerModelManager, &QmlProfilerModelManager::visibleFeaturesChanged, - d->eventsView, &QmlProfilerStatisticsView::onVisibleFeaturesChanged); - - QDockWidget *eventsDock = AnalyzerManager::createDockWidget - (Constants::QmlProfilerToolId, d->eventsView); - d->timelineDock = AnalyzerManager::createDockWidget - (Constants::QmlProfilerToolId, d->traceView); - - eventsDock->show(); + this, &QmlProfilerViewManager::typeSelected); + connect(this, &QmlProfilerViewManager::typeSelected, + d->traceView, &QmlProfilerTraceView::selectByTypeId); + d->timelineDock = AnalyzerManager::createDockWidget(Constants::QmlProfilerToolId, d->traceView); d->timelineDock->show(); - mw->splitDockWidget(mw->toolBarDockWidget(), d->timelineDock, Qt::Vertical); - mw->tabifyDockWidget(d->timelineDock, eventsDock); - d->timelineDock->raise(); - - new QmlProfilerStateWidget(d->profilerState, d->profilerModelManager, d->eventsView); new QmlProfilerStateWidget(d->profilerState, d->profilerModelManager, d->traceView); + + d->eventsViews << new QmlProfilerStatisticsView(mw, d->profilerModelManager); + if (d->eventsViewFactory) + d->eventsViews.append(d->eventsViewFactory->create(mw, d->profilerModelManager)); + + // Clear settings if the new views aren't there yet. Otherwise we get glitches + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("AnalyzerViewSettings_") + + QLatin1String(QmlProfiler::Constants::QmlProfilerToolId)); + + foreach (QmlProfilerEventsView *view, d->eventsViews) { + view->setParent(mw); + connect(view, &QmlProfilerEventsView::typeSelected, + this, &QmlProfilerViewManager::typeSelected); + connect(this, &QmlProfilerViewManager::typeSelected, + view, &QmlProfilerEventsView::selectByTypeId); + connect(d->profilerModelManager, &QmlProfilerModelManager::visibleFeaturesChanged, + view, &QmlProfilerEventsView::onVisibleFeaturesChanged); + connect(view, &QmlProfilerEventsView::gotoSourceLocation, + this, &QmlProfilerViewManager::gotoSourceLocation); + connect(view, &QmlProfilerEventsView::showFullRange, + this, [this](){restrictEventsToRange(-1, -1);}); + QDockWidget *eventsDock = AnalyzerManager::createDockWidget(Constants::QmlProfilerToolId, + view); + eventsDock->show(); + mw->tabifyDockWidget(d->timelineDock, eventsDock); + new QmlProfilerStateWidget(d->profilerState, d->profilerModelManager, view); + + if (!settings->contains(eventsDock->objectName())) + settings->remove(QString()); + } + + settings->endGroup(); + d->timelineDock->raise(); } bool QmlProfilerViewManager::hasValidSelection() const @@ -134,12 +153,17 @@ qint64 QmlProfilerViewManager::selectionEnd() const bool QmlProfilerViewManager::isEventsRestrictedToRange() const { - return d->eventsView->isRestrictedToRange(); + foreach (QmlProfilerEventsView *view, d->eventsViews) { + if (view->isRestrictedToRange()) + return true; + } + return false; } void QmlProfilerViewManager::restrictEventsToRange(qint64 rangeStart, qint64 rangeEnd) { - d->eventsView->restrictToRange(rangeStart, rangeEnd); + foreach (QmlProfilerEventsView *view, d->eventsViews) + view->restrictToRange(rangeStart, rangeEnd); } void QmlProfilerViewManager::raiseTimeline() @@ -151,7 +175,8 @@ void QmlProfilerViewManager::raiseTimeline() void QmlProfilerViewManager::clear() { d->traceView->clear(); - d->eventsView->clear(); + foreach (QmlProfilerEventsView *view, d->eventsViews) + view->clear(); } } // namespace Internal diff --git a/src/plugins/qmlprofiler/qmlprofilerviewmanager.h b/src/plugins/qmlprofiler/qmlprofilerviewmanager.h index b31849b67ec..9a1fd9057c5 100644 --- a/src/plugins/qmlprofiler/qmlprofilerviewmanager.h +++ b/src/plugins/qmlprofiler/qmlprofilerviewmanager.h @@ -65,6 +65,7 @@ public slots: void clear(); signals: + void typeSelected(int typeId); void gotoSourceLocation(QString,int,int); private: