From 63a691b5de9c2ac5f0bcbfed95fea8b867492ee3 Mon Sep 17 00:00:00 2001 From: Vikas Pachdha Date: Fri, 17 Mar 2017 15:16:36 +0100 Subject: [PATCH] Fix default device not being saved Task-number: QTCREATORBUG-17396 Change-Id: Idcee60b1fa3043690cd77de899a0a40cb0e25947 Reviewed-by: Tobias Hunger --- .../devicesupport/devicemanager.cpp | 32 +++++++++---------- .../devicesupport/devicemanager.h | 3 +- 2 files changed, 17 insertions(+), 18 deletions(-) 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;