BareMetal: Use a StringAspect to store debugServerProviderId

Change-Id: I001587a460af928a22c891ea5600b5d2676f4b4b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2024-08-01 17:09:54 +02:00
parent 9d6c78155f
commit 32505b21c8
2 changed files with 15 additions and 26 deletions

View File

@@ -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());

View File

@@ -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();