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

172 lines
3.5 KiB
C++

3 weeks ago
#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"];
if(type == "")
return;
// qDebug()<<"start_build";
if(type == "Widget")
{
// qDebug()<<"build 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()
{
if(conf->property["type"] == "Widget"){
return uiWidget;
}
if(conf->property["type"] == "GroupBox"){
return uiGroupBox;
}
if(conf->property["type"] == "LineEdit"){
return uiLineEdit;
}
if(conf->property["type"] == "TabWidget"){
return uiTabWidget;
}
if(conf->property["type"] == "ComboBox"){
return uiComboBox;
}
if(conf->property["type"] == "Item"){
return NULL;
}
if(conf->property["type"] == "PushButton"){
return uiPushButton;
}
if(conf->property["type"] == "CheckBox"){
return uiCheckBox;
}
if(conf->property["type"] == "ButtonBox"){
return uiButtonBox;
}
if(conf->property["type"] == "RadioButton"){
return uiRadioButton;
}
return NULL;
}
/**
* @brief CUI::getProperty
* @param key
* @return val
*/
QString CUI::getProperty(QString s)
{
return conf->property[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;
if(conf->property["type"] == "LineEdit"){
res = uiLineEdit->getLabelWidth();
}
else if(conf->property["type"] == "ComboBox"){
res = uiComboBox->getLabelWidth();
}else{
for(auto &ui:subCUI){
res = qMax(res,ui->getMaxLabelWidth());
}
}
return res;
}
void CUI::setLabelWidth(qint32 width)
{
if(conf->property["type"] == "LineEdit"){
uiLineEdit->setLabelWidth(width);
}
else if(conf->property["type"] == "ComboBox"){
uiComboBox->setLabelWidth(width);
}else{
for(auto &ui:subCUI){
ui->setLabelWidth(width);
}
}
}