Skip to content

Commit

Permalink
iio-widget: Fix parentless IIOWidgets
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop authored and adisuciu committed Aug 29, 2024
1 parent a3e0c1b commit fd23f71
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,7 +42,8 @@ class SCOPY_IIO_WIDGETS_EXPORT MultiDataStrategy : public QWidget, public DataSt
* added after creation.
* @param parent QWidget*
*/
explicit MultiDataStrategy(QList<DataStrategyInterface *> strategies, QWidget *parent = nullptr);
explicit MultiDataStrategy(QList<DataStrategyInterface *> strategies, QObject *parent = nullptr);
~MultiDataStrategy();

/**
* @brief addDataStrategy Add and connect a new Data Strategy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
#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)
public:
/**
* @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();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
#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)
public:
/**
* @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();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();

/**
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/channelattrdatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/cmdqchannelattrdatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ 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("")
{
m_recipe = recipe;
}

CmdQChannelAttrDataStrategy::~CmdQChannelAttrDataStrategy() {}

QString CmdQChannelAttrDataStrategy::data() { return m_dataRead; }

QString CmdQChannelAttrDataStrategy::optionalData() { return m_optionalDataRead; }
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/cmdqdeviceattrdatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ 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("")
{
m_recipe = recipe;
}

CmdQDeviceAttrDataStrategy::CmdQDeviceAttrDataStrategy() {}

QString CmdQDeviceAttrDataStrategy::data() { return m_dataRead; }

QString CmdQDeviceAttrDataStrategy::optionalData() { return m_optionalDataRead; }
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/contextattrdatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/deviceattrdatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/multidatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Q_LOGGING_CATEGORY(CAT_MULTI_DATA_STRATEGY, "MultiDataStrategy")
using namespace scopy;

MultiDataStrategy::MultiDataStrategy(QList<DataStrategyInterface *> strategies, QWidget *parent)
: QWidget(parent)
MultiDataStrategy::MultiDataStrategy(QList<DataStrategyInterface *> strategies, QObject *parent)
: QObject(parent)
, m_dataStrategies(strategies)
, m_data("")
, m_optionalData("")
Expand All @@ -27,6 +27,8 @@ MultiDataStrategy::MultiDataStrategy(QList<DataStrategyInterface *> strategies,
}
}

MultiDataStrategy::~MultiDataStrategy() {}

void MultiDataStrategy::addDataStrategy(DataStrategyInterface *ds)
{
m_dataStrategies.append(ds);
Expand Down
6 changes: 4 additions & 2 deletions iio-widgets/src/datastrategy/triggerdatastrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
7 changes: 4 additions & 3 deletions iio-widgets/src/guistrategy/comboguistrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }

Expand Down
6 changes: 3 additions & 3 deletions iio-widgets/src/guistrategy/editableguistrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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; }

Expand Down
8 changes: 4 additions & 4 deletions iio-widgets/src/guistrategy/rangeguistrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,15 +39,15 @@ 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,
[this](QString text) { Q_EMIT emitData(text); });
Q_EMIT requestData();
}

RangeAttrUi::~RangeAttrUi() { m_ui->deleteLater(); }
RangeAttrUi::~RangeAttrUi() {}

QWidget *RangeAttrUi::ui() { return m_ui; }

Expand Down
Loading

0 comments on commit fd23f71

Please sign in to comment.