|
|
|
#include "CUIComboBox.h"
|
|
|
|
|
|
|
|
#include<CUIConfig.h>
|
|
|
|
#include<QHBoxLayout>
|
|
|
|
#include<CUI.h>
|
|
|
|
#include<QLabel>
|
|
|
|
#include<QDebug>
|
|
|
|
#include<QAbstractItemView>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CUIComboBox::CUIComboBox 构造函数
|
|
|
|
* @param conf 配置信息
|
|
|
|
* @param parent
|
|
|
|
*/
|
|
|
|
CUIComboBox::CUIComboBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
this->conf = conf;
|
|
|
|
iniUI(subCUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CUIComboBox::getLabelWidth 获取combobox的label的最小宽度
|
|
|
|
* @return label的最小宽度
|
|
|
|
*/
|
|
|
|
qint32 CUIComboBox::getLabelWidth()
|
|
|
|
{
|
|
|
|
return label->minimumSizeHint().width();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CUIComboBox::setLabelWidth 设置label的宽度
|
|
|
|
* @param width 宽度
|
|
|
|
*/
|
|
|
|
void CUIComboBox::setLabelWidth(qint32 width)
|
|
|
|
{
|
|
|
|
label->setMinimumWidth(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CUIComboBox::iniUI 初始化widget,添加label和comboBox
|
|
|
|
*/
|
|
|
|
void CUIComboBox::iniUI(QVector<CUI*> &subCUI)
|
|
|
|
{
|
|
|
|
label = new QLabel(conf->getPropertyValue("name"));
|
|
|
|
comboBox = new QComboBox;
|
|
|
|
layout = new QHBoxLayout;
|
|
|
|
this->setLayout(layout);
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addWidget(comboBox);
|
|
|
|
layout->setStretchFactor(comboBox, 1);
|
|
|
|
|
|
|
|
iniComoboBox();
|
|
|
|
|
|
|
|
connect(comboBox, QOverload<int>::of(&QComboBox::activated), [ = ](int idx) {
|
|
|
|
this->conf->setValue(idx);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CUIComboBox::iniComoboBox 初始化ComboBox
|
|
|
|
*/
|
|
|
|
void CUIComboBox::iniComoboBox()
|
|
|
|
{
|
|
|
|
for(auto cui : conf->getSub()) {
|
|
|
|
QString type = cui->getPropertyValue("type");
|
|
|
|
if(type != "Item") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CUI* temp = new CUI(nullptr, cui);
|
|
|
|
Items.push_back(temp);
|
|
|
|
if(temp->getProperty("data_type") == "int") {
|
|
|
|
comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toInt());
|
|
|
|
} else if(temp->getProperty("data_type") == "double") {
|
|
|
|
comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toDouble());
|
|
|
|
} else {
|
|
|
|
comboBox->addItem(temp->getProperty("name"), temp->getProperty("data"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
QVariant vOrigin = conf->getPropertyOriginValue("value_origin");
|
|
|
|
int *ptr = qvariant_cast<int *>(vOrigin);
|
|
|
|
if(ptr!=nullptr)
|
|
|
|
{
|
|
|
|
comboBox->setCurrentIndex(*ptr);
|
|
|
|
}
|
|
|
|
}
|