126 lines
3.3 KiB
C++
126 lines
3.3 KiB
C++
/******************************************************************************
|
|
* @project JTDemoUI
|
|
* @file toolkit.h
|
|
* @brief 常用工具包
|
|
*
|
|
* @author LWQ
|
|
* @date 2021/12/01/10/23/43
|
|
* @history
|
|
*****************************************************************************/
|
|
#ifndef TOOLKIT_H
|
|
#define TOOLKIT_H
|
|
#include <QString>
|
|
#include <QDateTime>
|
|
#include <QStringList>
|
|
#include <QJsonObject>
|
|
#include <QJsonParseError>
|
|
#include <vector>
|
|
#include "io.h"
|
|
#include <iostream>
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
/********************************************//**
|
|
* <Time File>
|
|
***********************************************/
|
|
|
|
|
|
/**
|
|
* @brief GetTimeStamp
|
|
* @param Stamp 时间格式"yyyy-MM-dd hh:mm:ss:zzz"
|
|
* @return 时间戳
|
|
*/
|
|
QString GetTimeStamp(QString Stamp="yyyy-MM-dd hh:mm:ss:zzz");
|
|
|
|
/**
|
|
* @brief QGetRandom
|
|
* @param max 最大值
|
|
* @param min 最小值
|
|
* @param timeC 添加毫秒延时修正随机种子
|
|
* @return 生成 min~max内的随机数
|
|
*/
|
|
int QGetRandom(int max,int min=0,bool timeC=true);
|
|
|
|
/// \brief QSetFileTimes
|
|
/// \param filepath
|
|
/// \param CreationTime
|
|
/// \return 修改文件创建时间(QT 5.10版本之后有SetFileTimes)
|
|
bool QSetFileTimes(const QString & filepath,QDateTime& CreationTime);
|
|
|
|
/// \brief createMultipleFoldes
|
|
/// \param fullDirName
|
|
/// \param
|
|
/// \return 创建多级文件夹
|
|
QString createMultipleFoldes(const QString & fullDirName);
|
|
|
|
/// \brief isDirExist
|
|
/// \param fullDirName
|
|
/// \param Crt 创建
|
|
/// \return 判断文件夹是否存在,不存在则创建
|
|
bool isDirExist(const QString & fullDirName,bool Crt=false);
|
|
|
|
/// \brief isFileExist
|
|
/// \param fullFileName
|
|
/// \param Crt 是否创建文件
|
|
/// \return 判断文件是否存在,不存在则创建
|
|
bool isFileExist(const QString & fullFileName,bool Crt=false);
|
|
|
|
/// \brief deleteDirectory
|
|
/// \param fullFileName
|
|
/// \param
|
|
/// \return 删除文件夹下所有文件
|
|
void deleteDirectory(const QString &fullFileName);
|
|
|
|
/// \brief addNextDirectory
|
|
/// \param fullFileName
|
|
/// \param isDir 只读取文件夹
|
|
/// \param suffix 匹配文件格式
|
|
/// \return 遍历文件夹下一层文件
|
|
QStringList addNextDirectory(const QString &fullFileName,bool isDir=true,QString suffix="");
|
|
|
|
/// \brief addSubFolderDirectory
|
|
/// \param fullFileName
|
|
/// \param filters 匹配文件格式
|
|
/// \return 遍历文件夹所有匹配文件
|
|
QStringList addSubFolderDirectory(const QString &fullFileName,QStringList filters=QStringList()<<"*.jpeg"<<"*.jpg"<<"*.bmp"<<"*.png"<<"*.tiff");
|
|
|
|
/**
|
|
* @brief getAllFiles 遍历文件夹所有匹配文件
|
|
* @param path 遍历地址
|
|
* @param files string文件名容器
|
|
* @param format 匹配文件格式
|
|
*/
|
|
void getAllFiles(std::string path, std::vector<std::string>& files, std::string format);
|
|
|
|
/// <summary>
|
|
/// 加载Json
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
QJsonObject loadJsonCfg(const QString path);
|
|
|
|
QStringList ReadTextCfg(const QString path);
|
|
|
|
bool WriteTXTCfg(const QStringList& parm, const QString path);
|
|
|
|
// 编码格式检查
|
|
|
|
enum class EncodingFormat : int
|
|
{
|
|
ANSI = 0,//GBK
|
|
UTF16LE,
|
|
UTF16BE,
|
|
UTF8,
|
|
UTF8BOM,
|
|
};
|
|
|
|
/*!
|
|
* \brief 检查文件编码
|
|
*/
|
|
EncodingFormat FileCharacterEncoding(const QString& fileName);
|
|
|
|
//csv中文读取
|
|
QString gb2312ToUtf8(const QString strUtf8);
|
|
|
|
|
|
#endif // TOOLKIT_H
|