Commit 09f89d52 authored by Milian Wolff's avatar Milian Wolff Committed by hjk

enable adding custom config widgets from a run control factory

To achieve this there are two methods in IRunControlFactory you
need to implement:

1) createRunConfigurationAspect returns a IRunConfigurationAspect
which stores the settings specific to your plugin.
2) createConfigurationWidget returns a RunConfigWidget that will
be shown in the project settings

Merge-request: 258
Reviewed-by: default avatarhjk <qtc-committer@nokia.com>
parent f4609310
......@@ -65,7 +65,7 @@ public:
private:
QString displayName() const;
QWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
ProjectExplorer::RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
const unsigned m_enabledEngines;
};
......
......@@ -704,7 +704,7 @@ RunControl *DebuggerRunControlFactory::create
return create(sp, runConfiguration);
}
QWidget *DebuggerRunControlFactory::createConfigurationWidget
RunConfigWidget *DebuggerRunControlFactory::createConfigurationWidget
(RunConfiguration *runConfiguration)
{
// NBS TODO: Add GDB-specific configuration widget
......
......@@ -70,10 +70,10 @@ RunControl *LocalApplicationRunControlFactory::create(ProjectExplorer::RunConfig
return new LocalApplicationRunControl(qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration), mode);
}
QWidget *LocalApplicationRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
RunConfigWidget *LocalApplicationRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
{
Q_UNUSED(runConfiguration)
return new QLabel("TODO add Configuration widget");
return 0;
}
// ApplicationRunControl
......
......@@ -51,7 +51,7 @@ public:
virtual bool canRun(RunConfiguration *runConfiguration, const QString &mode) const;
virtual QString displayName() const;
virtual RunControl* create(RunConfiguration *runConfiguration, const QString &mode);
virtual QWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
virtual RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
};
class LocalApplicationRunControl : public RunControl
......
......@@ -160,6 +160,7 @@ RunConfiguration::RunConfiguration(Target *target, const QString &id) :
m_qmlDebugServerPort(Constants::QML_DEFAULT_DEBUG_SERVER_PORT)
{
Q_ASSERT(target);
addExtraAspects();
}
RunConfiguration::RunConfiguration(Target *target, RunConfiguration *source) :
......@@ -168,10 +169,20 @@ RunConfiguration::RunConfiguration(Target *target, RunConfiguration *source) :
m_useQmlDebugger(source->useQmlDebugger())
{
Q_ASSERT(target);
addExtraAspects();
}
RunConfiguration::~RunConfiguration()
{
qDeleteAll(m_aspects);
}
void RunConfiguration::addExtraAspects()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
foreach (IRunControlFactory *factory, pm->getObjects<IRunControlFactory>())
if (IRunConfigurationAspect *aspect = factory->createRunConfigurationAspect())
m_aspects.append(aspect);
}
bool RunConfiguration::isEnabled(BuildConfiguration *bc) const
......@@ -239,6 +250,9 @@ QVariantMap RunConfiguration::toMap() const
map.insert(QLatin1String(USE_CPP_DEBUGGER_KEY), m_useCppDebugger);
map.insert(QLatin1String(USE_QML_DEBUGGER_KEY), m_useQmlDebugger);
map.insert(QLatin1String(QML_DEBUG_SERVER_PORT_KEY), m_qmlDebugServerPort);
foreach (IRunConfigurationAspect *aspect, m_aspects)
map.unite(aspect->toMap());
return map;
}
......@@ -259,9 +273,18 @@ bool RunConfiguration::fromMap(const QVariantMap &map)
m_useQmlDebugger = map.value(QLatin1String(USE_QML_DEBUGGER_KEY), false).toBool();
m_qmlDebugServerPort = map.value(QLatin1String(QML_DEBUG_SERVER_PORT_KEY), Constants::QML_DEFAULT_DEBUG_SERVER_PORT).toUInt();
foreach (IRunConfigurationAspect *aspect, m_aspects)
if (!aspect->fromMap(map))
return false;
return ProjectConfiguration::fromMap(map);
}
QList<IRunConfigurationAspect *> RunConfiguration::extraAspects() const
{
return m_aspects;
}
ProjectExplorer::OutputFormatter *RunConfiguration::createOutputFormatter() const
{
return new OutputFormatter();
......@@ -303,6 +326,11 @@ IRunControlFactory::~IRunControlFactory()
{
}
IRunConfigurationAspect *IRunControlFactory::createRunConfigurationAspect()
{
return 0;
}
RunControl::RunControl(RunConfiguration *runConfiguration, QString mode)
: m_runMode(mode), m_runConfiguration(runConfiguration), m_outputFormatter(0)
{
......
......@@ -41,10 +41,10 @@
#include <QtCore/QMetaType>
#include <QtCore/QWeakPointer>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QString;
class QWidget;
QT_END_NAMESPACE
namespace ProjectExplorer {
......@@ -54,6 +54,7 @@ class Target;
class RunControl;
class BuildConfiguration;
class OutputFormatter;
class IRunConfigurationAspect;
/**
* Base class for a run configuration. A run configuration specifies how a
......@@ -103,6 +104,22 @@ public:
virtual QVariantMap toMap() const;
// aspects are a mechanism to add RunControl-specific options to a RunConfiguration without
// subclassing the RunConfiguration for every addition, preventing a combinatorical explosion
// of subclasses or the need to add all options to the base class.
QList<IRunConfigurationAspect *> extraAspects() const;
template <typename T> T *extraAspect() const
{
IRunConfigurationAspect *typeCheck = static_cast<T *>(0);
Q_UNUSED(typeCheck);
T *result = 0;
foreach (IRunConfigurationAspect *a, m_aspects) {
if ((result = dynamic_cast<T *>(a)) != 0)
break;
}
return result;
}
virtual ProjectExplorer::Abi abi() const;
signals:
......@@ -120,9 +137,23 @@ protected:
virtual bool fromMap(const QVariantMap &map);
private:
void addExtraAspects();
bool m_useCppDebugger;
bool m_useQmlDebugger;
uint m_qmlDebugServerPort;
QList<IRunConfigurationAspect *> m_aspects;
};
class PROJECTEXPLORER_EXPORT IRunConfigurationAspect
{
public:
virtual ~IRunConfigurationAspect() {}
virtual QVariantMap toMap() const = 0;
virtual QString displayName() const = 0;
protected:
friend class RunConfiguration;
virtual bool fromMap(const QVariantMap &map) = 0;
};
/**
......@@ -163,6 +194,8 @@ signals:
void availableCreationIdsChanged();
};
class RunConfigWidget;
class PROJECTEXPLORER_EXPORT IRunControlFactory : public QObject
{
Q_OBJECT
......@@ -175,8 +208,31 @@ public:
virtual QString displayName() const = 0;
/// Returns the widget used to configure this runner. Ownership is transferred to the caller
virtual QWidget *createConfigurationWidget(RunConfiguration *runConfiguration) = 0;
/// Return an IRunConfigurationAspect to carry options for RunControls this factory can create.
/// If no extra options are required it is allowed to return null like the default implementation does.
/// This is intended to be called from the RunConfiguration constructor, so passing a RunConfiguration
/// pointer makes no sense because that object is under construction at the time.
virtual IRunConfigurationAspect *createRunConfigurationAspect();
/// Return a widget used to configure this runner. Ownership is transferred to the caller.
/// If @p runConfiguration is not suitable for RunControls from this factory, or no user-accesible
/// configuration is required, return null.
virtual RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration) = 0;
};
class PROJECTEXPLORER_EXPORT RunConfigWidget
: public QWidget
{
Q_OBJECT
public:
RunConfigWidget()
: QWidget(0)
{}
virtual QString displayName() const = 0;
signals:
void displayNameChanged(const QString &);
};
/**
......
......@@ -204,15 +204,6 @@ RunSettingsWidget::RunSettingsWidget(Target *target)
connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
this, SLOT(activeRunConfigurationChanged()));
// TODO: Add support for custom runner configuration widgets once we have some
/*
QList<IRunControlFactory *> runners = PluginManager::instance()->getObjects<IRunControlFactory>();
foreach (IRunControlFactory * runner, runners) {
if (runner->canRun(activeRunConfiguration))
m_ui->layout->addWidget(runner->createConfigurationWidget(activeRunConfiguration));
}
*/
}
RunSettingsWidget::~RunSettingsWidget()
......@@ -419,10 +410,13 @@ void RunSettingsWidget::setConfigurationWidget(RunConfiguration *rc)
{
delete m_runConfigurationWidget;
m_runConfigurationWidget = 0;
removeSubWidgets();
if (!rc)
return;
m_runConfigurationWidget = m_target->activeRunConfiguration()->createConfigurationWidget();
m_runConfigurationWidget = rc->createConfigurationWidget();
m_runLayout->addWidget(m_runConfigurationWidget);
addRunControlWidgets();
}
QString RunSettingsWidget::uniqueDCName(const QString &name)
......@@ -454,3 +448,47 @@ QString RunSettingsWidget::uniqueRCName(const QString &name)
}
return result;
}
void RunSettingsWidget::addRunControlWidgets()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
foreach (IRunControlFactory *f, pm->getObjects<IRunControlFactory>()) {
ProjectExplorer::RunConfigWidget *rcw =
f->createConfigurationWidget(m_target->activeRunConfiguration());
if (rcw)
addSubWidget(rcw);
}
}
void RunSettingsWidget::addSubWidget(RunConfigWidget *widget)
{
widget->setContentsMargins(0, 10, 0, 0);
QLabel *label = new QLabel(this);
label->setText(widget->displayName());
connect(widget, SIGNAL(displayNameChanged(QString)),
label, SLOT(setText(QString)));
QFont f = label->font();
f.setBold(true);
f.setPointSizeF(f.pointSizeF() * 1.2);
label->setFont(f);
label->setContentsMargins(0, 10, 0, 0);
QGridLayout *l = m_ui->gridLayout;
l->addWidget(label, l->rowCount(), 0, 1, -1);
l->addWidget(widget, l->rowCount(), 0, 1, -1);
m_subWidgets.append(qMakePair(widget, label));
}
void RunSettingsWidget::removeSubWidgets()
{
// foreach does not like commas in types, it's only a macro after all
typedef QPair<RunConfigWidget *, QLabel *> RunConfigItem;
foreach (const RunConfigItem &item, m_subWidgets) {
delete item.first;
delete item.second;
}
m_subWidgets.clear();
}
......@@ -52,6 +52,7 @@ class DeployConfigurationWidget;
class DeployConfigurationModel;
class RunConfiguration;
class RunConfigurationModel;
class RunConfigWidget;
namespace Internal {
......@@ -115,6 +116,10 @@ private:
void updateDeployConfiguration(DeployConfiguration *);
void setConfigurationWidget(RunConfiguration *rc);
void addRunControlWidgets();
void addSubWidget(RunConfigWidget *subWidget);
void removeSubWidgets();
Target *m_target;
RunConfigurationModel *m_runConfigurationsModel;
DeployConfigurationModel *m_deployConfigurationModel;
......@@ -127,6 +132,7 @@ private:
QMenu *m_addRunMenu;
QMenu *m_addDeployMenu;
bool m_ignoreChange;
QList<QPair<RunConfigWidget *, QLabel *> > m_subWidgets;
};
} // namespace Internal
......
......@@ -180,10 +180,10 @@ QString QmlRunControlFactory::displayName() const
return tr("Run");
}
QWidget *QmlRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
ProjectExplorer::RunConfigWidget *QmlRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
{
Q_UNUSED(runConfiguration)
return new QLabel("TODO add Configuration widget");
return 0;
}
RunControl *QmlRunControlFactory::createDebugRunControl(QmlProjectRunConfiguration *runConfig)
......
......@@ -77,7 +77,8 @@ public:
virtual bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) const;
virtual ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode);
virtual QString displayName() const;
virtual QWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration *runConfiguration);
virtual ProjectExplorer::RunConfigWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration
*runConfiguration);
private:
ProjectExplorer::RunControl *createDebugRunControl(QmlProjectRunConfiguration *runConfig);
......
......@@ -202,7 +202,7 @@ QString MaemoRunControlFactory::displayName() const
return tr("Run on device");
}
QWidget *MaemoRunControlFactory::createConfigurationWidget(RunConfiguration *config)
RunConfigWidget *MaemoRunControlFactory::createConfigurationWidget(RunConfiguration *config)
{
Q_UNUSED(config)
return 0;
......
......@@ -44,6 +44,7 @@ namespace ProjectExplorer {
using ProjectExplorer::IRunConfigurationFactory;
using ProjectExplorer::IRunControlFactory;
using ProjectExplorer::RunConfiguration;
using ProjectExplorer::RunConfigWidget;
using ProjectExplorer::RunControl;
using ProjectExplorer::Target;
......@@ -79,7 +80,7 @@ public:
~MaemoRunControlFactory();
QString displayName() const;
QWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
RunConfigWidget *createConfigurationWidget(RunConfiguration *runConfiguration);
bool canRun(RunConfiguration *runConfiguration, const QString &mode) const;
RunControl *create(RunConfiguration *runConfiguration, const QString &mode);
......
......@@ -541,7 +541,7 @@ QString S60DeviceDebugRunControlFactory::displayName() const
return tr("Debug on Device");
}
QWidget *S60DeviceDebugRunControlFactory::createConfigurationWidget(ProjectExplorer::RunConfiguration * /*runConfiguration */)
ProjectExplorer::RunConfigWidget *S60DeviceDebugRunControlFactory::createConfigurationWidget(RunConfiguration* /*runConfiguration */)
{
return 0;
}
......@@ -150,7 +150,7 @@ public:
ProjectExplorer::RunControl* create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode);
QString displayName() const;
QWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration * /*runConfiguration */);
ProjectExplorer::RunConfigWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration * /*runConfiguration */);
};
} // namespace Internal
......
......@@ -95,7 +95,7 @@ public:
return m_name;
}
QWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration * /*runConfiguration */) {
ProjectExplorer::RunConfigWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration *) {
return 0;
}
......
......@@ -84,7 +84,7 @@ QString S60RunControlFactory::displayName() const
return m_name;
}
QWidget *S60RunControlFactory::createConfigurationWidget(RunConfiguration * /*S60DeviceRunConfiguration */)
RunConfigWidget *S60RunControlFactory::createConfigurationWidget(RunConfiguration* runConfiguration /*S60DeviceRunConfiguration */)
{
return 0;
}
......@@ -52,7 +52,7 @@ public:
QString displayName() const;
QWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration *runConfiguration);
ProjectExplorer::RunConfigWidget *createConfigurationWidget(ProjectExplorer::RunConfiguration *runConfiguration);
private:
const QString m_mode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment