diff --git a/CFDStruct/CUIProperty/CUIComboBox.cpp b/CFDStruct/CUIProperty/CUIComboBox.cpp index 6efbe3e..fced7a5 100644 --- a/CFDStruct/CUIProperty/CUIComboBox.cpp +++ b/CFDStruct/CUIProperty/CUIComboBox.cpp @@ -1,4 +1,4 @@ -#include "CUIComboBox.h" +#include "CUIComboBox.h" #include #include @@ -12,9 +12,9 @@ * @param conf 配置信息 * @param parent */ -CUIComboBox::CUIComboBox(CUIConfig* conf, QVector &subCUI, QWidget *parent) : QWidget(parent) +CUIComboBox::CUIComboBox(CUIConfig* conf, QVector &subCUI, QWidget *parent) : CUIComponentBaseWidget(parent) { - this->conf = conf; + this->m_conf = conf; initUI(subCUI); } @@ -24,7 +24,7 @@ CUIComboBox::CUIComboBox(CUIConfig* conf, QVector &subCUI, QWidget *parent */ qint32 CUIComboBox::getLabelWidth() { - return label->minimumSizeHint().width(); + return m_label->minimumSizeHint().width(); } /** @@ -33,7 +33,7 @@ qint32 CUIComboBox::getLabelWidth() */ void CUIComboBox::setLabelWidth(qint32 width) { - label->setMinimumWidth(width); + m_label->setMinimumWidth(width); } @@ -43,18 +43,17 @@ void CUIComboBox::setLabelWidth(qint32 width) */ void CUIComboBox::initUI(QVector &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); - + 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); iniComoboBox(); - - connect(comboBox, QOverload::of(&QComboBox::activated), [ = ](int idx) { - this->conf->setValue(idx); + connect(m_comboBox, QOverload::of(&QComboBox::activated), [ = ](int idx) { + this->m_conf->setValue(idx); }); } @@ -63,26 +62,24 @@ void CUIComboBox::initUI(QVector &subCUI) */ void CUIComboBox::iniComoboBox() { - for(auto cui : conf->getSub()) { + for(auto cui : m_conf->getSub()) { QString type = cui->getPropertyValue("type"); if(type != "Item") { return; } CUI* temp = new CUI(nullptr, cui); - Items.push_back(temp); + m_items.push_back(temp); if(temp->getProperty("data_type") == "int") { - comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toInt()); + m_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()); + m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data").toDouble()); } else { - comboBox->addItem(temp->getProperty("name"), temp->getProperty("data")); + m_comboBox->addItem(temp->getProperty("name"), temp->getProperty("data")); } - } - QVariant vOrigin = conf->getPropertyOriginValue("value_origin"); + QVariant vOrigin = m_conf->getPropertyOriginValue("value_origin"); int *ptr = qvariant_cast(vOrigin); - if(ptr!=nullptr) - { - comboBox->setCurrentIndex(*ptr); + if(ptr != nullptr) { + m_comboBox->setCurrentIndex(*ptr); } } diff --git a/CFDStruct/CUIProperty/CUIComboBox.h b/CFDStruct/CUIProperty/CUIComboBox.h index 4a19e2f..5acafc9 100644 --- a/CFDStruct/CUIProperty/CUIComboBox.h +++ b/CFDStruct/CUIProperty/CUIComboBox.h @@ -1,7 +1,9 @@ -#ifndef CUICOMBOBOX_H +#ifndef CUICOMBOBOX_H #define CUICOMBOBOX_H #include +#include "CUIComponentBaseWidget.h" +#include "CUIComponentBase.h" #include class CUIConfig; @@ -9,7 +11,7 @@ class CUI; class QLabel; class QHBoxLayout; -class CUIComboBox : public QWidget +class CUIComboBox : public CUIComponentBaseWidget, public CUIComponentBase { Q_OBJECT public: @@ -17,13 +19,11 @@ public: qint32 getLabelWidth(); void setLabelWidth(qint32 width); private: - void initUI(QVector &subCUI); + virtual void initUI(QVector &subCUI); void iniComoboBox(); - QComboBox* comboBox; - QLabel* label; - CUIConfig* conf; - QVector Items; - QHBoxLayout* layout; + QComboBox* m_comboBox; + QLabel* m_label; + QVector m_items; signals: }; diff --git a/CFDStruct/CUIProperty/CUIComponentBaseWidget.h b/CFDStruct/CUIProperty/CUIComponentBaseWidget.h index feefe9f..1a55b29 100644 --- a/CFDStruct/CUIProperty/CUIComponentBaseWidget.h +++ b/CFDStruct/CUIProperty/CUIComponentBaseWidget.h @@ -1,4 +1,4 @@ -#ifndef CUICOMPONENTBASEWIDGET_H +#ifndef CUICOMPONENTBASEWIDGET_H #define CUICOMPONENTBASEWIDGET_H #include @@ -14,6 +14,7 @@ protected: virtual void initUI(); protected: QLayout* m_layout = nullptr; + int m_labelLength = 100; signals: }; diff --git a/CFDStruct/CUIProperty/CUILineEdit.cpp b/CFDStruct/CUIProperty/CUILineEdit.cpp index 63340a1..a6d67d0 100644 --- a/CFDStruct/CUIProperty/CUILineEdit.cpp +++ b/CFDStruct/CUIProperty/CUILineEdit.cpp @@ -1,4 +1,4 @@ -#include "CUILineEdit.h" +#include "CUILineEdit.h" #include #include @@ -46,6 +46,7 @@ void CUILineEdit::initUI(QVector &subCUI) { m_layout = new QHBoxLayout(); m_label = new QLabel(m_conf->getPropertyValue("name")); + m_label->setFixedWidth(m_labelLength); m_lineEdit = new QLineEdit(this->getValueString()); m_layout->addWidget(m_label); m_layout->addWidget(m_lineEdit); @@ -82,7 +83,7 @@ void CUILineEdit::setInputTips() msg += m_inclusiveMax ? "]" : ")"; } if(m_required) { - msg += "\t(必填)"; + msg += "\t" + tr("(required)"); } m_lineEdit->setPlaceholderText(msg); } diff --git a/CFDStruct/CUIProperty/CUIMultiTableWidget.cpp b/CFDStruct/CUIProperty/CUIMultiTableWidget.cpp index 2d1a92d..5c15a23 100644 --- a/CFDStruct/CUIProperty/CUIMultiTableWidget.cpp +++ b/CFDStruct/CUIProperty/CUIMultiTableWidget.cpp @@ -1,4 +1,4 @@ -#include "CUIMultiTableWidget.h" +#include "CUIMultiTableWidget.h" #include #include #include @@ -16,8 +16,8 @@ CUIMultiTableWidget::CUIMultiTableWidget(CUIConfig* conf, QVector &subCUI, void CUIMultiTableWidget::initUI() { QStringList headers; - headers<> items; + headers << tr("index") << tr("name") << tr("alias") << tr("view"); + QList> items; QList item1 = {tr("quaility"), "quaility"}; QList item2 = {tr("x"), "x"}; QList item3 = {tr("y"), "y"}; @@ -28,7 +28,7 @@ void CUIMultiTableWidget::initUI() items.append(item4); // 根据配置来初始化tableWidget m_tableWidget = new QTableWidget(this); - m_tableWidget->setColumnCount(items.count() + 2); + m_tableWidget->setColumnCount(items[0].count() + 2); m_tableWidget->setRowCount(items.count()); m_tableWidget->setHorizontalHeaderLabels(headers); // 设置水平表头的背景颜色 @@ -38,29 +38,27 @@ void CUIMultiTableWidget::initUI() // 隐藏垂直表头 QHeaderView *verticalHeader = m_tableWidget->verticalHeader(); verticalHeader->setVisible(false); - - for (int i=0;i item = items[i]; // 序号 - QTableWidgetItem* indexItem = new QTableWidgetItem(QString("%1").arg(i+1)); - indexItem->setFlags(indexItem->flags() &~Qt::ItemIsSelectable); + QTableWidgetItem* indexItem = new QTableWidgetItem(QString("%1").arg(i + 1)); + indexItem->setFlags(indexItem->flags() & ~Qt::ItemIsSelectable); indexItem->setTextAlignment(Qt::AlignCenter); // 设置水平居中 - m_tableWidget->setItem(i,0, indexItem); + m_tableWidget->setItem(i, 0, indexItem); // 内容 - for (int j=0;jsetFlags(indexItem->flags() &~Qt::ItemIsSelectable); + nameItem->setFlags(indexItem->flags() & ~Qt::ItemIsSelectable); nameItem->setTextAlignment(Qt::AlignCenter); // 设置水平居中 - m_tableWidget->setItem(i,j+1, nameItem); + m_tableWidget->setItem(i, j + 1, nameItem); } // 复选框 QTableWidgetItem *checkBoxItem = new QTableWidgetItem(); - m_tableWidget->setItem(i,item.count() + 1, checkBoxItem); + m_tableWidget->setItem(i, item.count() + 1, checkBoxItem); QCheckBox* checkBox = new QCheckBox(); checkBox->setStyleSheet("margin-left:45%; margin-right:45%;");// 设置水平居中 m_tableWidget->setCellWidget(i, item.count() + 1, checkBox); } - m_layout = new QVBoxLayout; m_layout->addWidget(m_tableWidget); this->setLayout(m_layout);