Skip to content

Commit

Permalink
Eliminating configuration widget creation function from the plugin pr…
Browse files Browse the repository at this point in the history
…operties.
  • Loading branch information
arobenko committed Nov 4, 2024
1 parent 0b91525 commit 6ed27e7
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 87 deletions.
6 changes: 4 additions & 2 deletions lib/include/cc_tools_qt/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
#include <QtCore/QObject>
#include <QtCore/QtPlugin>
#include <QtCore/QVariantMap>
#include <QtWidgets/QWidget>

#include "Api.h"
#include "PluginProperties.h"

class QWidget;

namespace cc_tools_qt
{

Expand Down Expand Up @@ -115,7 +116,7 @@ class CC_API Plugin : public QObject
/// GUI application, i.e. the plugin doesn't need to perform any
/// delete operation on it.
/// @return Dynamically allocated widget object
QWidget* createConfiguarionWidget() const;
QWidget* createConfiguarionWidget();

/// @brief Retrieve custom property assigned by the derived class.
/// @param[in] name Name of the property
Expand Down Expand Up @@ -163,6 +164,7 @@ class CC_API Plugin : public QObject
virtual SocketPtr createSocketImpl();
virtual FilterPtr createFilterImpl();
virtual ToolsProtocolPtr createProtocolImpl();
virtual QWidget* createConfiguarionWidgetImpl();

/// @brief Get access to plugin properties
/// @details Expected to be called by the derived class to get an access
Expand Down
16 changes: 0 additions & 16 deletions lib/include/cc_tools_qt/PluginProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "Api.h"

class QAction;
class QWidget;

namespace cc_tools_qt
{
Expand All @@ -57,22 +56,11 @@ class CC_API PluginProperties
/// application. The plugin won't need to delete them explicitly.
using GuiActionsCreateFunc = std::function<ListOfGuiActions ()>;

/// @brief Type of callback to be used when a widget responsible to configure
/// the plugin needs to be allocated. The allocated widget will be
/// owned by the application. The plugin won't need to delete it
/// explicitly.
using ConfigWidgetCreateFunc = std::function<QWidget* ()>;

/// @brief Assign callback for list of @b QAction allocation.
/// @param[in] func Callback function
/// @return `*this`
PluginProperties& setGuiActionsCreateFunc(GuiActionsCreateFunc&& func);

/// @brief Assign callback for configuration widget creation.
/// @param[in] func Callback function
/// @return `*this`
PluginProperties& setConfigWidgetCreateFunc(ConfigWidgetCreateFunc&& func);

/// @brief Set custom property
/// @param[in] name Name of the property
/// @param[out] val Property value
Expand All @@ -81,9 +69,6 @@ class CC_API PluginProperties
/// @brief Retrieve GUI Actions creation callback.
GuiActionsCreateFunc getGuiActionsCreateFunc() const;

/// @brief Retrieve plugin configuration widget creation callback.
ConfigWidgetCreateFunc getConfigWidgetCreateFunc() const;

/// @brief Get custom property
/// @param[in] name Property name
/// @return Value of the property
Expand All @@ -96,6 +81,5 @@ class CC_API PluginProperties
} // namespace cc_tools_qt

Q_DECLARE_METATYPE(cc_tools_qt::PluginProperties::GuiActionsCreateFunc);
Q_DECLARE_METATYPE(cc_tools_qt::PluginProperties::ConfigWidgetCreateFunc);


14 changes: 7 additions & 7 deletions lib/src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,9 @@ Plugin::ListOfGuiActions Plugin::createGuiActions() const
return invokeCreationFunc(m_props.getGuiActionsCreateFunc());
}

QWidget* Plugin::createConfiguarionWidget() const
QWidget* Plugin::createConfiguarionWidget()
{
auto func = m_props.getConfigWidgetCreateFunc();
if (!func) {
return nullptr;
}

return func();
return createConfiguarionWidgetImpl();
}

QVariant Plugin::getCustomProperty(const QString& name)
Expand Down Expand Up @@ -172,6 +167,11 @@ ToolsProtocolPtr Plugin::createProtocolImpl()
return ToolsProtocolPtr();
}

QWidget* Plugin::createConfiguarionWidgetImpl()
{
return nullptr;
}

