-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataprocessor.h
More file actions
154 lines (135 loc) · 3.91 KB
/
Copy pathdataprocessor.h
File metadata and controls
154 lines (135 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef DATAPROCESSOR_H
#define DATAPROCESSOR_H
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QDateTime>
#include "appsettings.h"
/**
* @brief DataProcessor - 数据处理器
*
* 负责将原始字节数据转换为可显示格式(ASCII 或 Hexadecimal)。
* 支持时间戳格式化功能。
*
* Requirements: 3.1, 3.2, 3.3
*/
class DataProcessor : public QObject
{
Q_OBJECT
public:
/**
* @brief 数据显示格式
*/
enum Format {
ASCII, ///< ASCII 文本格式
Hexadecimal ///< 十六进制格式
};
Q_ENUM(Format)
/**
* @brief 构造函数
* @param parent 父对象
*/
explicit DataProcessor(QObject *parent = nullptr);
/**
* @brief 设置数据显示格式
* @param format 显示格式(ASCII 或 Hexadecimal)
* Requirements: 3.1
*/
void setFormat(Format format);
/**
* @brief 获取当前数据显示格式
* @return 当前格式
*/
Format format() const;
/**
* @brief 设置是否启用时间戳
* @param enabled true 启用时间戳,false 禁用
* Requirements: 3.2
*/
void setTimestampEnabled(bool enabled);
/**
* @brief 设置文本编码方式
* @param encoding 编码方式(ANSI, UTF8, GBK)
* Requirements: 1.2
*/
void setEncoding(AppSettings::Encoding encoding);
/**
* @brief 获取当前文本编码方式
* @return 当前编码方式
*/
AppSettings::Encoding encoding() const;
/**
* @brief 设置十六进制显示模式下是否启用换行
* @param enabled true 启用换行(0A/0D 触发换行),false 禁用
* Requirements: 2.2, 2.3
*/
void setHexNewlineEnabled(bool enabled);
/**
* @brief 检查十六进制换行是否启用
* @return true 如果十六进制换行已启用
*/
bool isHexNewlineEnabled() const;
/**
* @brief 检查时间戳是否启用
* @return true 如果时间戳已启用
*/
bool isTimestampEnabled() const;
public slots:
/**
* @brief 处理原始数据
*
* 将原始字节数据转换为指定格式的字符串。
* 如果启用时间戳,将在数据前添加时间戳。
* 处理完成后发出 dataProcessed 信号。
*
* @param data 原始字节数据
* Requirements: 3.1, 3.2, 3.3
*/
void process(const QByteArray &data);
signals:
/**
* @brief 数据处理完成信号
*
* 当数据转换完成时发出,携带处理后的字符串。
* Requirements: 3.3
*
* @param text 处理后的可显示字符串
*/
void dataProcessed(const QString &text);
private:
/**
* @brief 将字节数组转换为十六进制字符串
*
* 输出格式:大写十六进制,每字节用空格分隔。
* 例如:{0x48, 0x65} -> "48 65"
*
* @param data 原始字节数据
* @return 十六进制字符串
* Requirements: 3.1
*/
QString toHexString(const QByteArray &data) const;
/**
* @brief 将字节数组转换为 ASCII 字符串
*
* 保留可打印字符,不可打印字符保持原样(由 QString::fromLatin1 处理)。
*
* @param data 原始字节数据
* @return ASCII 字符串
* Requirements: 3.1
*/
QString toAsciiString(const QByteArray &data) const;
/**
* @brief 格式化当前时间戳
*
* 格式:HH:mm:ss.zzz
*
* @return 格式化的时间戳字符串
* Requirements: 3.2
*/
QString formatTimestamp() const;
Format m_format = ASCII; ///< 当前显示格式
bool m_timestampEnabled = false; ///< 时间戳启用状态
AppSettings::Encoding m_encoding = AppSettings::ANSI; ///< 文本编码方式
bool m_hexNewlineEnabled = true; ///< 十六进制换行启用状态 (Requirements: 2.2, 2.3)
};
#endif // DATAPROCESSOR_H