Analyzer: Dissolve IAnalyzerTool

Change-Id: I1fd90cf00d6b9dff54b4555a14747282830a4b93
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2015-02-18 14:35:20 +01:00
parent ca04d009f2
commit 73e2b0c579
17 changed files with 179 additions and 153 deletions

View File

@@ -178,9 +178,9 @@ public:
QComboBox *m_toolBox; QComboBox *m_toolBox;
QStackedWidget *m_controlsStackWidget; QStackedWidget *m_controlsStackWidget;
StatusLabel *m_statusLabel; StatusLabel *m_statusLabel;
typedef QMap<IAnalyzerTool *, FancyMainWindowSettings> MainWindowSettingsMap; typedef QMap<Id, FancyMainWindowSettings> MainWindowSettingsMap;
QHash<IAnalyzerTool *, QList<QDockWidget *> > m_toolWidgets; QHash<Id, QList<QDockWidget *> > m_toolWidgets;
QHash<IAnalyzerTool *, QWidget *> m_controlsWidgetFromTool; QHash<Id, QWidget *> m_controlsWidgetFromTool;
MainWindowSettingsMap m_defaultSettings; MainWindowSettingsMap m_defaultSettings;
// list of dock widgets to prevent memory leak // list of dock widgets to prevent memory leak
@@ -437,7 +437,7 @@ bool AnalyzerManagerPrivate::isActionRunnable(AnalyzerAction *action) const
void AnalyzerManagerPrivate::startTool() void AnalyzerManagerPrivate::startTool()
{ {
QTC_ASSERT(m_currentAction, return); QTC_ASSERT(m_currentAction, return);
m_currentAction->tool()->startTool(m_currentAction->startMode()); m_currentAction->toolStarter()(m_currentAction->startMode());
} }
void AnalyzerManagerPrivate::modeChanged(IMode *mode) void AnalyzerManagerPrivate::modeChanged(IMode *mode)
@@ -461,7 +461,7 @@ void AnalyzerManagerPrivate::selectSavedTool()
if (settings->contains(QLatin1String(LAST_ACTIVE_TOOL))) { if (settings->contains(QLatin1String(LAST_ACTIVE_TOOL))) {
const Id lastAction = Id::fromSetting(settings->value(QLatin1String(LAST_ACTIVE_TOOL))); const Id lastAction = Id::fromSetting(settings->value(QLatin1String(LAST_ACTIVE_TOOL)));
foreach (AnalyzerAction *action, m_actions) { foreach (AnalyzerAction *action, m_actions) {
if (action->id() == lastAction) { if (action->toolId() == lastAction) {
selectAction(action); selectAction(action);
return; return;
} }
@@ -497,29 +497,29 @@ void AnalyzerManagerPrivate::selectAction(AnalyzerAction *action)
// Clean up old tool. // Clean up old tool.
if (m_currentAction) { if (m_currentAction) {
saveToolSettings(m_currentAction); saveToolSettings(m_currentAction);
foreach (QDockWidget *widget, m_toolWidgets.value(m_currentAction->tool())) foreach (QDockWidget *widget, m_toolWidgets.value(m_currentAction->toolId()))
deactivateDock(widget); deactivateDock(widget);
} }
// Now change the tool. // Now change the tool.
m_currentAction = action; m_currentAction = action;
IAnalyzerTool *tool = action->tool(); Id toolId = action->toolId();
if (!m_defaultSettings.contains(tool)) { if (!m_defaultSettings.contains(toolId)) {
QWidget *widget = tool->createWidgets(); QWidget *widget = action->createWidget();
QTC_CHECK(widget); QTC_CHECK(widget);
m_defaultSettings.insert(tool, m_mainWindow->saveSettings()); m_defaultSettings.insert(toolId, m_mainWindow->saveSettings());
QTC_CHECK(!m_controlsWidgetFromTool.contains(tool)); QTC_CHECK(!m_controlsWidgetFromTool.contains(toolId));
m_controlsWidgetFromTool[tool] = widget; m_controlsWidgetFromTool[toolId] = widget;
m_controlsStackWidget->addWidget(widget); m_controlsStackWidget->addWidget(widget);
} }
foreach (QDockWidget *widget, m_toolWidgets.value(tool)) foreach (QDockWidget *widget, m_toolWidgets.value(toolId))
activateDock(Qt::DockWidgetArea(widget->property(INITIAL_DOCK_AREA).toInt()), widget); activateDock(Qt::DockWidgetArea(widget->property(INITIAL_DOCK_AREA).toInt()), widget);
loadToolSettings(action); loadToolSettings(action);
QTC_CHECK(m_controlsWidgetFromTool.contains(tool)); QTC_CHECK(m_controlsWidgetFromTool.contains(toolId));
m_controlsStackWidget->setCurrentWidget(m_controlsWidgetFromTool.value(tool)); m_controlsStackWidget->setCurrentWidget(m_controlsWidgetFromTool.value(toolId));
m_toolBox->setCurrentIndex(actionIndex); m_toolBox->setCurrentIndex(actionIndex);
updateRunActions(); updateRunActions();
@@ -533,7 +533,7 @@ void AnalyzerManagerPrivate::addAction(AnalyzerAction *action)
Id menuGroup = action->menuGroup(); Id menuGroup = action->menuGroup();
if (menuGroup.isValid()) { if (menuGroup.isValid()) {
Command *command = ActionManager::registerAction(action, action->id(), Context(C_GLOBAL)); Command *command = ActionManager::registerAction(action, action->actionId(), Context(C_GLOBAL));
m_menu->addAction(command, menuGroup); m_menu->addAction(command, menuGroup);
} }
@@ -560,11 +560,11 @@ void AnalyzerManagerPrivate::loadToolSettings(AnalyzerAction *action)
{ {
QTC_ASSERT(m_mainWindow, return); QTC_ASSERT(m_mainWindow, return);
QSettings *settings = ICore::settings(); QSettings *settings = ICore::settings();
settings->beginGroup(QLatin1String("AnalyzerViewSettings_") + action->id().toString()); settings->beginGroup(QLatin1String("AnalyzerViewSettings_") + action->toolId().toString());
if (settings->value(QLatin1String("ToolSettingsSaved"), false).toBool()) if (settings->value(QLatin1String("ToolSettingsSaved"), false).toBool())
m_mainWindow->restoreSettings(settings); m_mainWindow->restoreSettings(settings);
else else
m_mainWindow->restoreSettings(m_defaultSettings.value(action->tool())); m_mainWindow->restoreSettings(m_defaultSettings.value(action->toolId()));
settings->endGroup(); settings->endGroup();
} }
@@ -574,11 +574,11 @@ void AnalyzerManagerPrivate::saveToolSettings(AnalyzerAction *action)
QTC_ASSERT(m_mainWindow, return); QTC_ASSERT(m_mainWindow, return);
QSettings *settings = ICore::settings(); QSettings *settings = ICore::settings();
settings->beginGroup(QLatin1String("AnalyzerViewSettings_") + action->id().toString()); settings->beginGroup(QLatin1String("AnalyzerViewSettings_") + action->toolId().toString());
m_mainWindow->saveSettings(settings); m_mainWindow->saveSettings(settings);
settings->setValue(QLatin1String("ToolSettingsSaved"), true); settings->setValue(QLatin1String("ToolSettingsSaved"), true);
settings->endGroup(); settings->endGroup();
settings->setValue(QLatin1String(LAST_ACTIVE_TOOL), action->id().toString()); settings->setValue(QLatin1String(LAST_ACTIVE_TOOL), action->toolId().toString());
} }
void AnalyzerManagerPrivate::updateRunActions() void AnalyzerManagerPrivate::updateRunActions()
@@ -633,21 +633,21 @@ void AnalyzerManager::addAction(AnalyzerAction *action)
d->addAction(action); d->addAction(action);
} }
QDockWidget *AnalyzerManager::createDockWidget(IAnalyzerTool *tool, QDockWidget *AnalyzerManager::createDockWidget(Core::Id toolId,
QWidget *widget, Qt::DockWidgetArea area) QWidget *widget, Qt::DockWidgetArea area)
{ {
QTC_ASSERT(!widget->objectName().isEmpty(), return 0); QTC_ASSERT(!widget->objectName().isEmpty(), return 0);
QDockWidget *dockWidget = d->m_mainWindow->addDockForWidget(widget); QDockWidget *dockWidget = d->m_mainWindow->addDockForWidget(widget);
dockWidget->setProperty(INITIAL_DOCK_AREA, int(area)); dockWidget->setProperty(INITIAL_DOCK_AREA, int(area));
d->m_dockWidgets.append(AnalyzerManagerPrivate::DockPtr(dockWidget)); d->m_dockWidgets.append(AnalyzerManagerPrivate::DockPtr(dockWidget));
d->m_toolWidgets[tool].push_back(dockWidget); d->m_toolWidgets[toolId].push_back(dockWidget);
return dockWidget; return dockWidget;
} }
void AnalyzerManager::selectTool(IAnalyzerTool *tool, StartMode mode) void AnalyzerManager::selectTool(Id toolId, StartMode mode)
{ {
foreach (AnalyzerAction *action, d->m_actions) foreach (AnalyzerAction *action, d->m_actions)
if (action->tool() == tool && action->startMode() == mode) if (action->toolId() == toolId && action->startMode() == mode)
d->selectAction(action); d->selectAction(action);
} }
@@ -664,7 +664,7 @@ FancyMainWindow *AnalyzerManager::mainWindow()
void AnalyzerManagerPrivate::resetLayout() void AnalyzerManagerPrivate::resetLayout()
{ {
QTC_ASSERT(m_currentAction, return); QTC_ASSERT(m_currentAction, return);
m_mainWindow->restoreSettings(m_defaultSettings.value(m_currentAction->tool())); m_mainWindow->restoreSettings(m_defaultSettings.value(m_currentAction->toolId()));
} }
void AnalyzerManager::showStatusMessage(const QString &message, int timeoutMS) void AnalyzerManager::showStatusMessage(const QString &message, int timeoutMS)
@@ -708,7 +708,7 @@ AnalyzerRunControl *AnalyzerManager::createRunControl(
{ {
foreach (AnalyzerAction *action, d->m_actions) { foreach (AnalyzerAction *action, d->m_actions) {
if (action->runMode() == sp.runMode && action->startMode() == sp.startMode) if (action->runMode() == sp.runMode && action->startMode() == sp.startMode)
return action->tool()->createRunControl(sp, runConfiguration); return action->createRunControl(sp, runConfiguration);
} }
QTC_CHECK(false); QTC_CHECK(false);
return 0; return 0;

View File

@@ -35,6 +35,7 @@
#include "analyzerbase_global.h" #include "analyzerbase_global.h"
#include "analyzerconstants.h" #include "analyzerconstants.h"
#include <coreplugin/id.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <QObject> #include <QObject>
@@ -49,7 +50,6 @@ namespace ProjectExplorer { class RunConfiguration; }
namespace Analyzer { namespace Analyzer {
class IAnalyzerTool;
class AnalyzerAction; class AnalyzerAction;
class AnalyzerRunControl; class AnalyzerRunControl;
class AnalyzerStartParameters; class AnalyzerStartParameters;
@@ -70,13 +70,13 @@ public:
static void addAction(AnalyzerAction *action); static void addAction(AnalyzerAction *action);
// Dockwidgets are registered to the main window. // Dockwidgets are registered to the main window.
static QDockWidget *createDockWidget(IAnalyzerTool *tool, static QDockWidget *createDockWidget(Core::Id toolId,
QWidget *widget, Qt::DockWidgetArea area = Qt::BottomDockWidgetArea); QWidget *widget, Qt::DockWidgetArea area = Qt::BottomDockWidgetArea);
static Utils::FancyMainWindow *mainWindow(); static Utils::FancyMainWindow *mainWindow();
static void showMode(); static void showMode();
static void selectTool(IAnalyzerTool *tool, StartMode mode); static void selectTool(Core::Id toolId, StartMode mode);
static void startTool(); static void startTool();
static void stopTool(); static void stopTool();

View File

@@ -58,41 +58,24 @@ using namespace ProjectExplorer;
namespace Analyzer { namespace Analyzer {
IAnalyzerTool::IAnalyzerTool(QObject *parent)
: QObject(parent)
{}
ProjectExplorer::RunMode AnalyzerAction::runMode() const
{
return m_runMode;
}
void AnalyzerAction::setRunMode(ProjectExplorer::RunMode mode)
{
m_runMode = mode;
}
AnalyzerAction::AnalyzerAction(QObject *parent) AnalyzerAction::AnalyzerAction(QObject *parent)
: QAction(parent) : QAction(parent)
{} {}
static bool buildTypeAccepted(IAnalyzerTool::ToolMode toolMode, static bool buildTypeAccepted(ToolMode toolMode, BuildConfiguration::BuildType buildType)
BuildConfiguration::BuildType buildType)
{ {
if (toolMode == IAnalyzerTool::AnyMode) if (toolMode == AnyMode)
return true; return true;
if (buildType == BuildConfiguration::Unknown) if (buildType == BuildConfiguration::Unknown)
return true; return true;
if (buildType == BuildConfiguration::Debug if (buildType == BuildConfiguration::Debug && toolMode == DebugMode)
&& toolMode == IAnalyzerTool::DebugMode)
return true; return true;
if (buildType == BuildConfiguration::Release if (buildType == BuildConfiguration::Release && toolMode == ReleaseMode)
&& toolMode == IAnalyzerTool::ReleaseMode)
return true; return true;
return false; return false;
} }
bool checkForLocalStart(IAnalyzerTool::ToolMode toolMode) bool checkForLocalStart(ToolMode toolMode)
{ {
// Make sure mode is shown. // Make sure mode is shown.
AnalyzerManager::showMode(); AnalyzerManager::showMode();
@@ -117,10 +100,10 @@ bool checkForLocalStart(IAnalyzerTool::ToolMode toolMode)
QString toolModeString; QString toolModeString;
switch (toolMode) { switch (toolMode) {
case IAnalyzerTool::DebugMode: case DebugMode:
toolModeString = AnalyzerManager::tr("Debug"); toolModeString = AnalyzerManager::tr("Debug");
break; break;
case IAnalyzerTool::ReleaseMode: case ReleaseMode:
toolModeString = AnalyzerManager::tr("Release"); toolModeString = AnalyzerManager::tr("Release");
break; break;
default: default:

View File

@@ -41,61 +41,28 @@
#include <QObject> #include <QObject>
#include <QAction> #include <QAction>
#include <functional>
namespace ProjectExplorer { class RunConfiguration; } namespace ProjectExplorer { class RunConfiguration; }
namespace Analyzer { namespace Analyzer {
class AnalyzerRunControl; class AnalyzerRunControl;
/** /**
* This class represents an analyzation tool, e.g. "Valgrind Memcheck". * The mode in which this tool should preferably be run
* *
* Each tool can run in different run modes. The modes are specific to the tool. * The memcheck tool, for example, requires debug symbols, hence DebugMode
* * is preferred. On the other hand, callgrind should look at optimized code,
* @code * hence ReleaseMode.
* bool YourPlugin::initialize(const QStringList &arguments, QString *errorString)
* {
* AnalyzerManager::addTool(new MemcheckTool(this));
* return true;
* }
* @endcode
*/ */
class ANALYZER_EXPORT IAnalyzerTool : public QObject enum ToolMode {
{ DebugMode,
Q_OBJECT ReleaseMode,
AnyMode
public:
explicit IAnalyzerTool(QObject *parent = 0);
/**
* The mode in which this tool should preferably be run
*
* The memcheck tool, for example, requires debug symbols, hence DebugMode
* is preferred. On the other hand, callgrind should look at optimized code,
* hence ReleaseMode.
*/
enum ToolMode {
DebugMode,
ReleaseMode,
AnyMode
};
/// Creates all widgets used by the tool.
/// Returns a control widget which will be shown in the status bar when
/// this tool is selected. Must be non-zero.
virtual QWidget *createWidgets() = 0;
/// Returns a new engine for the given start parameters.
/// Called each time the tool is launched.
virtual AnalyzerRunControl *createRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) = 0;
virtual void startTool(StartMode mode) = 0;
}; };
ANALYZER_EXPORT bool checkForLocalStart(IAnalyzerTool::ToolMode toolMode); ANALYZER_EXPORT bool checkForLocalStart(ToolMode toolMode);
ANALYZER_EXPORT bool checkForRemoteStart(AnalyzerStartParameters *sp); ANALYZER_EXPORT bool checkForRemoteStart(AnalyzerStartParameters *sp);
@@ -112,30 +79,52 @@ public:
explicit AnalyzerAction(QObject *parent = 0); explicit AnalyzerAction(QObject *parent = 0);
public: public:
IAnalyzerTool *tool() const { return m_tool; }
void setTool(IAnalyzerTool *tool) { m_tool = tool; }
StartMode startMode() const { return m_startMode; } StartMode startMode() const { return m_startMode; }
void setStartMode(StartMode startMode) { m_startMode = startMode; } void setStartMode(StartMode startMode) { m_startMode = startMode; }
Core::Id menuGroup() const { return m_menuGroup; } Core::Id menuGroup() const { return m_menuGroup; }
void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; } void setMenuGroup(Core::Id menuGroup) { m_menuGroup = menuGroup; }
Core::Id id() const { return m_id; } Core::Id actionId() const { return m_actionId; }
void setId(Core::Id id) { m_id = id; } void setActionId(Core::Id id) { m_actionId = id; }
ProjectExplorer::RunMode runMode() const; Core::Id toolId() const { return m_toolId; }
void setRunMode(ProjectExplorer::RunMode mode); void setToolId(Core::Id id) { m_toolId = id; }
ProjectExplorer::RunMode runMode() const { return m_runMode; }
void setRunMode(ProjectExplorer::RunMode mode) { m_runMode = mode; }
/// Creates all widgets used by the tool.
/// Returns a control widget which will be shown in the status bar when
/// this tool is selected.
typedef std::function<QWidget *()> WidgetCreator;
QWidget *createWidget() const { return m_widgetCreator(); }
void setWidgetCreator(const WidgetCreator &creator) { m_widgetCreator = creator; }
/// Returns a new engine for the given start parameters.
/// Called each time the tool is launched.
typedef std::function<AnalyzerRunControl *(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)> RunControlCreator;
AnalyzerRunControl *createRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) const
{ return m_runControlCreator(sp, runConfiguration); }
void setRunControlCreator(const RunControlCreator &creator) { m_runControlCreator = creator; }
typedef std::function<void(StartMode)> ToolStarter;
ToolStarter toolStarter() const { return m_toolStarter; }
void setToolStarter(const ToolStarter &toolStarter) { m_toolStarter = toolStarter; }
protected: protected:
IAnalyzerTool *m_tool;
StartMode m_startMode; StartMode m_startMode;
Core::Id m_menuGroup; Core::Id m_menuGroup;
Core::Id m_id; Core::Id m_actionId;
Core::Id m_toolId;
ProjectExplorer::RunMode m_runMode; ProjectExplorer::RunMode m_runMode;
WidgetCreator m_widgetCreator;
RunControlCreator m_runControlCreator;
ToolStarter m_toolStarter;
}; };
} // namespace Analyzer } // namespace Analyzer
#endif // IANALYZERTOOL_H #endif // IANALYZERTOOL_H

View File

@@ -52,7 +52,13 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorString) Q_UNUSED(errorString)
IAnalyzerTool *tool = new QmlProfilerTool(this); auto tool = new QmlProfilerTool(this);
auto toolStarter = [tool](StartMode mode) { return tool->startTool(mode); };
auto widgetCreator = [tool] { return tool->createWidgets(); };
auto runControlCreator = [tool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) {
return tool->createRunControl(sp, runConfiguration);
};
AnalyzerAction *action = 0; AnalyzerAction *action = 0;
@@ -61,8 +67,11 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
"applications using QML."); "applications using QML.");
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("QmlProfiler.Local"); action->setActionId("QmlProfiler.Local");
action->setTool(tool); action->setToolId(QmlProfilerToolId);
action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator);
action->setToolStarter(toolStarter);
action->setRunMode(ProjectExplorer::QmlProfilerRunMode); action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
action->setText(tr("QML Profiler")); action->setText(tr("QML Profiler"));
action->setToolTip(description); action->setToolTip(description);
@@ -71,8 +80,11 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("QmlProfiler.Remote"); action->setActionId("QmlProfiler.Remote");
action->setTool(tool); action->setToolId(QmlProfilerToolId);
action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator);
action->setToolStarter(toolStarter);
action->setRunMode(ProjectExplorer::QmlProfilerRunMode); action->setRunMode(ProjectExplorer::QmlProfilerRunMode);
action->setText(tr("QML Profiler (External)")); action->setText(tr("QML Profiler (External)"));
action->setToolTip(description); action->setToolTip(description);

View File

@@ -121,7 +121,7 @@ public:
}; };
QmlProfilerTool::QmlProfilerTool(QObject *parent) QmlProfilerTool::QmlProfilerTool(QObject *parent)
: IAnalyzerTool(parent), d(new QmlProfilerToolPrivate) : QObject(parent), d(new QmlProfilerToolPrivate)
{ {
setObjectName(QLatin1String("QmlProfilerTool")); setObjectName(QLatin1String("QmlProfilerTool"));
@@ -486,7 +486,7 @@ void QmlProfilerTool::clearDisplay()
updateTimeDisplay(); updateTimeDisplay();
} }
static void startRemoteTool(IAnalyzerTool *tool, StartMode mode) static void startRemoteTool(QmlProfilerTool *tool, StartMode mode)
{ {
Id kitId; Id kitId;
quint16 port; quint16 port;
@@ -601,7 +601,7 @@ void QmlProfilerTool::showLoadDialog()
if (ModeManager::currentMode()->id() != MODE_ANALYZE) if (ModeManager::currentMode()->id() != MODE_ANALYZE)
AnalyzerManager::showMode(); AnalyzerManager::showMode();
AnalyzerManager::selectTool(this, StartRemote); AnalyzerManager::selectTool("QmlProfiler", StartRemote);
QString filename = QFileDialog::getOpenFileName(ICore::mainWindow(), tr("Load QML Trace"), QString(), QString filename = QFileDialog::getOpenFileName(ICore::mainWindow(), tr("Load QML Trace"), QString(),
tr("QML traces (*%1)").arg(QLatin1String(TraceFileExtension))); tr("QML traces (*%1)").arg(QLatin1String(TraceFileExtension)));

View File

@@ -42,7 +42,9 @@ QT_END_NAMESPACE
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
class QmlProfilerTool : public Analyzer::IAnalyzerTool const char QmlProfilerToolId[] = "QmlProfiler";
class QmlProfilerTool : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@@ -77,7 +77,7 @@ public:
QmlProfilerTraceView *q; QmlProfilerTraceView *q;
QmlProfilerStateManager *m_profilerState; QmlProfilerStateManager *m_profilerState;
Analyzer::IAnalyzerTool *m_profilerTool; QmlProfilerTool *m_profilerTool;
QmlProfilerViewManager *m_viewContainer; QmlProfilerViewManager *m_viewContainer;
QSize m_sizeHint; QSize m_sizeHint;
@@ -90,7 +90,7 @@ public:
Timeline::TimelineZoomControl *m_zoomControl; Timeline::TimelineZoomControl *m_zoomControl;
}; };
QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, Analyzer::IAnalyzerTool *profilerTool, QmlProfilerViewManager *container, QmlProfilerModelManager *modelManager, QmlProfilerStateManager *profilerState) QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerTool *profilerTool, QmlProfilerViewManager *container, QmlProfilerModelManager *modelManager, QmlProfilerStateManager *profilerState)
: QWidget(parent), d(new QmlProfilerTraceViewPrivate(this)) : QWidget(parent), d(new QmlProfilerTraceViewPrivate(this))
{ {
setObjectName(QLatin1String("QML Profiler")); setObjectName(QLatin1String("QML Profiler"));

View File

@@ -35,14 +35,13 @@
#include <QWidget> #include <QWidget>
#include <QTimer> #include <QTimer>
namespace Analyzer { class IAnalyzerTool; }
namespace QmlProfiler { namespace QmlProfiler {
class QmlProfilerModelManager; class QmlProfilerModelManager;
namespace Internal { namespace Internal {
class QmlProfilerStateManager; class QmlProfilerStateManager;
class QmlProfilerTool;
class QmlProfilerViewManager; class QmlProfilerViewManager;
class QmlProfilerTraceView : public QWidget class QmlProfilerTraceView : public QWidget
@@ -50,7 +49,7 @@ class QmlProfilerTraceView : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit QmlProfilerTraceView(QWidget *parent, Analyzer::IAnalyzerTool *profilerTool, explicit QmlProfilerTraceView(QWidget *parent, QmlProfilerTool *profilerTool,
QmlProfilerViewManager *container, QmlProfilerViewManager *container,
QmlProfilerModelManager *modelManager, QmlProfilerModelManager *modelManager,
QmlProfilerStateManager *profilerState); QmlProfilerStateManager *profilerState);

View File

@@ -124,11 +124,11 @@ void QmlProfilerViewManager::createViews()
d->v8profilerView, SLOT(selectBySourceLocation(QString,int,int))); d->v8profilerView, SLOT(selectBySourceLocation(QString,int,int)));
QDockWidget *eventsDock = AnalyzerManager::createDockWidget QDockWidget *eventsDock = AnalyzerManager::createDockWidget
(d->profilerTool, d->eventsView); (QmlProfilerToolId, d->eventsView);
QDockWidget *timelineDock = AnalyzerManager::createDockWidget QDockWidget *timelineDock = AnalyzerManager::createDockWidget
(d->profilerTool, d->traceView); (QmlProfilerToolId, d->traceView);
QDockWidget *v8profilerDock = AnalyzerManager::createDockWidget QDockWidget *v8profilerDock = AnalyzerManager::createDockWidget
(d->profilerTool, d->v8profilerView); (QmlProfilerToolId, d->v8profilerView);
eventsDock->show(); eventsDock->show();
timelineDock->show(); timelineDock->show();

View File

@@ -104,7 +104,7 @@ public:
QV8ProfilerEventsWidget *q; QV8ProfilerEventsWidget *q;
Analyzer::IAnalyzerTool *m_profilerTool; QmlProfilerTool *m_profilerTool;
QmlProfilerViewManager *m_viewContainer; QmlProfilerViewManager *m_viewContainer;
QV8ProfilerEventsMainView *m_eventTree; QV8ProfilerEventsMainView *m_eventTree;
@@ -115,7 +115,7 @@ public:
}; };
QV8ProfilerEventsWidget::QV8ProfilerEventsWidget(QWidget *parent, QV8ProfilerEventsWidget::QV8ProfilerEventsWidget(QWidget *parent,
Analyzer::IAnalyzerTool *profilerTool, QmlProfilerTool *profilerTool,
QmlProfilerViewManager *container, QmlProfilerViewManager *container,
QmlProfilerModelManager *profilerModelManager ) QmlProfilerModelManager *profilerModelManager )
: QWidget(parent), d(new QV8ProfilerEventsWidgetPrivate(this)) : QWidget(parent), d(new QV8ProfilerEventsWidgetPrivate(this))

View File

@@ -55,7 +55,7 @@ class QV8ProfilerEventsWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit QV8ProfilerEventsWidget(QWidget *parent, explicit QV8ProfilerEventsWidget(QWidget *parent,
Analyzer::IAnalyzerTool *profilerTool, QmlProfilerTool *profilerTool,
QmlProfilerViewManager *container, QmlProfilerViewManager *container,
QmlProfilerModelManager *profilerModelManager ); QmlProfilerModelManager *profilerModelManager );
~QV8ProfilerEventsWidget(); ~QV8ProfilerEventsWidget();

View File

@@ -500,7 +500,7 @@ static QToolButton *createToolButton(QAction *action)
} }
CallgrindTool::CallgrindTool(QObject *parent) CallgrindTool::CallgrindTool(QObject *parent)
: IAnalyzerTool(parent) : QObject(parent)
{ {
d = new CallgrindToolPrivate(this); d = new CallgrindToolPrivate(this);
setObjectName(QLatin1String("CallgrindTool")); setObjectName(QLatin1String("CallgrindTool"));
@@ -643,11 +643,11 @@ QWidget *CallgrindToolPrivate::createWidgets()
updateCostFormat(); updateCostFormat();
QDockWidget *callersDock = AnalyzerManager::createDockWidget(q, m_callersView); QDockWidget *callersDock = AnalyzerManager::createDockWidget(CallgrindToolId, m_callersView);
QDockWidget *flatDock = AnalyzerManager::createDockWidget(q, m_flatView); QDockWidget *flatDock = AnalyzerManager::createDockWidget(CallgrindToolId, m_flatView);
QDockWidget *calleesDock = AnalyzerManager::createDockWidget(q, m_calleesView); QDockWidget *calleesDock = AnalyzerManager::createDockWidget(CallgrindToolId, m_calleesView);
QDockWidget *visualizationDock = AnalyzerManager::createDockWidget QDockWidget *visualizationDock = AnalyzerManager::createDockWidget
(q, m_visualisation, Qt::RightDockWidgetArea); (CallgrindToolId, m_visualisation, Qt::RightDockWidgetArea);
callersDock->show(); callersDock->show();
calleesDock->show(); calleesDock->show();
@@ -925,7 +925,7 @@ void CallgrindToolPrivate::handleShowCostsOfFunction()
m_toggleCollectFunction = qualifiedFunctionName + QLatin1String("()"); m_toggleCollectFunction = qualifiedFunctionName + QLatin1String("()");
AnalyzerManager::selectTool(q, StartLocal); AnalyzerManager::selectTool(CallgrindToolId, StartLocal);
AnalyzerManager::startTool(); AnalyzerManager::startTool();
} }

