diff --git a/src/plugins/baremetal/baremetaldevice.cpp b/src/plugins/baremetal/baremetaldevice.cpp index 6099564af01..757d554b61f 100644 --- a/src/plugins/baremetal/baremetaldevice.cpp +++ b/src/plugins/baremetal/baremetaldevice.cpp @@ -20,20 +20,20 @@ using namespace Utils; namespace BareMetal::Internal { -const char debugServerProviderIdKeyC[] = "IDebugServerProviderId"; - // BareMetalDevice BareMetalDevice::BareMetalDevice() { setDisplayType(Tr::tr("Bare Metal")); setOsType(Utils::OsTypeOther); + + m_debugServerProviderId.setSettingsKey("IDebugServerProviderId"); } BareMetalDevice::~BareMetalDevice() { if (IDebugServerProvider *provider = DebugServerProviderManager::findProvider( - m_debugServerProviderId)) + debugServerProviderId())) provider->unregisterDevice(this); } @@ -44,49 +44,40 @@ QString BareMetalDevice::defaultDisplayName() QString BareMetalDevice::debugServerProviderId() const { - return m_debugServerProviderId; + return m_debugServerProviderId(); } void BareMetalDevice::setDebugServerProviderId(const QString &id) { - if (id == m_debugServerProviderId) + if (id == debugServerProviderId()) return; if (IDebugServerProvider *currentProvider = - DebugServerProviderManager::findProvider(m_debugServerProviderId)) + DebugServerProviderManager::findProvider(debugServerProviderId())) currentProvider->unregisterDevice(this); - m_debugServerProviderId = id; + m_debugServerProviderId.setValue(id); if (IDebugServerProvider *provider = DebugServerProviderManager::findProvider(id)) provider->registerDevice(this); } void BareMetalDevice::unregisterDebugServerProvider(IDebugServerProvider *provider) { - if (provider->id() == m_debugServerProviderId) - m_debugServerProviderId.clear(); + if (provider->id() == debugServerProviderId()) + m_debugServerProviderId.setValue(QString()); } void BareMetalDevice::fromMap(const Store &map) { IDevice::fromMap(map); - QString providerId = map.value(debugServerProviderIdKeyC).toString(); - if (providerId.isEmpty()) { + + if (debugServerProviderId().isEmpty()) { const QString name = displayName(); if (IDebugServerProvider *provider = DebugServerProviderManager::findByDisplayName(name)) { - providerId = provider->id(); - setDebugServerProviderId(providerId); + setDebugServerProviderId(provider->id()); } - } else { - setDebugServerProviderId(providerId); } } -void BareMetalDevice::toMap(Store &map) const -{ - IDevice::toMap(map); - map.insert(debugServerProviderIdKeyC, debugServerProviderId()); -} - IDeviceWidget *BareMetalDevice::createWidget() { return new BareMetalDeviceConfigurationWidget(shared_from_this()); diff --git a/src/plugins/baremetal/baremetaldevice.h b/src/plugins/baremetal/baremetaldevice.h index ed29c2b0ad7..cce3a08a3f1 100644 --- a/src/plugins/baremetal/baremetaldevice.h +++ b/src/plugins/baremetal/baremetaldevice.h @@ -25,13 +25,11 @@ public: void setDebugServerProviderId(const QString &id); void unregisterDebugServerProvider(class IDebugServerProvider *provider); -protected: - void fromMap(const Utils::Store &map) final; - void toMap(Utils::Store &map) const final; - private: + void fromMap(const Utils::Store &map) final; + BareMetalDevice(); - QString m_debugServerProviderId; + Utils::StringAspect m_debugServerProviderId{this}; }; void setupBareMetalDevice();