forked from qt-creator/qt-creator
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:
@@ -282,10 +282,10 @@ public:
|
||||
void removeProvider();
|
||||
void updateState();
|
||||
|
||||
void createProvider(IDebugServerProviderFactory *f);
|
||||
private:
|
||||
void addProviderToModel(IDebugServerProvider *p);
|
||||
QModelIndex currentIndex() const;
|
||||
|
||||
public:
|
||||
DebugServerProviderModel m_model;
|
||||
QItemSelectionModel *m_selectionModel = nullptr;
|
||||
QTreeView *m_providerView = nullptr;
|
||||
@@ -357,11 +357,24 @@ DebugServerProvidersSettingsWidget::DebugServerProvidersSettingsWidget()
|
||||
for (const auto f : DebugServerProviderManager::factories()) {
|
||||
const auto action = new QAction(addMenu);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -387,21 +400,9 @@ void DebugServerProvidersSettingsWidget::providerSelectionChanged()
|
||||
updateState();
|
||||
}
|
||||
|
||||
void DebugServerProvidersSettingsWidget::createProvider(IDebugServerProviderFactory *f)
|
||||
void DebugServerProvidersSettingsWidget::addProviderToModel(IDebugServerProvider *provider)
|
||||
{
|
||||
IDebugServerProvider *provider = nullptr;
|
||||
if (!f) {
|
||||
const IDebugServerProvider *old = m_model.provider(currentIndex());
|
||||
if (!old)
|
||||
return;
|
||||
provider = old->clone();
|
||||
} else {
|
||||
provider = f->create();
|
||||
}
|
||||
|
||||
if (!provider)
|
||||
return;
|
||||
|
||||
QTC_ASSERT(provider, return);
|
||||
m_model.markForAddition(provider);
|
||||
|
||||
m_selectionModel->select(m_model.indexForProvider(provider),
|
||||
|
@@ -71,22 +71,6 @@ EBlinkGdbServerProvider::EBlinkGdbServerProvider()
|
||||
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()
|
||||
{
|
||||
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 data = GdbServerProvider::toMap();
|
||||
|
@@ -50,7 +50,6 @@ public:
|
||||
bool operator==(const IDebugServerProvider &other) const final;
|
||||
|
||||
GdbServerProviderConfigWidget *configurationWidget() final;
|
||||
GdbServerProvider *clone() const final;
|
||||
|
||||
QString channelString() const final;
|
||||
Utils::CommandLine command() const final;
|
||||
@@ -59,8 +58,7 @@ public:
|
||||
bool isValid() const final;
|
||||
|
||||
private:
|
||||
explicit EBlinkGdbServerProvider();
|
||||
explicit EBlinkGdbServerProvider(const EBlinkGdbServerProvider &);
|
||||
EBlinkGdbServerProvider();
|
||||
|
||||
static QString defaultInitCommands();
|
||||
static QString defaultResetCommands();
|
||||
|
@@ -141,11 +141,6 @@ bool JLinkGdbServerProvider::isValid() const
|
||||
return true;
|
||||
}
|
||||
|
||||
GdbServerProvider *JLinkGdbServerProvider::clone() const
|
||||
{
|
||||
return new JLinkGdbServerProvider(*this);
|
||||
}
|
||||
|
||||
QVariantMap JLinkGdbServerProvider::toMap() const
|
||||
{
|
||||
QVariantMap data = GdbServerProvider::toMap();
|
||||
|
@@ -47,7 +47,6 @@ public:
|
||||
bool operator==(const IDebugServerProvider &other) const final;
|
||||
|
||||
GdbServerProviderConfigWidget *configurationWidget() final;
|
||||
GdbServerProvider *clone() const final;
|
||||
|
||||
QString channelString() const final;
|
||||
Utils::CommandLine command() const final;
|
||||
@@ -56,7 +55,7 @@ public:
|
||||
bool isValid() const final;
|
||||
|
||||
private:
|
||||
explicit JLinkGdbServerProvider();
|
||||
JLinkGdbServerProvider();
|
||||
|
||||
static QString defaultInitCommands();
|
||||
static QString defaultResetCommands();
|
||||
|
@@ -148,11 +148,6 @@ bool OpenOcdGdbServerProvider::isValid() const
|
||||
return true;
|
||||
}
|
||||
|
||||
GdbServerProvider *OpenOcdGdbServerProvider::clone() const
|
||||
{
|
||||
return new OpenOcdGdbServerProvider(*this);
|
||||
}
|
||||
|
||||
QVariantMap OpenOcdGdbServerProvider::toMap() const
|
||||
{
|
||||
QVariantMap data = GdbServerProvider::toMap();
|
||||
|
@@ -47,7 +47,6 @@ public:
|
||||
bool operator==(const IDebugServerProvider &other) const final;
|
||||
|
||||
GdbServerProviderConfigWidget *configurationWidget() final;
|
||||
GdbServerProvider *clone() const final;
|
||||
|
||||
QString channelString() const final;
|
||||
Utils::CommandLine command() const final;
|
||||
|
@@ -63,17 +63,6 @@ StLinkUtilGdbServerProvider::StLinkUtilGdbServerProvider()
|
||||
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()
|
||||
{
|
||||
return {"load\n"};
|
||||
@@ -141,11 +130,6 @@ bool StLinkUtilGdbServerProvider::isValid() const
|
||||
return true;
|
||||
}
|
||||
|
||||
GdbServerProvider *StLinkUtilGdbServerProvider::clone() const
|
||||
{
|
||||
return new StLinkUtilGdbServerProvider(*this);
|
||||
}
|
||||
|
||||
QVariantMap StLinkUtilGdbServerProvider::toMap() const
|
||||
{
|
||||
QVariantMap data = GdbServerProvider::toMap();
|
||||
|
@@ -50,7 +50,6 @@ public:
|
||||
bool operator==(const IDebugServerProvider &other) const final;
|
||||
|
||||
GdbServerProviderConfigWidget *configurationWidget() final;
|
||||
GdbServerProvider *clone() const final;
|
||||
|
||||
QString channelString() const final;
|
||||
Utils::CommandLine command() const final;
|
||||
@@ -59,8 +58,7 @@ public:
|
||||
bool isValid() const final;
|
||||
|
||||
private:
|
||||
explicit StLinkUtilGdbServerProvider();
|
||||
explicit StLinkUtilGdbServerProvider(const StLinkUtilGdbServerProvider &);
|
||||
StLinkUtilGdbServerProvider();
|
||||
|
||||
static QString defaultInitCommands();
|
||||
static QString defaultResetCommands();
|
||||
|
@@ -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()
|
||||
{
|
||||
const QSet<BareMetalDevice *> devices = m_devices;
|
||||
@@ -189,6 +181,11 @@ void IDebugServerProvider::providerUpdated()
|
||||
DebugServerProviderManager::notifyAboutUpdate(this);
|
||||
}
|
||||
|
||||
void IDebugServerProvider::resetId()
|
||||
{
|
||||
m_id = createId(m_id);
|
||||
}
|
||||
|
||||
bool IDebugServerProvider::fromMap(const QVariantMap &data)
|
||||
{
|
||||
m_id = data.value(idKeyC).toString();
|
||||
|
@@ -61,6 +61,11 @@ class IDebugServerProviderConfigWidget;
|
||||
|
||||
class IDebugServerProvider
|
||||
{
|
||||
protected:
|
||||
explicit IDebugServerProvider(const QString &id);
|
||||
IDebugServerProvider(const IDebugServerProvider &provider) = delete;
|
||||
IDebugServerProvider &operator=(const IDebugServerProvider &provider) = delete;
|
||||
|
||||
public:
|
||||
virtual ~IDebugServerProvider();
|
||||
|
||||
@@ -81,9 +86,8 @@ public:
|
||||
|
||||
virtual IDebugServerProviderConfigWidget *configurationWidget() = 0;
|
||||
|
||||
virtual IDebugServerProvider *clone() const = 0;
|
||||
|
||||
virtual QVariantMap toMap() const;
|
||||
virtual bool fromMap(const QVariantMap &data);
|
||||
|
||||
virtual bool aboutToRun(Debugger::DebuggerRunTool *runTool,
|
||||
QString &errorMessage) const = 0;
|
||||
@@ -96,16 +100,12 @@ public:
|
||||
void unregisterDevice(BareMetalDevice *device);
|
||||
|
||||
protected:
|
||||
explicit IDebugServerProvider(const QString &id);
|
||||
explicit IDebugServerProvider(const IDebugServerProvider &provider);
|
||||
|
||||
void setTypeDisplayName(const QString &typeDisplayName);
|
||||
void setEngineType(Debugger::DebuggerEngineType engineType);
|
||||
void setSettingsKeyBase(const QString &settingsBase);
|
||||
|
||||
void providerUpdated();
|
||||
|
||||
virtual bool fromMap(const QVariantMap &data);
|
||||
void resetId();
|
||||
|
||||
QString m_id;
|
||||
mutable QString m_displayName;
|
||||
@@ -115,6 +115,7 @@ protected:
|
||||
Debugger::DebuggerEngineType m_engineType = Debugger::NoEngineType;
|
||||
QSet<BareMetalDevice *> m_devices;
|
||||
|
||||
friend class DebugServerProvidersSettingsWidget;
|
||||
friend class IDebugServerProviderConfigWidget;
|
||||
friend class IDebugServerProviderFactory;
|
||||
};
|
||||
|
Reference in New Issue
Block a user