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

178 lines
4.0 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>
#include<QVBoxLayout>
3 weeks ago
/**
* @brief CUI::CUI
* @param conf
*/
CUI::CUI(QWidget *parent, CUIConfig *conf): QWidget(parent)
3 weeks ago
{
this->conf = conf;
// this->conf->printConfig();
qDebug() << "----------------------";
3 weeks ago
buildUI();
}
/**
* @brief CUI::buildUI
*/
void CUI::buildUI()
{
QWidget* widget = nullptr;
QString type = conf->getPropertyValue("type");
if(type == "") {
3 weeks ago
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);
}
if (widget) {
qDebug() << "----------- ui widget is not null";
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(widget);
this->setLayout(layout);
// QSpacerItem* spacer = new QSpacerItem(5000,5000,QSizePolicy::Maximum,QSizePolicy::Maximum);
// layout->addItem(spacer);
} else {
qDebug() << "----------- ui widget is null";
3 weeks ago
}
}
/**
* @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") {
3 weeks ago
return uiWidget;
}
if(type == "GroupBox") {
3 weeks ago
return uiGroupBox;
}
if(type == "LineEdit") {
3 weeks ago
return uiLineEdit;
}
if(type == "TabWidget") {
3 weeks ago
return uiTabWidget;
}
if(type == "ComboBox") {
3 weeks ago
return uiComboBox;
}
if(type == "Item") {
3 weeks ago
return NULL;
}
if(type == "PushButton") {
3 weeks ago
return uiPushButton;
}
if(type == "CheckBox") {
3 weeks ago
return uiCheckBox;
}
if(type == "ButtonBox") {
3 weeks ago
return uiButtonBox;
}
if(type == "RadioButton") {
3 weeks ago
return uiRadioButton;
}
return NULL;
}
/**
* @brief CUI::getProperty
* @param key
* @return val
*/
QString CUI::getProperty(QString s)
{
// return conf->property[s];
return conf->getPropertyValue(s);
3 weeks ago
}
/**
* @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") {
3 weeks ago
res = uiLineEdit->getLabelWidth();
} else if(type == "ComboBox") {
3 weeks ago
res = uiComboBox->getLabelWidth();
} else {
for(auto &ui : subCUI) {
res = qMax(res, ui->getMaxLabelWidth());
3 weeks ago
}
}
return res;
}
void CUI::setLabelWidth(qint32 width)
{
QString type = conf->getPropertyValue("type");
if(type == "LineEdit") {
3 weeks ago
uiLineEdit->setLabelWidth(width);
} else if(type == "ComboBox") {
3 weeks ago
uiComboBox->setLabelWidth(width);
} else {
for(auto &ui : subCUI) {
3 weeks ago
ui->setLabelWidth(width);
}
}
}