|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
|
#include <QMap>
|
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
|
|
|
|
#include "zxBindWxPair.h"
|
|
|
|
|
|
|
|
|
|
|
|
// 单位控件绑定器 - 将QLineEdit和QComboBox绑定,统一管理单位转换
|
|
|
|
|
|
// 每个对话框/窗口独立拥有自己的实例
|
|
|
|
|
|
class X_GUI_BASE_EXPORT iUnitWxBinder : public QObject
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
explicit iUnitWxBinder(QObject *parent = 0, QString sParaSrcTag = "");
|
|
|
|
|
|
~iUnitWxBinder();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
// 禁止拷贝
|
|
|
|
|
|
iUnitWxBinder(const iUnitWxBinder&);
|
|
|
|
|
|
iUnitWxBinder& operator=(const iUnitWxBinder&);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 注册单位组(根据参数进行)
|
|
|
|
|
|
/// @param pTbxValue 数值输入区
|
|
|
|
|
|
/// @param pCbxUnit 单位下拉框
|
|
|
|
|
|
/// @param sPara 绑定的参数,可以为空,但是不建议为空,如果为空,则自动根据combo已经填写的内容,搜索UnitGroup
|
|
|
|
|
|
/// @param bBindWxOnly 是否仅仅绑定,true,这时候不重新填写数值和下拉
|
|
|
|
|
|
bool registerUnitGroup(QLineEdit* pTbxValue, \
|
|
|
|
|
|
QComboBox* pCbxUnit, \
|
|
|
|
|
|
QString sPara = "", \
|
|
|
|
|
|
bool bBindWxOnly = false);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 注册单位组(根据参数进行,两个算比较常见的,所以单位增加一个接口)
|
|
|
|
|
|
/// @param pTbxValue1 数值输入区
|
|
|
|
|
|
/// @param pTbxValue2 数值输入区
|
|
|
|
|
|
/// @param pCbxUnit 单位下拉框
|
|
|
|
|
|
/// @param sPara 绑定的参数,可以为空,但是不建议为空,如果为空,则自动根据combo已经填写的内容,搜索UnitGroup
|
|
|
|
|
|
/// @param bBindWxOnly 是否仅仅绑定,true,这时候不重新填写数值和下拉
|
|
|
|
|
|
bool registerUnitGroup(QLineEdit* pTbxValue1, \
|
|
|
|
|
|
QLineEdit* pTbxValue2, \
|
|
|
|
|
|
QComboBox* pCbxUnit, \
|
|
|
|
|
|
QString sPara = "", \
|
|
|
|
|
|
bool bBindWxOnly = false);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
// 注册单位组(单个LineEdit)
|
|
|
|
|
|
bool _registerUnitGroup(QLineEdit* pTbxValue, \
|
|
|
|
|
|
QComboBox* pCbxUnit, \
|
|
|
|
|
|
iUnitGroup* pUnitGroup, \
|
|
|
|
|
|
const QString& sBaseUnit, \
|
|
|
|
|
|
double dValueInit = 0.0, \
|
|
|
|
|
|
QString sPara = "", \
|
|
|
|
|
|
bool bBindWxOnly = false);
|
|
|
|
|
|
|
|
|
|
|
|
// 注册单位组(多个LineEdit共用一个ComboBox)
|
|
|
|
|
|
bool _registerUnitGroup(QList<QLineEdit*> listTbxValues, \
|
|
|
|
|
|
QComboBox* pCbxUnit, \
|
|
|
|
|
|
iUnitGroup* pUnitGroup, \
|
|
|
|
|
|
const QString& sBaseUnit, \
|
|
|
|
|
|
QList<double> listValueInits = QList<double>(), \
|
|
|
|
|
|
QString sPara = "", \
|
|
|
|
|
|
bool bBindWxOnly = false);
|
|
|
|
|
|
|
|
|
|
|
|
void _freshTips(zxBindWxPair* pBindPair);
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
// 获取基准单位的数值
|
|
|
|
|
|
double getBaseValue(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
double getBaseValue(QString sPara) const; //慎用,只有一对一的情形才能用
|
|
|
|
|
|
// 设置基准值(会同步更新显示)
|
|
|
|
|
|
void setBaseValue(QLineEdit* pTbxValue, double baseValue);
|
|
|
|
|
|
void setBaseValue(double baseValue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前单位下的显示值
|
|
|
|
|
|
double getDisplayValue(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
double getDisplayValue(QString sPara) const; //慎用,只有一对一的情形才能用
|
|
|
|
|
|
|
|
|
|
|
|
QString getShowValue(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
QString getShowValue(QString sPara) const; //慎用,只有一对一的情形才能用
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前单位名称
|
|
|
|
|
|
QString getCurrentUnit(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
QString getBaseUnit(QString sPara) const; //慎用,只有一对一的情形才能用
|
|
|
|
|
|
|
|
|
|
|
|
// 设置当前单位(会同步转换数值)
|
|
|
|
|
|
void setCurrentUnit(QLineEdit* pTbxValue, const QString& unitName);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前单位索引
|
|
|
|
|
|
int getCurrentUnitIndex(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
|
|
|
|
|
|
// 获取单位组
|
|
|
|
|
|
iUnitGroup* getUnitGroup(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
|
|
|
|
|
|
zxBindWxPair* getWxPairOf(QLineEdit* pTbxValue);
|
|
|
|
|
|
const zxBindWxPair* getWxPairOf(QLineEdit* pTbxValue) const;
|
|
|
|
|
|
zxBindWxPair* getWxPairOf(QComboBox* pCbxUnit);
|
|
|
|
|
|
const zxBindWxPair* getWxPairOf(QComboBox* pCbxUnit) const;
|
|
|
|
|
|
|
|
|
|
|
|
zxBindWxPair* getDefaultWxPair();
|
|
|
|
|
|
const zxBindWxPair* getDefaultWxPair() const;
|
|
|
|
|
|
|
|
|
|
|
|
// 这一组慎用,只有一对一情形适用
|
|
|
|
|
|
zxBindWxPair* getWxPairOf(QString sPara);
|
|
|
|
|
|
const zxBindWxPair* getWxPairOf(QString sPara) const;
|
|
|
|
|
|
|
|
|
|
|
|
// 手动触发更新显示
|
|
|
|
|
|
void updateDisplay(QLineEdit* pTbxValue);
|
|
|
|
|
|
|
|
|
|
|
|
// 移除单位组(当控件销毁时自动调用)
|
|
|
|
|
|
void removeUnitGroup(QLineEdit* pTbxValue);
|
|
|
|
|
|
|
|
|
|
|
|
// 清理所有已销毁控件的组数据
|
|
|
|
|
|
void cleanupDestroyedGroups();
|
|
|
|
|
|
|
|
|
|
|
|
QString getEditorCss(bool bValid);
|
|
|
|
|
|
|
|
|
|
|
|
QString getLastError();
|
|
|
|
|
|
|
|
|
|
|
|
// 判断输入是否OK,如果为空,则默认第一个
|
|
|
|
|
|
bool isInputOK(QLineEdit* pTbxValue = nullptr, \
|
|
|
|
|
|
bool bCheckOnly = true, \
|
|
|
|
|
|
double* ptrBaseValue = nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
|
|
|
|
// 触发信号,由外部控制,是否输入OK,比如参数ValidStr校验
|
|
|
|
|
|
void sigInputOK(const QString sPara, const double dBaseValue, bool& bOK);
|
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
|
|
|
|
void onUnitChanged(int index);
|
|
|
|
|
|
void onEditingFinished();
|
|
|
|
|
|
void onWidgetDestroyed(QObject* obj);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
void updateDisplayInternal(zxBindWxPair* pBindPair);
|
|
|
|
|
|
int getDecimalDigitsFromUnit(zxBindWxPair* pBindPair, const QString& unitName) const;
|
|
|
|
|
|
QString formatNumber(double value, int nDigit) const;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
QList<zxBindWxPair*> m_listPairs;
|
|
|
|
|
|
|
|
|
|
|
|
// 参数来源标识,默认情况下,为 s_Sys_Para_Default
|
|
|
|
|
|
// 不涉及序列化
|
|
|
|
|
|
QString m_sParaSrcTag;
|
|
|
|
|
|
|
|
|
|
|
|
// Error
|
|
|
|
|
|
QString m_sError;
|
|
|
|
|
|
|
|
|
|
|
|
};
|