diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index da3bbfaa01a..b1792e6fd5e 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -148,13 +148,14 @@ void DeviceManager::load() Utils::PersistentSettingsReader reader; // read devices file from global settings path + QHash defaultDevices; QList sdkDevices; if (reader.load(systemSettingsFilePath(QLatin1String("/qtcreator/devices.xml")))) - sdkDevices = fromMap(reader.restoreValues().value(QLatin1String(DeviceManagerKey)).toMap()); + sdkDevices = fromMap(reader.restoreValues().value(DeviceManagerKey).toMap(), &defaultDevices); // read devices file from user settings path QList userDevices; if (reader.load(settingsFilePath(QLatin1String("/devices.xml")))) - userDevices = fromMap(reader.restoreValues().value(QLatin1String(DeviceManagerKey)).toMap()); + userDevices = fromMap(reader.restoreValues().value(DeviceManagerKey).toMap(), &defaultDevices); // Insert devices into the model. Prefer the higher device version when there are multiple // devices with the same id. foreach (IDevice::Ptr device, userDevices) { @@ -172,18 +173,25 @@ void DeviceManager::load() foreach (const IDevice::Ptr &sdkDevice, sdkDevices) addDevice(sdkDevice); - ensureOneDefaultDevicePerType(); + // Overwrite with the saved default devices. + for (auto itr = defaultDevices.constBegin(); itr != defaultDevices.constEnd(); ++itr) { + IDevice::ConstPtr device = find(itr.value()); + if (device) + d->defaultDevices[device->type()] = device->id(); + } emit devicesLoaded(); } -QList DeviceManager::fromMap(const QVariantMap &map) +QList DeviceManager::fromMap(const QVariantMap &map, + QHash *defaultDevices) { QList devices; - const QVariantMap defaultDevsMap = map.value(QLatin1String(DefaultDevicesKey)).toMap(); - for (QVariantMap::ConstIterator it = defaultDevsMap.constBegin(); - it != defaultDevsMap.constEnd(); ++it) { - d->defaultDevices.insert(Core::Id::fromString(it.key()), Core::Id::fromSetting(it.value())); + + if (defaultDevices) { + const QVariantMap defaultDevsMap = map.value(DefaultDevicesKey).toMap(); + for (auto it = defaultDevsMap.constBegin(); it != defaultDevsMap.constEnd(); ++it) + defaultDevices->insert(Core::Id::fromString(it.key()), Core::Id::fromSetting(it.value())); } const QVariantList deviceList = map.value(QLatin1String(DeviceListKey)).toList(); foreach (const QVariant &v, deviceList) { @@ -398,14 +406,6 @@ IDevice::ConstPtr DeviceManager::defaultDevice(Core::Id deviceType) const return id.isValid() ? find(id) : IDevice::ConstPtr(); } -void DeviceManager::ensureOneDefaultDevicePerType() -{ - foreach (const IDevice::Ptr &device, d->devices) { - if (!defaultDevice(device->type())) - d->defaultDevices.insert(device->type(), device->id()); - } -} - QString DeviceManager::hostKeysFilePath() { return settingsFilePath(QLatin1String("/ssh-hostkeys")).toString(); diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.h b/src/plugins/projectexplorer/devicesupport/devicemanager.h index 80620616b69..cbfbafb0ce2 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.h +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.h @@ -85,9 +85,8 @@ private: void load(); static const IDeviceFactory *restoreFactory(const QVariantMap &map); - QList fromMap(const QVariantMap &map); + QList fromMap(const QVariantMap &map, QHash *defaultDevices); QVariantMap toMap() const; - void ensureOneDefaultDevicePerType(); // For SettingsWidget. IDevice::Ptr mutableDevice(Core::Id id) const;