1、LineEdit 渲染时展示默认值;

feature/struct-menu-20241023
simonyan 6 days ago
parent a4c77fe195
commit 70f2b7533b

@ -11,17 +11,17 @@ class CUIConfig;
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverComputingControlManager : public CFDStructDataManagerBase { class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverComputingControlManager : public CFDStructDataManagerBase {
Q_OBJECT Q_OBJECT
public: public:
explicit CFDStructDataSolverComputingControlManager(QObject *parent = nullptr); explicit CFDStructDataSolverComputingControlManager(QObject* parent = nullptr);
~CFDStructDataSolverComputingControlManager(); ~CFDStructDataSolverComputingControlManager();
CUIConfig *getParamUIConfig(); CUIConfig* getParamUIConfig();
void saveDataToDom(rapidjson::Document &dom); void saveDataToDom(rapidjson::Document& dom);
void readDataFromDom(rapidjson::Document &dom); void readDataFromDom(rapidjson::Document& dom);
private: private:
// 生成界面配置 // 生成界面配置
CUIConfig *genUIConfig(); CUIConfig* genUIConfig();
signals: signals:
private: private:

@ -8,26 +8,25 @@
#include "CFDStructDataManager_global.h" #include "CFDStructDataManager_global.h"
class CUIConfig; class CUIConfig;
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverInitializationManager : public CFDStructDataManagerBase class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverInitializationManager : public CFDStructDataManagerBase {
{
Q_OBJECT Q_OBJECT
public: public:
explicit CFDStructDataSolverInitializationManager(QObject *parent = nullptr); explicit CFDStructDataSolverInitializationManager(QObject* parent = nullptr);
~CFDStructDataSolverInitializationManager(); ~CFDStructDataSolverInitializationManager();
CUIConfig *getParamUIConfig(); CUIConfig* getParamUIConfig();
void saveDataToDom(rapidjson::Document &dom); void saveDataToDom(rapidjson::Document& dom);
void readDataFromDom(rapidjson::Document &dom); void readDataFromDom(rapidjson::Document& dom);
private: private:
// 生成界面配置 柱坐标系 // 生成界面配置 柱坐标系
CUIConfig *genCylindricalUIConfig(); CUIConfig* genCylindricalUIConfig();
// 生成界面配置 笛卡尔坐标系 // 生成界面配置 笛卡尔坐标系
CUIConfig *genCartesianUIConfig(); CUIConfig* genCartesianUIConfig();
signals: signals:
private: private:
// 参考值取自 // 参考值取自
int m_ReferenceValuesFrom = 0; // Reference Values From int m_ReferenceValuesFrom = 0; // Reference Values From

@ -14,11 +14,10 @@
* @param conf * @param conf
* @param parent * @param parent
*/ */
CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf, CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig* conf,
QVector<CUIPropertyWidget *> &subCUI, QVector<CUIPropertyWidget*>& subCUI,
QWidget *parent) QWidget* parent)
: CUIComponentBaseWidget(parent),CUIComponentBase() : CUIComponentBaseWidget(parent), CUIComponentBase() {
{
this->m_conf = conf; this->m_conf = conf;
this->initSetting(); this->initSetting();
this->initUI(subCUI); this->initUI(subCUI);
@ -28,8 +27,7 @@ CUIComponentLineEdit::CUIComponentLineEdit(CUIConfig *conf,
* @brief CUIComponentLineEdit::getLabelWidth label * @brief CUIComponentLineEdit::getLabelWidth label
* @return label * @return label
*/ */
qint32 CUIComponentLineEdit::getLabelWidth() qint32 CUIComponentLineEdit::getLabelWidth() {
{
return m_label->minimumSizeHint().width(); return m_label->minimumSizeHint().width();
} }
@ -37,16 +35,14 @@ qint32 CUIComponentLineEdit::getLabelWidth()
* @brief CUIComponentLineEdit::setLabelWidth label * @brief CUIComponentLineEdit::setLabelWidth label
* @param width * @param width
*/ */
void CUIComponentLineEdit::setLabelWidth(qint32 width) void CUIComponentLineEdit::setLabelWidth(qint32 width) {
{
m_label->setMinimumWidth(width); m_label->setMinimumWidth(width);
} }
/** /**
* @brief CUIComponentLineEdit::initUI * @brief CUIComponentLineEdit::initUI
*/ */
void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI) void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget*>& subCUI) {
{
m_layout = new QHBoxLayout(); m_layout = new QHBoxLayout();
m_label = new QLabel(m_conf->getPropertyValue("name")); m_label = new QLabel(m_conf->getPropertyValue("name"));
m_label->setFixedWidth(m_labelLength); m_label->setFixedWidth(m_labelLength);
@ -58,22 +54,25 @@ void CUIComponentLineEdit::initUI(QVector<CUIPropertyWidget *> &subCUI)
// 设置格式校验 // 设置格式校验
this->setValidator(); this->setValidator();
this->setInputTips(); this->setInputTips();
// 显示值
m_lineEdit->setText(m_conf->getOriginValueString());
connect(m_lineEdit, &QLineEdit::textEdited, this, connect(m_lineEdit, &QLineEdit::textEdited, this,
&CUIComponentLineEdit::onTextChanged); &CUIComponentLineEdit::onTextChanged);
} }
void CUIComponentLineEdit::setValidator() void CUIComponentLineEdit::setValidator() {
{ qDebug() << m_dataType;
qDebug()<<m_dataType;
switch ((int)m_dataType) { switch ((int)m_dataType) {
case CUI_DATA_TYPE_DOUBLE: { case CUI_DATA_TYPE_DOUBLE: {
qDebug()<<m_rangeMin.toInt()<<' '<< m_rangeMax.toInt(); qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(), m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(),
m_rangeMax.toDouble(), 10)); m_rangeMax.toDouble(), 10));
break; break;
} }
case CUI_DATA_TYPE_INT: { case CUI_DATA_TYPE_INT: {
qDebug()<<m_rangeMin.toInt()<<' '<< m_rangeMax.toInt(); qDebug() << m_rangeMin.toInt() << ' ' << m_rangeMax.toInt();
m_lineEdit->setValidator( m_lineEdit->setValidator(
new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt())); new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt()));
break; break;
@ -84,32 +83,36 @@ void CUIComponentLineEdit::setValidator()
/** /**
* @brief CUIComponentLineEdit::showMsg * @brief CUIComponentLineEdit::showMsg
*/ */
void CUIComponentLineEdit::setInputTips() void CUIComponentLineEdit::setInputTips() {
{
QString msg = ""; QString msg = "";
if (m_checkRange) { if (m_checkRange) {
msg += m_inclusiveMin ? "[" : "("; msg += m_inclusiveMin ? "[" : "(";
msg += this->getRangeMinString() + "," + this->getRangeMaxString(); msg += this->getRangeMinString() + "," + this->getRangeMaxString();
msg += m_inclusiveMax ? "]" : ")"; msg += m_inclusiveMax ? "]" : ")";
} }
if (m_required) { if (m_required) {
msg += "\t" + tr("(required)"); msg += "\t" + tr("(required)");
} }
m_lineEdit->setPlaceholderText(msg); m_lineEdit->setPlaceholderText(msg);
} }
/** /**
* @brief CUIComponentLineEdit::checkRange * @brief CUIComponentLineEdit::checkRange
*/ */
void CUIComponentLineEdit::showRangeError() void CUIComponentLineEdit::showRangeError() {
{
if (m_checkRange) { if (m_checkRange) {
QPalette palette = m_lineEdit->palette(); QPalette palette = m_lineEdit->palette();
if (this->inRange(this->getQVFrom(m_lineEdit->text()))) { if (this->inRange(this->getQVFrom(m_lineEdit->text()))) {
palette.setColor(QPalette::Text, Qt::black); palette.setColor(QPalette::Text, Qt::black);
} else { } else {
palette.setColor(QPalette::Text, Qt::red); palette.setColor(QPalette::Text, Qt::red);
} }
m_lineEdit->setPalette(palette); m_lineEdit->setPalette(palette);
} }
} }
@ -122,9 +125,9 @@ void CUIComponentLineEdit::showRangeError()
* *
* @param text * @param text
*/ */
void CUIComponentLineEdit::onTextChanged(const QString &text) void CUIComponentLineEdit::onTextChanged(const QString& text) {
{
this->showRangeError(); this->showRangeError();
if (this->inRange(m_lineEdit->text())) { if (this->inRange(m_lineEdit->text())) {
// switch (m_dataType) { // switch (m_dataType) {
// case CUI_DATA_TYPE_DOUBLE: { // case CUI_DATA_TYPE_DOUBLE: {

@ -8,8 +8,7 @@
* @brief CUIConfig::CUIConfig * @brief CUIConfig::CUIConfig
* @param property * @param property
*/ */
CUIConfig::CUIConfig(QMap<QString, QVariant> property) CUIConfig::CUIConfig(QMap<QString, QVariant> property) {
{
setDefault(); setDefault();
this->property = property; this->property = property;
this->m_sigsCenter = CUISigsCenter::getInstance(); this->m_sigsCenter = CUISigsCenter::getInstance();
@ -74,8 +73,7 @@ CUIConfig::CUIConfig(QMap<QString, QVariant> property)
* @param property * @param property
* @param sub * @param sub
*/ */
CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> sub) CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig*> sub) {
{
setDefault(); setDefault();
this->property = property; this->property = property;
this->sub = sub; this->sub = sub;
@ -85,8 +83,7 @@ CUIConfig::CUIConfig(QMap<QString, QVariant> property, QVector<CUIConfig *> sub)
/** /**
* @brief CUIConfig::printConfig * @brief CUIConfig::printConfig
*/ */
void CUIConfig::printConfig() void CUIConfig::printConfig() {
{
// qDebug() << "{"; // qDebug() << "{";
// for(auto it = property.begin(); it != property.end(); it++) { // for(auto it = property.begin(); it != property.end(); it++) {
// qDebug() << it.key() << ' ' << it.value(); // qDebug() << it.key() << ' ' << it.value();
@ -97,29 +94,59 @@ void CUIConfig::printConfig()
// qDebug() << "}"; // qDebug() << "}";
} }
void CUIConfig::setValue(QVariant value) QString CUIConfig::getOriginValueString() {
{ QVariant pValue = property["value_origin"];
// 如果没有设置原始值
if (pValue == QVariant::Invalid) {
return QString("");
}
if (property["value_type"] == CUI_DATA_TYPE_INT) {
int* ptr = qvariant_cast<int*>(pValue);
return QString::number(*ptr);
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) {
double* ptr = qvariant_cast<double*>(pValue);
return QString::number(*ptr);
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
QString* ptr = qvariant_cast<QString*>(pValue);
return *ptr;
}
return QString("");
}
void CUIConfig::setValue(QVariant value) {
bool changed = false; bool changed = false;
QVariant pValue = property["value_origin"]; QVariant pValue = property["value_origin"];
if (property["value_type"] == CUI_DATA_TYPE_INT) { if (property["value_type"] == CUI_DATA_TYPE_INT) {
int* ptr = qvariant_cast<int*>(pValue); int* ptr = qvariant_cast<int*>(pValue);
if (*ptr != value.toInt()) { if (*ptr != value.toInt()) {
*ptr = value.toInt(); *ptr = value.toInt();
changed = true; changed = true;
} }
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) { } else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) {
double* ptr = qvariant_cast<double*>(pValue); double* ptr = qvariant_cast<double*>(pValue);
if (*ptr != value.toDouble()) { if (*ptr != value.toDouble()) {
*ptr = value.toDouble(); *ptr = value.toDouble();
changed = true; changed = true;
} }
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) { } else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
double* ptr = qvariant_cast<double*>(pValue); QString* ptr = qvariant_cast<QString*>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble(); if (*ptr != value.toString()) {
*ptr = value.toString();
changed = true; changed = true;
} }
} }
// 如果需要通知,则通知参数值发生修改 // 如果需要通知,则通知参数值发生修改
if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) { if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
QTimer::singleShot(50, m_sigsCenter, [ = ]() { QTimer::singleShot(50, m_sigsCenter, [ = ]() {
@ -134,11 +161,11 @@ void CUIConfig::setValue(QVariant value)
* @param key * @param key
* @return * @return
*/ */
QString CUIConfig::getPropertyValue(QString key) QString CUIConfig::getPropertyValue(QString key) {
{ if (property.contains(key)) {
if(property.contains(key)) {
return qvariant_cast<QString>(property[key]); return qvariant_cast<QString>(property[key]);
} }
return QString(); return QString();
} }
@ -147,16 +174,15 @@ QString CUIConfig::getPropertyValue(QString key)
* @param key * @param key
* @return * @return
*/ */
QVariant CUIConfig::getPropertyOriginValue(QString key) QVariant CUIConfig::getPropertyOriginValue(QString key) {
{ if (property.contains(key)) {
if(property.contains(key)) {
return property[key]; return property[key];
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
QVector<CUIConfig *> CUIConfig::getSub() QVector<CUIConfig*> CUIConfig::getSub() {
{
return this->sub; return this->sub;
} }
@ -164,10 +190,10 @@ QVector<CUIConfig *> CUIConfig::getSub()
/** /**
* @brief CUIConfig::setDefault * @brief CUIConfig::setDefault
*/ */
void CUIConfig::setDefault() void CUIConfig::setDefault() {
{
QString type = qvariant_cast<QString>(property["type"]); QString type = qvariant_cast<QString>(property["type"]);
if(type == "LineEdit") {
if (type == "LineEdit") {
setDefault("name", ""); setDefault("name", "");
setDefault("data_type", "string"); // 数据类型 setDefault("data_type", "string"); // 数据类型
setDefault("initial_value_", ""); // 初始值 setDefault("initial_value_", ""); // 初始值
@ -177,16 +203,20 @@ void CUIConfig::setDefault()
setDefault("inclusive_min", true); // 左范围是否包括 setDefault("inclusive_min", true); // 左范围是否包括
setDefault("inclusive_max", true); // 右范围是否包括 setDefault("inclusive_max", true); // 右范围是否包括
setDefault("required_", true); // 是否为必选 setDefault("required_", true); // 是否为必选
} else if(type == "Widget") {
} else if (type == "Widget") {
setDefault("layout", "QVBoxLayout"); setDefault("layout", "QVBoxLayout");
setDefault("name", ""); setDefault("name", "");
} else if(type == "GroupBox") {
} else if (type == "GroupBox") {
setDefault("name", ""); setDefault("name", "");
setDefault("layout", "QVBoxLayout"); setDefault("layout", "QVBoxLayout");
} else if(type == "TabWidget") {
} else if(type == "ComboBox") { } else if (type == "TabWidget") {
} else if (type == "ComboBox") {
setDefault("name", ""); setDefault("name", "");
} else if(type == "Item") {
} else if (type == "Item") {
setDefault("name", ""); setDefault("name", "");
setDefault("data_type", "string"); setDefault("data_type", "string");
setDefault("data", ""); setDefault("data", "");
@ -199,9 +229,8 @@ void CUIConfig::setDefault()
* @param key * @param key
* @param val * @param val
*/ */
void CUIConfig::setDefault(QString key, QVariant val) void CUIConfig::setDefault(QString key, QVariant val) {
{ if (!property.contains(key)) {
if(!property.contains(key)) {
property[key] = val; property[key] = val;
} }
} }

@ -8,9 +8,8 @@
class CUISigsCenter; class CUISigsCenter;
class CUIPropertyAPI CUIConfig class CUIPropertyAPI CUIConfig {
{ public:
public:
CUIConfig(QMap<QString, QVariant> temp); CUIConfig(QMap<QString, QVariant> temp);
CUIConfig(QMap<QString, QVariant> temp, QVector<CUIConfig*> sub); CUIConfig(QMap<QString, QVariant> temp, QVector<CUIConfig*> sub);
void printConfig(); void printConfig();
@ -19,11 +18,12 @@ public:
QString getPropertyValue(QString); QString getPropertyValue(QString);
QVariant getPropertyOriginValue(QString); QVariant getPropertyOriginValue(QString);
QVector<CUIConfig*> getSub(); QVector<CUIConfig*> getSub();
private: QString getOriginValueString();
private:
void setDefault(); void setDefault();
void setDefault(QString key, QVariant val); void setDefault(QString key, QVariant val);
private: private:
QMap<QString, QVariant> property; QMap<QString, QVariant> property;
QVector<CUIConfig*> sub; QVector<CUIConfig*> sub;
static int labelMinWidth; static int labelMinWidth;

Loading…
Cancel
Save