2026年5月23日暂存
This commit is contained in:
+39
-9
@@ -6,6 +6,7 @@
|
||||
#include "BarCode/barcode.h"
|
||||
#include <QPainter>
|
||||
#include <cstring>
|
||||
#include <QDebug>
|
||||
|
||||
/**
|
||||
* @brief 将libqrencode的QRcode结构渲染成QImage
|
||||
@@ -308,10 +309,15 @@ static QImage generateBarCodeImage(const QString &content, int barCodeType)
|
||||
return generateBarCodeImage(content, vm);
|
||||
}
|
||||
|
||||
QString generateTxtFromDateItemModel(const DateItemModel &model, const QDateTime &time)
|
||||
QString ItemUtils::generateTxtFromDateItemModel(const DateItemModel &model, const QDateTime &time)
|
||||
{
|
||||
QString result = model.datetimePattern;
|
||||
|
||||
|
||||
if (!time.isValid()) {
|
||||
qWarning() << "generateTxtFromDateItemModel: invalid QDateTime passed";
|
||||
return result;
|
||||
}
|
||||
|
||||
// 应用偏移量
|
||||
QDateTime applyDateTime = time;
|
||||
if(model.monthsOffset != 0) {
|
||||
@@ -341,19 +347,37 @@ QString generateTxtFromDateItemModel(const DateItemModel &model, const QDateTime
|
||||
// 匹配两位数月份 MM
|
||||
i = result.indexOf("MM");
|
||||
if(i != -1) {
|
||||
result.replace(i, 2, model.monthsMap[applyDateTime.date().month() - 1]);
|
||||
int monthIdx = applyDateTime.date().month() - 1;
|
||||
if (monthIdx >= 0 && monthIdx < model.monthsMap.size()) {
|
||||
result.replace(i, 2, model.monthsMap[monthIdx]);
|
||||
} else {
|
||||
qWarning() << "generateTxtFromDateItemModel: monthsMap index out of range:" << monthIdx;
|
||||
result.replace(i, 2, QString::number(applyDateTime.date().month()).rightJustified(2, '0'));
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配两位数日期 dd
|
||||
i = result.indexOf("dd");
|
||||
if(i != -1) {
|
||||
result.replace(i, 2, model.daysMap[applyDateTime.date().day() - 1]);
|
||||
int dayIdx = applyDateTime.date().day() - 1;
|
||||
if (dayIdx >= 0 && dayIdx < model.daysMap.size()) {
|
||||
result.replace(i, 2, model.daysMap[dayIdx]);
|
||||
} else {
|
||||
qWarning() << "generateTxtFromDateItemModel: daysMap index out of range:" << dayIdx;
|
||||
result.replace(i, 2, QString::number(applyDateTime.date().day()).rightJustified(2, '0'));
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配两位数小时 HH
|
||||
i = result.indexOf("HH");
|
||||
if(i != -1) {
|
||||
result.replace(i, 2, model.hoursMap[applyDateTime.time().hour()]);
|
||||
int hourIdx = applyDateTime.time().hour();
|
||||
if (hourIdx >= 0 && hourIdx < model.hoursMap.size()) {
|
||||
result.replace(i, 2, model.hoursMap[hourIdx]);
|
||||
} else {
|
||||
qWarning() << "generateTxtFromDateItemModel: hoursMap index out of range:" << hourIdx;
|
||||
result.replace(i, 2, QString::number(applyDateTime.time().hour()).rightJustified(2, '0'));
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配两位数分钟 mm
|
||||
@@ -373,7 +397,13 @@ QString generateTxtFromDateItemModel(const DateItemModel &model, const QDateTime
|
||||
// 格式化周几 w
|
||||
i = result.indexOf("w");
|
||||
if (i != -1) {
|
||||
result.replace(i, 1, model.weeksMap[applyDateTime.date().dayOfWeek() - 1]);
|
||||
int weekIdx = applyDateTime.date().dayOfWeek() - 1;
|
||||
if (weekIdx >= 0 && weekIdx < model.weeksMap.size()) {
|
||||
result.replace(i, 1, model.weeksMap[weekIdx]);
|
||||
} else {
|
||||
qWarning() << "generateTxtFromDateItemModel: weeksMap index out of range:" << weekIdx;
|
||||
result.replace(i, 1, QString::number(applyDateTime.date().dayOfWeek()));
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化年中周数 c
|
||||
@@ -386,7 +416,7 @@ QString generateTxtFromDateItemModel(const DateItemModel &model, const QDateTime
|
||||
}
|
||||
|
||||
|
||||
QString generateTxtFromBarcodeViewModel(const BarcodeViewModel &vm, const std::array<int, 2> counterValues, const QDateTime &time)
|
||||
QString ItemUtils::generateTxtFromBarcodeViewModel(const BarcodeViewModel &vm, const std::array<int, 2> counterValues, const QDateTime &time)
|
||||
{
|
||||
QString txt = vm.contentPattern;
|
||||
auto pos = vm.contentPattern.indexOf("{t}");
|
||||
@@ -424,7 +454,7 @@ QString generateTxtFromBarcodeViewModel(const BarcodeViewModel &vm, const std::a
|
||||
* - BARCODE_TYPE_BARCODE: DlgBarcodeFormatVM(完整配置)或 int(条形码类型索引,使用默认值)
|
||||
* @return QImage 生成的图像;失败返回空QImage
|
||||
*/
|
||||
QImage generateBarcodeImage(const QString &content, BarcodeType type, const QVariant &format)
|
||||
QImage ItemUtils::generateBarcodeImage(const QString &content, BarcodeType type, const QVariant &format)
|
||||
{
|
||||
if (content.isEmpty()) {
|
||||
return QImage();
|
||||
@@ -516,7 +546,7 @@ end:
|
||||
return img.copy(clipRect);
|
||||
}
|
||||
|
||||
QImage txtToImage(const QString &txt, const QFont &font, const QColor &fgColor, const QColor &bgColor)
|
||||
QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor &fgColor, const QColor &bgColor)
|
||||
{
|
||||
if (txt.isEmpty()) {
|
||||
return QImage();
|
||||
|
||||
Reference in New Issue
Block a user