BareMetal: De-virtualize IDebugServerProvider::createConfigWidget

There is no change in functionality intended.

The original version is good in principle, but Creator core has been
moving to use this 'setFoo(std::function<>)' pattern during the last
year, greatly reducing the need for boilerplate on the "user" side.

The effect isn't as significant here, but generally I don't want to
use too many different patterns being used.

Change-Id: I3ec8c677c19c1ed3f8145e0c3cba337dff7ce1cf
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
This commit is contained in:
hjk
2019-12-12 17:41:43 +01:00
parent 66371198ec
commit 3d7a3b4749
10 changed files with 19 additions and 29 deletions

View File

@@ -69,6 +69,7 @@ EBlinkGdbServerProvider::EBlinkGdbServerProvider()
setChannel("127.0.0.1", 2331);
setSettingsKeyBase("BareMetal.EBlinkGdbServerProvider");
setTypeDisplayName(EBlinkGdbServerProviderFactory::tr("EBlink"));
setConfigurationWidgetCreator([this] { return new EBlinkGdbServerProviderConfigWidget(this); });
}
QString EBlinkGdbServerProvider::defaultInitCommands()
@@ -227,11 +228,6 @@ bool EBlinkGdbServerProvider::operator==(const IDebugServerProvider &other) cons
&& m_gdbNotUseCache == p->m_gdbNotUseCache;
}
GdbServerProviderConfigWidget *EBlinkGdbServerProvider::configurationWidget()
{
return new EBlinkGdbServerProviderConfigWidget(this);
}
// EBlinkGdbServerProviderFactory
EBlinkGdbServerProviderFactory::EBlinkGdbServerProviderFactory()

View File

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

View File

@@ -65,6 +65,7 @@ JLinkGdbServerProvider::JLinkGdbServerProvider()
setChannel("localhost", 2331);
setSettingsKeyBase("BareMetal.JLinkGdbServerProvider");
setTypeDisplayName(JLinkGdbServerProviderFactory::tr("JLink"));
setConfigurationWidgetCreator([this] { return new JLinkGdbServerProviderConfigWidget(this); });
}
QString JLinkGdbServerProvider::defaultInitCommands()
@@ -179,11 +180,6 @@ bool JLinkGdbServerProvider::operator==(const IDebugServerProvider &other) const
&& m_additionalArguments == p->m_additionalArguments;
}
GdbServerProviderConfigWidget *JLinkGdbServerProvider::configurationWidget()
{
return new JLinkGdbServerProviderConfigWidget(this);
}
// JLinkGdbServerProviderFactory
JLinkGdbServerProviderFactory::JLinkGdbServerProviderFactory()

View File

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

View File

@@ -60,6 +60,7 @@ OpenOcdGdbServerProvider::OpenOcdGdbServerProvider()
setChannel("localhost", 3333);
setSettingsKeyBase("BareMetal.OpenOcdGdbServerProvider");
setTypeDisplayName(OpenOcdGdbServerProviderFactory::tr("OpenOCD"));
setConfigurationWidgetCreator([this] { return new OpenOcdGdbServerProviderConfigWidget(this); });
}
QString OpenOcdGdbServerProvider::defaultInitCommands()
@@ -182,11 +183,6 @@ bool OpenOcdGdbServerProvider::operator==(const IDebugServerProvider &other) con
&& m_additionalArguments == p->m_additionalArguments;
}
GdbServerProviderConfigWidget *OpenOcdGdbServerProvider::configurationWidget()
{
return new OpenOcdGdbServerProviderConfigWidget(this);
}
// OpenOcdGdbServerProviderFactory
OpenOcdGdbServerProviderFactory::OpenOcdGdbServerProviderFactory()

View File

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

View File

@@ -61,6 +61,7 @@ StLinkUtilGdbServerProvider::StLinkUtilGdbServerProvider()
setChannel("localhost", 4242);
setSettingsKeyBase("BareMetal.StLinkUtilGdbServerProvider");
setTypeDisplayName(StLinkUtilGdbServerProviderFactory::tr("ST-LINK Utility"));
setConfigurationWidgetCreator([this] { return new StLinkUtilGdbServerProviderConfigWidget(this); });
}
QString StLinkUtilGdbServerProvider::defaultInitCommands()
@@ -168,11 +169,6 @@ bool StLinkUtilGdbServerProvider::operator==(const IDebugServerProvider &other)
&& m_transport == p->m_transport;
}
GdbServerProviderConfigWidget *StLinkUtilGdbServerProvider::configurationWidget()
{
return new StLinkUtilGdbServerProviderConfigWidget(this);
}
// StLinkUtilGdbServerProviderFactory
StLinkUtilGdbServerProviderFactory::StLinkUtilGdbServerProviderFactory()

View File

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

View File

@@ -155,6 +155,12 @@ bool IDebugServerProvider::operator==(const IDebugServerProvider &other) const
&& m_channel == other.m_channel;
}
IDebugServerProviderConfigWidget *IDebugServerProvider::configurationWidget() const
{
QTC_ASSERT(m_configurationWidgetCreator, return nullptr);
return m_configurationWidgetCreator();
}
QVariantMap IDebugServerProvider::toMap() const
{
return {
@@ -197,6 +203,11 @@ bool IDebugServerProvider::fromMap(const QVariantMap &data)
return true;
}
void IDebugServerProvider::setConfigurationWidgetCreator(const std::function<IDebugServerProviderConfigWidget *()> &configurationWidgetCreator)
{
m_configurationWidgetCreator = configurationWidgetCreator;
}
// IDebugServerProviderFactory
QString IDebugServerProviderFactory::id() const

View File

@@ -84,7 +84,9 @@ public:
virtual bool operator==(const IDebugServerProvider &other) const;
virtual IDebugServerProviderConfigWidget *configurationWidget() = 0;
IDebugServerProviderConfigWidget *configurationWidget() const;
void setConfigurationWidgetCreator
(const std::function<IDebugServerProviderConfigWidget *()> &configurationWidgetCreator);
virtual QVariantMap toMap() const;
virtual bool fromMap(const QVariantMap &data);
@@ -114,6 +116,7 @@ protected:
QUrl m_channel;
Debugger::DebuggerEngineType m_engineType = Debugger::NoEngineType;
QSet<BareMetalDevice *> m_devices;
std::function<IDebugServerProviderConfigWidget *()> m_configurationWidgetCreator;
friend class DebugServerProvidersSettingsWidget;
friend class IDebugServerProviderConfigWidget;