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.7 KiB
C++

#include "CUIComponentComboBox.h"
3 weeks ago
#include <CUIConfig.h>
#include <CUIPropertyWidget.h>
#include <QAbstractItemView>
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
3 weeks ago
/**
* @brief CUIComponentComboBox::CUIComponentComboBox
3 weeks ago
* @param conf
* @param parent
*/
CUIComponentComboBox::CUIComponentComboBox(CUIConfig *conf,
QVector<CUIPropertyWidget *> &subCUI,
QWidget *parent)
: CUIComponentBaseWidget(parent) {
this->m_conf = conf;
initUI(subCUI);
3 weeks ago
}
/**
* @brief CUIComponentComboBox::getLabelWidth comboboxlabel
3 weeks ago
* @return label
*/
qint32 CUIComponentComboBox::getLabelWidth() {
return m_label->minimumSizeHint().width();
3 weeks ago
}
/**
* @brief CUIComponentComboBox::setLabelWidth label
3 weeks ago
* @param width
*/
void CUIComponentComboBox::setLabelWidth(qint32 width) {
m_label->setMinimumWidth(width);
3 weeks ago
}
/**
* @brief CUIComponentComboBox::initUI widget,labelcomboBox
3 weeks ago
*/
void CUIComponentComboBox::initUI(QVector<CUIPropertyWidget *> &subCUI) {
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() {
for (auto cui : m_conf->getSub()) {
QString type = cui->getPropertyValue("type");
if (type != "Item") {
3 weeks ago
return;
}
CUIPropertyWidget *temp = new CUIPropertyWidget(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
}