2026年5月23日暂存
This commit is contained in:
+63
-60
@@ -9,68 +9,71 @@
|
||||
#include <array>
|
||||
#include <QImage>
|
||||
|
||||
/**
|
||||
* @brief 根据日期视图模型和时间生成字符串
|
||||
* @param model 包含日期格式模版和相关配置的视图模型
|
||||
* @param time 用于生成字符串的时间
|
||||
* @return QString 生成的字符串
|
||||
* @remark
|
||||
* 该函数根据 model.datetimePattern 中的格式模版生成字符串,支持以下格式:
|
||||
* - yyyy: 四位数年份,支持替换为自定义字符串(通过 model.yearsMap)
|
||||
* - YY: 两位数年份
|
||||
* - MM: 两位数月份,支持替换为自定义字符串(通过 model.monthsMap)
|
||||
* - dd: 两位数日期,支持替换为自定义字符串(通过 model.daysMap)
|
||||
* - HH: 两位数小时,支持替换为自定义字符串(通过 model.hoursMap)
|
||||
* - mm: 两位数分钟
|
||||
* - ss: 两位数秒钟
|
||||
* - w: 星期几,支持替换为自定义字符串(通过 model.weeksMap)
|
||||
* - c: 年中周数
|
||||
*/
|
||||
QString generateTxtFromDateItemModel(const DateItemModel& model, const QDateTime& time);
|
||||
|
||||
/**
|
||||
* @brief 根据条形码视图模型的内容模版生成字符串,
|
||||
* 生成的字符串可用于创建条形码或二维码
|
||||
*
|
||||
* @example
|
||||
* input: "ABC_{c}_{t}"
|
||||
* output: "ABC_1230_2026/04/30"
|
||||
*
|
||||
* @remark
|
||||
* 函数根据vm中的 contentPattern 是否存在变量模版,如果存在计数器变量,则使用 counterViewModel 格式化,同理也处理时间变量。
|
||||
*
|
||||
* @param vm 包含格式化所需的内容模版及相关配置
|
||||
* @param counterValues 所有计数器的当前值,counterValues[0] 为计数器1的当前值,counterValues[1]为计数器2的当前值......
|
||||
* @param time 要用于格式化的时间,通常是当前时间
|
||||
* @return QString 格式化后的字符串
|
||||
*
|
||||
*/
|
||||
QString generateTxtFromBarcodeViewModel(const BarcodeViewModel& vm, const std::array<int, 2> counterValues, const QDateTime& time);
|
||||
namespace ItemUtils
|
||||
{
|
||||
/**
|
||||
* @brief 根据日期视图模型和时间生成字符串
|
||||
* @param model 包含日期格式模版和相关配置的视图模型
|
||||
* @param time 用于生成字符串的时间
|
||||
* @return QString 生成的字符串
|
||||
* @remark
|
||||
* 该函数根据 model.datetimePattern 中的格式模版生成字符串,支持以下格式:
|
||||
* - yyyy: 四位数年份,支持替换为自定义字符串(通过 model.yearsMap)
|
||||
* - YY: 两位数年份
|
||||
* - MM: 两位数月份,支持替换为自定义字符串(通过 model.monthsMap)
|
||||
* - dd: 两位数日期,支持替换为自定义字符串(通过 model.daysMap)
|
||||
* - HH: 两位数小时,支持替换为自定义字符串(通过 model.hoursMap)
|
||||
* - mm: 两位数分钟
|
||||
* - ss: 两位数秒钟
|
||||
* - w: 星期几,支持替换为自定义字符串(通过 model.weeksMap)
|
||||
* - c: 年中周数
|
||||
*/
|
||||
QString generateTxtFromDateItemModel(const DateItemModel& model, const QDateTime& time);
|
||||
|
||||
/**
|
||||
* @brief 根据条形码类型和内容生成条形码或二维码图像
|
||||
* @param content 已格式化的文本内容
|
||||
* @param type 条码类型
|
||||
* @param format 配置参数
|
||||
* @return QImage 生成的图像;如果失败返回空图像
|
||||
* @note
|
||||
* format 参数类型:
|
||||
* - BARCODE_TYPE_QRCODE: DlgQrcodeFormatVM 或 int
|
||||
* - BARCODE_TYPE_BARCODE: DlgBarcodeFormatVM 或 int
|
||||
* 如果 format 是 int 类型, 对于 QR Code,0 表示 Data Matrix,1 表示 QR Code;对于条形码,int 值对应 DlgBarcodeFormatVM 中 type 的索引。
|
||||
* 如果 format 是 int 类型,则使用默认配置并根据 int 值选择二维码或条形码的子类型;如果 format 是对应的 VM 类型,则使用其中的详细配置。
|
||||
*/
|
||||
QImage generateBarcodeImage(const QString& content, BarcodeType type, const QVariant& format);
|
||||
/**
|
||||
* @brief 根据条形码视图模型的内容模版生成字符串,
|
||||
* 生成的字符串可用于创建条形码或二维码
|
||||
*
|
||||
* @example
|
||||
* input: "ABC_{c}_{t}"
|
||||
* output: "ABC_1230_2026/04/30"
|
||||
*
|
||||
* @remark
|
||||
* 函数根据vm中的 contentPattern 是否存在变量模版,如果存在计数器变量,则使用 counterViewModel 格式化,同理也处理时间变量。
|
||||
*
|
||||
* @param vm 包含格式化所需的内容模版及相关配置
|
||||
* @param counterValues 所有计数器的当前值,counterValues[0] 为计数器1的当前值,counterValues[1]为计数器2的当前值......
|
||||
* @param time 要用于格式化的时间,通常是当前时间
|
||||
* @return QString 格式化后的字符串
|
||||
*
|
||||
*/
|
||||
QString generateTxtFromBarcodeViewModel(const BarcodeViewModel& vm, const std::array<int, 2> counterValues, const QDateTime& time);
|
||||
|
||||
/**
|
||||
* @brief 将文本转换为图像
|
||||
* @param txt 要转换的文本
|
||||
* @param font 文本使用的字体
|
||||
* @param fgColor 文本颜色,默认为黑色
|
||||
* @param bgColor 背景颜色,默认为白色
|
||||
* @return QImage 转换后的图像
|
||||
* @note 返回的字符串图像会裁剪至最小边界以节省空间。例如字符串"aaa"的高度会比"bbbjjj"小,因为前者没有上下行部分。
|
||||
*/
|
||||
QImage txtToImage(const QString& txt, const QFont& font, const QColor& fgColor = Qt::black, const QColor& bgColor = Qt::white);
|
||||
/**
|
||||
* @brief 根据条形码类型和内容生成条形码或二维码图像
|
||||
* @param content 已格式化的文本内容
|
||||
* @param type 条码类型
|
||||
* @param format 配置参数
|
||||
* @return QImage 生成的图像;如果失败返回空图像
|
||||
* @note
|
||||
* format 参数类型:
|
||||
* - BARCODE_TYPE_QRCODE: DlgQrcodeFormatVM 或 int
|
||||
* - BARCODE_TYPE_BARCODE: DlgBarcodeFormatVM 或 int
|
||||
* 如果 format 是 int 类型, 对于 QR Code,0 表示 Data Matrix,1 表示 QR Code;对于条形码,int 值对应 DlgBarcodeFormatVM 中 type 的索引。
|
||||
* 如果 format 是 int 类型,则使用默认配置并根据 int 值选择二维码或条形码的子类型;如果 format 是对应的 VM 类型,则使用其中的详细配置。
|
||||
*/
|
||||
QImage generateBarcodeImage(const QString& content, BarcodeType type, const QVariant& format);
|
||||
|
||||
/**
|
||||
* @brief 将文本转换为图像
|
||||
* @param txt 要转换的文本
|
||||
* @param font 文本使用的字体
|
||||
* @param fgColor 文本颜色,默认为黑色
|
||||
* @param bgColor 背景颜色,默认为白色
|
||||
* @return QImage 转换后的图像
|
||||
* @note 返回的字符串图像会裁剪至最小边界以节省空间。例如字符串"aaa"的高度会比"bbbjjj"小,因为前者没有上下行部分。
|
||||
*/
|
||||
QImage txtToImage(const QString& txt, const QFont& font, const QColor& fgColor = Qt::black, const QColor& bgColor = Qt::white);
|
||||
}
|
||||
#endif // _ITEM_COMMON_H_
|
||||
|
||||
Reference in New Issue
Block a user