Commit 3ddb7b02 authored by con's avatar con
Browse files

API review of IRunConfigurationFactory.

Done with dt.
parent 9c780195
......@@ -313,7 +313,7 @@ CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
}
// used to recreate the runConfigurations when restoring settings
bool CMakeRunConfigurationFactory::canCreate(const QString &type) const
bool CMakeRunConfigurationFactory::canRestore(const QString &type) const
{
if (type.startsWith(Constants::CMAKERUNCONFIGURATION))
return true;
......@@ -321,7 +321,7 @@ bool CMakeRunConfigurationFactory::canCreate(const QString &type) const
}
// used to show the list of possible additons to a project, returns a list of types
QStringList CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *project) const
QStringList CMakeRunConfigurationFactory::availableCreationTypes(ProjectExplorer::Project *project) const
{
CMakeProject *pro = qobject_cast<CMakeProject *>(project);
if (!pro)
......@@ -334,7 +334,7 @@ QStringList CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *pr
}
// used to translate the types to names to display to the user
QString CMakeRunConfigurationFactory::nameForType(const QString &type) const
QString CMakeRunConfigurationFactory::displayNameForType(const QString &type) const
{
Q_ASSERT(type.startsWith(Constants::CMAKERUNCONFIGURATION));
......
......@@ -119,11 +119,11 @@ public:
CMakeRunConfigurationFactory();
virtual ~CMakeRunConfigurationFactory();
// used to recreate the runConfigurations when restoring settings
virtual bool canCreate(const QString &type) const;
virtual bool canRestore(const QString &type) const;
// used to show the list of possible additons to a project, returns a list of types
virtual QStringList canCreate(ProjectExplorer::Project *pro) const;
virtual QStringList availableCreationTypes(ProjectExplorer::Project *pro) const;
// used to translate the types to names to display to the user
virtual QString nameForType(const QString &type) const;
virtual QString displayNameForType(const QString &type) const;
virtual QSharedPointer<ProjectExplorer::RunConfiguration> create(ProjectExplorer::Project *project, const QString &type);
};
......
......@@ -472,7 +472,7 @@ CustomExecutableRunConfigurationFactory::~CustomExecutableRunConfigurationFactor
}
// used to recreate the runConfigurations when restoring settings
bool CustomExecutableRunConfigurationFactory::canCreate(const QString &type) const
bool CustomExecutableRunConfigurationFactory::canRestore(const QString &type) const
{
return type == "ProjectExplorer.CustomExecutableRunConfiguration";
}
......@@ -488,13 +488,13 @@ QSharedPointer<RunConfiguration> CustomExecutableRunConfigurationFactory::create
}
}
QStringList CustomExecutableRunConfigurationFactory::canCreate(Project *pro) const
QStringList CustomExecutableRunConfigurationFactory::availableCreationTypes(Project *pro) const
{
Q_UNUSED(pro)
return QStringList()<< "ProjectExplorer.CustomExecutableRunConfiguration";
}
QString CustomExecutableRunConfigurationFactory::nameForType(const QString &type) const
QString CustomExecutableRunConfigurationFactory::displayNameForType(const QString &type) const
{
if (type == "ProjectExplorer.CustomExecutableRunConfiguration")
return tr("Custom Executable");
......
......@@ -128,10 +128,10 @@ public:
CustomExecutableRunConfigurationFactory();
virtual ~CustomExecutableRunConfigurationFactory();
// used to recreate the runConfigurations when restoring settings
virtual bool canCreate(const QString &type) const;
virtual bool canRestore(const QString &type) const;
virtual QSharedPointer<RunConfiguration> create(Project *project, const QString &type);
QStringList canCreate(Project *pro) const;
QString nameForType(const QString &type) const;
QStringList availableCreationTypes(Project *pro) const;
QString displayNameForType(const QString &type) const;
};
namespace Internal {
......
......@@ -361,7 +361,7 @@ void Project::restoreSettingsImpl(PersistentSettingsReader &reader)
break;
const QString &type = typeVariant.toString();
foreach (IRunConfigurationFactory *factory, factories) {
if (factory->canCreate(type)) {
if (factory->canRestore(type)) {
QSharedPointer<RunConfiguration> rc = factory->create(this, type);
rc->restore(reader);
addRunConfiguration(rc);
......
......@@ -90,10 +90,10 @@ private:
/* The run configuration factory is used for restoring run configurations from
* settings. And used to create new runconfigurations in the "Run Settings" Dialog.
* For the first case bool canCreate(const QString &type) and
* For the first case bool canRestore(const QString &type) and
* QSharedPointer<RunConfiguration> create(Project *project, QString type) are used.
* For the second type the functions QStringList canCreate(Project *pro) and
* QString nameForType(const QString&) are used to generate a list of creatable
* For the second type the functions QStringList availableCreationTypes(Project *pro) and
* QString displayNameForType(const QString&) are used to generate a list of creatable
* RunConfigurations, and create(..) is used to create it.
*/
class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject
......@@ -103,11 +103,12 @@ public:
IRunConfigurationFactory();
virtual ~IRunConfigurationFactory();
// used to recreate the runConfigurations when restoring settings
virtual bool canCreate(const QString &type) const = 0;
virtual bool canRestore(const QString &type) const = 0;
// used to show the list of possible additons to a project, returns a list of types
virtual QStringList canCreate(Project *pro) const = 0;
virtual QStringList availableCreationTypes(Project *pro) const = 0;
// used to translate the types to names to display to the user
virtual QString nameForType(const QString &type) const = 0;
virtual QString displayNameForType(const QString &type) const = 0;
// used to create a run configuration from scratch
virtual QSharedPointer<RunConfiguration> create(Project *project, const QString &type) = 0;
};
......
......@@ -226,9 +226,9 @@ void RunSettingsWidget::aboutToShowAddMenu()
QList<IRunConfigurationFactory *> factories =
ExtensionSystem::PluginManager::instance()->getObjects<IRunConfigurationFactory>();
foreach (IRunConfigurationFactory *factory, factories) {
QStringList types = factory->canCreate(m_project);
QStringList types = factory->availableCreationTypes(m_project);
foreach (const QString &type, types) {
QAction *action = m_addMenu->addAction(factory->nameForType(type));;
QAction *action = m_addMenu->addAction(factory->displayNameForType(type));;
FactoryAndType fat;
fat.factory = factory;
fat.type = type;
......
......@@ -478,7 +478,7 @@ QmlRunConfigurationFactory::~QmlRunConfigurationFactory()
{
}
bool QmlRunConfigurationFactory::canCreate(const QString &type) const
bool QmlRunConfigurationFactory::canRestore(const QString &type) const
{
if (type.startsWith(m_type))
return true;
......@@ -486,12 +486,12 @@ bool QmlRunConfigurationFactory::canCreate(const QString &type) const
return false;
}
QStringList QmlRunConfigurationFactory::canCreate(ProjectExplorer::Project *) const
QStringList QmlRunConfigurationFactory::availableCreationTypes(ProjectExplorer::Project *) const
{
return QStringList();
}
QString QmlRunConfigurationFactory::nameForType(const QString &type) const
QString QmlRunConfigurationFactory::displayNameForType(const QString &type) const
{
return type;
}
......
......@@ -179,13 +179,13 @@ public:
virtual ~QmlRunConfigurationFactory();
// used to recreate the runConfigurations when restoring settings
virtual bool canCreate(const QString &type) const;
virtual bool canRestore(const QString &type) const;
// used to show the list of possible additons to a project, returns a list of types
virtual QStringList canCreate(ProjectExplorer::Project *pro) const;
virtual QStringList availableCreationTypes(ProjectExplorer::Project *pro) const;
// used to translate the types to names to display to the user
virtual QString nameForType(const QString &type) const;
virtual QString displayNameForType(const QString &type) const;
virtual QSharedPointer<ProjectExplorer::RunConfiguration> create(ProjectExplorer::Project *project,
const QString &type);
......
......@@ -130,7 +130,6 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
addAutoReleasedObject(new MakeStepFactory);
addAutoReleasedObject(new Qt4RunConfigurationFactory);
addAutoReleasedObject(new Qt4RunConfigurationFactoryUser);
#ifdef Q_OS_MAC
addAutoReleasedObject(new MacDesignerExternalEditor);
......
......@@ -653,7 +653,7 @@ Qt4RunConfigurationFactory::~Qt4RunConfigurationFactory()
}
// used to recreate the runConfigurations when restoring settings
bool Qt4RunConfigurationFactory::canCreate(const QString &type) const
bool Qt4RunConfigurationFactory::canRestore(const QString &type) const
{
return type == "Qt4ProjectManager.Qt4RunConfiguration";
}
......@@ -663,56 +663,17 @@ QSharedPointer<ProjectExplorer::RunConfiguration> Qt4RunConfigurationFactory::cr
{
Qt4Project *p = qobject_cast<Qt4Project *>(project);
Q_ASSERT(p);
if (type.startsWith("Qt4RunConfiguration.")) {
QString fileName = type.mid(QString("Qt4RunConfiguration.").size());
return QSharedPointer<ProjectExplorer::RunConfiguration>(new Qt4RunConfiguration(p, fileName));
}
Q_ASSERT(type == "Qt4ProjectManager.Qt4RunConfiguration");
// The right path is set in restoreSettings
QSharedPointer<ProjectExplorer::RunConfiguration> rc(new Qt4RunConfiguration(p, QString::null));
return rc;
}
QStringList Qt4RunConfigurationFactory::canCreate(ProjectExplorer::Project *pro) const
{
Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro);
if (qt4project)
return QStringList();
else
return QStringList();
}
QString Qt4RunConfigurationFactory::nameForType(const QString &type) const
{
Q_UNUSED(type);
return "Run Qt4 application";
}
///
/// Qt4RunConfigurationFactoryUser
/// This class is used to create new RunConfiguration from the runsettings page
///
Qt4RunConfigurationFactoryUser::Qt4RunConfigurationFactoryUser()
{
}
Qt4RunConfigurationFactoryUser::~Qt4RunConfigurationFactoryUser()
{
}
bool Qt4RunConfigurationFactoryUser::canCreate(const QString &type) const
{
Q_UNUSED(type);
return false;
}
QSharedPointer<ProjectExplorer::RunConfiguration> Qt4RunConfigurationFactoryUser::create(ProjectExplorer::Project *project, const QString &type)
{
Qt4Project *p = qobject_cast<Qt4Project *>(project);
Q_ASSERT(p);
QString fileName = type.mid(QString("Qt4RunConfiguration.").size());
return QSharedPointer<ProjectExplorer::RunConfiguration>(new Qt4RunConfiguration(p, fileName));
}
QStringList Qt4RunConfigurationFactoryUser::canCreate(ProjectExplorer::Project *pro) const
QStringList Qt4RunConfigurationFactory::availableCreationTypes(ProjectExplorer::Project *pro) const
{
Qt4Project *qt4project = qobject_cast<Qt4Project *>(pro);
if (qt4project) {
......@@ -727,7 +688,7 @@ QStringList Qt4RunConfigurationFactoryUser::canCreate(ProjectExplorer::Project *
}
}
QString Qt4RunConfigurationFactoryUser::nameForType(const QString &type) const
QString Qt4RunConfigurationFactory::displayNameForType(const QString &type) const
{
QString fileName = type.mid(QString("Qt4RunConfiguration.").size());
return QFileInfo(fileName).completeBaseName();
......
......@@ -185,22 +185,10 @@ class Qt4RunConfigurationFactory : public ProjectExplorer::IRunConfigurationFact
public:
Qt4RunConfigurationFactory();
virtual ~Qt4RunConfigurationFactory();
virtual bool canCreate(const QString &type) const;
virtual bool canRestore(const QString &type) const;
virtual QSharedPointer<ProjectExplorer::RunConfiguration> create(ProjectExplorer::Project *project, const QString &type);
QStringList canCreate(ProjectExplorer::Project *pro) const;
QString nameForType(const QString &type) const;
};
class Qt4RunConfigurationFactoryUser : public ProjectExplorer::IRunConfigurationFactory
{
Q_OBJECT
public:
Qt4RunConfigurationFactoryUser();
virtual ~Qt4RunConfigurationFactoryUser();
virtual bool canCreate(const QString &type) const;
virtual QSharedPointer<ProjectExplorer::RunConfiguration> create(ProjectExplorer::Project *project, const QString &type);
QStringList canCreate(ProjectExplorer::Project *pro) const;
QString nameForType(const QString &type) const;
QStringList availableCreationTypes(ProjectExplorer::Project *pro) const;
QString displayNameForType(const QString &type) const;
};
} // namespace Internal
......
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