Merge branch 'feature/struct-menu-20241023' of http://1.92.128.200:3000/YXS/AppFlow into feature/struct-menu-20241023

# Conflicts:
#	CFDStruct/CFDStructMain/CFDTreeWidget.cpp
feature/struct-menu-20241023
mzh 2 weeks ago
commit bc8a8863fa

@ -1,10 +1,12 @@
SOURCES += \
$$PWD/CFDStructDataManagerBase.cpp \
$$PWD/CFDStructDataSolverTimeModeManager.cpp \
$$PWD/CFDStructDataSolverBasicModelManager.cpp \
$$PWD/CFDStructSigsCenter.cpp \
$$PWD/CFDStructDataManager.cpp \
HEADERS += \
$$PWD/CFDStructDataManagerBase.h \
$$PWD/CFDStructDataSolverTimeModeManager.h \
$$PWD/CFDStructDataSolverBasicModelManager.h \
$$PWD/CFDStructSigsCenter.h \

@ -0,0 +1,19 @@
#include "CFDStructDataManagerBase.h"
CFDStructDataManagerBase::CFDStructDataManagerBase(QObject *parent) : QObject(parent)
{
m_cuiSigsCenter = CUISigsCenter::getInstance();
}
CFDStructDataManagerBase::~CFDStructDataManagerBase()
{
if (m_uiConfig != nullptr) {
delete m_uiConfig;
m_uiConfig = nullptr;
}
}
CUIConfig *CFDStructDataManagerBase::getParamUIConfig()
{
return nullptr;
}

@ -0,0 +1,25 @@
#ifndef CFDSTRUCTDATAMANAGERBASE_H
#define CFDSTRUCTDATAMANAGERBASE_H
#include <QObject>
#include "CFDStructDataManager_global.h"
#include "CUIProperty/CUISigsCenter.h"
#include "CUIProperty/CUIConfig.h"
#include "CUIProperty/CUIDefine.h"
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManagerBase : public QObject
{
Q_OBJECT
public:
explicit CFDStructDataManagerBase(QObject *parent = nullptr);
~CFDStructDataManagerBase();
// 获取参数界面的配置
virtual CUIConfig* getParamUIConfig();
signals:
protected:
CUIConfig* m_uiConfig = nullptr;
CUISigsCenter* m_cuiSigsCenter = nullptr;
};
#endif // CFDSTRUCTDATAMANAGERBASE_H

@ -5,10 +5,10 @@
#include "CUIProperty/CUISigsCenter.h"
#include <QVariant>
CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject *parent) : QObject(parent)
CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject *parent) : CFDStructDataManagerBase(parent)
{
m_uiConfig = nullptr;
connect(CUISigsCenter::getInstance(), &CUISigsCenter::sig_cuiPropertyChanged, this, [ = ](int semaphore) {
connect(m_cuiSigsCenter, &CUISigsCenter::sig_cuiPropertyChanged, this, [ = ](int semaphore) {
qDebug() << semaphore << " ========================";
emit CFDStructSigsCenter::getInstance()->sig_solverTimeModeDataChanged();
});
@ -16,10 +16,7 @@ CFDStructDataSolverTimeModeManager::CFDStructDataSolverTimeModeManager(QObject *
CFDStructDataSolverTimeModeManager::~CFDStructDataSolverTimeModeManager()
{
if (m_uiConfig != nullptr) {
delete m_uiConfig;
m_uiConfig = nullptr;
}
// CFDStructDataManagerBase::~CFDStructDataManagerBase();
}
CUIConfig *CFDStructDataSolverTimeModeManager::getParamUIConfig()
@ -48,24 +45,24 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genSteadyModeUIConfig()
new CUIConfig({
{"type", "ComboBox"},
{"name", "Time Mode"},
{"valueType", "Int"},
{"valueOrigin", QVA_GLOBAL(&m_runtype)},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_runtype)},
{"semaphore", 1},
}, {
new CUIConfig({
{"type", "Item"},
{"name", "steady"},
{"data", "0"},
}),
new CUIConfig({
{"type", "Item"},
{"name", "unsteady"},
{"data", "1"},
})
}),
new CUIConfig({
{"type", "LineEdit"},
{"name", "iteration count"}
{"name", "iteration count"},
{"value_type", "Int"},
{"value_origin", QVA_GLOBAL(&m_mcyc)},
})
});
}
@ -77,8 +74,8 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genUnsteadyModeUIConfig()
new CUIConfig({
{"type", "ComboBox"},
{"name", "Time Mode"},
{"valueType", "Int"},
{"valueOrigin", QVA_GLOBAL(&m_runtype)},
{"value_type", CUI_DATA_TYPE::CUI_DATA_TYPE_INT},
{"value_origin", QVA_GLOBAL(&m_runtype)},
{"semaphore", 1},
}, {
new CUIConfig({
@ -92,19 +89,27 @@ CUIConfig *CFDStructDataSolverTimeModeManager::genUnsteadyModeUIConfig()
}),
new CUIConfig({
{"type", "LineEdit"},
{"name", "alf0"}
{"name", "alf0"},
{"value_type", "Double"},
{"value_origin", QVA_GLOBAL(&m_alf0)},
}),
new CUIConfig({
{"type", "LineEdit"},
{"name", "realdt"}
{"name", "realdt"},
{"value_type", "Double"},
{"value_origin", QVA_GLOBAL(&m_realdt)},
}),
new CUIConfig({
{"type", "LineEdit"},
{"name", "nstep"}
{"name", "nstep"},
{"value_type", "Int"},
{"value_origin", QVA_GLOBAL(&m_nstep)},
}),
new CUIConfig({
{"type", "LineEdit"},
{"name", "mcyc"}
{"name", "mcyc"},
{"value_type", "Int"},
{"value_origin", QVA_GLOBAL(&m_mcyc)},
})
});
}

