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.
nmWTAI-Platform/Include/iBase/iUtils/ZxBaseUtil.h

287 lines
13 KiB
C

#pragma once
#include "Defines.h"
#include "iBase_global.h"
#include "LlUtils_global.h"
/// @brief 该类是一些公有函数库的实现,比较杂
/// @note 通常一些不知道应放在何处的代码可以仍在该类中实现
/// 该类请不要添加成员变量或非静态的方法
class I_UTILS_EXPORT ZxBaseUtil
{
public:
ZxBaseUtil();
// 获取当前APP文件所在的路径 ..\Bin\Release
static QString getAppDir();
// 获得当前DLl文件所在的路径 ..\Bin\Release
static QString getDllDir(QString strDll);
/// @brief 获取相应的组合路径
/// @param sCategory 对应 defines.h中 s_Dir_Config 之类
/// @param sSubDir 对应 defines.h中 s_SubDir_AlgoConfig 之类
/// @param sTag 对应 defines.h中 s_Tag_Plot 之类
static QString getDirOf(QString sCategory, QString sSubDir = "", QString sTag = "",QString sDll = "");
/// @brief 获取当前项目下的相应的组合路径
/// @param sTag 对应 defines.h中 s_Tag_Plot 之类
static QString getCurProjectDirOf(QString sTag = "");
/// @brief 创建(如果不存在)路径
/// @note 作用包括如下:
/// (1)、创建 sDir 目录,如果未创建
/// (2)、\\替换为/,并且确保路径以 / 结尾
/// (3)、去除 ../ 之类的路径(规范)
static bool makeSureDir(QString& sDir);
/// @brief 拷贝文件夹
/// @param fromDir : 源目录
/// @param toDir : 目标目录
/// @param bCoverIfFileExists : ture:同名时覆盖 false:同名时返回false,终止拷贝
/// @note 返回: ture拷贝成功 false:拷贝未完成
//static bool copyDir(const QDir& fromDir, const QDir& toDir, bool bCoverIfFileExists = true);
// 把QStringList或QVector转换为QString为了打印方便
//static QString convert2Str(QStringList vecStr, QString seprator = " ");
//static QString convert2Str(QVector<QString> vecStr, QString seprator = " ");
/// @brief 获取当前打开的工区,对框架接口的封装
//static void setCurrentProject(ZxProjectData* project);
/// @brief 上次打开项目,
static void setLastProject(const QString& sProjectName);
static QString getLastProject();
/// @brief 当前打开的项目 test log
static void setCurrentProjectName(const QString& sProjectName);
static QString getCurrentProjectName();
/// @brief 当前打开的项目的路径 ../Bin\Test_Data\test log/
static void setCurProjectDir(const QString& sProjectDir);
static QString getCurProjectDir();
/// @brief 获取当前工区下某口井的相应的组合路径
/// @param sTag 对应 defines.h中 s_Tag_Plot 之类
static QString getWellDirOf(QString sWellName, QString sTag = "", QString sTagChild = "");
/// @brief 获取当前工区下当前井的相应的组合路径
/// @param sTag 对应 defines.h中 s_Tag_Plot 之类
static QString getCurWellDirOf(QString sTag = "");
/// @brief 设置当前井
static void setCurrentWellName(const QString& s);
static QString getCurrentWellName();
static void setCurrentWellCode(const QString& s);
static QString getCurrentWellCode();
/// @brief 上次打开路径
static void setLastDir(const QString& sDir);
static QString getLastDir();
/// @brief 自定义信息
static void setCustomValue(QString sKey, const QString& s);
static QString getCustomValue(QString sKeu);
static void setCustomValueEx(QString sKey, const QStringList& list);
static QStringList getCustomValueEx(QString sKey);
/// @brief 获取当前系统日期
static QString getSysDate();
/// @brief 获取当前系统时间
static QString getSysDateTime(bool bNormalFormat = false);
/// @brief 获取当前系统登录用户
static QString getSysUserName();
/// @brief 对项目或项目所在的上一级目录进行个性化设定
/// @param sDir 路径
/// @param bTop 是否项目路径的上一级目录,仅仅为了换个图标而已,也可以修改该参数直接传过来路径
/// bTop仅仅当 sIcon 为空时有效,这次测井软件固定两个图标中的一个
/// @param sIcon 图标路径,绝对路径
/// @note 只有windows平台有效
static bool customProjectFolder(QString sDir, bool bTop = false, QString sIcon = "");
/// @brief 针对Qt暂未找到trimRight之类的接口
/// @note 后续可能封闭该接口
static bool trimStrRight(QString& s);
/// @brief 求取坐标轴的刻度显示
/// @param dMin 左值,通常为最小值
/// @param dMax 右值,通常为最大值
/// @param bAxisX 是否X轴
/// @param bLinear 是否线性
/// @param bExpand 是否流量自动扩展一个tick
/// @param pVecScales结果存储位置
/// @note 1通常 dMin < dMax; 对于dMin > dMax 的情况也做了相应处理(返回结果也是倒着)
static bool calAxisScales(double& dMin,
double& dMax,
bool bAxisX,
bool bLinear = true,
bool bExpand = false,
QVector<double>* pVecScales = nullptr);
/// @brief 随机颜色提取
static QColor getCustomColor(int nIndex);
/// @brief 循环迭代删除文件夹
static bool removeDir(const QString &sDir);
/// @brief 把文件夹的最后一级重命名
static bool renameDir(const QString& sDir, const QString& sNewLast);
/// @brief 循环迭代拷贝文件夹
static bool copyDir(const QString& sFrom, const QString& sTo);
static bool _copyDir(const QString& sFrom, const QString& sTo, QStringList& listDirCopied);
/// @brief 判断字符串是否一致,不考虑大小写
static bool isSameStr(QString s1, QString s2);
/// @brief 判断字符串是否包括中文字符
static bool strContainsChs(QString s);
/// @brief 对字符串进行排序,如果包括中文,则以汉语拼音进行
static bool sortStrList(QStringList& list, bool bAscMode = true);
/// @brief 打开文件夹调用API接口
static void openFolder(QString sDir);
/// @brief 获取下一个可以用的标题默认加_1,_2_3
/// @param nFixedLen取值如下
/// -1则加_1,_2,_3
/// 0-1则加1,2,3,...,10
/// 2+则加01,02,03,...,10或001,002...
static QString getNextOneName(QStringList& listOlds, \
QString& sBase, \
int nFixedLen = -1);
// 对于Cross改为自定义因为系统的太大不美观
static void customerCrossCusor(QCursor &o);
// 获取字符串表示的double的小数位数
// ”1.230"返回3”100“返回0
static int getStrDigit(QString s);
/// @brief 根据小数位数,获取其字符串
/// @param d:数值
/// @param nDigit:小数位数 > 0
/// @param bAutoAdjust:是否自动调整
/// @param bAutoTrimmed:自动截取末尾0
/// @note 如果bAutoAdjust=1d=0.0001,nDigit=3则返回“0.0001”
static QString getValidStr(double d, \
int nDigit, \
bool bAutoTrimmed = true, \
bool bAutoAdjust = true);
/// @brief 根据小数位数,获取其字符串
/// @param v:数值
/// @param nDigit:小数位数 > 0
/// @param bAutoAdjust:是否自动调整
/// @param bAutoTrimmed:自动截取末尾0
/// @note 如果bAutoAdjust=1d=0.0001,nDigit=3则返回“0.0001”
static QString getValidStrEx(QVariant v, \
int nDigit, \
bool bAutoTrimmed = true, \
bool bAutoAdjust = true);
/// @brief double 转为科学计数法 表示
/// @param d 待转换的数值
/// @param nDigit 小数位数这是指的转化为e前面的小数位数
/// @param bCleanMode 是否trim比如9.800e-2是否改为 9.8e-2
/// @param bIgnoreExpZero 是否忽略e0即不显示e0比如9.8e0是否改为 9.8
/// @param bIgnoreZeroOne 是否忽略0,1,之类,即这类直接返回
static QString getScientificStrOf(double d, int nDigit, \
bool bCleanMode = true, \
bool bIgnoreExpZero = true, \
bool bIgnoreZeroOne = true);
/// @brief double 按照约定的规定转为字符串
/// @param d 待转换的数值
/// @param nValidDigit 有效数字位默认为2
/// @note 按照约定的规则nValidDigit目前只能为2保留该参数只是方便后续扩展
/* 新增 20260415考虑到对于小数位数影响计算精度尤其是自动拟合过程。
// 经20260415周例会讨论确定如下原则
// 仅仅针对 对于解释结果的参数部分(主窗口四部分的左下角部分)
// 1.全部参数统一处理
// 2.如果数值 ∈ [1,+∞) 则保留2位小数同时自动裁剪
// 12.374==》12.37
// 1.008==》1.01
// 10.7==》10.7
// 3.如果数值 ∈ [0.001,1) 则保留2位 有效 数字,同时自动裁剪,即:
// 0.001==》0.001
// 0.0017==》0.0017
// 0.05405==》0.054
// 0.8017==》0.8
// 0.5476==》0.58
// 10.7==》10.7
// 4.如果数值 ∈ [-∞,0.001) ,以 科学计数法方式则保留2位 有效 数字,同时自动裁剪,即:
// 0.0001==》1e-4
// 0.00098==》9.8e-4
// 0.0009868==》9.9e-4
// 0.0009003==》9e-4
// 0.000009003==》9e-6//*/
static QString fuzzyFormatDouble(double d, int nValidDigit = 2);
static QString trimValueStrZero(QString s);
// 启动Help
static bool startHelp(QString sChm = "");
/// @brief 开启一个一个进程
/// @param sApp 进程名exe名
/// @param sCmdLine 命令行
/// @param sWorkDir 工作目录
static bool startProcess(QString sApp, \
QString sCmdLine, \
QString sWorkDir = "");
// 判断字符串可否作为路径或者文件明,注:只是判断能否作为文件名或路径名,而不作存在性判断
static bool isValidFileName(const QString s);
static bool isValidFilePath(const QString s);
/// @brief 获取屏幕Dpi
/// @param bX X方向或Y方向
/// @param bPhysicalDpi 物理Dpi还是逻辑Dpi
static int getDpi(bool bX = true, bool bPhysicalDpi = true);
/// @brief 检测是否有效的邮箱地址
static bool isValidEmail(QString sEmail);
///////////////////////////////////////////////////////////////////////
// 为了更改QFileDialog的字体样式特此更改
static QString getExistingDirectory(QWidget *parent = 0,
const QString &caption = QString(),
const QString &dir = QString(),
QFileDialog::Options options = QFileDialog::ShowDirsOnly);
static QString getOpenFileName(QWidget *parent = 0,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = 0,
QFileDialog::Options options = 0);
static QString getSaveFileName(QWidget *parent = 0,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = 0,
QFileDialog::Options options = 0);
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// 表格数据/标题 与 QVariant 的相互转换,为了方便序列化及接口传递
//
static bool sumTableInfos(const QStringList& listTitles, \
const VVecVariant& vvec, \
QVariant& v);
static bool parseTableInfos(const QVariant& v, \
QStringList& listTitles, \
VVecVariant& vvec);
//
///////////////////////////////////////////////////////////////////////
};