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.
148 lines
3.9 KiB
C++
148 lines
3.9 KiB
C++
#include "CUIPropertyWidget.h"
|
|
|
|
#include<CUIConfig.h>
|
|
#include<CUIContainerWidget.h>
|
|
#include<CUIContainerGroupBox.h>
|
|
#include<CUIComponentILineEdit.h>
|
|
#include<CUIContainerTabWidget.h>
|
|
#include<CUIComponentComboBox.h>
|
|
#include<CUIComponentPushButton.h>
|
|
#include<CUIComponentCheckBox.h>
|
|
#include<CUIComponentRadioButton.h>
|
|
#include<CUIComponentRadioGroup.h>
|
|
#include<QDebug>
|
|
#include<QVBoxLayout>
|
|
#include"CUIComponentMultiTableWidget.h"
|
|
#include"CUIComponentBaseWidget.h"
|
|
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::CUI 构造函数
|
|
* @param conf 配置信息
|
|
*/
|
|
CUIPropertyWidget::CUIPropertyWidget(QWidget *parent, CUIConfig *conf): QWidget(parent)
|
|
{
|
|
this->conf = conf;
|
|
buildUI();
|
|
if(conf->getPropertyValue("type") == "Widget") {
|
|
qDebug() << "new a Widget";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::buildUI 创建组件
|
|
*/
|
|
void CUIPropertyWidget::buildUI()
|
|
{
|
|
QString type = conf->getPropertyValue("type");
|
|
if(type == "") {
|
|
return;
|
|
}
|
|
if(type == "Widget") {
|
|
m_mainWidget = new CUIContainerWidget(conf, subCUI);
|
|
} else if(type == "GroupBox") {
|
|
m_mainWidget = new CUIContainerGroupBox(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 == "RadioComponent") {
|
|
m_mainWidget = new CUIComponentRadioGroup(conf, subCUI);
|
|
} else if(type == "MultiTableWidget") {
|
|
m_mainWidget = new CUIComponentMultiTableWidget(conf, subCUI);
|
|
} else {
|
|
m_mainWidget = new CUIComponentBaseWidget;
|
|
}
|
|
if (m_mainWidget) {
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
layout->setSpacing(0);
|
|
layout->setMargin(0);
|
|
layout->addWidget(m_mainWidget);
|
|
this->setLayout(layout);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::check 对管理的组件进行检查
|
|
*/
|
|
void CUIPropertyWidget::check()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::getUI 返回组件
|
|
* @return QWidget,组件
|
|
*/
|
|
QWidget *CUIPropertyWidget::getUI()
|
|
{
|
|
QString type = conf->getPropertyValue("type");
|
|
if(type == "Item") {
|
|
return NULL;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::getProperty 获取该配置的某一项
|
|
* @param key
|
|
* @return val
|
|
*/
|
|
QString CUIPropertyWidget::getProperty(QString s)
|
|
{
|
|
// return conf->property[s];
|
|
return conf->getPropertyValue(s);
|
|
}
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::autoArrangeWidgets 自动整理组件
|
|
*/
|
|
void CUIPropertyWidget::autoArrangeWidgets()
|
|
{
|
|
qint32 labelMaxWidth = INT_MIN;
|
|
labelMaxWidth = getMaxLabelWidth();
|
|
setLabelWidth(labelMaxWidth);
|
|
}
|
|
|
|
/**
|
|
* @brief CUIPropertyWidget::getMaxLabelWidth 根据类型,获取组件的宽度
|
|
* @return 宽度
|
|
*/
|
|
qint32 CUIPropertyWidget::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 CUIPropertyWidget::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);
|
|
}
|
|
}
|
|
}
|
|
|