@ -1,11 +1,11 @@
#ifndef CFDSTRUCTDATASOLVERTIMEMODEMANAGER_H
#define CFDSTRUCTDATASOLVERTIMEMODEMANAGER_H
#include <QObject>
#include <CFDStructDataManagerBase.h>
#include "CFDStructDataManager_global.h"
class CUIConfig;
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverTimeModeManager : public QObject
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataSolverTimeModeManager : public CFDStructDataManagerBase
{
Q_OBJECT
public:
@ -22,19 +22,18 @@ private:
signals:
private:
// 鏃堕棿妯″紡
// 时间模式定常0非定常1
int m_runtype = 0;
// 杩唬姝ユ暟锛>=1锛屽畾甯告椂锛氳凯浠鏁帮紝闈炲畾甯革細鍐呰凯浠鏁 int m_mcyc = 1000;
// 姝ラ暱妯″紡锛屽浐瀹氾紝涓嶅彲淇敼
// 时间模式定常0则是迭代步数时间模式非定常1则是内迭代步数
int m_mcyc = 1000;
// 步长模式 >=1
double m_alf0 = 1.0;
// 鏃堕棿姝ラ暱锛0
// 时间步长 >0
double m_realdt = 1.0;
// 鏃堕棿姝ユ暟锛=1
double m_nstep = 10;
// 鏃跺潎缁熻閲忔暟鎹噰鏍0,1
// 时间步数 >=1
int m_nstep = 10;
// 时均统计量数据采样0 | 1
int m_timeaverage = 0;
CUIConfig* m_uiConfig = nullptr;
};
#endif // CFDSTRUCTDATASOLVERTIMEMODEMANAGER_H

