#include "CUIComponentRadioGroup.h" #include "CUIConfig.h" #include "QVBoxLayout" #include #include #include #include #include CUIComponentRadioGroup::CUIComponentRadioGroup(CUIConfig *conf, QVector &subCUI, QWidget *parent) : CUIComponentBaseContainerWidget(parent) { this->m_conf = conf; iniUI(subCUI); connect(m_ButtonGroup, QOverload::of(&QButtonGroup::buttonClicked), [ = ](int idx) { this->m_conf->setValue((int)idx); }); } void CUIComponentRadioGroup::iniUI(QVector &subCUI) { QString widget_type = this->m_conf->getPropertyValue("widget"); QHBoxLayout* mainLayout = new QHBoxLayout; m_layout = this->getLayout(m_conf); m_ButtonGroup = new QButtonGroup; if(widget_type == "GroupBox") { iniUI_GroupBox(); mainLayout->addWidget(m_GroupBox); } else if(widget_type == "Component") { iniUI_Component(); mainLayout->addWidget(m_label); mainLayout->addWidget(m_Component); } this->setLayout(mainLayout); QVariant vOrigin = m_conf->getPropertyOriginValue("value_origin"); int *ptr = qvariant_cast(vOrigin); if (ptr != nullptr) { m_ButtonGroup->button(*ptr)->setChecked(true); } } void CUIComponentRadioGroup::iniUI_GroupBox() { m_GroupBox = new QGroupBox; m_GroupBox->setTitle(this->m_conf->getPropertyValue("name")); m_GroupBox->setLayout(m_layout); int idx = 0; for(auto conf : this->m_conf->getSub()) { QRadioButton* radio = new QRadioButton(conf->getPropertyValue("name")); m_layout->addWidget(radio); m_ButtonGroup->addButton(radio, idx); idx++; } } void CUIComponentRadioGroup::iniUI_Component() { m_label = new QLabel(this->m_conf->getPropertyValue("name")); m_Component = new QWidget; m_Component->setLayout(m_layout); int idx = 0; for(auto conf : this->m_conf->getSub()) { QRadioButton* radio = new QRadioButton(conf->getPropertyValue("name")); m_layout->addWidget(radio); m_ButtonGroup->addButton(radio, idx); idx++; } }