153 lines
4.1 KiB
C++
153 lines
4.1 KiB
C++
#include <QTextStream>
|
|
#include "readthread.h"
|
|
|
|
ReadThread::ReadThread(QObject *parent)
|
|
: QThread{parent} {
|
|
/*正则表达式*/
|
|
//时间
|
|
dateTimeRegex.setPattern("([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{3})");
|
|
//基带
|
|
jdRegex.setPattern(R"(\[.*(\d)\])");
|
|
//匹配数字和可选的正负号
|
|
pattern.setPattern("^[+-]?([1-9][0-9]*|0)[.]?[0-9]*$");
|
|
//科学计数法
|
|
kexue.setPattern("^[0-9].[0-9]e[+-][0-9][0-9]");
|
|
}
|
|
|
|
bool ReadThread::isNumeric(const QString& data) {
|
|
bool flag = false;
|
|
patternMatch = pattern.match(data);
|
|
if (patternMatch.hasMatch()) {
|
|
flag = true;
|
|
}
|
|
kexueMatch = kexue.match(data);
|
|
if (kexueMatch.hasMatch()) {
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
void ReadThread::run() {
|
|
//初始化数据
|
|
int bytesRead = 0; //进度条数值
|
|
for (auto &i: g_param) {
|
|
i.clear();
|
|
}
|
|
QMap<QString, QString> temData;
|
|
bool isBeginTime = true;
|
|
//清除下拉框数据
|
|
emit clearCombo();
|
|
if (!namelist.empty()) {
|
|
namelist.clear();
|
|
completer->deleteLater();
|
|
}
|
|
|
|
//设置状态栏
|
|
emit showStatusbar("正在打开文件");
|
|
|
|
//读取文件
|
|
QTextStream in(&file);
|
|
while (!in.atEnd()) {
|
|
//读取一行
|
|
QString line = in.readLine();
|
|
|
|
//更新进度条
|
|
bytesRead += line.size();
|
|
emit setProgressBar(bytesRead * 2);
|
|
|
|
/* 匹配数据 */
|
|
//匹配日期时间
|
|
QMap<QString, QString> temMap;
|
|
int JD;
|
|
QString temtime;
|
|
matchDateTime = dateTimeRegex.match(line);
|
|
if (matchDateTime.hasMatch()) {
|
|
temtime = matchDateTime.captured(1);
|
|
temMap["时间"] = temtime;
|
|
} else {
|
|
continue;
|
|
}
|
|
// //匹配基带
|
|
// QString temjd;
|
|
// matchLogLevel = jdRegex.match(line);//正则表达式匹配
|
|
// if (matchLogLevel.hasMatch()) {//是否匹配
|
|
// temjd = matchLogLevel.captured(1);//匹配之后取第一个匹配的值
|
|
// temMap["基带"] = temjd;
|
|
// JD = temjd.toInt() - 1;
|
|
// } else {
|
|
// continue;
|
|
// }
|
|
|
|
//匹配基带
|
|
if (line.contains("基带 1")){
|
|
temMap["基带"] = "1";
|
|
JD = 0;
|
|
}else if(line.contains("基带 2")){
|
|
temMap["基带"] = "2";
|
|
JD = 1;
|
|
}else if(line.contains("基带 3")){
|
|
temMap["基带"] = "3";
|
|
JD = 2;
|
|
}else if(line.contains("基带 4")){
|
|
temMap["基带"] = "4";
|
|
JD = 3;
|
|
}else if(line.contains("其他单元")){
|
|
temMap["基带"] = "5";
|
|
JD = 4;
|
|
}else {
|
|
continue;
|
|
}
|
|
|
|
//获取开始时间
|
|
if (isBeginTime) {
|
|
beginTime = QDateTime::fromString(temtime, "yyyy-MM-dd hh:mm:ss:zzz");
|
|
isBeginTime = false;
|
|
}
|
|
temData.clear();
|
|
temData["时间"] = temtime;
|
|
//将左右拆分
|
|
QStringList dataParts = line.split(']');
|
|
//判断右侧是否有数据
|
|
if (dataParts[1].isEmpty()) {
|
|
continue;
|
|
}
|
|
//将右侧数据拆分
|
|
QStringList data = dataParts[1].split(',');
|
|
for (int i = 0; i < data.size(); i++) {
|
|
//将每一条数据拆为数据名和值
|
|
QStringList tem = data[i].split('=');
|
|
if (tem.size() < 2) {
|
|
continue;
|
|
}
|
|
if (!namelist.contains(tem[0])) {
|
|
namelist[tem[0]] = isNumeric(tem[1]);
|
|
if (tem[0].contains("版本号")) {
|
|
namelist[tem[0]] = false;
|
|
}
|
|
}
|
|
temData[tem[0]] = tem[1];
|
|
}
|
|
//记录数据
|
|
g_param[JD].append(temData);
|
|
|
|
}
|
|
//获取结束时间
|
|
endTime = QDateTime::fromString(temData["时间"], "yyyy-MM-dd hh:mm:ss:zzz");
|
|
|
|
//设置时间
|
|
emit setTime();
|
|
|
|
//设置状态栏
|
|
emit showStatusbar("打开成功:" + file.fileName());
|
|
|
|
//添加下拉框数据
|
|
emit addCombo(namelist.keys());
|
|
|
|
//关闭
|
|
emit closeProg();
|
|
file.close();
|
|
temData.clear();
|
|
quit();
|
|
}
|
|
|