@ -1,97 +0,0 @@
#include "CFDStructOperatorsBasicModelManager.h"
#include "GUIFrame/MainWindow.h"
#include "GUIFrame/PropertyWidget.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "CFDStruct/CUIProperty/CUI.h"
#include "CUIProperty/CUIConfig.h"
#include <QLabel>
#include <QDebug>
namespace ModelOper
{
CFDStructOperatorsBasicModelManager::CFDStructOperatorsBasicModelManager()
{
qDebug() << "build Time Mode Manager";
}
CFDStructOperatorsBasicModelManager::~CFDStructOperatorsBasicModelManager()
{
}
bool CFDStructOperatorsBasicModelManager::execGUI()
{
QWidget* widget = nullptr;
GUI::MainWindow* mainWindow = dynamic_cast<GUI::MainWindow*>(FITKAPP->getGlobalData()->getMainWindow());
if (mainWindow == nullptr) {
return false;
}
GUI::PropertyWidget* propertyWidget = mainWindow->getPropertyWidget();
if (propertyWidget == nullptr) {
return false;
}
// switch (_operType){
// case ModelOper::OperManagerBase::Edit:
// {
// widget = new GUI::BasicModelWidget(this);
// break;
// }
// }
qDebug() << "Time Mode Manager11111111111";
widget = new QLabel("Time Mode Manager11111");
// CUI* cui = new CUI(new CUIConfig({
// {"type","Widget"}
// },{
// new CUIConfig({
// {"type","LineEidt"},
// {"name","Solver type"}
// }),
// new CUIConfig({
// {"type","ComboBox"},
// {"name","flow model"}
// },{}),
// new CUIConfig({
// {"type","PushButton"},
// {"name","flow model"}
// }),
// new CUIConfig({
// {"type","GroupBox"},
// {"name","Fluid properties"}
// },{
// new CUIConfig({
// {"type","LineEdit"},
// {"name","Gas composition"}
// }),
// new CUIConfig({
// {"type","LineEdit"},
// {"name","Gas constant (R)"}
// }),
// new CUIConfig({
// {"type","LineEdit"},
// {"name","Heat ratio"}
// }),
// new CUIConfig({
// {"type","LineEdit"},
// {"name","Laminar Prandtl number"}
// }),
// new CUIConfig({
// {"type","LineEdit"},
// {"name","Turbulent Prandtl number"}
// }),
// })
// }));
// widget = cui->getUI();
// if (mainWindow->getPropertyWidget() && widget) {
propertyWidget->setWidget(widget);
// }
return false;
}
bool CFDStructOperatorsBasicModelManager::execProfession()
{
return true;
}
}

@ -1,40 +0,0 @@
#ifndef _CFDStructOperatorsBasicModelManager_H
#define _CFDStructOperatorsBasicModelManager_H
#include "CFDStructOperatorsModelAPI.h"
#include "OperatorsModel/OperManagerBase.h"
namespace ModelOper
{
class CFDStructOperatorsModelAPI CFDStructOperatorsBasicModelManager : public OperManagerBase
{
Q_OBJECT;
public:
/**
* @brief Construct a new Operators Mesh Base Manager object
*/
CFDStructOperatorsBasicModelManager();
/**
* @brief Destroy the Operators Mesh Base Manager object
*/
~CFDStructOperatorsBasicModelManager();
/**
* @brief
* @return true
* @return false
*/
virtual bool execGUI();
/**
* @brief
* @return true
* @return false
*/
virtual bool execProfession();
};
// 按钮注册相关操作
Register2FITKOPeratorRepo(actionBasicModelEdit, CFDStructOperatorsBasicModelManager);
}
#endif

@ -1,9 +1,7 @@
HEADERS += \
$$PWD/CFDStructOperatorsModelAPI.h \
$$PWD/CFDStructOperatorsBasicModelManager.h \
$$PWD/CFDStructOperatorsTimeModeManager.h
SOURCES += \
$$PWD/CFDStructOperatorsBasicModelManager.cpp \
$$PWD/CFDStructOperatorsTimeModeManager.cpp

