This commit is contained in:
2025-10-28 11:23:22 +08:00
parent a3f955b180
commit 4fe5cff926
3 changed files with 16 additions and 131 deletions
+2 -2
View File
@@ -55,8 +55,8 @@ public:
std::vector<cv::Mat> oriImgs;//原图容器
std::vector<std::string> oriFormat;//原图格式 如果数量不一致直接全存bmp
//NAME_SAMPLE : "{imgSaveRootDir}/{yyyy-MM-dd}/{HH}H/{imageType}/{processResult}/{SN}/"
//PATH_SAMPLE {SN}_{cameraName}_{index}}
//PATH_SAMPLE : "{imgSaveRootDir}/{yyyy-MM-dd}/{HH}H/{imageType}/{processResult}/{SN}/"
//NAME_SAMPLE {SN}_{cameraName}_{index}}
QString customPath = "",customFileName = "";
std::vector<std::pair <QString, QString>>customImageSaveTemplateParams;
#pragma endregion
+2 -2
View File
@@ -130,8 +130,8 @@ public:
}
private:
QString defaultPath = "{imgSaveRootDir}/{yyyy-MM-dd}/{HH}H/{imageType}/{processResult}/{SN}/";
QString defaultFileName = "{SN}_{cameraName}_{index}.{format}";
QString defaultClsFileName = "{SN}_{cameraName}_{param1}_{index}.{format}";
QString defaultFileName = "{SN}_{cameraName}_{index}";
QString defaultClsFileName = "{SN}_{cameraName}_{param1}_{index}";
};
struct saveJob {
saveJob(std::string jobNameIn) :jobName(jobNameIn) {}
+12 -127
View File
@@ -139,41 +139,16 @@ public:
widgetLayout->setContentsMargins(0, 0, 0, 0);
widgetLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
// 第一行工具栏:过滤器
QHBoxLayout* toolHLayout = new QHBoxLayout();
widgetLayout->addLayout(toolHLayout);
QLabel* toolName = new QLabel(u8"日志级别:");
toolName->setFont(font2);
toolName->setPalette(palette);
toolHLayout->addWidget(toolName);
QStringList options = { "全部", "Debug", "Info", "Warning", "Error" };
QComboBox* filterSelector = new QComboBox();
filterSelector->addItems(options);
toolHLayout->addWidget(filterSelector);
QLabel* toolName2 = new QLabel(u8"正则匹配:");
toolName2->setFont(font2);
toolName2->setPalette(palette);
toolHLayout->addWidget(toolName2);
QLineEdit* lineedit = new QLineEdit();
lineedit->setPlaceholderText("输入正则表达式...");
toolHLayout->addWidget(lineedit);
// 第二行工具栏:功能按钮
QHBoxLayout* toolHLayout2 = new QHBoxLayout();
widgetLayout->addLayout(toolHLayout2);
QPushButton* saveBtn = new QPushButton("保存日志");
QPushButton* clearBtn = new QPushButton("清空");
QPushButton* openDirBtn = new QPushButton("打开日志文件夹");
QPushButton* autoScrollBtn = new QPushButton("自动滚动");
autoScrollBtn->setCheckable(true);
autoScrollBtn->setChecked(true);
saveBtn->setFixedSize(80, 25);
clearBtn->setFixedSize(60, 25);
openDirBtn->setFixedSize(120, 25);
autoScrollBtn->setFixedSize(80, 25);
// 设置按钮样式
@@ -197,36 +172,30 @@ public:
}
)";
saveBtn->setStyleSheet(buttonStyle);
clearBtn->setStyleSheet(buttonStyle);
openDirBtn->setStyleSheet(buttonStyle);
autoScrollBtn->setStyleSheet(buttonStyle);
toolHLayout2->addWidget(saveBtn);
toolHLayout2->addWidget(clearBtn);
toolHLayout2->addWidget(openDirBtn);
toolHLayout2->addWidget(autoScrollBtn);
toolHLayout2->addStretch();
// 存储过滤器状态
FilterState& state = filterStates[index];
state.levelFilter = filterSelector;
state.regexFilter = lineedit;
state.textWidget = textWidget;
state.autoScroll = true;
// 连接过滤器信号
connect(filterSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
[this, index]() { applyFilters(index); });
connect(lineedit, &QLineEdit::textChanged,
[this, index]() { applyFilters(index); });
// 连接功能按钮
connect(clearBtn, &QPushButton::clicked, [this, index]() { clearLog(index); });
connect(autoScrollBtn, &QPushButton::toggled, [this, index](bool checked) {
filterStates[index].autoScroll = checked;
});
connect(openDirBtn, &QPushButton::clicked,
[=]() {
QDesktopServices::openUrl(QUrl::fromLocalFile("./Log"));
});
widgetLayout->addWidget(textWidget);
}
QString getCurrentDate() {
@@ -240,8 +209,8 @@ public:
private:
// 用于存储过滤器状态
struct FilterState {
QComboBox* levelFilter;
QLineEdit* regexFilter;
//QComboBox* levelFilter;
//QLineEdit* regexFilter;
QPlainTextEdit* textWidget;
QStringList allMessages; // 存储所有原始消息
bool autoScroll = true;
@@ -281,72 +250,7 @@ private:
batchUpdateTimer->start();
}
}
// 判断消息是否应该显示
bool shouldShowMessage(const QString& message, const FilterState& state) {
QString levelFilter = state.levelFilter->currentText();
QString regexPattern = state.regexFilter->text();
// 级别过滤
if (levelFilter != "全部") {
if (!message.contains(levelFilter, Qt::CaseInsensitive)) {
return false;
}
}
// 正则过滤
if (!regexPattern.isEmpty()) {
QRegularExpression regex(regexPattern);
if (regex.isValid() && !regex.match(message).hasMatch()) {
return false;
}
}
return true;
}
// 应用过滤器
void applyFilters(int index) {
QMutexLocker globalLocker(&globalMutex);
if (filterStates.find(index) == filterStates.end()) return;
FilterState& state = filterStates[index];
QMutexLocker stateLocker(&state.mutex);
QString levelFilter = state.levelFilter->currentText();
QString regexPattern = state.regexFilter->text();
// 清空当前显示
state.textWidget->clear();
QRegularExpression regex;
bool regexValid = true;
if (!regexPattern.isEmpty()) {
regex.setPattern(regexPattern);
if (!regex.isValid()) {
state.textWidget->appendPlainText("正则表达式无效: " + regexPattern);
return;
}
}
// 过滤并显示消息
for (const QString& message : state.allMessages) {
if (shouldShowMessage(message, state)) {
// 根据日志级别设置颜色
appendColoredMessage(state.textWidget, message);
}
}
// 清空待处理消息,因为已经全部重新过滤了
state.pendingMessages.clear();
// 自动滚动到底部
if (state.autoScroll) {
scrollToBottom(state.textWidget);
}
}
// 添加带颜色的消息
QTextCharFormat whiteFormat;
QTextCharFormat redFormat;
@@ -377,23 +281,6 @@ private:
scrollBar->setValue(scrollBar->maximum());
}
// 清空日志
void clearLog(int index) {
QMutexLocker globalLocker(&globalMutex);
if (filterStates.find(index) == filterStates.end()) return;
auto reply = QMessageBox::question(this, "确认", "确定要清空当前日志吗?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
FilterState& state = filterStates[index];
QMutexLocker stateLocker(&state.mutex);
state.allMessages.clear();
state.pendingMessages.clear();
state.textWidget->clear();
}
}
public slots:
void recvStdLogMsg(QString logMsg) {
@@ -426,9 +313,7 @@ private slots:
if (index == currentIndex) {
// 增量添加消息而不是重新过滤所有消息
for (const QString& message : state.pendingMessages) {
if (shouldShowMessage(message, state)) {
appendColoredMessage(state.textWidget, message);
}
appendColoredMessage(state.textWidget, message);
}
// 自动滚动到底部