143 lines
3.9 KiB
C++
143 lines
3.9 KiB
C++
#ifndef VIEWMODELS_H
|
|
#define VIEWMODELS_H
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QDate>
|
|
|
|
#include <QSharedPointer>
|
|
#include "SysPara.h"
|
|
#include <QMap>
|
|
|
|
/**
|
|
* @brief 计数器类型
|
|
*
|
|
*/
|
|
enum COUNTER_TYPE {
|
|
COUNTER_TYPE_1 = 7,
|
|
COUNTER_TYPE_2 = 8,
|
|
};
|
|
|
|
/**
|
|
* @brief 计数器设置界面所用的视图模型
|
|
*
|
|
*/
|
|
struct CounterViewModel {
|
|
int counterType = 0; // 实际类型为 COUNTER_TYPE
|
|
int digitalNum = 0;
|
|
int letterSpace = 0;
|
|
int charWidth = 0; // 字符宽度,仅在 enbCustomCharWidth == true 时有意义
|
|
bool enbCustomCharWidth = false;
|
|
|
|
SysPara* m_sysPara = nullptr; // 计数器设置界面中还依赖此对象,所以先给它
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(CounterViewModel);
|
|
|
|
/**
|
|
* @brief 日期设置界面所用的视图模型
|
|
*
|
|
*/
|
|
struct DateItemModel {
|
|
QString datetimePattern;
|
|
int monthsOffset = 0;
|
|
int daysOffset = 0;
|
|
QStringList dataMap; // unused
|
|
QStringList daysMap;
|
|
QStringList monthsMap;
|
|
QMap<int, QString> yearsMap;
|
|
QStringList weeksMap;
|
|
QStringList hoursMap;
|
|
|
|
static DateItemModel createDefaultReplaceModel();
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(DateItemModel);
|
|
|
|
/**
|
|
* @brief 条码设置界面所用的视图模型
|
|
*
|
|
*/
|
|
class BarcodeViewModel : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
/**
|
|
* @brief 条形码内容模版 ,用于生成条形码
|
|
*
|
|
* @example "1234567890{t}{c}"
|
|
* @remark 条形码内容模版中可以包含计数器变量,例如 {t} 表示当前时间,{c} 表示当前计数器值
|
|
* @note 仅当条形码内容模版中包含日期变量或计数器变量时,属性 counterViewModel、dateViewModel 才会有意义
|
|
*/
|
|
Q_PROPERTY(QString contentPattern READ contentPattern WRITE setContentPattern NOTIFY contentPatternChanged)
|
|
|
|
/**
|
|
* @brief 计数器视图模型,用于填充条形码内容模版中的计数器变量
|
|
*
|
|
*/
|
|
Q_PROPERTY(CounterViewModel counterViewModel READ counterViewModel WRITE setCounterViewModel NOTIFY counterViewModelChanged)
|
|
|
|
/**
|
|
* @brief 日期视图模型,用于填充条形码内容模版中的日期变量
|
|
*
|
|
*/
|
|
Q_PROPERTY(DateItemModel dateViewModel READ dateViewModel WRITE setDateViewModel NOTIFY dateViewModelChanged)
|
|
|
|
public:
|
|
explicit BarcodeViewModel(QObject *parent = nullptr);
|
|
|
|
/**
|
|
* @brief 获取条形码内容模版
|
|
*
|
|
* @return QString
|
|
*/
|
|
QString contentPattern() const { return m_contentPattern; }
|
|
|
|
/**
|
|
* @brief 设置条形码内容模版
|
|
*
|
|
* @param contentPattern
|
|
*/
|
|
void setContentPattern(const QString& contentPattern);
|
|
|
|
/**
|
|
* @brief 获取用于合成条形码内容的所需的计数器视图模型
|
|
*
|
|
* @return CounterViewModel
|
|
*/
|
|
const CounterViewModel& counterViewModel() const { return m_counterViewModel; }
|
|
|
|
/**
|
|
* @brief 设置计数器视图模型
|
|
* @note 设置计数器视图模型后,总会触发 counterViewModelChanged 信号,因为该函数不负责检查计数器视图模型是否有更改
|
|
*
|
|
* @param counterViewModel
|
|
*/
|
|
void setCounterViewModel(CounterViewModel counterViewModel);
|
|
|
|
/**
|
|
* @brief 获取用于合成条形码内容的所需的日期视图模型
|
|
*
|
|
* @return DateItemModel
|
|
*/
|
|
const DateItemModel& dateViewModel() const { return m_dateViewModel; }
|
|
|
|
/**
|
|
* @brief 设置日期视图模型
|
|
* @note 设置日期视图模型后,总会触发 dateViewModelChanged 信号,因为该函数不负责检查日期视图模型是否有更改
|
|
*
|
|
* @param dateViewModel
|
|
*/
|
|
void setDateViewModel(DateItemModel dateViewModel);
|
|
|
|
signals:
|
|
void contentPatternChanged();
|
|
void counterViewModelChanged();
|
|
void dateViewModelChanged();
|
|
|
|
private:
|
|
QString m_contentPattern; // 条形码内容模版
|
|
CounterViewModel m_counterViewModel; // 计数器视图模型
|
|
DateItemModel m_dateViewModel; // 日期视图模型
|
|
};
|
|
|
|
#endif // VIEWMODELS_H
|