#include "CUI.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include"CUIMultiTableWidget.h" #include"CUIComponentBaseWidget.h" /** * @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() { QString type = conf->getPropertyValue("type"); if(type == "") { return; } if(type == "Widget") { m_mainWidget = new CUIWidget(conf, subCUI); } else if(type == "GroupBox") { m_mainWidget = new CUIGroupBox(conf, subCUI); } else if(type == "LineEdit") { m_mainWidget = new CUIComponentLineEdit(conf, subCUI); } else if(type == "TabWidget") { m_mainWidget = new CUIContainerTabWidget(conf, subCUI); } else if(type == "ComboBox") { m_mainWidget = new CUIComponentComboBox(conf, subCUI); } else if(type == "PushButton") { m_mainWidget = new CUIComponentPushButton(conf, subCUI); } else if(type == "CheckBox") { m_mainWidget = new CUIComponentCheckBox(conf, subCUI); } else if(type == "RadioButton") { m_mainWidget = new CUIComponentRadioButton(conf, subCUI); } else if(type == "ButtonBox") { m_mainWidget = new CUIButtonBox(conf, subCUI); } else if(type == "RadioComponent") { m_mainWidget = new CUIRadioComponent(conf, subCUI); } else if(type == "MultiTableWidget") { m_mainWidget = new CUIMultiTableWidget(conf, subCUI); } if (m_mainWidget) { QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(0); layout->setMargin(0); layout->addWidget(m_mainWidget); this->setLayout(layout); } } /** * @brief CUI::check 对管理的组件进行检查 */ void CUI::check() { } /** * @brief CUI::getUI 返回组件 * @return QWidget,组件 */ QWidget *CUI::getUI() { QString type = conf->getPropertyValue("type"); if(type == "Item") { return NULL; } return this; } /** * @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 = m_mainWidget->getLabelWidth(); } else if(type == "ComboBox") { res = m_mainWidget->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") { m_mainWidget->setLabelWidth(width); } else if(type == "ComboBox") { m_mainWidget->setLabelWidth(width); } else { for(auto &ui : subCUI) { ui->setLabelWidth(width); } } }