PluginProperties& Plugin::pluginProperties()
{
return m_props;
Expand Down
12 changes: 0 additions & 12 deletions lib/src/PluginProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ PluginProperties& PluginProperties::setGuiActionsCreateFunc(
return *this;
}

PluginProperties& PluginProperties::setConfigWidgetCreateFunc(
ConfigWidgetCreateFunc&& func)
{
m_props.insert(ConfigWidgetCreateFuncPropName, QVariant::fromValue(std::move(func)));
return *this;
}

PluginProperties& PluginProperties::setCustomProperty(
const QString& name,
QVariant&& val)
Expand All @@ -85,11 +78,6 @@ PluginProperties::GuiActionsCreateFunc PluginProperties::getGuiActionsCreateFunc
return getFuncProperty<GuiActionsCreateFunc>(m_props, GuiActionsCreateFuncPropName);
}

PluginProperties::ConfigWidgetCreateFunc PluginProperties::getConfigWidgetCreateFunc() const
{
return getFuncProperty<ConfigWidgetCreateFunc>(m_props, ConfigWidgetCreateFuncPropName);
}

QVariant PluginProperties::getCustomProperty(const QString& name) const
{
if (name.startsWith(PropPrefix)) {
Expand Down
13 changes: 6 additions & 7 deletions plugin/serial_socket/SerialSocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ const QString FlowControlSubKey("flow");
SerialSocketPlugin::SerialSocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]()
{
createSocketIfNeeded();
return new SerialSocketConfigWidget(*m_socket);
});
}

SerialSocketPlugin::~SerialSocketPlugin() noexcept = default;
Expand Down Expand Up @@ -137,6 +130,12 @@ SocketPtr SerialSocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* SerialSocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new SerialSocketConfigWidget(*m_socket);
}

void SerialSocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/serial_socket/SerialSocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SerialSocketPlugin : public cc_tools_qt::Plugin
virtual void getCurrentConfigImpl(QVariantMap& config) override;
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual SocketPtr createSocketImpl() override;

virtual QWidget* createConfiguarionWidgetImpl() override;
private:

void createSocketIfNeeded();
Expand Down
13 changes: 6 additions & 7 deletions plugin/ssl_socket/client/SslClientSocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ const QString PrivFormatSubKey("priv_format");
SslClientSocketPlugin::SslClientSocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]()
{
createSocketIfNeeded();
return new SslClientSocketConfigWidget(*m_socket);
});
}

SslClientSocketPlugin::~SslClientSocketPlugin() noexcept = default;
Expand Down Expand Up @@ -195,6 +188,12 @@ SocketPtr SslClientSocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* SslClientSocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new SslClientSocketConfigWidget(*m_socket);
}

void SslClientSocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
1 change: 1 addition & 0 deletions plugin/ssl_socket/client/SslClientSocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SslClientSocketPlugin : public cc_tools_qt::Plugin
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual void applyInterPluginConfigImpl(const QVariantMap& props) override;
virtual SocketPtr createSocketImpl() override;
virtual QWidget* createConfiguarionWidgetImpl() override;

private:

Expand Down
13 changes: 6 additions & 7 deletions plugin/tcp_socket/client/TcpClientSocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ const QString PortSubKey("port");
TcpClientSocketPlugin::TcpClientSocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]()
{
createSocketIfNeeded();
return new TcpClientSocketConfigWidget(*m_socket);
});
}

TcpClientSocketPlugin::~TcpClientSocketPlugin() noexcept = default;
Expand Down Expand Up @@ -98,6 +91,12 @@ SocketPtr TcpClientSocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* TcpClientSocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new TcpClientSocketConfigWidget(*m_socket);
}

void TcpClientSocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
1 change: 1 addition & 0 deletions plugin/tcp_socket/client/TcpClientSocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TcpClientSocketPlugin : public cc_tools_qt::Plugin
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual void applyInterPluginConfigImpl(const QVariantMap& props) override;
virtual SocketPtr createSocketImpl() override;
virtual QWidget* createConfiguarionWidgetImpl() override;

private:

Expand Down
13 changes: 6 additions & 7 deletions plugin/tcp_socket/proxy/TcpProxySocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ const QString RemotePortSubKey("remote_port");
TcpProxySocketPlugin::TcpProxySocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]()
{
createSocketIfNeeded();
return new TcpProxySocketConfigWidget(*m_socket);
});
}

