iOS: Move towards more aspect use

Put the remaining device related pieces into a new IosDeviceTypeAspect.

Change-Id: Ia1ce2002edebedc2d409edc1144ade0ffe24a084
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
hjk
2018-09-19 09:01:01 +02:00
parent 7de461e40b
commit ad7d37cc36
2 changed files with 54 additions and 59 deletions

View File

@@ -78,19 +78,29 @@ static IosDeviceType toIosDeviceType(const SimulatorInfo &device)
return iosDeviceType; return iosDeviceType;
} }
class IosRunConfigurationWidget : public QWidget class IosDeviceTypeAspect : public ProjectConfigurationAspect
{ {
public: public:
IosRunConfigurationWidget(IosRunConfiguration *runConfiguration); IosDeviceTypeAspect(IosRunConfiguration *runConfiguration);
void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override;
void addToConfigurationLayout(QFormLayout *layout) override;
IosDeviceType deviceType() const;
void setDeviceType(const IosDeviceType &deviceType);
private:
void updateValues(); void updateValues();
void setDeviceTypeIndex(int devIndex); void setDeviceTypeIndex(int devIndex);
void deviceChanges();
void updateDeviceType();
IosRunConfiguration *m_runConfiguration; public:
IosDeviceType m_deviceType;
IosRunConfiguration *m_runConfiguration = nullptr;
QStandardItemModel m_deviceTypeModel; QStandardItemModel m_deviceTypeModel;
QLabel *m_deviceTypeLabel; QLabel *m_deviceTypeLabel = nullptr;
QComboBox *m_deviceTypeComboBox; QComboBox *m_deviceTypeComboBox = nullptr;
}; };
IosRunConfiguration::IosRunConfiguration(Target *target, Core::Id id) IosRunConfiguration::IosRunConfiguration(Target *target, Core::Id id)
@@ -100,34 +110,28 @@ IosRunConfiguration::IosRunConfiguration(Target *target, Core::Id id)
executableAspect->setDisplayStyle(BaseStringAspect::LabelDisplay); executableAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
setOutputFormatter<QtSupport::QtOutputFormatter>();
connect(DeviceManager::instance(), &DeviceManager::updated, m_deviceTypeAspect = addAspect<IosDeviceTypeAspect>(this);
this, &IosRunConfiguration::deviceChanges);
connect(KitManager::instance(), &KitManager::kitsChanged, setOutputFormatter<QtSupport::QtOutputFormatter>();
this, &IosRunConfiguration::deviceChanges);
} }
void IosRunConfiguration::deviceChanges() void IosDeviceTypeAspect::deviceChanges()
{ {
updateDeviceType(); updateDeviceType();
updateDisplayNames(); m_runConfiguration->updateDisplayNames();
updateEnabledState(); m_runConfiguration->updateEnabledState();
} }
void IosRunConfiguration::updateDeviceType() void IosDeviceTypeAspect::updateDeviceType()
{ {
if (DeviceTypeKitInformation::deviceTypeId(target()->kit()) == Constants::IOS_DEVICE_TYPE) if (DeviceTypeKitInformation::deviceTypeId(m_runConfiguration->target()->kit())
== Constants::IOS_DEVICE_TYPE)
m_deviceType = IosDeviceType(IosDeviceType::IosDevice); m_deviceType = IosDeviceType(IosDeviceType::IosDevice);
else if (m_deviceType.type == IosDeviceType::IosDevice) else if (m_deviceType.type == IosDeviceType::IosDevice)
m_deviceType = IosDeviceType(IosDeviceType::SimulatedDevice); m_deviceType = IosDeviceType(IosDeviceType::SimulatedDevice);
} }
QWidget *IosRunConfiguration::createConfigurationWidget()
{
return new IosRunConfigurationWidget(this);
}
void IosRunConfiguration::updateDisplayNames() void IosRunConfiguration::updateDisplayNames()
{ {
IDevice::ConstPtr dev = DeviceKitInformation::device(target()->kit()); IDevice::ConstPtr dev = DeviceKitInformation::device(target()->kit());
@@ -236,26 +240,19 @@ FileName IosRunConfiguration::localExecutable() const
return bundleDirectory().appendPath(applicationName()); return bundleDirectory().appendPath(applicationName());
} }
bool IosRunConfiguration::fromMap(const QVariantMap &map) void IosDeviceTypeAspect::fromMap(const QVariantMap &map)
{ {
if (!RunConfiguration::fromMap(map))
return false;
bool deviceTypeIsInt; bool deviceTypeIsInt;
map.value(deviceTypeKey).toInt(&deviceTypeIsInt); map.value(deviceTypeKey).toInt(&deviceTypeIsInt);
if (deviceTypeIsInt || !m_deviceType.fromMap(map.value(deviceTypeKey).toMap())) { if (deviceTypeIsInt || !m_deviceType.fromMap(map.value(deviceTypeKey).toMap()))
updateDeviceType(); updateDeviceType();
}
updateDisplayNames(); m_runConfiguration->updateDisplayNames();
return true;
} }
QVariantMap IosRunConfiguration::toMap() const void IosDeviceTypeAspect::toMap(QVariantMap &map) const
{ {
QVariantMap res = RunConfiguration::toMap(); map.insert(deviceTypeKey, deviceType().toMap());
res[deviceTypeKey] = deviceType().toMap();
return res;
} }
QString IosRunConfiguration::disabledReason() const QString IosRunConfiguration::disabledReason() const
@@ -310,6 +307,11 @@ QString IosRunConfiguration::disabledReason() const
} }
IosDeviceType IosRunConfiguration::deviceType() const IosDeviceType IosRunConfiguration::deviceType() const
{
return m_deviceTypeAspect->deviceType();
}
IosDeviceType IosDeviceTypeAspect::deviceType() const
{ {
if (m_deviceType.type == IosDeviceType::SimulatedDevice) { if (m_deviceType.type == IosDeviceType::SimulatedDevice) {
QList<SimulatorInfo> availableSimulators = SimulatorControl::availableSimulators(); QList<SimulatorInfo> availableSimulators = SimulatorControl::availableSimulators();
@@ -333,50 +335,50 @@ IosDeviceType IosRunConfiguration::deviceType() const
return m_deviceType; return m_deviceType;
} }
void IosRunConfiguration::setDeviceType(const IosDeviceType &deviceType) void IosDeviceTypeAspect::setDeviceType(const IosDeviceType &deviceType)
{ {
m_deviceType = deviceType; m_deviceType = deviceType;
} }
void IosRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInfo &) void IosRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInfo &)
{ {
updateDeviceType(); m_deviceTypeAspect->updateDeviceType();
updateDisplayNames(); updateDisplayNames();
} }
IosRunConfigurationWidget::IosRunConfigurationWidget(IosRunConfiguration *runConfiguration) IosDeviceTypeAspect::IosDeviceTypeAspect(IosRunConfiguration *runConfiguration)
: m_runConfiguration(runConfiguration) : m_runConfiguration(runConfiguration)
{ {
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); connect(DeviceManager::instance(), &DeviceManager::updated,
sizePolicy.setHorizontalStretch(0); this, &IosDeviceTypeAspect::deviceChanges);
sizePolicy.setVerticalStretch(0); connect(KitManager::instance(), &KitManager::kitsChanged,
setSizePolicy(sizePolicy); this, &IosDeviceTypeAspect::deviceChanges);
}
m_deviceTypeComboBox = new QComboBox(this); void IosDeviceTypeAspect::addToConfigurationLayout(QFormLayout *layout)
{
m_deviceTypeComboBox = new QComboBox(layout->parentWidget());
m_deviceTypeComboBox->setModel(&m_deviceTypeModel); m_deviceTypeComboBox->setModel(&m_deviceTypeModel);
m_deviceTypeLabel = new QLabel(IosRunConfiguration::tr("Device type:"), this); m_deviceTypeLabel = new QLabel(IosRunConfiguration::tr("Device type:"), layout->parentWidget());
auto layout = new QFormLayout(this);
runConfiguration->extraAspect<ArgumentsAspect>()->addToConfigurationLayout(layout);
runConfiguration->extraAspect<ExecutableAspect>()->addToConfigurationLayout(layout);
layout->addRow(m_deviceTypeLabel, m_deviceTypeComboBox); layout->addRow(m_deviceTypeLabel, m_deviceTypeComboBox);
updateValues(); updateValues();
connect(m_deviceTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(m_deviceTypeComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &IosRunConfigurationWidget::setDeviceTypeIndex); this, &IosDeviceTypeAspect::setDeviceTypeIndex);
} }
void IosRunConfigurationWidget::setDeviceTypeIndex(int devIndex) void IosDeviceTypeAspect::setDeviceTypeIndex(int devIndex)
{ {
QVariant selectedDev = m_deviceTypeModel.data(m_deviceTypeModel.index(devIndex, 0), Qt::UserRole + 1); QVariant selectedDev = m_deviceTypeModel.data(m_deviceTypeModel.index(devIndex, 0), Qt::UserRole + 1);
if (selectedDev.isValid()) if (selectedDev.isValid())
m_runConfiguration->setDeviceType(toIosDeviceType(selectedDev.value<SimulatorInfo>())); setDeviceType(toIosDeviceType(selectedDev.value<SimulatorInfo>()));
} }
void IosRunConfigurationWidget::updateValues() void IosDeviceTypeAspect::updateValues()
{ {
bool showDeviceSelector = m_runConfiguration->deviceType().type != IosDeviceType::IosDevice; bool showDeviceSelector = m_runConfiguration->deviceType().type != IosDeviceType::IosDevice;
m_deviceTypeLabel->setVisible(showDeviceSelector); m_deviceTypeLabel->setVisible(showDeviceSelector);

View File

@@ -36,8 +36,7 @@ namespace Ios {
namespace Internal { namespace Internal {
class IosDeployStep; class IosDeployStep;
class IosRunConfigurationFactory; class IosDeviceTypeAspect;
class IosRunConfigurationWidget;
class IosRunConfiguration : public ProjectExplorer::RunConfiguration class IosRunConfiguration : public ProjectExplorer::RunConfiguration
{ {
@@ -46,7 +45,6 @@ class IosRunConfiguration : public ProjectExplorer::RunConfiguration
public: public:
IosRunConfiguration(ProjectExplorer::Target *target, Core::Id id); IosRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
QWidget *createConfigurationWidget() override;
IosDeployStep *deployStep() const; IosDeployStep *deployStep() const;
Utils::FileName profilePath() const; Utils::FileName profilePath() const;
@@ -55,21 +53,16 @@ public:
Utils::FileName localExecutable() const; Utils::FileName localExecutable() const;
QString disabledReason() const override; QString disabledReason() const override;
IosDeviceType deviceType() const; IosDeviceType deviceType() const;
void setDeviceType(const IosDeviceType &deviceType);
void doAdditionalSetup(const ProjectExplorer::RunConfigurationCreationInfo &) override; void doAdditionalSetup(const ProjectExplorer::RunConfigurationCreationInfo &) override;
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
private: private:
void deviceChanges(); friend class IosDeviceTypeAspect;
friend class IosRunConfigurationWidget;
void updateDeviceType();
void updateDisplayNames(); void updateDisplayNames();
void updateEnabledState() final; void updateEnabledState() final;
bool canRunForNode(const ProjectExplorer::Node *node) const final; bool canRunForNode(const ProjectExplorer::Node *node) const final;
IosDeviceType m_deviceType; IosDeviceTypeAspect *m_deviceTypeAspect = nullptr;
}; };
class IosRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory class IosRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory