From fd23f71cb91ecb54ec75e2d60672c24b39341cdf Mon Sep 17 00:00:00 2001 From: Andrei-Fabian-Pop Date: Mon, 26 Aug 2024 15:27:18 +0300 Subject: [PATCH] iio-widget: Fix parentless IIOWidgets The Data and UI strategy from the IIOWidget are not QObjects, not QWidgets. The LAZY_LOAD function from the IIOWidget now contains only the initial read operation, the setup is done in the constructor. Signed-off-by: Andrei-Fabian-Pop --- .../datastrategy/channelattrdatastrategy.h | 5 +- .../cmdqchannelattrdatastrategy.h | 5 +- .../datastrategy/cmdqdeviceattrdatastrategy.h | 5 +- .../datastrategy/contextattrdatastrategy.h | 5 +- .../datastrategy/deviceattrdatastrategy.h | 5 +- .../datastrategy/multidatastrategy.h | 5 +- .../datastrategy/triggerdatastrategy.h | 5 +- .../guistrategy/comboguistrategy.h | 4 +- .../guistrategy/editableguistrategy.h | 4 +- .../guistrategy/rangeguistrategy.h | 4 +- .../guistrategy/switchguistrategy.h | 4 +- .../datastrategy/channelattrdatastrategy.cpp | 6 +- .../cmdqchannelattrdatastrategy.cpp | 6 +- .../cmdqdeviceattrdatastrategy.cpp | 6 +- .../datastrategy/contextattrdatastrategy.cpp | 6 +- .../datastrategy/deviceattrdatastrategy.cpp | 6 +- .../src/datastrategy/multidatastrategy.cpp | 6 +- .../src/datastrategy/triggerdatastrategy.cpp | 6 +- .../src/guistrategy/comboguistrategy.cpp | 7 +- .../src/guistrategy/editableguistrategy.cpp | 6 +- .../src/guistrategy/rangeguistrategy.cpp | 8 +- .../src/guistrategy/switchguistrategy.cpp | 10 +-- iio-widgets/src/iiowidget.cpp | 74 +++++++++---------- .../src/iioexplorer/iiostandarditem.cpp | 2 +- 24 files changed, 108 insertions(+), 92 deletions(-) diff --git a/iio-widgets/include/iio-widgets/datastrategy/channelattrdatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/channelattrdatastrategy.h index b078857bb7..705412b0e3 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/channelattrdatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/channelattrdatastrategy.h @@ -28,12 +28,13 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT ChannelAttrDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT ChannelAttrDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) public: - explicit ChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent = nullptr); + explicit ChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent = nullptr); + ~ChannelAttrDataStrategy(); QString data() override; QString optionalData() override; diff --git a/iio-widgets/include/iio-widgets/datastrategy/cmdqchannelattrdatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/cmdqchannelattrdatastrategy.h index a872697bf6..ccd838e064 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/cmdqchannelattrdatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/cmdqchannelattrdatastrategy.h @@ -28,12 +28,13 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT CmdQChannelAttrDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT CmdQChannelAttrDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) public: - explicit CmdQChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent = nullptr); + explicit CmdQChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent = nullptr); + ~CmdQChannelAttrDataStrategy(); QString data() override; QString optionalData() override; diff --git a/iio-widgets/include/iio-widgets/datastrategy/cmdqdeviceattrdatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/cmdqdeviceattrdatastrategy.h index 4adc7d91cf..b174773e68 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/cmdqdeviceattrdatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/cmdqdeviceattrdatastrategy.h @@ -8,12 +8,13 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT CmdQDeviceAttrDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT CmdQDeviceAttrDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) public: - explicit CmdQDeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent = nullptr); + explicit CmdQDeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent = nullptr); + CmdQDeviceAttrDataStrategy(); QString data() override; QString optionalData() override; diff --git a/iio-widgets/include/iio-widgets/datastrategy/contextattrdatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/contextattrdatastrategy.h index 43639fe838..8ec8932013 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/contextattrdatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/contextattrdatastrategy.h @@ -7,12 +7,13 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT ContextAttrDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT ContextAttrDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) public: - explicit ContextAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent = nullptr); + explicit ContextAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent = nullptr); + ContextAttrDataStrategy(); QString data() override; QString optionalData() override; diff --git a/iio-widgets/include/iio-widgets/datastrategy/deviceattrdatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/deviceattrdatastrategy.h index 1abc66cb8e..e89228b6e9 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/deviceattrdatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/deviceattrdatastrategy.h @@ -28,12 +28,13 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT DeviceAttrDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT DeviceAttrDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) public: - explicit DeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent = nullptr); + explicit DeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent = nullptr); + ~DeviceAttrDataStrategy(); QString data() override; QString optionalData() override; diff --git a/iio-widgets/include/iio-widgets/datastrategy/multidatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/multidatastrategy.h index 620451e54f..0de7310bab 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/multidatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/multidatastrategy.h @@ -29,7 +29,7 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT MultiDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT MultiDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) @@ -42,7 +42,8 @@ class SCOPY_IIO_WIDGETS_EXPORT MultiDataStrategy : public QWidget, public DataSt * added after creation. * @param parent QWidget* */ - explicit MultiDataStrategy(QList strategies, QWidget *parent = nullptr); + explicit MultiDataStrategy(QList strategies, QObject *parent = nullptr); + ~MultiDataStrategy(); /** * @brief addDataStrategy Add and connect a new Data Strategy. diff --git a/iio-widgets/include/iio-widgets/datastrategy/triggerdatastrategy.h b/iio-widgets/include/iio-widgets/datastrategy/triggerdatastrategy.h index b3c8e78940..c48b62c942 100644 --- a/iio-widgets/include/iio-widgets/datastrategy/triggerdatastrategy.h +++ b/iio-widgets/include/iio-widgets/datastrategy/triggerdatastrategy.h @@ -28,12 +28,13 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT TriggerDataStrategy : public QWidget, public DataStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT TriggerDataStrategy : public QObject, public DataStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::DataStrategyInterface) public: - explicit TriggerDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent = nullptr); + explicit TriggerDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent = nullptr); + ~TriggerDataStrategy(); QString data() override; QString optionalData() override; diff --git a/iio-widgets/include/iio-widgets/guistrategy/comboguistrategy.h b/iio-widgets/include/iio-widgets/guistrategy/comboguistrategy.h index 60a7647401..c7d8d9c36c 100644 --- a/iio-widgets/include/iio-widgets/guistrategy/comboguistrategy.h +++ b/iio-widgets/include/iio-widgets/guistrategy/comboguistrategy.h @@ -29,7 +29,7 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT ComboAttrUi : public QWidget, public GuiStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT ComboAttrUi : public QObject, public GuiStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::GuiStrategyInterface) @@ -37,7 +37,7 @@ class SCOPY_IIO_WIDGETS_EXPORT ComboAttrUi : public QWidget, public GuiStrategyI /** * @brief This contain a MenuComboWidget that takes the options for the combo from recipe->linkedAttributeValue. * */ - explicit ComboAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QWidget *parent = nullptr); + explicit ComboAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QObject *parent = nullptr); ~ComboAttrUi(); /** diff --git a/iio-widgets/include/iio-widgets/guistrategy/editableguistrategy.h b/iio-widgets/include/iio-widgets/guistrategy/editableguistrategy.h index 03f478f8f7..5b749eeb68 100644 --- a/iio-widgets/include/iio-widgets/guistrategy/editableguistrategy.h +++ b/iio-widgets/include/iio-widgets/guistrategy/editableguistrategy.h @@ -29,7 +29,7 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT EditableGuiStrategy : public QWidget, public GuiStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT EditableGuiStrategy : public QObject, public GuiStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::GuiStrategyInterface) @@ -37,7 +37,7 @@ class SCOPY_IIO_WIDGETS_EXPORT EditableGuiStrategy : public QWidget, public GuiS /** * @brief This contain a MenuLineEdit with no validation on what the text can or cannot be set. * */ - explicit EditableGuiStrategy(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QWidget *parent = nullptr); + explicit EditableGuiStrategy(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QObject *parent = nullptr); ~EditableGuiStrategy(); /** diff --git a/iio-widgets/include/iio-widgets/guistrategy/rangeguistrategy.h b/iio-widgets/include/iio-widgets/guistrategy/rangeguistrategy.h index 6d1261a6d7..ee5106f4eb 100644 --- a/iio-widgets/include/iio-widgets/guistrategy/rangeguistrategy.h +++ b/iio-widgets/include/iio-widgets/guistrategy/rangeguistrategy.h @@ -30,7 +30,7 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT RangeAttrUi : public QWidget, public GuiStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT RangeAttrUi : public QObject, public GuiStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::GuiStrategyInterface) @@ -40,7 +40,7 @@ class SCOPY_IIO_WIDGETS_EXPORT RangeAttrUi : public QWidget, public GuiStrategyI * string from recipe->linkedAttributeValue should look like "[begin step end]" where "begin", "step" and "end" * will be converted to double. * */ - explicit RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QWidget *parent = nullptr); + explicit RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QObject *parent = nullptr); ~RangeAttrUi(); /** diff --git a/iio-widgets/include/iio-widgets/guistrategy/switchguistrategy.h b/iio-widgets/include/iio-widgets/guistrategy/switchguistrategy.h index 06b07c3325..4887fbde55 100644 --- a/iio-widgets/include/iio-widgets/guistrategy/switchguistrategy.h +++ b/iio-widgets/include/iio-widgets/guistrategy/switchguistrategy.h @@ -29,7 +29,7 @@ #include "scopy-iio-widgets_export.h" namespace scopy { -class SCOPY_IIO_WIDGETS_EXPORT SwitchAttrUi : public QWidget, public GuiStrategyInterface +class SCOPY_IIO_WIDGETS_EXPORT SwitchAttrUi : public QObject, public GuiStrategyInterface { Q_OBJECT Q_INTERFACES(scopy::GuiStrategyInterface) @@ -38,7 +38,7 @@ class SCOPY_IIO_WIDGETS_EXPORT SwitchAttrUi : public QWidget, public GuiStrategy * @brief This contain a CustomSwitch capable of holding no more than 2 values, the ones specified in * recipe->linkedAttributeValue. * */ - explicit SwitchAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QWidget *parent = nullptr); + explicit SwitchAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact = false, QObject *parent = nullptr); ~SwitchAttrUi(); /** diff --git a/iio-widgets/src/datastrategy/channelattrdatastrategy.cpp b/iio-widgets/src/datastrategy/channelattrdatastrategy.cpp index f4dcb310eb..c9946639bf 100644 --- a/iio-widgets/src/datastrategy/channelattrdatastrategy.cpp +++ b/iio-widgets/src/datastrategy/channelattrdatastrategy.cpp @@ -25,13 +25,15 @@ Q_LOGGING_CATEGORY(CAT_IIO_DATA_STRATEGY, "AttrDataStrategy") using namespace scopy; -ChannelAttrDataStrategy::ChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent) - : QWidget(parent) +ChannelAttrDataStrategy::ChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent) + : QObject(parent) { m_recipe = recipe; m_returnCode = 0; } +ChannelAttrDataStrategy::~ChannelAttrDataStrategy() {} + QString ChannelAttrDataStrategy::data() { return m_data; } QString ChannelAttrDataStrategy::optionalData() { return m_optionalData; } diff --git a/iio-widgets/src/datastrategy/cmdqchannelattrdatastrategy.cpp b/iio-widgets/src/datastrategy/cmdqchannelattrdatastrategy.cpp index c19f9bd909..192653dbb2 100644 --- a/iio-widgets/src/datastrategy/cmdqchannelattrdatastrategy.cpp +++ b/iio-widgets/src/datastrategy/cmdqchannelattrdatastrategy.cpp @@ -28,8 +28,8 @@ Q_LOGGING_CATEGORY(CAT_CMDQ_CHANNEL_DATA_STATEGY, "CmdQChannelDataStrategy") using namespace scopy; -CmdQChannelAttrDataStrategy::CmdQChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent) - : QWidget(parent) +CmdQChannelAttrDataStrategy::CmdQChannelAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent) + : QObject(parent) , m_cmdQueue(recipe.connection->commandQueue()) , m_dataRead("") , m_optionalDataRead("") @@ -37,6 +37,8 @@ CmdQChannelAttrDataStrategy::CmdQChannelAttrDataStrategy(IIOWidgetFactoryRecipe m_recipe = recipe; } +CmdQChannelAttrDataStrategy::~CmdQChannelAttrDataStrategy() {} + QString CmdQChannelAttrDataStrategy::data() { return m_dataRead; } QString CmdQChannelAttrDataStrategy::optionalData() { return m_optionalDataRead; } diff --git a/iio-widgets/src/datastrategy/cmdqdeviceattrdatastrategy.cpp b/iio-widgets/src/datastrategy/cmdqdeviceattrdatastrategy.cpp index 18b69955bc..e87a86071f 100644 --- a/iio-widgets/src/datastrategy/cmdqdeviceattrdatastrategy.cpp +++ b/iio-widgets/src/datastrategy/cmdqdeviceattrdatastrategy.cpp @@ -29,8 +29,8 @@ Q_LOGGING_CATEGORY(CAT_CMDQ_DEVICE_DATA_STRATEGY, "CmdQDeviceDataStrategy") using namespace scopy; -CmdQDeviceAttrDataStrategy::CmdQDeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent) - : QWidget(parent) +CmdQDeviceAttrDataStrategy::CmdQDeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent) + : QObject(parent) , m_cmdQueue(recipe.connection->commandQueue()) , m_dataRead("") , m_optionalDataRead("") @@ -38,6 +38,8 @@ CmdQDeviceAttrDataStrategy::CmdQDeviceAttrDataStrategy(IIOWidgetFactoryRecipe re m_recipe = recipe; } +CmdQDeviceAttrDataStrategy::CmdQDeviceAttrDataStrategy() {} + QString CmdQDeviceAttrDataStrategy::data() { return m_dataRead; } QString CmdQDeviceAttrDataStrategy::optionalData() { return m_optionalDataRead; } diff --git a/iio-widgets/src/datastrategy/contextattrdatastrategy.cpp b/iio-widgets/src/datastrategy/contextattrdatastrategy.cpp index 32b7b44913..614a665a9c 100644 --- a/iio-widgets/src/datastrategy/contextattrdatastrategy.cpp +++ b/iio-widgets/src/datastrategy/contextattrdatastrategy.cpp @@ -4,13 +4,15 @@ Q_LOGGING_CATEGORY(CAT_CONTEXT_ATTR_DATA_STRATEGY, "ContextAttrDataStrategy") using namespace scopy; -ContextAttrDataStrategy::ContextAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent) - : QWidget(parent) +ContextAttrDataStrategy::ContextAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent) + : QObject(parent) { m_recipe = recipe; m_optionalData = ""; } +ContextAttrDataStrategy::ContextAttrDataStrategy() {} + QString ContextAttrDataStrategy::data() { return m_data; } QString ContextAttrDataStrategy::optionalData() { return m_optionalData; } diff --git a/iio-widgets/src/datastrategy/deviceattrdatastrategy.cpp b/iio-widgets/src/datastrategy/deviceattrdatastrategy.cpp index de4b075fd0..38e5994f18 100644 --- a/iio-widgets/src/datastrategy/deviceattrdatastrategy.cpp +++ b/iio-widgets/src/datastrategy/deviceattrdatastrategy.cpp @@ -24,12 +24,14 @@ Q_LOGGING_CATEGORY(CAT_DEVICE_DATA_STRATEGY, "DeviceDataStrategy") using namespace scopy; -DeviceAttrDataStrategy::DeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent) - : QWidget(parent) +DeviceAttrDataStrategy::DeviceAttrDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent) + : QObject(parent) { m_recipe = recipe; } +DeviceAttrDataStrategy::~DeviceAttrDataStrategy() {} + QString DeviceAttrDataStrategy::data() { return m_data; } QString DeviceAttrDataStrategy::optionalData() { return m_optionalData; } diff --git a/iio-widgets/src/datastrategy/multidatastrategy.cpp b/iio-widgets/src/datastrategy/multidatastrategy.cpp index fc63492e31..b59ef781e7 100644 --- a/iio-widgets/src/datastrategy/multidatastrategy.cpp +++ b/iio-widgets/src/datastrategy/multidatastrategy.cpp @@ -3,8 +3,8 @@ Q_LOGGING_CATEGORY(CAT_MULTI_DATA_STRATEGY, "MultiDataStrategy") using namespace scopy; -MultiDataStrategy::MultiDataStrategy(QList strategies, QWidget *parent) - : QWidget(parent) +MultiDataStrategy::MultiDataStrategy(QList strategies, QObject *parent) + : QObject(parent) , m_dataStrategies(strategies) , m_data("") , m_optionalData("") @@ -27,6 +27,8 @@ MultiDataStrategy::MultiDataStrategy(QList strategies, } } +MultiDataStrategy::~MultiDataStrategy() {} + void MultiDataStrategy::addDataStrategy(DataStrategyInterface *ds) { m_dataStrategies.append(ds); diff --git a/iio-widgets/src/datastrategy/triggerdatastrategy.cpp b/iio-widgets/src/datastrategy/triggerdatastrategy.cpp index 09b7e9c446..1d1bcfe021 100644 --- a/iio-widgets/src/datastrategy/triggerdatastrategy.cpp +++ b/iio-widgets/src/datastrategy/triggerdatastrategy.cpp @@ -26,12 +26,14 @@ using namespace scopy; Q_LOGGING_CATEGORY(CAT_TRIGGER_DATA_STRATEGY, "TriggerDataStrategy") -TriggerDataStrategy::TriggerDataStrategy(IIOWidgetFactoryRecipe recipe, QWidget *parent) - : QWidget(parent) +TriggerDataStrategy::TriggerDataStrategy(IIOWidgetFactoryRecipe recipe, QObject *parent) + : QObject(parent) { m_recipe = recipe; } +TriggerDataStrategy::~TriggerDataStrategy() {} + QString TriggerDataStrategy::data() { return m_data; } QString TriggerDataStrategy::optionalData() { return m_optionalData; } diff --git a/iio-widgets/src/guistrategy/comboguistrategy.cpp b/iio-widgets/src/guistrategy/comboguistrategy.cpp index b266657ea7..bf916cf1e7 100644 --- a/iio-widgets/src/guistrategy/comboguistrategy.cpp +++ b/iio-widgets/src/guistrategy/comboguistrategy.cpp @@ -23,8 +23,9 @@ using namespace scopy; -ComboAttrUi::ComboAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget *parent) - : m_ui(new QWidget(nullptr)) +ComboAttrUi::ComboAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QObject *parent) + : QObject(parent) + , m_ui(new QWidget(nullptr)) , m_isCompact(isCompact) { m_recipe = recipe; @@ -63,7 +64,7 @@ ComboAttrUi::ComboAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget Q_EMIT requestData(); } -ComboAttrUi::~ComboAttrUi() { m_ui->deleteLater(); } +ComboAttrUi::~ComboAttrUi() {} QWidget *ComboAttrUi::ui() { return m_ui; } diff --git a/iio-widgets/src/guistrategy/editableguistrategy.cpp b/iio-widgets/src/guistrategy/editableguistrategy.cpp index d73cf4a535..0175290ce1 100644 --- a/iio-widgets/src/guistrategy/editableguistrategy.cpp +++ b/iio-widgets/src/guistrategy/editableguistrategy.cpp @@ -22,8 +22,8 @@ using namespace scopy; -EditableGuiStrategy::EditableGuiStrategy(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget *parent) - : QWidget(parent) +EditableGuiStrategy::EditableGuiStrategy(IIOWidgetFactoryRecipe recipe, bool isCompact, QObject *parent) + : QObject(parent) , m_ui(new QWidget(nullptr)) , m_lineEdit(new MenuLineEdit(m_ui)) { @@ -55,7 +55,7 @@ EditableGuiStrategy::EditableGuiStrategy(IIOWidgetFactoryRecipe recipe, bool isC Q_EMIT requestData(); } -EditableGuiStrategy::~EditableGuiStrategy() { m_ui->deleteLater(); } +EditableGuiStrategy::~EditableGuiStrategy() {} QWidget *EditableGuiStrategy::ui() { return m_ui; } diff --git a/iio-widgets/src/guistrategy/rangeguistrategy.cpp b/iio-widgets/src/guistrategy/rangeguistrategy.cpp index b1e618a169..9c426c4fa0 100644 --- a/iio-widgets/src/guistrategy/rangeguistrategy.cpp +++ b/iio-widgets/src/guistrategy/rangeguistrategy.cpp @@ -25,8 +25,8 @@ using namespace scopy; Q_LOGGING_CATEGORY(CAT_ATTR_GUI_STRATEGY, "AttrGuiStrategy") -RangeAttrUi::RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget *parent) - : QWidget(parent) +RangeAttrUi::RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QObject *parent) + : QObject(parent) , m_ui(new QWidget(nullptr)) { m_recipe = recipe; @@ -39,7 +39,7 @@ RangeAttrUi::RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget m_ui->layout()->setContentsMargins(0, 0, 0, 0); // FIXME: this does not look right when uninitialized, also crashes... - m_spinBox = new TitleSpinBox(m_recipe.data.toUpper(), isCompact, this); + m_spinBox = new TitleSpinBox(m_recipe.data.toUpper(), isCompact, m_ui); m_ui->layout()->addWidget(m_spinBox); connect(m_spinBox->getLineEdit(), &QLineEdit::textChanged, this, @@ -47,7 +47,7 @@ RangeAttrUi::RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget Q_EMIT requestData(); } -RangeAttrUi::~RangeAttrUi() { m_ui->deleteLater(); } +RangeAttrUi::~RangeAttrUi() {} QWidget *RangeAttrUi::ui() { return m_ui; } diff --git a/iio-widgets/src/guistrategy/switchguistrategy.cpp b/iio-widgets/src/guistrategy/switchguistrategy.cpp index 22f6b7e44d..94610b2e9a 100644 --- a/iio-widgets/src/guistrategy/switchguistrategy.cpp +++ b/iio-widgets/src/guistrategy/switchguistrategy.cpp @@ -25,8 +25,8 @@ using namespace scopy; Q_LOGGING_CATEGORY(CAT_SWITCHGUISTRATEGY, "SwitchGuiStrategy") -SwitchAttrUi::SwitchAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget *parent) - : QWidget(parent) +SwitchAttrUi::SwitchAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QObject *parent) + : QObject(parent) , m_ui(new QWidget(nullptr)) , m_optionsList(new QStringList) { @@ -43,11 +43,7 @@ SwitchAttrUi::SwitchAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidge }); } -SwitchAttrUi::~SwitchAttrUi() -{ - delete m_optionsList; - m_ui->deleteLater(); -} +SwitchAttrUi::~SwitchAttrUi() { delete m_optionsList; } QWidget *SwitchAttrUi::ui() { return m_ui; } diff --git a/iio-widgets/src/iiowidget.cpp b/iio-widgets/src/iiowidget.cpp index f594fd9376..42b8ab3fd0 100644 --- a/iio-widgets/src/iiowidget.cpp +++ b/iio-widgets/src/iiowidget.cpp @@ -35,6 +35,41 @@ IIOWidget::IIOWidget(GuiStrategyInterface *uiStrategy, DataStrategyInterface *da , m_lastOpState(nullptr) , m_lastReturnCode(0) { + setLayout(new QVBoxLayout(this)); + layout()->setContentsMargins(0, 0, 0, 0); + layout()->setSpacing(0); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + QWidget *ui = m_uiStrategy->ui(); + if(ui) { + layout()->addWidget(ui); + } + layout()->addWidget(m_progressBar); + + QObject *uiStrategyObject = dynamic_cast(m_uiStrategy); + QObject *dataStrategyObject = dynamic_cast(m_dataStrategy); + + uiStrategyObject->setParent(this); + dataStrategyObject->setParent(this); + + connect(m_progressBar, &SmallProgressBar::progressFinished, this, [this]() { this->saveData(m_lastData); }); + + connect(uiStrategyObject, SIGNAL(emitData(QString)), this, SLOT(startTimer(QString))); + + connect(dataStrategyObject, SIGNAL(emitStatus(QDateTime, QString, QString, int, bool)), this, + SLOT(emitDataStatus(QDateTime, QString, QString, int, bool))); + + // forward data request from ui strategy to data strategy + connect(uiStrategyObject, SIGNAL(requestData()), dataStrategyObject, SLOT(readAsync())); + + // forward data from data strategy to ui strategy + connect(dataStrategyObject, SIGNAL(sendData(QString, QString)), uiStrategyObject, + SLOT(receiveData(QString, QString))); + + // intercept the sendData from dataStrategy to collect information + connect(dataStrategyObject, SIGNAL(sendData(QString, QString)), this, SLOT(storeReadInfo(QString, QString))); + + // The data will be populated here bool useLazyLoading = Preferences::GetInstance()->get("iiowidgets_use_lazy_loading").toBool(); if(!useLazyLoading) { // force skip lazy load LAZY_LOAD(initialize); @@ -125,44 +160,7 @@ void IIOWidget::storeReadInfo(QString data, QString optionalData) setLastOperationTimestamp(QDateTime::currentDateTime()); } -void IIOWidget::initialize() -{ - setLayout(new QVBoxLayout(this)); - layout()->setContentsMargins(0, 0, 0, 0); - layout()->setSpacing(0); - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - QWidget *ui = m_uiStrategy->ui(); - if(ui) { - layout()->addWidget(ui); - } - layout()->addWidget(m_progressBar); - - QWidget *uiStrategyWidget = dynamic_cast(m_uiStrategy); - QWidget *dataStrategyWidget = dynamic_cast(m_dataStrategy); - - connect(m_progressBar, &SmallProgressBar::progressFinished, this, [this]() { this->saveData(m_lastData); }); - - connect(uiStrategyWidget, SIGNAL(emitData(QString)), this, SLOT(startTimer(QString))); - - connect(dataStrategyWidget, SIGNAL(emitStatus(QDateTime, QString, QString, int, bool)), this, - SLOT(emitDataStatus(QDateTime, QString, QString, int, bool))); - - // forward data request from ui strategy to data strategy - connect(uiStrategyWidget, SIGNAL(requestData()), dataStrategyWidget, SLOT(readAsync())); - - // forward data from data strategy to ui strategy - connect(dataStrategyWidget, SIGNAL(sendData(QString, QString)), uiStrategyWidget, - SLOT(receiveData(QString, QString))); - - // intercept the sendData from dataStrategy to collect information - connect(dataStrategyWidget, SIGNAL(sendData(QString, QString)), this, SLOT(storeReadInfo(QString, QString))); - - connect(dynamic_cast(m_dataStrategy), SIGNAL(sendData(QString, QString)), this, - SLOT(storeReadInfo(QString, QString))); - - m_dataStrategy->readAsync(); -} +void IIOWidget::initialize() { m_dataStrategy->readAsync(); } void IIOWidget::setLastOperationTimestamp(QDateTime timestamp) { diff --git a/plugins/debugger/src/iioexplorer/iiostandarditem.cpp b/plugins/debugger/src/iioexplorer/iiostandarditem.cpp index 40bea83f3d..6f5b6a6ac6 100644 --- a/plugins/debugger/src/iioexplorer/iiostandarditem.cpp +++ b/plugins/debugger/src/iioexplorer/iiostandarditem.cpp @@ -143,7 +143,7 @@ void IIOStandardItem::connectLog() // this is leaf iio widget, it can probably read/write IIOWidget *widget = m_iioWidgets.at(0); - connect(dynamic_cast(widget->getDataStrategy()), + connect(dynamic_cast(widget->getDataStrategy()), SIGNAL(emitStatus(QDateTime, QString, QString, int, bool)), this, SLOT(forwardLog(QDateTime, QString, QString, int, bool))); }