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/CUIComboBox.cpp

91 lines
2.6 KiB
C++

3 weeks ago
#include "CUIComboBox.h"
#include<CUIConfig.h>
#include<QHBoxLayout>
#include<CUI.h>
#include<QLabel>
#include<QDebug>
#include<QAbstractItemView>
#include "CFDStructDataManager/CFDStructDataDefine.h"
3 weeks ago
/**
* @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 comboboxlabel
* @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,labelcomboBox
*/
void CUIComboBox::iniUI(QVector<CUI*> &subCUI)
{
label = new QLabel(conf->getPropertyValue("name"));
3 weeks ago
comboBox = new QComboBox;
layout = new QHBoxLayout;
this->setLayout(layout);
layout->addWidget(label);
layout->addWidget(comboBox);
// layout->setStretchFactor(label,1);
layout->setStretchFactor(comboBox, 1);
3 weeks ago
// comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
// comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
// label->setMinimumWidth(114);
qDebug() << label->minimumSizeHint() << " combobox";
3 weeks ago
iniComoboBox();
connect(comboBox, QOverload<int>::of(&QComboBox::activated), [ = ](int idx) {
qDebug() << comboBox->itemData(idx);
this->conf->setValue(idx);
3 weeks ago
});
}
/**
* @brief CUIComboBox::iniComoboBox ComboBox
*/
void CUIComboBox::iniComoboBox()
{
for(auto cui : conf->getSub()) {
QString type = cui->getPropertyValue("type");
if(type != "Item") {
qDebug() << "wrong type!!!";
3 weeks ago
return;
}
CUI* temp = new CUI(nullptr, cui);
3 weeks ago
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"));
}
3 weeks ago
}
QVariant vOrigin = conf->getPropertyOriginValue("valueOrigin");
int *ptr = qvariant_cast<int *>(vOrigin);
comboBox->setCurrentIndex(*ptr);
3 weeks ago
}