forked from qt-creator/qt-creator
ProjectExplorer: Remove some Id use from DeployConfig interface
There's a 1:1 relation between the involved types, having either the factory or the id implies having the other. So shorten interfaces that used both so far. Also canCreate() == canHandle() && id matches, so use that directly. Also drop/QTC_ASSERT former canHandle() checks that are implicit in preceding ::find() calls. Change-Id: I686ea5774c5a01b05b3b4882b3d59080a812a677 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -190,19 +190,9 @@ void DeployConfigurationFactory::setConfigBaseId(Core::Id deployConfigBaseId)
|
||||
m_deployConfigBaseId = deployConfigBaseId;
|
||||
}
|
||||
|
||||
bool DeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const
|
||||
DeployConfiguration *DeployConfigurationFactory::create(Target *parent)
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
if (!id.name().startsWith(m_deployConfigBaseId.name()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
DeployConfiguration *DeployConfigurationFactory::create(Target *parent, Core::Id id)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return nullptr;
|
||||
QTC_ASSERT(canHandle(parent), return nullptr);
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
DeployConfiguration *dc = m_creator(parent);
|
||||
if (!dc)
|
||||
|
@@ -79,8 +79,7 @@ public:
|
||||
// the name to display to the user
|
||||
QString defaultDisplayName() const;
|
||||
|
||||
bool canCreate(Target *parent, Core::Id id) const;
|
||||
virtual DeployConfiguration *create(Target *parent, Core::Id id);
|
||||
DeployConfiguration *create(Target *parent);
|
||||
|
||||
static const QList<DeployConfigurationFactory *> find(Target *parent);
|
||||
static DeployConfiguration *restore(Target *parent, const QVariantMap &map);
|
||||
|
@@ -61,19 +61,10 @@ struct FactoryAndId
|
||||
Core::Id id;
|
||||
};
|
||||
|
||||
class DeployFactoryAndId
|
||||
{
|
||||
public:
|
||||
DeployConfigurationFactory *factory;
|
||||
Core::Id id;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndId)
|
||||
Q_DECLARE_METATYPE(ProjectExplorer::Internal::DeployFactoryAndId)
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace ProjectExplorer::Internal;
|
||||
@@ -367,16 +358,10 @@ void RunSettingsWidget::aboutToShowDeployMenu()
|
||||
|
||||
for (DeployConfigurationFactory *factory : DeployConfigurationFactory::find(m_target)) {
|
||||
QAction *action = m_addDeployMenu->addAction(factory->defaultDisplayName());
|
||||
const Core::Id id = factory->creationId();
|
||||
DeployFactoryAndId data = {factory, id};
|
||||
action->setData(QVariant::fromValue(data));
|
||||
connect(action, &QAction::triggered, [factory, id, this]() {
|
||||
if (!factory->canCreate(m_target, id))
|
||||
return;
|
||||
DeployConfiguration *newDc = factory->create(m_target, id);
|
||||
connect(action, &QAction::triggered, [factory, this]() {
|
||||
DeployConfiguration *newDc = factory->create(m_target);
|
||||
if (!newDc)
|
||||
return;
|
||||
QTC_CHECK(!newDc || newDc->id() == id);
|
||||
m_target->addDeployConfiguration(newDc);
|
||||
SessionManager::setActiveDeployConfiguration(m_target, newDc, SetActive::Cascade);
|
||||
m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
|
||||
|
@@ -527,8 +527,8 @@ void Target::updateDefaultDeployConfigurations()
|
||||
|
||||
foreach (Core::Id id, toCreate) {
|
||||
foreach (DeployConfigurationFactory *dcFactory, dcFactories) {
|
||||
if (dcFactory->canCreate(this, id)) {
|
||||
DeployConfiguration *dc = dcFactory->create(this, id);
|
||||
if (dcFactory->creationId() == id) {
|
||||
DeployConfiguration *dc = dcFactory->create(this);
|
||||
if (dc) {
|
||||
QTC_CHECK(dc->id() == id);
|
||||
addDeployConfiguration(dc);
|
||||
|
Reference in New Issue
Block a user