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

86 lines
2.4 KiB
C++

#include "CUIComponentComboBox.h"
3 weeks ago
#include<CUIConfig.h>
#include<QHBoxLayout>
#include<CUI.h>
#include<QLabel>
#include<QDebug>
#include<QAbstractItemView>
/**
* @brief CUIComponentComboBox::CUIComponentComboBox
3 weeks ago
* @param conf
* @param parent
*/
CUIComponentComboBox::CUIComponentComboBox(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : CUIComponentBaseWidget(parent)
3 weeks ago
{
this->m_conf = conf;
initUI(subCUI);
3 weeks ago
}
/**
* @brief CUIComponentComboBox::getLabelWidth comboboxlabel
3 weeks ago
* @return label
*/
qint32 CUIComponentComboBox::getLabelWidth()
3 weeks ago
{
return m_label->minimumSizeHint().width();
3 weeks ago
}
/**
* @brief CUIComponentComboBox::setLabelWidth label
3 weeks ago
* @param width
*/
void CUIComponentComboBox::setLabelWidth(qint32 width)
3 weeks ago
{
m_label->setMinimumWidth(width);
3 weeks ago
}
/**
* @brief CUIComponentComboBox::initUI widget,labelcomboBox
3 weeks ago
*/
void CUIComponentComboBox::initUI(QVector<CUI*> &subCUI)
3 weeks ago
{
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength);
m_comboBox = new QComboBox;
m_layout = new QHBoxLayout;
this->setLayout(m_layout);
m_layout->addWidget(m_label);
m_layout->addWidget(m_comboBox);
((QHBoxLayout*)m_layout)->setStretchFactor(m_comboBox, 1);
3 weeks ago
iniComoboBox();
connect(m_comboBox, QOverload<int>::of(&QComboBox::activated), [ = ](int idx) {
this->m_conf->setValue(idx);
3 weeks ago
});
}
/**
* @brief CUIComponentComboBox::iniComoboBox ComboBox
3 weeks ago
*/
void CUIComponentComboBox::iniComoboBox()
3 weeks ago
{
for(auto cui : m_conf->getSub()) {
QString type = cui->getPropertyValue("type");
if(type != "Item") {
3 weeks ago
return;
}
CUI* temp = new CUI(nullptr, cui);
m_items.push_back(temp);
if(temp->getProperty("data_type") == "int") {
m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toInt());
} else if(temp->getProperty("data_type") == "double") {
m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toDouble());
} else {
m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data"));
}
3 weeks ago
}
QVariant vOrigin = m_conf->getPropertyOriginValue("value_origin");
int *ptr = qvariant_cast<int *>(vOrigin);
if(ptr != nullptr) {
m_comboBox->setCurrentIndex(*ptr);
}
3 weeks ago
}