Analyzer: create a run control factory for all tools.

Having one factory per tool (or plugin) created some bugs:
 * analyzer project settings being created twice
 * per-project analyzer settings widget duplicated
Also, most of the code from the run control factory were copied.

Now, the Analyzer only creates one run control factory shared among all tools, and the IAnalyzerTool
has two new virtual method: canRun and createStartParameters. It simplify the code a bit, and
creating a new analyzer tool is easier (only two classes to subclass: IAnalyzerTool and IAnalyzerEngine).

Change-Id: I4e180846a26b74b2b77cb99bc97534d680a80a4d
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Nicolas Arnaud-Cormos
2011-12-27 22:41:31 +01:00
committed by hjk
parent 26ae954fae
commit 4a8432112a
21 changed files with 424 additions and 326 deletions

View File

@@ -497,7 +497,7 @@ static QToolButton *createToolButton(QAction *action)
}
CallgrindTool::CallgrindTool(QObject *parent)
: Analyzer::IAnalyzerTool(parent)
: ValgrindTool(parent)
{
d = new CallgrindToolPrivate(this);
setObjectName(QLatin1String("CallgrindTool"));

View File

@@ -33,14 +33,14 @@
#ifndef CALLGRINDTOOL_H
#define CALLGRINDTOOL_H
#include <analyzerbase/ianalyzertool.h>
#include "valgrindtool.h"
namespace Valgrind {
namespace Internal {
class CallgrindToolPrivate;
class CallgrindTool : public Analyzer::IAnalyzerTool
class CallgrindTool : public ValgrindTool
{
Q_OBJECT

View File

@@ -185,7 +185,7 @@ static void initKindFilterAction(QAction *action, const QList<int> &kinds)
}
MemcheckTool::MemcheckTool(QObject *parent)
: Analyzer::IAnalyzerTool(parent)
: ValgrindTool(parent)
{
m_settings = 0;
m_errorModel = 0;

View File

@@ -35,7 +35,7 @@
#ifndef MEMCHECKTOOL_H
#define MEMCHECKTOOL_H
#include <analyzerbase/ianalyzertool.h>
#include "valgrindtool.h"
#include <QtGui/QSortFilterProxyModel>
#include <QtCore/QSharedPointer>
@@ -86,7 +86,7 @@ private:
bool m_filterExternalIssues;
};
class MemcheckTool : public Analyzer::IAnalyzerTool
class MemcheckTool : public ValgrindTool
{
Q_OBJECT

View File

@@ -30,7 +30,8 @@ HEADERS += \
memchecktool.h \
memcheckengine.h \
memcheckerrorview.h \
suppressiondialog.h
suppressiondialog.h \
valgrindtool.h
SOURCES += \
valgrindplugin.cpp \
@@ -52,7 +53,8 @@ SOURCES += \
memchecktool.cpp \
memcheckengine.cpp \
memcheckerrorview.cpp \
suppressiondialog.cpp
suppressiondialog.cpp \
valgrindtool.cpp
FORMS += \
valgrindconfigwidget.ui

View File

@@ -59,112 +59,12 @@
#include <QtGui/QAction>
using namespace Analyzer;
using namespace Valgrind::Internal;
using namespace ProjectExplorer;
/////////////////////////////////////////////////////////////////////////////////
//
// ValgrindRunControlFactory
//
/////////////////////////////////////////////////////////////////////////////////
namespace Valgrind {
namespace Internal {
class ValgrindRunControlFactory : public ProjectExplorer::IRunControlFactory
{
Q_OBJECT
public:
ValgrindRunControlFactory(QObject *parent = 0);
// IRunControlFactory
bool canRun(RunConfiguration *runConfiguration, const QString &mode) const;
RunControl *create(RunConfiguration *runConfiguration, const QString &mode);
QString displayName() const;
IRunConfigurationAspect *createRunConfigurationAspect();
RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
};
ValgrindRunControlFactory::ValgrindRunControlFactory(QObject *parent)
: IRunControlFactory(parent)
{
setObjectName(QLatin1String("ValgrindRunControlFactory"));
}
bool ValgrindRunControlFactory::canRun(RunConfiguration *runConfiguration, const QString &mode) const
{
Q_UNUSED(runConfiguration);
return mode.startsWith("Callgrind") || mode.startsWith("Memcheck");
}
RunControl *ValgrindRunControlFactory::create(RunConfiguration *runConfiguration, const QString &mode)
{
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
AnalyzerStartParameters sp;
if (LocalApplicationRunConfiguration *rc1 =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) {
sp.startMode = StartLocal;
sp.environment = rc1->environment();
sp.workingDirectory = rc1->workingDirectory();
sp.debuggee = rc1->executable();
sp.debuggeeArgs = rc1->commandLineArguments();
sp.displayName = rc1->displayName();
sp.connParams.host = QLatin1String("localhost");
sp.connParams.port = rc1->qmlDebugServerPort();
} else if (RemoteLinux::RemoteLinuxRunConfiguration *rc2 =
qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration)) {
sp.startMode = StartRemote;
sp.debuggee = rc2->remoteExecutableFilePath();
sp.debuggeeArgs = rc2->arguments();
sp.connParams = rc2->deviceConfig()->sshParameters();
sp.analyzerCmdPrefix = rc2->commandPrefix();
sp.displayName = rc2->displayName();
} else {
// Might be S60DeviceRunfiguration, or something else ...
//sp.startMode = StartRemote;
sp.startMode = StartRemote;
}
IAnalyzerTool *tool = AnalyzerManager::toolFromId(Core::Id(mode));
AnalyzerRunControl *rc = new AnalyzerRunControl(tool, sp, runConfiguration);
QObject::connect(AnalyzerManager::stopAction(), SIGNAL(triggered()), rc, SLOT(stopIt()));
return rc;
}
QString ValgrindRunControlFactory::displayName() const
{
return tr("Analyzer");
}
IRunConfigurationAspect *ValgrindRunControlFactory::createRunConfigurationAspect()
{
return new AnalyzerProjectSettings;
}
RunConfigWidget *ValgrindRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
{
LocalApplicationRunConfiguration *localRc =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
if (!localRc)
return 0;
AnalyzerProjectSettings *settings = runConfiguration->extraAspect<AnalyzerProjectSettings>();
if (!settings)
return 0;
AnalyzerRunConfigWidget *ret = new AnalyzerRunConfigWidget;
ret->setRunConfiguration(runConfiguration);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////
//
// ValgrindPlugin
//
/////////////////////////////////////////////////////////////////////////////////
static void startRemoteTool(IAnalyzerTool *tool)
{
Q_UNUSED(tool);
@@ -219,9 +119,6 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
AnalyzerManager::addTool(new MemcheckTool(this), modes);
AnalyzerManager::addTool(new CallgrindTool(this), modes);
ValgrindRunControlFactory *factory = new ValgrindRunControlFactory();
addAutoReleasedObject(factory);
return true;
}
@@ -230,5 +127,3 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *)
Q_EXPORT_PLUGIN(Valgrind::Internal::ValgrindPlugin)
#include "valgrindplugin.moc"

View File

@@ -0,0 +1,91 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (C) 2011 Kläralvdalens Datakonsult AB, a KDAB Group company.
**
** Contact: Kläralvdalens Datakonsult AB (info@kdab.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "valgrindtool.h"
#include <remotelinux/remotelinuxrunconfiguration.h>
#include <remotelinux/linuxdeviceconfiguration.h>
#include <projectexplorer/applicationrunconfiguration.h>
#include <projectexplorer/projectexplorer.h>
using namespace ProjectExplorer;
using namespace RemoteLinux;
namespace Valgrind {
namespace Internal {
ValgrindTool::ValgrindTool(QObject *parent) :
Analyzer::IAnalyzerTool(parent)
{
}
bool ValgrindTool::canRun(ProjectExplorer::RunConfiguration *, const QString &) const
{
return true;
}
Analyzer::AnalyzerStartParameters ValgrindTool::createStartParameters(
ProjectExplorer::RunConfiguration *runConfiguration,
const QString &mode) const
{
Q_UNUSED(mode);
Analyzer::AnalyzerStartParameters sp;
if (LocalApplicationRunConfiguration *rc1 =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) {
sp.startMode = Analyzer::StartLocal;
sp.environment = rc1->environment();
sp.workingDirectory = rc1->workingDirectory();
sp.debuggee = rc1->executable();
sp.debuggeeArgs = rc1->commandLineArguments();
sp.displayName = rc1->displayName();
sp.connParams.host = QLatin1String("localhost");
sp.connParams.port = rc1->qmlDebugServerPort();
} else if (RemoteLinuxRunConfiguration *rc2 =
qobject_cast<RemoteLinuxRunConfiguration *>(runConfiguration)) {
sp.startMode = Analyzer::StartRemote;
sp.debuggee = rc2->remoteExecutableFilePath();
sp.debuggeeArgs = rc2->arguments();
sp.connParams = rc2->deviceConfig()->sshParameters();
sp.analyzerCmdPrefix = rc2->commandPrefix();
sp.displayName = rc2->displayName();
} else {
// Might be S60DeviceRunfiguration, or something else ...
//sp.startMode = StartRemote;
sp.startMode = Analyzer::StartRemote;
}
return sp;
}
} // namespace Internal
} // namespace Valgrind

View File

@@ -0,0 +1,58 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (C) 2011 Kläralvdalens Datakonsult AB, a KDAB Group company.
**
** Contact: Kläralvdalens Datakonsult AB (info@kdab.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef VALGRINDTOOL_H
#define VALGRINDTOOL_H
#include <analyzerbase/ianalyzertool.h>
namespace Valgrind {
namespace Internal {
class ValgrindTool : public Analyzer::IAnalyzerTool
{
Q_OBJECT
public:
explicit ValgrindTool(QObject *parent);
bool canRun(ProjectExplorer::RunConfiguration *runConfiguration,
const QString &mode) const;
Analyzer::AnalyzerStartParameters createStartParameters(
ProjectExplorer::RunConfiguration *runConfiguration,
const QString &mode) const;
};
} // namespace Internal
} // namespace Valgrind
#endif // VALGRINDTOOL_H