chore(cpn): implement ui bindings to auto widgets and apply to timers (#7331)

This commit is contained in:
Neil Horne
2026-06-16 17:14:57 +10:00
committed by GitHub
parent 4ebf3486f1
commit 892410b797
41 changed files with 791 additions and 178 deletions
+1
View File
@@ -22,6 +22,7 @@ set(${PROJECT_NAME}_NAMES
scrollarea
textvalidator
exclusivecombogroup
widgetbindings
)
AddHeadersSources()
@@ -76,7 +76,7 @@ void AutoBitMappedCheckBox::onToggled(bool checked)
unsigned int fieldmask = (bitmask() << shiftbits());
*m_field = (*m_field & ~fieldmask) | (val << shiftbits());
emit currentDataChanged(val);
dataChanged();
runPostChanged();
}
}
@@ -101,3 +101,8 @@ unsigned int AutoBitMappedCheckBox::bitmask()
mask = ~(mask << m_bits);
return (unsigned int)mask;
}
void AutoBitMappedCheckBox::setAutoText(QString text)
{
QCheckBox::setText(text);
}
@@ -34,6 +34,7 @@ class AutoBitMappedCheckBox : public QCheckBox, public AutoWidget
virtual ~AutoBitMappedCheckBox();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setField(int & field, GenericPanel * panel = nullptr, bool invert = false);
void setField(unsigned int & field, GenericPanel * panel = nullptr, bool invert = false);
@@ -47,6 +48,9 @@ class AutoBitMappedCheckBox : public QCheckBox, public AutoWidget
protected slots:
void onToggled(bool checked);
protected:
virtual void setAutoText(QString text) override;
private:
int *m_field;
bool m_invert;
+13 -6
View File
@@ -78,6 +78,11 @@ void AutoBitMappedComboBox::addItem(const QString & item, int value)
updateValue();
}
void AutoBitMappedComboBox::setAutoModel(QAbstractItemModel * model)
{
AutoBitMappedComboBox::setModel(model);
}
void AutoBitMappedComboBox::setField(unsigned int & field, GenericPanel * panel)
{
m_field = (int *)&field;
@@ -130,11 +135,13 @@ void AutoBitMappedComboBox::setBits(const unsigned int numBits, const unsigned i
void AutoBitMappedComboBox::setModel(QAbstractItemModel * model)
{
setLock(true);
QComboBox::setModel(model);
setLock(false);
m_hasModel = true;
updateValue();
if (model && QComboBox::model() != model) {
setLock(true);
QComboBox::setModel(model);
setLock(false);
m_hasModel = true;
updateValue();
}
}
void AutoBitMappedComboBox::setAutoIndexes()
@@ -190,7 +197,7 @@ void AutoBitMappedComboBox::onCurrentIndexChanged(int index)
return;
emit currentDataChanged(val);
dataChanged();
runPostChanged();
}
unsigned int AutoBitMappedComboBox::shiftbits()
@@ -41,6 +41,8 @@ class AutoBitMappedComboBox : public QComboBox, public AutoWidget
virtual void insertItems(int index, const QStringList & items);
// AutoWidget
virtual void updateValue() override;
virtual void setAutoModel(QAbstractItemModel * model);
void setBindText(std::function<QString()> fn) = delete;
void clear();
+6 -1
View File
@@ -145,7 +145,7 @@ void AutoBitsetCheckBox::onToggled(bool checked)
}
emit currentDataChanged(checked);
dataChanged();
runPostChanged();
}
void AutoBitsetCheckBox::init()
@@ -160,3 +160,8 @@ void AutoBitsetCheckBox::initField(int bitmask, bool invert, int toggleMask)
m_invert = toggleMask ? false : invert;
updateValue();
}
void AutoBitsetCheckBox::setAutoText(QString text)
{
QCheckBox::setText(text);
}
@@ -46,6 +46,7 @@ class AutoBitsetCheckBox: public QCheckBox, public AutoWidget
virtual ~AutoBitsetCheckBox();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setField(int & field, int bitmask = 0, bool invert = false, int toggleMask = 0);
void setField(unsigned & field, int bitmask = 0, bool invert = false, int toggleMask = 0);
@@ -59,6 +60,9 @@ class AutoBitsetCheckBox: public QCheckBox, public AutoWidget
protected slots:
void onToggled(bool checked);
protected:
virtual void setAutoText(QString text) override;
private:
int *m_field = nullptr;
int m_bitmask = 0;
+12 -7
View File
@@ -34,6 +34,16 @@ AutoCheckBox::~AutoCheckBox()
{
}
void AutoCheckBox::onToggled(bool checked)
{
if (m_field && !lock()) {
const bool val = m_invert ? !checked : checked;
*m_field = val;
emit currentDataChanged(val);
runPostChanged();
}
}
void AutoCheckBox::setField(bool & field, GenericPanel * panel, bool invert)
{
m_field = &field;
@@ -48,14 +58,9 @@ void AutoCheckBox::setInvert(bool invert)
updateValue();
}
void AutoCheckBox::onToggled(bool checked)
void AutoCheckBox::setAutoText(QString text)
{
if (m_field && !lock()) {
const bool val = m_invert ? !checked : checked;
*m_field = val;
emit currentDataChanged(val);
dataChanged();
}
QCheckBox::setText(text);
}
void AutoCheckBox::updateValue()
+4
View File
@@ -34,6 +34,7 @@ class AutoCheckBox : public QCheckBox, public AutoWidget
virtual ~AutoCheckBox();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setField(bool & field, GenericPanel * panel = nullptr, bool invert = false);
void setInvert(bool invert);
@@ -44,6 +45,9 @@ class AutoCheckBox : public QCheckBox, public AutoWidget
protected slots:
void onToggled(bool checked);
protected:
virtual void setAutoText(QString text) override;
private:
bool *m_field;
bool m_invert;
+13 -6
View File
@@ -82,6 +82,11 @@ void AutoComboBox::addItem(const QString & item, int value)
}
}
void AutoComboBox::setAutoModel(QAbstractItemModel * model)
{
AutoComboBox::setModel(model);
}
void AutoComboBox::setField(unsigned int & field, GenericPanel * panel)
{
setFieldInit(panel);
@@ -153,11 +158,13 @@ void AutoComboBox::setFieldInit(GenericPanel * panel)
void AutoComboBox::setModel(QAbstractItemModel * model)
{
setLock(true);
QComboBox::setModel(model);
setLock(false);
m_hasModel = true;
updateValue();
if (model && QComboBox::model() != model) {
setLock(true);
QComboBox::setModel(model);
setLock(false);
m_hasModel = true;
updateValue();
}
}
void AutoComboBox::setAutoIndexes()
@@ -231,6 +238,6 @@ void AutoComboBox::onCurrentIndexChanged(int index)
return;
emit currentDataChanged(val);
dataChanged();
runPostChanged();
}
}
+2
View File
@@ -49,6 +49,8 @@ class AutoComboBox : public QComboBox, public AutoWidget
virtual void insertItems(int index, const QStringList & items);
// AutoWidget
virtual void updateValue() override;
virtual void setAutoModel(QAbstractItemModel * model);
void setBindText(std::function<QString()> fn) = delete;
void clear();
+1 -1
View File
@@ -88,6 +88,6 @@ void AutoDoubleSpinBox::onValueChanged(double value)
if (m_field && !lock()) {
*m_field = round(value * multiplier() - m_offset);
emit currentDataChanged(*m_field);
dataChanged();
runPostChanged();
}
}
+2
View File
@@ -38,6 +38,8 @@ class AutoDoubleSpinBox : public QDoubleSpinBox, public AutoWidget
virtual ~AutoDoubleSpinBox();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setBindText(std::function<QString()> fn) = delete;
void setField(int & field, GenericPanel * panel = nullptr);
void setField(unsigned int & field, GenericPanel * panel = nullptr);
+1 -1
View File
@@ -75,7 +75,7 @@ void AutoHexSpinBox::onValueChanged(int value)
if (*m_field != (unsigned)value) {
*m_field = (unsigned)value;
emit currentDataChanged(value);
dataChanged();
runPostChanged();
}
}
}
+2
View File
@@ -39,6 +39,8 @@ class AutoHexSpinBox : public QSpinBox, public AutoWidget
virtual ~AutoHexSpinBox();
virtual void updateValue();
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setBindText(std::function<QString()> fn) = delete;
void setField(unsigned int & field, const unsigned int min = 0, const unsigned int max = AUTOHEXSPINBOX_MAX_VALUE, GenericPanel * panel = nullptr);
void setField(unsigned int & field, GenericPanel * panel = nullptr);
+7 -2
View File
@@ -61,8 +61,13 @@ void AutoLabel::updateValue()
{
setLock(true);
if (m_strField)
setText(*m_strField);
QLabel::setText(*m_strField);
else if (m_charField)
setText(m_charField);
QLabel::setText(m_charField);
setLock(false);
}
void AutoLabel::setAutoText(QString text)
{
QLabel::setText(text);
}
+4
View File
@@ -34,11 +34,15 @@ class AutoLabel: public QLabel, public AutoWidget
virtual ~AutoLabel();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setField(char * field, GenericPanel * panel = nullptr);
void setField(QString & field, GenericPanel * panel = nullptr);
void setWidth(int numChars);
protected:
virtual void setAutoText(QString text) override;
private:
char *m_charField;
QString *m_strField;
+10 -3
View File
@@ -61,9 +61,9 @@ void AutoLineEdit::updateValue()
{
setLock(true);
if (m_strField)
setText(*m_strField);
QLineEdit::setText(*m_strField);
else if (m_charField)
setText(m_charField);
QLineEdit::setText(m_charField);
setLock(false);
}
@@ -80,5 +80,12 @@ void AutoLineEdit::onEdited()
return;
emit currentDataChanged();
dataChanged();
runPostChanged();
}
void AutoLineEdit::setAutoText(QString text)
{
setLock(true);
QLineEdit::setText(text);
setLock(false);
}
+4
View File
@@ -34,6 +34,7 @@ class AutoLineEdit: public QLineEdit, public AutoWidget
virtual ~AutoLineEdit();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setField(char * field, int len, GenericPanel * panel = nullptr);
void setField(QString & field, int len = 0, GenericPanel * panel = nullptr);
@@ -44,6 +45,9 @@ class AutoLineEdit: public QLineEdit, public AutoWidget
protected slots:
void onEdited();
protected:
virtual void setAutoText(QString text) override;
private:
char *m_charField;
QString *m_strField;
@@ -114,9 +114,9 @@ void AutoPrecisionComboBox::setValue(int value)
const unsigned int val = (unsigned int)value;
if (*m_field != val) {
*m_field = rangecheckDecimals(val);
updateValue();
emit currentDataChanged(value);
dataChanged();
runPostChanged();
updateValue();
}
}
@@ -127,9 +127,9 @@ void AutoPrecisionComboBox::setValue(unsigned int value)
if (*m_field != value) {
*m_field = rangecheckDecimals(value);
updateValue();
emit currentDataChanged((int)value);
dataChanged();
runPostChanged();
updateValue();
}
}
@@ -203,7 +203,7 @@ void AutoPrecisionComboBox::onCurrentIndexChanged(int index)
if (*m_field != itemData(index).toUInt()) {
*m_field = itemData(index).toUInt();
emit currentDataChanged(index);
dataChanged();
runPostChanged();
}
}
@@ -37,6 +37,8 @@ class AutoPrecisionComboBox : public QComboBox, public AutoWidget
virtual ~AutoPrecisionComboBox();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setBindText(std::function<QString()> fn) = delete;
void setField(int & field, unsigned int minDecimals = 0, unsigned int maxDecimals = 1, bool padding = false, QString suffix = "", GenericPanel * panel = nullptr);
void setField(unsigned int & field, unsigned int minDecimals = 0, unsigned int maxDecimals = 1, bool padding = false, QString suffix = "", GenericPanel * panel = nullptr);
+1 -1
View File
@@ -84,7 +84,7 @@ void AutoSlider::onValueChanged(int value)
if (*m_field != value) {
*m_field = value;
emit currentDataChanged(value);
dataChanged();
runPostChanged();
}
}
}
+2
View File
@@ -35,6 +35,8 @@ class AutoSlider : public QSlider, public AutoWidget
virtual ~AutoSlider();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setBindText(std::function<QString()> fn) = delete;
void setField(int & field, int min, int max, GenericPanel * panel = nullptr);
void setField(unsigned int & field, int min, int max, GenericPanel * panel = nullptr);
+1 -1
View File
@@ -66,7 +66,7 @@ void AutoSpinBox::onValueChanged(int value)
if (*m_field != value) {
*m_field = value;
emit currentDataChanged(value);
dataChanged();
runPostChanged();
}
}
}
+2
View File
@@ -34,6 +34,8 @@ class AutoSpinBox : public QSpinBox, public AutoWidget
virtual ~AutoSpinBox();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setBindText(std::function<QString()> fn) = delete;
void setField(int & field, GenericPanel * panel = nullptr);
void setField(unsigned int & field, GenericPanel * panel = nullptr);
+1 -1
View File
@@ -67,6 +67,6 @@ void AutoTimeEdit::onTimeChanged(QTime time)
if (*m_field != val) {
*m_field = val;
emit currentDataChanged(val);
dataChanged();
runPostChanged();
}
}
+2
View File
@@ -34,6 +34,8 @@ class AutoTimeEdit : public QTimeEdit, public AutoWidget
virtual ~AutoTimeEdit();
virtual void updateValue() override;
void setBindModel(std::function<QAbstractItemModel*()> fn) = delete;
void setBindText(std::function<QString()> fn) = delete;
void setField(unsigned int & field, GenericPanel * panel = nullptr);
void setTimeRange(const QTime min, const QTime max);
+150 -16
View File
@@ -22,14 +22,112 @@
#include "autowidget.h"
#include "genericpanel.h"
#include <memory>
AutoWidget::AutoWidget():
m_panel(nullptr),
m_lock(false)
m_lock(false),
m_buddyWidgets(QList<AutoWidget *> {nullptr}),
m_enabled(nullptr),
m_model(nullptr),
m_text(nullptr),
m_visible(nullptr)
{
}
AutoWidget::~AutoWidget()
AutoWidget::~AutoWidget() = default;
void AutoWidget::addBuddyWidget(AutoWidget * wgt)
{
if (wgt) {
m_buddyWidgets.append(wgt);
// just in case set as we want parent to control
clearBuddyBinds(wgt);
}
}
void AutoWidget::addBuddyWidgets(QList<AutoWidget *> wgts)
{
m_buddyWidgets.append(wgts);
// just in case set as we want parent to control
for (const auto wgt: m_buddyWidgets) {
if (wgt) clearBuddyBinds(wgt);
}
}
// Apply bindings to this AutoWidget also enabled and visible to all buddy AutoWidgets
void AutoWidget::applyBindings()
{
if (m_enabled) {
// buddy widget has no bind so no code executed when it is updated
// so apply parent value
bool val = m_enabled();
setAutoEnabled(val);
for (const auto wgt: m_buddyWidgets) {
if (wgt) wgt->setAutoEnabled(val);
}
}
if (m_visible) {
// buddy widget has no bind so no code executed when it is updated
// so apply parent value
bool val = m_visible();
setAutoVisible(val);
for (const auto wgt: m_buddyWidgets) {
if (wgt) wgt->setAutoVisible(val);
}
}
if (m_text) {
// makes no sense to apply parent bind to buddies
// leave it to each buddy to apply when it is updated
setAutoText(m_text());
}
if (m_model) {
// makes no sense to apply parent bind to buddies
// leave it to each buddy to apply when it is updated
setAutoModel(m_model());
}
}
void AutoWidget::clearBindEnabled()
{
m_enabled = nullptr;
}
void AutoWidget::clearBindVisible()
{
m_visible = nullptr;
}
void AutoWidget::clearBuddyBinds(AutoWidget * wgt)
{
if (wgt) {
wgt->clearBindEnabled();
wgt->clearBindVisible();
}
}
void AutoWidget::clearBuddyWidget(AutoWidget * wgt)
{
if (wgt) {
if (!m_buddyWidgets.removeOne(wgt))
qDebug() << "Warning: widget not removed from list";
}
}
void AutoWidget::clearBuddyWidgets()
{
m_buddyWidgets.clear();
}
void AutoWidget::dataChanged()
{
if (m_panel)
emit m_panel->modified();
}
bool AutoWidget::lock()
@@ -37,6 +135,56 @@ bool AutoWidget::lock()
return panelLock() | m_lock;
}
bool AutoWidget::panelLock()
{
return m_panel ? m_panel->lock : false;
}
void AutoWidget::runPostChanged()
{
dataChanged();
if (m_postChanged)
m_postChanged();
}
void AutoWidget::setAutoEnabled(bool enabled)
{
QWidget *wgt = dynamic_cast<QWidget *>(this);
if (wgt) wgt->setEnabled(enabled);
}
void AutoWidget::setAutoVisible(bool visible)
{
QWidget *wgt = dynamic_cast<QWidget *>(this);
if (wgt) wgt->setVisible(visible);
}
void AutoWidget::setBindEnabled(std::function<bool()> pred)
{
m_enabled = std::move(pred);
}
void AutoWidget::setBindModel(std::function<QAbstractItemModel*()> fn)
{
m_model = std::move(fn);
}
void AutoWidget::setBindPostChanged(std::function<void()> fn)
{
m_postChanged = std::move(fn);
}
void AutoWidget::setBindText(std::function<QString()> fn)
{
m_text = std::move(fn);
}
void AutoWidget::setBindVisible(std::function<bool()> pred)
{
m_visible = std::move(pred);
}
void AutoWidget::setLock(bool lock)
{
m_lock = lock;
@@ -46,17 +194,3 @@ void AutoWidget::setPanel(GenericPanel * panel)
{
m_panel = panel;
}
void AutoWidget::dataChanged()
{
if (m_panel)
emit m_panel->modified();
}
bool AutoWidget::panelLock()
{
if (m_panel)
return m_panel->lock;
else
return false;
}
+45 -3
View File
@@ -21,9 +21,17 @@
#pragma once
#include <functional>
#include <QWidget>
#include <QString>
#include <QList>
#include <QAbstractItemModel>
class GenericPanel;
// Note: cannot be a Qt object otherwise it will create a compiler ambiguity in the inheriting class
// Base class for all Auto name prefixed widgets
// Note: ths class cannot be a Qt object as it will trigger a compile time ambiguity in the inheriting class
class AutoWidget
{
friend class GenericPanel;
@@ -32,17 +40,51 @@ class AutoWidget
explicit AutoWidget();
~AutoWidget();
// buddy Auto widgets have their bindings mirroring the parent
// example buddies are AutoLabel and AutoComboBox
void addBuddyWidget(AutoWidget * wgt);
void addBuddyWidgets(QList<AutoWidget *> wgts);
void clearBuddyWidget(AutoWidget * wgt);
void clearBuddyWidgets();
// mark those unsupported by the base Qt widget as deleted in the child widget
// these are not marked as virtual to support deletion
void setBindEnabled(std::function<bool()> pred);
void setBindModel(std::function<QAbstractItemModel*()> fn);
void setBindPostChanged(std::function<void()> fn);
void setBindText(std::function<QString()> fn);
void setBindVisible(std::function<bool()> pred);
protected:
virtual void setAutoModel(QAbstractItemModel * model) {};
virtual void setAutoText(QString text) {};
virtual void updateValue() = 0;
void applyBindings();
void clearBindEnabled();
void clearBindVisible();
void clearBuddyBinds(AutoWidget * wgt);
bool lock();
bool panelLock();
void runPostChanged();
void setAutoEnabled(bool enabled);
void setAutoVisible(bool visible);
void setLock(bool lock);
void setPanel(GenericPanel * panel);
void dataChanged();
bool panelLock();
private:
GenericPanel *m_panel;
bool m_lock;
QList<AutoWidget *> m_buddyWidgets;
std::function<bool()> m_enabled;
std::function<QAbstractItemModel*()> m_model;
std::function<QString()> m_text;
std::function<bool()> m_visible;
std::function<void()> m_postChanged;
void dataChanged();
};
+16 -3
View File
@@ -21,6 +21,7 @@
#include "genericpanel.h"
#include "autowidget.h"
#include "widgetbindings.h"
#include <TimerEdit>
#include <QComboBox>
@@ -39,9 +40,7 @@ GenericPanel::GenericPanel(QWidget * parent, ModelData * model, GeneralSettings
{
}
GenericPanel::~GenericPanel()
{
}
GenericPanel::~GenericPanel() = default;
void GenericPanel::update()
{
@@ -137,6 +136,20 @@ void GenericPanel::updateAutoWidgets()
AutoWidget *autowdgt = dynamic_cast<AutoWidget *>(wdgt);
if (autowdgt) {
autowdgt->updateValue();
autowdgt->applyBindings();
}
}
}
WidgetBindings *GenericPanel::bindings()
{
if (!m_bindings)
m_bindings = std::make_unique<WidgetBindings>();
return m_bindings.get();
}
void GenericPanel::applyBindings()
{
if (m_bindings)
m_bindings->applyAll();
}
+8
View File
@@ -22,12 +22,14 @@
#pragma once
#include <QWidget>
#include <memory>
class ModelData;
class GeneralSettings;
class Firmware;
class QGridLayout;
class QString;
class WidgetBindings;
class GenericPanel : public QWidget
{
@@ -62,4 +64,10 @@ class GenericPanel : public QWidget
void setFocusFilter(QWidget * w);
void disableMouseScrolling();
void updateAutoWidgets();
WidgetBindings *bindings();
void applyBindings();
private:
std::unique_ptr<WidgetBindings> m_bindings;
};
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "widgetbindings.h"
void WidgetBindings::bindVisible(QWidget *widget, std::function<bool()> pred)
{
m_visible.push_back({widget, std::move(pred)});
}
void WidgetBindings::bindEnabled(QWidget *widget, std::function<bool()> pred)
{
m_enabled.push_back({widget, std::move(pred)});
}
void WidgetBindings::bindText(QLabel *label, std::function<QString()> fn)
{
m_text.push_back({label, std::move(fn)});
}
void WidgetBindings::applyAll()
{
for (const auto &b : m_visible)
b.widget->setVisible(b.pred());
for (const auto &b : m_enabled)
b.widget->setEnabled(b.pred());
for (const auto &b : m_text)
b.label->setText(b.fn());
}
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QWidget>
#include <QLabel>
#include <functional>
#include <vector>
class WidgetBindings
{
public:
WidgetBindings() = default;
void bindVisible(QWidget *widget, std::function<bool()> pred);
void bindEnabled(QWidget *widget, std::function<bool()> pred);
void bindText(QLabel *label, std::function<QString()> fn);
void applyAll();
private:
struct VisibleBinding { QWidget *widget; std::function<bool()> pred; };
struct EnabledBinding { QWidget *widget; std::function<bool()> pred; };
struct TextBinding { QLabel *label; std::function<QString()> fn; };
std::vector<VisibleBinding> m_visible;
std::vector<EnabledBinding> m_enabled;
std::vector<TextBinding> m_text;
};