@ -0,0 +1,148 @@
#include "CUIComponentBase.h"
CUIComponentBase::CUIComponentBase(QWidget *parent) : QWidget(parent)
{
this->initSetting();
}
void CUIComponentBase::initSetting()
{
if (!m_conf) {
return;
}
m_dataType = (CUI_DATA_TYPE)m_conf->getPropertyOriginValue("m_dataType").toInt();
if(m_conf->getPropertyValue("initial_value") != QVariant::Invalid) {
m_value = m_conf->getPropertyOriginValue("initial_value");
}
// 初始化是否必填
if(m_conf->getPropertyValue("required") != QVariant::Invalid) {
m_required = m_conf->getPropertyOriginValue("required").toBool();
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
m_checkRange = false;
return;
}
// 是否检查范围
if(m_conf->getPropertyValue("check_range") != QVariant::Invalid) {
m_checkRange = m_conf->getPropertyOriginValue("check_range").toBool();
}
// 左值和右值是否包含
if(m_conf->getPropertyOriginValue("inclusive_min") != QVariant::Invalid) {
m_inclusiveMin = m_conf->getPropertyOriginValue("inclusive_min").toBool();
}
if(m_conf->getPropertyOriginValue("inclusive_max") != QVariant::Invalid) {
m_inclusiveMax = m_conf->getPropertyOriginValue("inclusive_max").toBool();
}
// 初始化左值和右值
if (m_checkRange) {
if(m_conf->getPropertyOriginValue("range_min") != QVariant::Invalid) {
m_rangeMin = m_conf->getPropertyValue("range_min");
} else {
if (m_dataType == CUI_DATA_TYPE_INT) {
m_rangeMin = INT_MIN;
} else if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
m_rangeMin = DBL_MIN;
}
}
if(m_conf->getPropertyOriginValue("range_max") != QVariant::Invalid) {
m_rangeMax = m_conf->getPropertyValue("range_max");
} else {
if (m_dataType == CUI_DATA_TYPE_INT) {
m_rangeMin = INT_MAX;
} else if (m_dataType == CUI_DATA_TYPE_DOUBLE) {
m_rangeMin = DBL_MAX;
}
}
}
}
bool CUIComponentBase::inRange()
{
if(m_checkRange) {
// 如果包含最小值,但是修改后的值小于最小值,则不在范围内
if (m_inclusiveMin && m_value < m_rangeMin ) {
return false;
}
// 如果不包含最小值,但是修改后的值小于等于最小值,则不在范围内
if (!m_inclusiveMin && m_value <= m_rangeMin ) {
return false;
}
// 如果包含最大值,但是修改后的值大于最大值,则不在范围内
if (m_inclusiveMax && m_value > m_rangeMax ) {
return false;
}
// 如果不包含最大值,但是修改后的值大于等于最大值,则不在范围内
if (!m_inclusiveMax && m_value >= m_rangeMax ) {
return false;
}
}
return true;
}
void CUIComponentBase::initUI()
{
}
void CUIComponentBase::initValidator()
{
}
QString CUIComponentBase::getValueString()
{
if (m_value == QVariant::Invalid) {
return QString("");
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
return m_value.toString();
}
if(m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_value.toInt());
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
return QString::number(m_value.toDouble());
}
return QString("");
}
QString CUIComponentBase::getRangeMinString()
{
if (m_rangeMin == QVariant::Invalid) {
return QString("");
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
return m_rangeMin.toString();
}
if(m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_rangeMin.toInt());
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
return QString::number(m_rangeMin.toDouble());
}
return QString("");
}
QString CUIComponentBase::getRangeMaxString()
{
if (m_rangeMax == QVariant::Invalid) {
return QString("");
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
return m_rangeMax.toString();
}
if(m_dataType == CUI_DATA_TYPE_INT) {
return QString::number(m_rangeMax.toInt());
}
if(m_dataType == CUI_DATA_TYPE_STRING) {
return QString::number(m_rangeMax.toDouble());
}
return QString("");
}
void CUIComponentBase::setValueToOrigin()
{
if (m_conf) {
m_conf->setValue(m_value);
}
}

@ -0,0 +1,55 @@
#ifndef CUICOMPONENTBASE_H
#define CUICOMPONENTBASE_H
#include <QWidget>
#include <QVariant>
#include "CUIPropertyAPI.h"
#include "CUIConfig.h"
#include "CUIDefine.h"
class CUIPropertyAPI CUIComponentBase : public QWidget
{
Q_OBJECT
public:
explicit CUIComponentBase(QWidget *parent = nullptr);
protected:
// 初始化配置
void initSetting();
// 判断是否在范围内
bool inRange();
// 初始化UI
virtual void initUI();
// 初始化值校验器
virtual void initValidator();
// 获取值的字符串形式
QString getValueString();
// 获取最小值的字符串形式
QString getRangeMinString();
// 获取最大值的字符串形式
QString getRangeMaxString();
// 同步到数据来源
void setValueToOrigin();
protected:
CUIConfig* m_conf = nullptr;
// 值类型
CUI_DATA_TYPE m_dataType = CUI_DATA_TYPE::CUI_DATA_TYPE_UNKNOW;
// 具体值
QVariant m_value = QVariant::Invalid;
// 是否检查范围
bool m_checkRange = false;
// 左值
QVariant m_rangeMin;
// 右值
QVariant m_rangeMax;
// 是否包含左值
bool m_inclusiveMin = false;
// 是否包含右值
bool m_inclusiveMax = false;
// 是否是必填
bool m_required = true;
signals:
};
#endif // CUICOMPONENTBASE_H

