BareMetal: Use the plain creation and fromMap(toMap()) for clones

This allows to drop the hierarchy of copy constructors and makes
the setup more similar to what various other factory types in
the ProjectExplorer use nowadays.

This slightly changes clone() behavior in some cases. If that's
not considered harmless, we can introduce some 'polishAfterClone'
or similar.

Change-Id: I935a1f4165bb88e517c136bf4594087aedfdd760
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-01-15 17:48:50 +01:00
parent 850ae600fb
commit 66371198ec
11 changed files with 35 additions and 89 deletions

View File

@@ -282,10 +282,10 @@ public:
void removeProvider(); void removeProvider();
void updateState(); void updateState();
void createProvider(IDebugServerProviderFactory *f); private:
void addProviderToModel(IDebugServerProvider *p);
QModelIndex currentIndex() const; QModelIndex currentIndex() const;
public:
DebugServerProviderModel m_model; DebugServerProviderModel m_model;
QItemSelectionModel *m_selectionModel = nullptr; QItemSelectionModel *m_selectionModel = nullptr;
QTreeView *m_providerView = nullptr; QTreeView *m_providerView = nullptr;
@@ -357,11 +357,24 @@ DebugServerProvidersSettingsWidget::DebugServerProvidersSettingsWidget()
for (const auto f : DebugServerProviderManager::factories()) { for (const auto f : DebugServerProviderManager::factories()) {
const auto action = new QAction(addMenu); const auto action = new QAction(addMenu);
action->setText(f->displayName()); action->setText(f->displayName());
connect(action, &QAction::triggered, this, [this, f] { createProvider(f); }); connect(action, &QAction::triggered, this, [this, f] { addProviderToModel(f->create()); });
addMenu->addAction(action); addMenu->addAction(action);
} }
connect(m_cloneButton, &QAbstractButton::clicked, this, [this] { createProvider(nullptr); }); connect(m_cloneButton, &QAbstractButton::clicked, this, [this] {
if (const IDebugServerProvider *old = m_model.provider(currentIndex())) {
QString id = old->id();
for (const auto f : DebugServerProviderManager::factories()) {
if (id.startsWith(f->id())) {
IDebugServerProvider *p = f->create();
p->fromMap(old->toMap());
p->setDisplayName(tr("Clone of %1").arg(old->displayName()));
p->resetId();
addProviderToModel(p);
}
}
}
});
m_addButton->setMenu(addMenu); m_addButton->setMenu(addMenu);
@@ -387,21 +400,9 @@ void DebugServerProvidersSettingsWidget::providerSelectionChanged()
updateState(); updateState();
} }
void DebugServerProvidersSettingsWidget::createProvider(IDebugServerProviderFactory *f) void DebugServerProvidersSettingsWidget::addProviderToModel(IDebugServerProvider *provider)
{ {
IDebugServerProvider *provider = nullptr; QTC_ASSERT(provider, return);
if (!f) {
const IDebugServerProvider *old = m_model.provider(currentIndex());
if (!old)
return;
provider = old->clone();
} else {
provider = f->create();
}
if (!provider)
return;
m_model.markForAddition(provider); m_model.markForAddition(provider);
m_selectionModel->select(m_model.indexForProvider(provider), m_selectionModel->select(m_model.indexForProvider(provider),

View File

@@ -71,22 +71,6 @@ EBlinkGdbServerProvider::EBlinkGdbServerProvider()
setTypeDisplayName(EBlinkGdbServerProviderFactory::tr("EBlink")); setTypeDisplayName(EBlinkGdbServerProviderFactory::tr("EBlink"));
} }
EBlinkGdbServerProvider::EBlinkGdbServerProvider(
const EBlinkGdbServerProvider &other)
: GdbServerProvider(other)
, m_executableFile(other.m_executableFile)
, m_verboseLevel(0)
, m_interfaceType(other.m_interfaceType)
, m_deviceScript(other.m_deviceScript)
, m_interfaceResetOnConnect(other.m_interfaceResetOnConnect)
, m_interfaceSpeed(other.m_interfaceSpeed)
, m_interfaceExplicidDevice(other.m_interfaceExplicidDevice)
, m_targetName(other.m_targetName)
, m_targetDisableStack(other.m_targetDisableStack)
, m_gdbShutDownAfterDisconnect(other.m_gdbShutDownAfterDisconnect)
, m_gdbNotUseCache(other.m_gdbNotUseCache){
}
QString EBlinkGdbServerProvider::defaultInitCommands() QString EBlinkGdbServerProvider::defaultInitCommands()
{ {
return {"monitor reset halt\n" return {"monitor reset halt\n"
@@ -184,11 +168,6 @@ bool EBlinkGdbServerProvider::isValid() const
} }
} }
GdbServerProvider *EBlinkGdbServerProvider::clone() const
{
return new EBlinkGdbServerProvider(*this);
}
QVariantMap EBlinkGdbServerProvider::toMap() const QVariantMap EBlinkGdbServerProvider::toMap() const
{ {
QVariantMap data = GdbServerProvider::toMap(); QVariantMap data = GdbServerProvider::toMap();

View File

@@ -50,7 +50,6 @@ public:
bool operator==(const IDebugServerProvider &other) const final; bool operator==(const IDebugServerProvider &other) const final;
GdbServerProviderConfigWidget *configurationWidget() final; GdbServerProviderConfigWidget *configurationWidget() final;
GdbServerProvider *clone() const final;
QString channelString() const final; QString channelString() const final;
Utils::CommandLine command() const final; Utils::CommandLine command() const final;
@@ -59,8 +58,7 @@ public:
bool isValid() const final; bool isValid() const final;
private: private:
explicit EBlinkGdbServerProvider(); EBlinkGdbServerProvider();
explicit EBlinkGdbServerProvider(const EBlinkGdbServerProvider &);
static QString defaultInitCommands(); static QString defaultInitCommands();
static QString defaultResetCommands(); static QString defaultResetCommands();

View File

@@ -141,11 +141,6 @@ bool JLinkGdbServerProvider::isValid() const
return true; return true;
} }
GdbServerProvider *JLinkGdbServerProvider::clone() const
{
return new JLinkGdbServerProvider(*this);
}
QVariantMap JLinkGdbServerProvider::toMap() const QVariantMap JLinkGdbServerProvider::toMap() const
{ {
QVariantMap data = GdbServerProvider::toMap(); QVariantMap data = GdbServerProvider::toMap();

View File

@@ -47,7 +47,6 @@ public:
bool operator==(const IDebugServerProvider &other) const final; bool operator==(const IDebugServerProvider &other) const final;
GdbServerProviderConfigWidget *configurationWidget() final; GdbServerProviderConfigWidget *configurationWidget() final;
GdbServerProvider *clone() const final;
QString channelString() const final; QString channelString() const final;
Utils::CommandLine command() const final; Utils::CommandLine command() const final;
@@ -56,7 +55,7 @@ public:
bool isValid() const final; bool isValid() const final;
private: private:
explicit JLinkGdbServerProvider(); JLinkGdbServerProvider();
static QString defaultInitCommands(); static QString defaultInitCommands();
static QString defaultResetCommands(); static QString defaultResetCommands();

View File

@@ -148,11 +148,6 @@ bool OpenOcdGdbServerProvider::isValid() const
return true; return true;
} }
GdbServerProvider *OpenOcdGdbServerProvider::clone() const
{
return new OpenOcdGdbServerProvider(*this);
}
QVariantMap OpenOcdGdbServerProvider::toMap() const QVariantMap OpenOcdGdbServerProvider::toMap() const
{ {
QVariantMap data = GdbServerProvider::toMap(); QVariantMap data = GdbServerProvider::toMap();

View File

@@ -47,7 +47,6 @@ public:
bool operator==(const IDebugServerProvider &other) const final; bool operator==(const IDebugServerProvider &other) const final;
GdbServerProviderConfigWidget *configurationWidget() final; GdbServerProviderConfigWidget *configurationWidget() final;
GdbServerProvider *clone() const final;
QString channelString() const final; QString channelString() const final;
Utils::CommandLine command() const final; Utils::CommandLine command() const final;

View File

@@ -63,17 +63,6 @@ StLinkUtilGdbServerProvider::StLinkUtilGdbServerProvider()
setTypeDisplayName(StLinkUtilGdbServerProviderFactory::tr("ST-LINK Utility")); setTypeDisplayName(StLinkUtilGdbServerProviderFactory::tr("ST-LINK Utility"));
} }
StLinkUtilGdbServerProvider::StLinkUtilGdbServerProvider(
const StLinkUtilGdbServerProvider &other)
: GdbServerProvider(other)
, m_executableFile(other.m_executableFile)
, m_verboseLevel(0)
, m_extendedMode(false)
, m_resetBoard(true)
, m_transport(RawUsb)
{
}
QString StLinkUtilGdbServerProvider::defaultInitCommands() QString StLinkUtilGdbServerProvider::defaultInitCommands()
{ {
return {"load\n"}; return {"load\n"};
@@ -141,11 +130,6 @@ bool StLinkUtilGdbServerProvider::isValid() const
return true; return true;
} }
GdbServerProvider *StLinkUtilGdbServerProvider::clone() const
{
return new StLinkUtilGdbServerProvider(*this);
}
QVariantMap StLinkUtilGdbServerProvider::toMap() const QVariantMap StLinkUtilGdbServerProvider::toMap() const
{ {
QVariantMap data = GdbServerProvider::toMap(); QVariantMap data = GdbServerProvider::toMap();

View File

@@ -50,7 +50,6 @@ public:
bool operator==(const IDebugServerProvider &other) const final; bool operator==(const IDebugServerProvider &other) const final;
GdbServerProviderConfigWidget *configurationWidget() final; GdbServerProviderConfigWidget *configurationWidget() final;
GdbServerProvider *clone() const final;
QString channelString() const final; QString channelString() const final;
Utils::CommandLine command() const final; Utils::CommandLine command() const final;
@@ -59,8 +58,7 @@ public:
bool isValid() const final; bool isValid() const final;
private: private:
explicit StLinkUtilGdbServerProvider(); StLinkUtilGdbServerProvider();
explicit StLinkUtilGdbServerProvider(const StLinkUtilGdbServerProvider &);
static QString defaultInitCommands(); static QString defaultInitCommands();
static QString defaultResetCommands(); static QString defaultResetCommands();

View File

@@ -61,14 +61,6 @@ IDebugServerProvider::IDebugServerProvider(const QString &id)
{ {
} }
IDebugServerProvider::IDebugServerProvider(const IDebugServerProvider &provider)
: m_id(createId(provider.m_id))
{
m_displayName = QCoreApplication::translate(
"BareMetal::IDebugServerProvider", "Clone of %1")
.arg(provider.displayName());
}
IDebugServerProvider::~IDebugServerProvider() IDebugServerProvider::~IDebugServerProvider()
{ {
const QSet<BareMetalDevice *> devices = m_devices; const QSet<BareMetalDevice *> devices = m_devices;
@@ -189,6 +181,11 @@ void IDebugServerProvider::providerUpdated()
DebugServerProviderManager::notifyAboutUpdate(this); DebugServerProviderManager::notifyAboutUpdate(this);
} }
void IDebugServerProvider::resetId()
{
m_id = createId(m_id);
}
bool IDebugServerProvider::fromMap(const QVariantMap &data) bool IDebugServerProvider::fromMap(const QVariantMap &data)
{ {
m_id = data.value(idKeyC).toString(); m_id = data.value(idKeyC).toString();

View File

@@ -61,6 +61,11 @@ class IDebugServerProviderConfigWidget;
class IDebugServerProvider class IDebugServerProvider
{ {
protected:
explicit IDebugServerProvider(const QString &id);
IDebugServerProvider(const IDebugServerProvider &provider) = delete;
IDebugServerProvider &operator=(const IDebugServerProvider &provider) = delete;
public: public:
virtual ~IDebugServerProvider(); virtual ~IDebugServerProvider();
@@ -81,9 +86,8 @@ public:
virtual IDebugServerProviderConfigWidget *configurationWidget() = 0; virtual IDebugServerProviderConfigWidget *configurationWidget() = 0;
virtual IDebugServerProvider *clone() const = 0;
virtual QVariantMap toMap() const; virtual QVariantMap toMap() const;
virtual bool fromMap(const QVariantMap &data);
virtual bool aboutToRun(Debugger::DebuggerRunTool *runTool, virtual bool aboutToRun(Debugger::DebuggerRunTool *runTool,
QString &errorMessage) const = 0; QString &errorMessage) const = 0;
@@ -96,16 +100,12 @@ public:
void unregisterDevice(BareMetalDevice *device); void unregisterDevice(BareMetalDevice *device);
protected: protected:
explicit IDebugServerProvider(const QString &id);
explicit IDebugServerProvider(const IDebugServerProvider &provider);
void setTypeDisplayName(const QString &typeDisplayName); void setTypeDisplayName(const QString &typeDisplayName);
void setEngineType(Debugger::DebuggerEngineType engineType); void setEngineType(Debugger::DebuggerEngineType engineType);
void setSettingsKeyBase(const QString &settingsBase); void setSettingsKeyBase(const QString &settingsBase);
void providerUpdated(); void providerUpdated();
void resetId();
virtual bool fromMap(const QVariantMap &data);
QString m_id; QString m_id;
mutable QString m_displayName; mutable QString m_displayName;
@@ -115,6 +115,7 @@ protected:
Debugger::DebuggerEngineType m_engineType = Debugger::NoEngineType; Debugger::DebuggerEngineType m_engineType = Debugger::NoEngineType;
QSet<BareMetalDevice *> m_devices; QSet<BareMetalDevice *> m_devices;
friend class DebugServerProvidersSettingsWidget;
friend class IDebugServerProviderConfigWidget; friend class IDebugServerProviderConfigWidget;
friend class IDebugServerProviderFactory; friend class IDebugServerProviderFactory;
}; };