You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/CFDStruct/CUIProperty/CUI.cpp

175 lines
3.5 KiB
C++

#include "CUI.h"
#include<CUIConfig.h>
#include<CUIWidget.h>
#include<CUIGroupBox.h>
#include<CUILineEdit.h>
#include<CUITabWidget.h>
#include<CUIComboBox.h>
#include<CUIPushButton.h>
#include<CUICheckBox.h>
#include<CUIRadioButton.h>
#include<QDebug>
#include<CUIButtonBox.h>
/**
* @brief CUI::CUI 构造函数
* @param conf 配置信息
*/
CUI::CUI(CUIConfig *conf)
{
this->conf = conf;
this->conf->printConfig();
buildUI();
}
/**
* @brief CUI::buildUI 创建组件
*/
void CUI::buildUI()
{
// QString type = conf->property["type"];
QString type = conf->getPropertyValue("type");
if(type == "")
return;
if(type == "Widget")
{
uiWidget = new CUIWidget(conf,subCUI);
}
if(type == "GroupBox")
{
uiGroupBox = new CUIGroupBox(conf,subCUI);
}
if(type == "LineEdit")
{
uiLineEdit = new CUILineEdit(conf,subCUI);
}
if(type == "TabWidget")
{
uiTabWidget = new CUITabWidget(conf,subCUI);
}
if(type == "ComboBox"){
uiComboBox = new CUIComboBox(conf,subCUI);
}
if(type == "PushButton"){
uiPushButton = new CUIPushButton(conf,subCUI);
}
if(type == "CheckBox"){
uiCheckBox = new CUICheckBox(conf,subCUI);
}
if(type == "RadioButton"){
uiRadioButton = new CUIRadioButton(conf,subCUI);
}
if(type == "ButtonBox"){
uiButtonBox = new CUIButtonBox(conf,subCUI);
}
}
/**
* @brief CUI::check 对管理的组件进行检查
*/
void CUI::check()
{
}
/**
* @brief CUI::getUI 返回组件
* @return QWidget,组件
*/
QWidget *CUI::getUI()
{
QString type = conf->getPropertyValue("type");
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);
}
}
}