@ -2,6 +2,7 @@
#include "CUISigsCenter.h"
#include <QDebug>
#include <QTimer>
#include "CUIDefine.h"
/**
* @brief CUIConfig::CUIConfig
@ -98,19 +99,33 @@ void CUIConfig::printConfig()
void CUIConfig::setValue(QVariant value)
{
QVariant pValue = property["valueOrigin"];
if (property["valueType"] == "Int") {
bool changed = false;
QVariant pValue = property["value_origin"];
if (property["value_type"] == CUI_DATA_TYPE_INT) {
int* ptr = qvariant_cast<int*>(pValue);
if (*ptr != value.toInt()) {
*ptr = value.toInt();
// 如果需要通知,则通知参数值发生修改
if (this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
QTimer::singleShot(50, m_sigsCenter, [ = ]() {
int semaphore = this->getPropertyOriginValue("semaphore").toInt();
emit m_sigsCenter->sig_cuiPropertyChanged(semaphore);
});
}
changed = true;
}
} else if (property["value_type"] == CUI_DATA_TYPE_DOUBLE) {
double* ptr = qvariant_cast<double*>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble();
changed = true;
}
} else if (property["value_type"] == CUI_DATA_TYPE_STRING) {
double* ptr = qvariant_cast<double*>(pValue);
if (*ptr != value.toDouble()) {
*ptr = value.toDouble();
changed = true;
}
}
// 如果需要通知,则通知参数值发生修改
if (changed && this->getPropertyOriginValue("semaphore") != QVariant::Invalid) {
QTimer::singleShot(50, m_sigsCenter, [ = ]() {
int semaphore = this->getPropertyOriginValue("semaphore").toInt();
emit m_sigsCenter->sig_cuiPropertyChanged(semaphore);
});
}
}
@ -154,13 +169,14 @@ void CUIConfig::setDefault()
QString type = qvariant_cast<QString>(property["type"]);
if(type == "LineEdit") {
setDefault("name", "");
setDefault("data_type", "string"); //数据类型
setDefault("initial_value_", ""); //初始值
setDefault("check_range_", "false"); //是否检查范围
setDefault("range_min_", ""); //最小值
setDefault("range_max_", ""); //最大值
setDefault("inclusive_", "true"); //范围是否包括
setDefault("required_", "false"); //是否为必选
setDefault("data_type", "string"); // 数据类型
setDefault("initial_value_", ""); // 初始值
setDefault("check_range_", false); // 是否检查范围
setDefault("range_min_", ""); // 最小值
setDefault("range_max_", ""); // 最大值
setDefault("inclusive_min", true); // 左范围是否包括
setDefault("inclusive_max", true); // 右范围是否包括
setDefault("required_", true); // 是否为必选
} else if(type == "Widget") {
setDefault("layout", "QVBoxLayout");
setDefault("name", "");

@ -0,0 +1,11 @@
#ifndef CUIDEFINE_H
#define CUIDEFINE_H
enum CUI_DATA_TYPE {
CUI_DATA_TYPE_INT,
CUI_DATA_TYPE_DOUBLE,
CUI_DATA_TYPE_STRING,
CUI_DATA_TYPE_UNKNOW,
};
#endif // CUIDEFINE_H

@ -1,56 +1,24 @@
#include "CUILineEdit.h"
#include <QHBoxLayout>
#include<CUIConfig.h>
#include<QLabel>
#include<CUI.h>
#include<QDebug>
#include <CUIConfig.h>
#include <QLabel>
#include <CUI.h>
#include <QDebug>
#include <QDoubleValidator>
#include <QIntValidator>
/**
* @brief CUILineEdit::CUILineEdit
* @param conf
* @param parent
*/
CUILineEdit::CUILineEdit(CUIConfig* conf, QVector<CUI*> &subCUI,QWidget *parent) : QWidget(parent)
CUILineEdit::CUILineEdit(CUIConfig* conf, QVector<CUI*> &subCUI, QWidget *parent) : CUIComponentBase(parent)
{
this->conf = conf;
appSetting();
iniUI(subCUI);
showMsg();
checkRange();
this->m_conf = conf;
this->iniUI(subCUI);
}
/**
* @brief CUILineEdit::isInRange ,
* @return true\false
*/
bool CUILineEdit::isInRange() const
{
bool res = false;
if(check_range_){
if(data_type == "int")
{
if(inclusive_){
res = range_min_.toInt() <= lineedit->text().toInt() &&
lineedit->text().toInt() <= range_max_.toInt();
}else{
res = range_min_.toInt() < lineedit->text().toInt() &&
lineedit->text().toInt() < range_max_.toInt();
}
}
if(data_type == "double")
{
if(inclusive_){
res = range_min_.toDouble() <= lineedit->text().toDouble() &&
lineedit->text().toDouble() <= range_max_.toDouble();
}else{
res = range_min_.toDouble() < lineedit->text().toDouble() &&
lineedit->text().toDouble() < range_max_.toDouble();
}
}
}
return res;
}
/**
* @brief CUILineEdit::getLabelWidth label
@ -58,7 +26,7 @@ bool CUILineEdit::isInRange() const
*/
qint32 CUILineEdit::getLabelWidth()
{
return label->minimumSizeHint().width();
return m_label->minimumSizeHint().width();
}
/**
@ -67,7 +35,7 @@ qint32 CUILineEdit::getLabelWidth()
*/
void CUILineEdit::setLabelWidth(qint32 width)
{
label->setMinimumWidth(width);
m_label->setMinimumWidth(width);
}
@ -76,89 +44,28 @@ void CUILineEdit::setLabelWidth(qint32 width)
*/
void CUILineEdit::iniUI(QVector<CUI*> &subCUI)
{
layout = new QHBoxLayout();
label = new QLabel(conf->getPropertyValue("name"));
lineedit = new QLineEdit(initial_value_);
layout->addWidget(label);
layout->addWidget(lineedit);
this->setLayout(layout);
connect(lineedit, &QLineEdit::textEdited, this, &CUILineEdit::onTextChanged);
}
/**
* @brief CUILineEdit::appSetting ,
*/
void CUILineEdit::appSetting()
{
data_type = conf->getPropertyValue("data_type");
initial_value_ = conf->getPropertyValue("initial_value_");
qDebug()<< initial_value_;
if(data_type == "string"){
check_range_ = 0;
}
if(data_type == "int"){
if(conf->getPropertyValue("check_range_") == "true")
{
check_range_ = true;
range_min_ = conf->getPropertyValue("range_min_").toInt();
range_max_ = conf->getPropertyValue("range_max_").toInt();
if(conf->getPropertyValue("inclusive_") == "true")
inclusive_ = true;
else
inclusive_ = false;
}else{
check_range_ = false;
}
}
if(data_type == "double"){
if(conf->getPropertyValue("check_range_") == "true"){
check_range_ = true;
range_min_ = conf->getPropertyValue("range_min_").toDouble();
range_max_ = conf->getPropertyValue("range_max_").toDouble();
if(conf->getPropertyValue("inclusive_") == "true")
inclusive_ = true;
else
inclusive_ = false;
}else{
check_range_ = false;
}
}
if(conf->getPropertyValue("required_") == "false")
required_ = false;
else
required_ = true;
m_layout = new QHBoxLayout();
m_label = new QLabel(m_conf->getPropertyValue("name"));
m_lineEdit = new QLineEdit(this->getValueString());
m_layout->addWidget(m_label);
m_layout->addWidget(m_lineEdit);
this->setLayout(m_layout);
// 设置格式校验
this->setValidator();
this->setInputTips();
connect(m_lineEdit, &QLineEdit::textEdited, this, &CUILineEdit::onTextChanged);
}
/**
* @brief CUILineEdit::checkType
*/
void CUILineEdit::checkType(const QString &text)
void CUILineEdit::setValidator()
{
qint32 cursorPosition = lineedit->cursorPosition();
if(data_type == "int"){
bool ok;
text.toInt(&ok);
if(ok || text == "" || text == "-")
lastEdited = text;
else
{
lineedit->setText(lastEdited);
lineedit->setCursorPosition(cursorPosition-1);
switch (m_dataType) {
case CUI_DATA_TYPE_DOUBLE: {
m_lineEdit->setValidator(new QDoubleValidator(m_rangeMin.toDouble(), m_rangeMax.toDouble(), 10));
break;
}
}
if(data_type == "double"){
bool ok;
text.toDouble(&ok);
if(ok || text == "" || text == "-")
lastEdited = text;
else
{
lineedit->setText(lastEdited);
lineedit->setCursorPosition(cursorPosition-1);
case CUI_DATA_TYPE_INT: {
m_lineEdit->setValidator(new QIntValidator(m_rangeMin.toInt(), m_rangeMax.toInt()));
break;
}
}
}
@ -166,43 +73,34 @@ void CUILineEdit::checkType(const QString &text)
/**
* @brief CUILineEdit::showMsg
*/
void CUILineEdit::showMsg()
void CUILineEdit::setInputTips()
{
QString msg = "";
if(check_range_){
if(inclusive_){
msg += "["+range_min_.toString()+","+range_max_.toString()+"] ";
}else{
msg += "("+range_min_.toString()+","+range_max_.toString()+") ";
}
if(m_checkRange) {
msg += m_inclusiveMin ? "[" : "(";
msg += this->getRangeMinString() + "," + this->getRangeMaxString();
msg += m_inclusiveMax ? "]" : ")";
}
if(required_){
if(m_required) {
msg += "\t(必填)";
}
lineedit->setPlaceholderText(msg);
m_lineEdit->setPlaceholderText(msg);
}
/**
* @brief CUILineEdit::checkRange
*/
bool CUILineEdit::checkRange()
void CUILineEdit::showRangeError()
{
bool res = true;
if(check_range_){
QPalette palette = lineedit->palette();
res = isInRange();
if(res){
if(m_checkRange) {
QPalette palette = m_lineEdit->palette();
if(this->inRange()) {
palette.setColor(QPalette::Text, Qt::black);
}else{
} else {
palette.setColor(QPalette::Text, Qt::red);
}
lineedit->setPalette(palette);
m_lineEdit->setPalette(palette);
}
return res;
}
@ -216,6 +114,22 @@ bool CUILineEdit::checkRange()
*/
void CUILineEdit::onTextChanged(const QString &text)
{
checkType(text);
checkRange();
this->showRangeError();
if (this->inRange()) {
switch (m_dataType) {
case CUI_DATA_TYPE_DOUBLE: {
m_value = qvariant_cast<double>(m_lineEdit->text().toDouble());
break;
}
case CUI_DATA_TYPE_INT: {
m_value = qvariant_cast<int>(m_lineEdit->text().toInt());
break;
}
case CUI_DATA_TYPE_STRING: {
m_value = m_lineEdit->text();
break;
}
}
this->setValueToOrigin();
}
}

@ -3,50 +3,37 @@
#include <QLineEdit>
#include "CUIPropertyAPI.h"
#include "CUIComponentBase.h"
class CUIConfig;
class QLabel;
class QHBoxLayout;
class CUI;
class CUIPropertyAPI CUILineEdit : public QWidget
class CUIPropertyAPI CUILineEdit : public CUIComponentBase
{
Q_OBJECT
public:
explicit CUILineEdit(CUIConfig* config, QVector<CUI*> &subCUI, QWidget *parent = nullptr);
bool isInRange() const;
qint32 getLabelWidth();
void setLabelWidth(qint32 width);
private:
void iniUI(QVector<CUI*> &subCUI);
void appSetting();
void checkType(const QString &text);
void showMsg();
bool checkRange();
CUIConfig* conf;
QLabel* label;
QLineEdit* lineedit;
// QLayout* layout;
QHBoxLayout* layout;
QString lastEdited;
QString data_type;
QString initial_value_;
bool check_range_;
QVariant range_min_;
QVariant range_max_;
bool inclusive_;
bool required_;
// 设置格式校验器
void setValidator();
// 设置输入提示
void setInputTips();
void showRangeError();
QLabel* m_label;
QLineEdit* m_lineEdit;
QHBoxLayout* m_layout;
// QString lastEdited;
signals:
private slots:
void onTextChanged(const QString &text);
};
#endif // CUILINEEDIT_H

@ -1,4 +1,6 @@
HEADERS += \
$$PWD/CUIComponentBase.h \
$$PWD/CUIDefine.h \
CUI.h \
CUIButtonBox.h \
CUICheckBox.h \
@ -15,6 +17,7 @@ HEADERS += \
CUIConfig.h
SOURCES += \
$$PWD/CUIComponentBase.cpp \
CUI.cpp \
CUIButtonBox.cpp \
CUICheckBox.cpp \

Loading…
Cancel
Save