TcpProxySocketPlugin::~TcpProxySocketPlugin() noexcept = default;
Expand Down Expand Up @@ -111,6 +104,12 @@ SocketPtr TcpProxySocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* TcpProxySocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new TcpProxySocketConfigWidget(*m_socket);
}

void TcpProxySocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
1 change: 1 addition & 0 deletions plugin/tcp_socket/proxy/TcpProxySocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TcpProxySocketPlugin : public cc_tools_qt::Plugin
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual void applyInterPluginConfigImpl(const QVariantMap& props) override;
virtual SocketPtr createSocketImpl() override;
virtual QWidget* createConfiguarionWidgetImpl() override;

private:

Expand Down
13 changes: 6 additions & 7 deletions plugin/tcp_socket/server/TcpServerSocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ const QString PortSubKey("port");
TcpServerSocketPlugin::TcpServerSocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]()
{
createSocketIfNeeded();
return new TcpServerSocketConfigWidget(*m_socket);
});
}

TcpServerSocketPlugin::~TcpServerSocketPlugin() noexcept = default;
Expand Down Expand Up @@ -93,6 +86,12 @@ SocketPtr TcpServerSocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* TcpServerSocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new TcpServerSocketConfigWidget(*m_socket);
}

void TcpServerSocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
1 change: 1 addition & 0 deletions plugin/tcp_socket/server/TcpServerSocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TcpServerSocketPlugin : public cc_tools_qt::Plugin
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual void applyInterPluginConfigImpl(const QVariantMap& props) override;
virtual SocketPtr createSocketImpl() override;
virtual QWidget* createConfiguarionWidgetImpl() override;

private:

Expand Down
13 changes: 6 additions & 7 deletions plugin/udp_socket/generic/UdpGenericSocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ const QString BroadcastMaskSubKey("broadcast_prop");
UdpGenericSocketPlugin::UdpGenericSocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]() -> QWidget*
{
createSocketIfNeeded();
return new UdpGenericSocketConfigWidget(*m_socket);
});
}

UdpGenericSocketPlugin::~UdpGenericSocketPlugin() noexcept = default;
Expand Down Expand Up @@ -114,6 +107,12 @@ SocketPtr UdpGenericSocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* UdpGenericSocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new UdpGenericSocketConfigWidget(*m_socket);
}

void UdpGenericSocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
1 change: 1 addition & 0 deletions plugin/udp_socket/generic/UdpGenericSocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class UdpGenericSocketPlugin : public cc_tools_qt::Plugin
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual void applyInterPluginConfigImpl(const QVariantMap& props) override;
virtual SocketPtr createSocketImpl() override;
virtual QWidget* createConfiguarionWidgetImpl() override;

private:

Expand Down
13 changes: 6 additions & 7 deletions plugin/udp_socket/proxy/UdpProxySocketPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ const QString LocalPortSubKey("local_port");
UdpProxySocketPlugin::UdpProxySocketPlugin() :
Base(Type_Socket)
{
pluginProperties()
.setConfigWidgetCreateFunc(
[this]() -> QWidget*
{
createSocketIfNeeded();
return new UdpProxySocketConfigWidget(*m_socket);
});
}

UdpProxySocketPlugin::~UdpProxySocketPlugin() noexcept = default;
Expand Down Expand Up @@ -105,6 +98,12 @@ SocketPtr UdpProxySocketPlugin::createSocketImpl()
return m_socket;
}

QWidget* UdpProxySocketPlugin::createConfiguarionWidgetImpl()
{
createSocketIfNeeded();
return new UdpProxySocketConfigWidget(*m_socket);
}

void UdpProxySocketPlugin::createSocketIfNeeded()
{
if (!m_socket) {
Expand Down
1 change: 1 addition & 0 deletions plugin/udp_socket/proxy/UdpProxySocketPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class UdpProxySocketPlugin : public cc_tools_qt::Plugin
virtual void reconfigureImpl(const QVariantMap& config) override;
virtual void applyInterPluginConfigImpl(const QVariantMap& props) override;
virtual SocketPtr createSocketImpl() override;
virtual QWidget* createConfiguarionWidgetImpl() override;

private:
void createSocketIfNeeded();
Expand Down

0 comments on commit 6ed27e7

Please sign in to comment.