View File

@@ -36,9 +36,11 @@
namespace Valgrind { namespace Valgrind {
namespace Internal { namespace Internal {
const char CallgrindToolId[] = "Callgrind";
class CallgrindToolPrivate; class CallgrindToolPrivate;
class CallgrindTool : public Analyzer::IAnalyzerTool class CallgrindTool : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@@ -187,7 +187,7 @@ static void initKindFilterAction(QAction *action, const QList<int> &kinds)
} }
MemcheckTool::MemcheckTool(QObject *parent) MemcheckTool::MemcheckTool(QObject *parent)
: IAnalyzerTool(parent) : QObject(parent)
{ {
m_settings = 0; m_settings = 0;
m_errorModel = 0; m_errorModel = 0;
@@ -358,7 +358,7 @@ QWidget *MemcheckTool::createWidgets()
m_errorView->setObjectName(QLatin1String("Valgrind.MemcheckTool.ErrorView")); m_errorView->setObjectName(QLatin1String("Valgrind.MemcheckTool.ErrorView"));
m_errorView->setWindowTitle(tr("Memory Issues")); m_errorView->setWindowTitle(tr("Memory Issues"));
QDockWidget *errorDock = AnalyzerManager::createDockWidget(this, m_errorView); QDockWidget *errorDock = AnalyzerManager::createDockWidget("Memcheck", m_errorView);
errorDock->show(); errorDock->show();
mw->splitDockWidget(mw->toolBarDockWidget(), errorDock, Qt::Vertical); mw->splitDockWidget(mw->toolBarDockWidget(), errorDock, Qt::Vertical);

View File

@@ -76,13 +76,19 @@ private:
bool m_filterExternalIssues; bool m_filterExternalIssues;
}; };
class MemcheckTool : public Analyzer::IAnalyzerTool class MemcheckTool : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
MemcheckTool(QObject *parent); MemcheckTool(QObject *parent);
void startTool(Analyzer::StartMode mode);
QWidget *createWidgets();
Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0);
private slots: private slots:
void settingsDestroyed(QObject *settings); void settingsDestroyed(QObject *settings);
void maybeActiveRunConfigurationChanged(); void maybeActiveRunConfigurationChanged();
@@ -99,8 +105,6 @@ private slots:
void loadExternalXmlLogFile(); void loadExternalXmlLogFile();
private: private:
void startTool(Analyzer::StartMode mode);
QWidget *createWidgets();
void setBusyCursor(bool busy); void setBusyCursor(bool busy);
void clearErrorView(); void clearErrorView();
@@ -108,9 +112,6 @@ private:
int updateUiAfterFinishedHelper(); int updateUiAfterFinishedHelper();
protected: protected:
Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0);
virtual MemcheckRunControl *createMemcheckRunControl( virtual MemcheckRunControl *createMemcheckRunControl(
const Analyzer::AnalyzerStartParameters &sp, const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration); ProjectExplorer::RunConfiguration *runConfiguration);
@@ -138,7 +139,6 @@ class MemcheckWithGdbTool : public MemcheckTool
public: public:
MemcheckWithGdbTool(QObject *parent); MemcheckWithGdbTool(QObject *parent);
protected:
void startTool(Analyzer::StartMode mode); void startTool(Analyzer::StartMode mode);
MemcheckRunControl *createMemcheckRunControl( MemcheckRunControl *createMemcheckRunControl(
const Analyzer::AnalyzerStartParameters &sp, const Analyzer::AnalyzerStartParameters &sp,

View File

@@ -124,10 +124,37 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
"Valgrind Analyze Memory with GDB uses the \"memcheck\" tool to find memory leaks.\n" "Valgrind Analyze Memory with GDB uses the \"memcheck\" tool to find memory leaks.\n"
"When a problem is detected, the application is interrupted and can be debugged"); "When a problem is detected, the application is interrupted and can be debugged");
MemcheckTool *mcTool = m_memcheckTool;
auto mcToolStarter = [mcTool](StartMode mode) { return mcTool->startTool(mode); };
auto mcWidgetCreator = [mcTool] { return mcTool->createWidgets(); };
auto mcRunControlCreator = [mcTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) {
return mcTool->createRunControl(sp, runConfiguration);
};
MemcheckWithGdbTool *mcgTool = m_memcheckWithGdbTool;
auto mcgToolStarter = [mcgTool](StartMode mode) { return mcgTool->startTool(mode); };
auto mcgWidgetCreator = [mcgTool] { return mcgTool->createWidgets(); };
auto mcgRunControlCreator = [mcgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) {
return mcgTool->createRunControl(sp, runConfiguration);
};
CallgrindTool *cgTool = m_callgrindTool;
auto cgToolStarter = [cgTool](StartMode mode) { return cgTool->startTool(mode); };
auto cgWidgetCreator = [cgTool] { return cgTool->createWidgets(); };
auto cgRunControlCreator = [cgTool](const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration) {
return cgTool->createRunControl(sp, runConfiguration);
};
if (!Utils::HostOsInfo::isWindowsHost()) { if (!Utils::HostOsInfo::isWindowsHost()) {
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("Memcheck.Local"); action->setActionId("Memcheck.Local");
action->setTool(m_memcheckTool); action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter(mcToolStarter);
action->setRunMode(ProjectExplorer::MemcheckRunMode); action->setRunMode(ProjectExplorer::MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer")); action->setText(tr("Valgrind Memory Analyzer"));
action->setToolTip(memcheckToolTip); action->setToolTip(memcheckToolTip);
@@ -137,8 +164,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("MemcheckWithGdb.Local"); action->setActionId("MemcheckWithGdb.Local");
action->setTool(m_memcheckWithGdbTool); action->setToolId("MemcheckWithGdb");
action->setWidgetCreator(mcgWidgetCreator);
action->setRunControlCreator(mcgRunControlCreator);
action->setToolStarter(mcgToolStarter);
action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode); action->setRunMode(ProjectExplorer::MemcheckWithGdbRunMode);
action->setText(tr("Valgrind Memory Analyzer with GDB")); action->setText(tr("Valgrind Memory Analyzer with GDB"));
action->setToolTip(memcheckWithGdbToolTip); action->setToolTip(memcheckWithGdbToolTip);
@@ -148,8 +178,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("Callgrind.Local"); action->setActionId("Callgrind.Local");
action->setTool(m_callgrindTool); action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter(cgToolStarter);
action->setRunMode(ProjectExplorer::CallgrindRunMode); action->setRunMode(ProjectExplorer::CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler")); action->setText(tr("Valgrind Function Profiler"));
action->setToolTip(callgrindToolTip); action->setToolTip(callgrindToolTip);
@@ -160,8 +193,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
} }
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("Memcheck.Remote"); action->setActionId("Memcheck.Remote");
action->setTool(m_memcheckTool); action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator);
action->setRunControlCreator(mcRunControlCreator);
action->setToolStarter(mcToolStarter);
action->setRunMode(ProjectExplorer::MemcheckRunMode); action->setRunMode(ProjectExplorer::MemcheckRunMode);
action->setText(tr("Valgrind Memory Analyzer (External Remote Application)")); action->setText(tr("Valgrind Memory Analyzer (External Remote Application)"));
action->setToolTip(memcheckToolTip); action->setToolTip(memcheckToolTip);
@@ -170,8 +206,11 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
AnalyzerManager::addAction(action); AnalyzerManager::addAction(action);
action = new AnalyzerAction(this); action = new AnalyzerAction(this);
action->setId("Callgrind.Remote"); action->setActionId("Callgrind.Remote");
action->setTool(m_callgrindTool); action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator);
action->setRunControlCreator(cgRunControlCreator);
action->setToolStarter(cgToolStarter);
action->setRunMode(ProjectExplorer::CallgrindRunMode); action->setRunMode(ProjectExplorer::CallgrindRunMode);
action->setText(tr("Valgrind Function Profiler (External Remote Application)")); action->setText(tr("Valgrind Function Profiler (External Remote Application)"));
action->setToolTip(callgrindToolTip); action->setToolTip(callgrindToolTip);