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;
|
m_deployConfigBaseId = deployConfigBaseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const
|
DeployConfiguration *DeployConfigurationFactory::create(Target *parent)
|
||||||
{
|
{
|
||||||
if (!canHandle(parent))
|
QTC_ASSERT(canHandle(parent), return nullptr);
|
||||||
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(m_creator, return nullptr);
|
QTC_ASSERT(m_creator, return nullptr);
|
||||||
DeployConfiguration *dc = m_creator(parent);
|
DeployConfiguration *dc = m_creator(parent);
|
||||||
if (!dc)
|
if (!dc)
|
||||||
|
@@ -79,8 +79,7 @@ public:
|
|||||||
// the name to display to the user
|
// the name to display to the user
|
||||||
QString defaultDisplayName() const;
|
QString defaultDisplayName() const;
|
||||||
|
|
||||||
bool canCreate(Target *parent, Core::Id id) const;
|
DeployConfiguration *create(Target *parent);
|
||||||
virtual DeployConfiguration *create(Target *parent, Core::Id id);
|
|
||||||
|
|
||||||
static const QList<DeployConfigurationFactory *> find(Target *parent);
|
static const QList<DeployConfigurationFactory *> find(Target *parent);
|
||||||
static DeployConfiguration *restore(Target *parent, const QVariantMap &map);
|
static DeployConfiguration *restore(Target *parent, const QVariantMap &map);
|
||||||
|
@@ -61,19 +61,10 @@ struct FactoryAndId
|
|||||||
Core::Id id;
|
Core::Id id;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeployFactoryAndId
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DeployConfigurationFactory *factory;
|
|
||||||
Core::Id id;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndId)
|
Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndId)
|
||||||
Q_DECLARE_METATYPE(ProjectExplorer::Internal::DeployFactoryAndId)
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace ProjectExplorer::Internal;
|
using namespace ProjectExplorer::Internal;
|
||||||
@@ -367,16 +358,10 @@ void RunSettingsWidget::aboutToShowDeployMenu()
|
|||||||
|
|
||||||
for (DeployConfigurationFactory *factory : DeployConfigurationFactory::find(m_target)) {
|
for (DeployConfigurationFactory *factory : DeployConfigurationFactory::find(m_target)) {
|
||||||
QAction *action = m_addDeployMenu->addAction(factory->defaultDisplayName());
|
QAction *action = m_addDeployMenu->addAction(factory->defaultDisplayName());
|
||||||
const Core::Id id = factory->creationId();
|
connect(action, &QAction::triggered, [factory, this]() {
|
||||||
DeployFactoryAndId data = {factory, id};
|
DeployConfiguration *newDc = factory->create(m_target);
|
||||||
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);
|
|
||||||
if (!newDc)
|
if (!newDc)
|
||||||
return;
|
return;
|
||||||
QTC_CHECK(!newDc || newDc->id() == id);
|
|
||||||
m_target->addDeployConfiguration(newDc);
|
m_target->addDeployConfiguration(newDc);
|
||||||
SessionManager::setActiveDeployConfiguration(m_target, newDc, SetActive::Cascade);
|
SessionManager::setActiveDeployConfiguration(m_target, newDc, SetActive::Cascade);
|
||||||
m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
|
m_removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
|
||||||
|
@@ -527,8 +527,8 @@ void Target::updateDefaultDeployConfigurations()
|
|||||||
|
|
||||||
foreach (Core::Id id, toCreate) {
|
foreach (Core::Id id, toCreate) {
|
||||||
foreach (DeployConfigurationFactory *dcFactory, dcFactories) {
|
foreach (DeployConfigurationFactory *dcFactory, dcFactories) {
|
||||||
if (dcFactory->canCreate(this, id)) {
|
if (dcFactory->creationId() == id) {
|
||||||
DeployConfiguration *dc = dcFactory->create(this, id);
|
DeployConfiguration *dc = dcFactory->create(this);
|
||||||
if (dc) {
|
if (dc) {
|
||||||
QTC_CHECK(dc->id() == id);
|
QTC_CHECK(dc->id() == id);
|
||||||
addDeployConfiguration(dc);
|
addDeployConfiguration(dc);
|
||||||
|
Reference in New Issue
Block a user