#include "CUI.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** * @brief CUI::CUI 构造函数 * @param conf 配置信息 */ CUI::CUI(QWidget *parent, CUIConfig *conf): QWidget(parent) { this->conf = conf; buildUI(); if(conf->getPropertyValue("type") == "Widget") qDebug()<<"new a Widget"; } /** * @brief CUI::buildUI 创建组件 */ void CUI::buildUI() { QWidget* widget = nullptr; QString type = conf->getPropertyValue("type"); if(type == "") { return; } if(type == "Widget") { widget = new CUIWidget(conf, subCUI); } else if(type == "GroupBox") { widget = new CUIGroupBox(conf, subCUI); } else if(type == "LineEdit") { widget = new CUILineEdit(conf, subCUI); } else if(type == "TabWidget") { widget = new CUITabWidget(conf, subCUI); } else if(type == "ComboBox") { widget = new CUIComboBox(conf, subCUI); } else if(type == "PushButton") { widget = new CUIPushButton(conf, subCUI); } else if(type == "CheckBox") { widget = new CUICheckBox(conf, subCUI); } else if(type == "RadioButton") { widget = new CUIRadioButton(conf, subCUI); } else if(type == "ButtonBox") { widget = new CUIButtonBox(conf, subCUI); } else if(type == "RadioComponent"){ widget = new CUIRadioComponent(conf,subCUI); } else if(type == "MultiTableWidget") { widget = new CUIMultiTableWidget(conf, subCUI); } if (widget) { QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(0); layout->setMargin(0); layout->addWidget(widget); this->setLayout(layout); } else { } } /** * @brief CUI::check 对管理的组件进行检查 */ void CUI::check() { } /** * @brief CUI::getUI 返回组件 * @return QWidget,组件 */ QWidget *CUI::getUI() { QString type = conf->getPropertyValue("type"); if(type == "Item") { return NULL; } else { return this; } return NULL; if(type == "Widget") { return uiWidget; } if(type == "GroupBox") { return uiGroupBox; } if(type == "LineEdit") { return uiLineEdit; } if(type == "TabWidget") { return uiTabWidget; } if(type == "ComboBox") { return uiComboBox; } if(type == "Item") { return NULL; } if(type == "PushButton") { return uiPushButton; } if(type == "CheckBox") { return uiCheckBox; } if(type == "ButtonBox") { return uiButtonBox; } if(type == "RadioButton") { return uiRadioButton; } return NULL; } /** * @brief CUI::getProperty 获取该配置的某一项 * @param key * @return val */ QString CUI::getProperty(QString s) { // return conf->property[s]; return conf->getPropertyValue(s); } /** * @brief CUI::autoArrangeWidgets 自动整理组件 */ void CUI::autoArrangeWidgets() { qint32 labelMaxWidth = INT_MIN; labelMaxWidth = getMaxLabelWidth(); setLabelWidth(labelMaxWidth); } /** * @brief CUI::getMaxLabelWidth 根据类型,获取组件的宽度 * @return 宽度 */ qint32 CUI::getMaxLabelWidth() { qint32 res = INT_MIN; QString type = conf->getPropertyValue("type"); if(type == "LineEdit") { res = uiLineEdit->getLabelWidth(); } else if(type == "ComboBox") { res = uiComboBox->getLabelWidth(); } else { for(auto &ui : subCUI) { res = qMax(res, ui->getMaxLabelWidth()); } } return res; } void CUI::setLabelWidth(qint32 width) { QString type = conf->getPropertyValue("type"); if(type == "LineEdit") { uiLineEdit->setLabelWidth(width); } else if(type == "ComboBox") { uiComboBox->setLabelWidth(width); } else { for(auto &ui : subCUI) { ui->setLabelWidth(width); } } }