QmlProfiler: Retrieve common actions from ActionManager

This removes the need to pass the QmlProfilerTool instance to all views.
QmlProfilerTool is exported so that we can access the common actions
from plugins.

Change-Id: Ie7072c23ef35763b729f4b87acce47ecbdb76e43
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2016-01-04 17:20:13 +01:00
parent c16b843ecc
commit e4efb9bb3b
9 changed files with 32 additions and 38 deletions

View File

@@ -49,6 +49,11 @@ const char QmlProfilerToolId[] = "QmlProfiler";
const char QmlProfilerLocalActionId[] = "QmlProfiler.Local"; const char QmlProfilerLocalActionId[] = "QmlProfiler.Local";
const char QmlProfilerRemoteActionId[] = "QmlProfiler.Remote"; const char QmlProfilerRemoteActionId[] = "QmlProfiler.Remote";
const char QmlProfilerLoadActionId[] =
"Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace";
const char QmlProfilerSaveActionId[] =
"Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.SaveQMLTrace";
} // namespace Constants } // namespace Constants
} // namespace QmlProfiler } // namespace QmlProfiler

View File

@@ -117,7 +117,6 @@ public:
QmlProfilerStatisticsView *q; QmlProfilerStatisticsView *q;
QmlProfilerTool *m_profilerTool;
QmlProfilerStatisticsMainView *m_eventTree; QmlProfilerStatisticsMainView *m_eventTree;
QmlProfilerStatisticsRelativesView *m_eventChildren; QmlProfilerStatisticsRelativesView *m_eventChildren;
QmlProfilerStatisticsRelativesView *m_eventParents; QmlProfilerStatisticsRelativesView *m_eventParents;
@@ -188,8 +187,8 @@ static void getSourceLocation(QStandardItem *infoItem,
receiver(fileName, line, column); receiver(fileName, line, column);
} }
QmlProfilerStatisticsView::QmlProfilerStatisticsView(QWidget *parent, QmlProfilerTool *profilerTool, QmlProfilerStatisticsView::QmlProfilerStatisticsView(QWidget *parent,
QmlProfilerModelManager *profilerModelManager ) QmlProfilerModelManager *profilerModelManager)
: QmlProfilerEventsView(parent), d(new QmlProfilerStatisticsViewPrivate(this)) : QmlProfilerEventsView(parent), d(new QmlProfilerStatisticsViewPrivate(this))
{ {
setObjectName(QLatin1String("QmlProfilerStatisticsView")); setObjectName(QLatin1String("QmlProfilerStatisticsView"));
@@ -239,7 +238,6 @@ QmlProfilerStatisticsView::QmlProfilerStatisticsView(QWidget *parent, QmlProfile
groupLayout->addWidget(splitterVertical); groupLayout->addWidget(splitterVertical);
setLayout(groupLayout); setLayout(groupLayout);
d->m_profilerTool = profilerTool;
d->rangeStart = d->rangeEnd = -1; d->rangeStart = d->rangeEnd = -1;
} }
@@ -278,12 +276,9 @@ void QmlProfilerStatisticsView::contextMenuEvent(QContextMenuEvent *ev)
QPoint position = ev->globalPos(); QPoint position = ev->globalPos();
if (d->m_profilerTool) { QList <QAction *> commonActions = QmlProfilerTool::profilerContextMenuActions();
QList <QAction *> commonActions = d->m_profilerTool->profilerContextMenuActions(); foreach (QAction *act, commonActions)
foreach (QAction *act, commonActions) { menu.addAction(act);
menu.addAction(act);
}
}
if (mouseOnTable(position)) { if (mouseOnTable(position)) {
menu.addSeparator(); menu.addSeparator();

View File

@@ -81,7 +81,7 @@ class QmlProfilerStatisticsView : public QmlProfilerEventsView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QmlProfilerStatisticsView(QWidget *parent, QmlProfilerTool *profilerTool, explicit QmlProfilerStatisticsView(QWidget *parent,
QmlProfilerModelManager *profilerModelManager); QmlProfilerModelManager *profilerModelManager);
~QmlProfilerStatisticsView(); ~QmlProfilerStatisticsView();

View File

@@ -178,13 +178,13 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
options->menu()->setEnabled(true); options->menu()->setEnabled(true);
QAction *act = d->m_loadQmlTrace = new QAction(tr("Load QML Trace"), options); QAction *act = d->m_loadQmlTrace = new QAction(tr("Load QML Trace"), options);
command = ActionManager::registerAction(act, "Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace"); command = ActionManager::registerAction(act, Constants::QmlProfilerLoadActionId);
connect(act, &QAction::triggered, this, &QmlProfilerTool::showLoadDialog); connect(act, &QAction::triggered, this, &QmlProfilerTool::showLoadDialog);
options->addAction(command); options->addAction(command);
act = d->m_saveQmlTrace = new QAction(tr("Save QML Trace"), options); act = d->m_saveQmlTrace = new QAction(tr("Save QML Trace"), options);
d->m_saveQmlTrace->setEnabled(false); d->m_saveQmlTrace->setEnabled(false);
command = ActionManager::registerAction(act, "Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.SaveQMLTrace"); command = ActionManager::registerAction(act, Constants::QmlProfilerSaveActionId);
connect(act, &QAction::triggered, this, &QmlProfilerTool::showSaveDialog); connect(act, &QAction::triggered, this, &QmlProfilerTool::showSaveDialog);
options->addAction(command); options->addAction(command);
@@ -257,7 +257,6 @@ QWidget *QmlProfilerTool::createWidgets()
d->m_viewContainer = new QmlProfilerViewManager(this, d->m_viewContainer = new QmlProfilerViewManager(this,
this,
d->m_profilerModelManager, d->m_profilerModelManager,
d->m_profilerState); d->m_profilerState);
connect(d->m_viewContainer, &QmlProfilerViewManager::gotoSourceLocation, connect(d->m_viewContainer, &QmlProfilerViewManager::gotoSourceLocation,
@@ -750,10 +749,18 @@ void QmlProfilerTool::profilerDataModelStateChanged()
} }
} }
QList <QAction *> QmlProfilerTool::profilerContextMenuActions() const QList <QAction *> QmlProfilerTool::profilerContextMenuActions()
{ {
QList <QAction *> commonActions; QList <QAction *> commonActions;
commonActions << d->m_loadQmlTrace << d->m_saveQmlTrace; ActionManager *manager = ActionManager::instance();
if (manager) {
Command *command = manager->command(Constants::QmlProfilerLoadActionId);
if (command)
commonActions << command->action();
command = manager->command(Constants::QmlProfilerSaveActionId);
if (command)
commonActions << command->action();
}
return commonActions; return commonActions;
} }

View File

@@ -31,6 +31,7 @@
#ifndef QMLPROFILERTOOL_H #ifndef QMLPROFILERTOOL_H
#define QMLPROFILERTOOL_H #define QMLPROFILERTOOL_H
#include "qmlprofiler_global.h"
#include "qmlprofilerconstants.h" #include "qmlprofilerconstants.h"
#include "qmldebug/qmlprofilereventtypes.h" #include "qmldebug/qmlprofilereventtypes.h"
@@ -44,7 +45,7 @@ QT_END_NAMESPACE
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
class QmlProfilerTool : public QObject class QMLPROFILER_EXPORT QmlProfilerTool : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -59,7 +60,7 @@ public:
bool prepareTool(); bool prepareTool();
void startRemoteTool(); void startRemoteTool();
QList <QAction *> profilerContextMenuActions() const; static QList <QAction *> profilerContextMenuActions();
// display dialogs / log output // display dialogs / log output
static QMessageBox *requestMessageBox(); static QMessageBox *requestMessageBox();

View File

@@ -77,7 +77,6 @@ public:
QmlProfilerTraceViewPrivate(QmlProfilerTraceView *qq) : q(qq) {} QmlProfilerTraceViewPrivate(QmlProfilerTraceView *qq) : q(qq) {}
QmlProfilerTraceView *q; QmlProfilerTraceView *q;
QmlProfilerTool *m_profilerTool;
QmlProfilerViewManager *m_viewContainer; QmlProfilerViewManager *m_viewContainer;
QSize m_sizeHint; QSize m_sizeHint;
@@ -90,7 +89,8 @@ public:
Timeline::TimelineZoomControl *m_zoomControl; Timeline::TimelineZoomControl *m_zoomControl;
}; };
QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerTool *profilerTool, QmlProfilerViewManager *container, QmlProfilerModelManager *modelManager) QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManager *container,
QmlProfilerModelManager *modelManager)
: QWidget(parent), d(new QmlProfilerTraceViewPrivate(this)) : QWidget(parent), d(new QmlProfilerTraceViewPrivate(this))
{ {
setObjectName(QLatin1String("QML Profiler")); setObjectName(QLatin1String("QML Profiler"));
@@ -126,9 +126,7 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerTool *pro
groupLayout->addWidget(new Core::FindToolBarPlaceHolder(this)); groupLayout->addWidget(new Core::FindToolBarPlaceHolder(this));
setLayout(groupLayout); setLayout(groupLayout);
d->m_profilerTool = profilerTool;
d->m_viewContainer = container; d->m_viewContainer = container;
d->m_modelProxy = new Timeline::TimelineModelAggregator(modelManager->notesModel(), this); d->m_modelProxy = new Timeline::TimelineModelAggregator(modelManager->notesModel(), this);
d->m_modelManager = modelManager; d->m_modelManager = modelManager;
@@ -241,11 +239,7 @@ void QmlProfilerTraceView::showContextMenu(QPoint position)
QMenu menu; QMenu menu;
QAction *viewAllAction = 0; QAction *viewAllAction = 0;
QmlProfilerTool *profilerTool = qobject_cast<QmlProfilerTool *>(d->m_profilerTool); menu.addActions(QmlProfilerTool::profilerContextMenuActions());
if (profilerTool)
menu.addActions(profilerTool->profilerContextMenuActions());
menu.addSeparator(); menu.addSeparator();
QAction *getLocalStatsAction = menu.addAction(tr("Limit Statistics Pane to Current Range")); QAction *getLocalStatsAction = menu.addAction(tr("Limit Statistics Pane to Current Range"));

View File

@@ -53,8 +53,7 @@ class QmlProfilerTraceView : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit QmlProfilerTraceView(QWidget *parent, QmlProfilerTool *profilerTool, explicit QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManager *container,
QmlProfilerViewManager *container,
QmlProfilerModelManager *modelManager); QmlProfilerModelManager *modelManager);
~QmlProfilerTraceView(); ~QmlProfilerTraceView();

View File

@@ -57,11 +57,9 @@ public:
QmlProfilerStatisticsView *eventsView; QmlProfilerStatisticsView *eventsView;
QmlProfilerStateManager *profilerState; QmlProfilerStateManager *profilerState;
QmlProfilerModelManager *profilerModelManager; QmlProfilerModelManager *profilerModelManager;
QmlProfilerTool *profilerTool;
}; };
QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent, QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
QmlProfilerTool *profilerTool,
QmlProfilerModelManager *modelManager, QmlProfilerModelManager *modelManager,
QmlProfilerStateManager *profilerState) QmlProfilerStateManager *profilerState)
: QObject(parent), d(new QmlProfilerViewManagerPrivate(this)) : QObject(parent), d(new QmlProfilerViewManagerPrivate(this))
@@ -71,7 +69,6 @@ QmlProfilerViewManager::QmlProfilerViewManager(QObject *parent,
d->eventsView = 0; d->eventsView = 0;
d->profilerState = profilerState; d->profilerState = profilerState;
d->profilerModelManager = modelManager; d->profilerModelManager = modelManager;
d->profilerTool = profilerTool;
createViews(); createViews();
} }
@@ -88,15 +85,12 @@ void QmlProfilerViewManager::createViews()
Utils::FancyMainWindow *mw = AnalyzerManager::mainWindow(); Utils::FancyMainWindow *mw = AnalyzerManager::mainWindow();
d->traceView = new QmlProfilerTraceView(mw, d->traceView = new QmlProfilerTraceView(mw, this, d->profilerModelManager);
d->profilerTool,
this,
d->profilerModelManager);
d->traceView->setWindowTitle(tr("Timeline")); d->traceView->setWindowTitle(tr("Timeline"));
connect(d->traceView, &QmlProfilerTraceView::gotoSourceLocation, connect(d->traceView, &QmlProfilerTraceView::gotoSourceLocation,
this, &QmlProfilerViewManager::gotoSourceLocation); this, &QmlProfilerViewManager::gotoSourceLocation);
d->eventsView = new QmlProfilerStatisticsView(mw, d->profilerTool, d->profilerModelManager); d->eventsView = new QmlProfilerStatisticsView(mw, d->profilerModelManager);
d->eventsView->setWindowTitle(tr("Statistics")); d->eventsView->setWindowTitle(tr("Statistics"));
connect(d->eventsView, &QmlProfilerStatisticsView::gotoSourceLocation, connect(d->eventsView, &QmlProfilerStatisticsView::gotoSourceLocation,
this, &QmlProfilerViewManager::gotoSourceLocation); this, &QmlProfilerViewManager::gotoSourceLocation);

View File

@@ -46,7 +46,6 @@ class QmlProfilerViewManager : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit QmlProfilerViewManager(QObject *parent, explicit QmlProfilerViewManager(QObject *parent,
QmlProfilerTool *profilerTool,
QmlProfilerModelManager *modelManager, QmlProfilerModelManager *modelManager,
QmlProfilerStateManager *profilerState); QmlProfilerStateManager *profilerState);
~QmlProfilerViewManager(); ~QmlProfilerViewManager();