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 QmlProfilerRemoteActionId[] = "QmlProfiler.Remote";
const char QmlProfilerLoadActionId[] =
"Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.LoadQMLTrace";
const char QmlProfilerSaveActionId[] =
"Analyzer.Menu.StartAnalyzer.QMLProfilerOptions.SaveQMLTrace";
} // namespace Constants
} // namespace QmlProfiler

View File

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

View File

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

View File

@@ -178,13 +178,13 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
options->menu()->setEnabled(true);
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);
options->addAction(command);
act = d->m_saveQmlTrace = new QAction(tr("Save QML Trace"), options);
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);
options->addAction(command);
@@ -257,7 +257,6 @@ QWidget *QmlProfilerTool::createWidgets()
d->m_viewContainer = new QmlProfilerViewManager(this,
this,
d->m_profilerModelManager,
d->m_profilerState);
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;
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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