Tag-Filter hinzugefügt

This commit is contained in:
2026-06-09 09:04:59 +02:00
parent cc102c93eb
commit 2181f254d2
40 changed files with 4161 additions and 74 deletions

View File

@@ -5,6 +5,11 @@
#include <QFont>
#include <QPalette>
#include <QApplication>
#include <QClipboard>
#include <QDateTime>
const QRegularExpression RawView::s_tagRe(
R"(\[([A-Z][A-Z0-9_]*)\])", QRegularExpression::CaseInsensitiveOption);
RawView::RawView(QWidget *parent)
: QWidget(parent)
@@ -15,7 +20,7 @@ RawView::RawView(QWidget *parent)
void RawView::setupUi()
{
auto *mainLayout = new QVBoxLayout(this);
auto *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(4, 4, 4, 4);
mainLayout->setSpacing(4);
@@ -23,7 +28,7 @@ void RawView::setupUi()
auto *toolbar = new QHBoxLayout();
m_searchEdit = new QLineEdit(this);
m_searchEdit->setPlaceholderText(tr("Search… (Enter)"));
m_searchEdit->setPlaceholderText(tr("Search…"));
m_searchEdit->setClearButtonEnabled(true);
connect(m_searchEdit, &QLineEdit::textChanged, this, &RawView::onSearch);
@@ -31,33 +36,35 @@ void RawView::setupUi()
m_autoScrollCb->setChecked(true);
connect(m_autoScrollCb, &QCheckBox::toggled, this, &RawView::onAutoScrollToggled);
m_clearBtn = new QPushButton(tr("Clear"), this);
connect(m_clearBtn, &QPushButton::clicked, this, &RawView::clear);
m_lineCountLbl = new QLabel(tr("Lines: 0"), this);
m_lineCountLbl->setMinimumWidth(90);
m_copyBtn = new QPushButton(tr("📋 Copy"), this);
m_copyBtn->setToolTip(tr("Copy all raw output to clipboard"));
connect(m_copyBtn, &QPushButton::clicked, this, &RawView::copyToClipboard);
m_clearBtn = new QPushButton(tr("Clear"), this);
connect(m_clearBtn, &QPushButton::clicked, this, &RawView::clear);
toolbar->addWidget(new QLabel(tr("Search:"), this));
toolbar->addWidget(m_searchEdit, 1);
toolbar->addWidget(m_autoScrollCb);
toolbar->addWidget(m_lineCountLbl);
toolbar->addWidget(m_copyBtn);
toolbar->addWidget(m_clearBtn);
mainLayout->addLayout(toolbar);
// ── Text area ────────────────────────────────────────────────────────────
// ── Text area ────────────────────────────────────────────────────────────
m_textEdit = new QPlainTextEdit(this);
m_textEdit->setReadOnly(true);
m_textEdit->setLineWrapMode(QPlainTextEdit::NoWrap); // horizontal scroll
// Practically unlimited history (Qt uses a block count limit internally)
m_textEdit->setMaximumBlockCount(0); // 0 = unlimited
m_textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
m_textEdit->setMaximumBlockCount(0); // unlimited
// Monospaced font for alignment
QFont monoFont("Monospace");
monoFont.setStyleHint(QFont::Monospace);
monoFont.setPointSize(10);
m_textEdit->setFont(monoFont);
// Don't let the text edit swallow horizontal scroll events from the viewport
m_textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
@@ -69,31 +76,48 @@ void RawView::setupUi()
void RawView::applyColorScheme()
{
// Dark terminal style
QPalette p = m_textEdit->palette();
p.setColor(QPalette::Base, QColor(0x1e, 0x1e, 0x1e));
p.setColor(QPalette::Text, QColor(0xd4, 0xd4, 0xd4));
p.setColor(QPalette::Base, QColor(0x1e, 0x1e, 0x1e));
p.setColor(QPalette::Text, QColor(0xd4, 0xd4, 0xd4));
m_textEdit->setPalette(p);
}
void RawView::appendLine(const QString &line)
void RawView::appendLine(const QString &line, const QSet<QString> &suppressedTags)
{
// Check whether this line belongs to a suppressed tag
if (!suppressedTags.isEmpty()) {
const auto match = s_tagRe.match(line);
if (match.hasMatch()) {
if (suppressedTags.contains(match.captured(1).toUpper()))
return; // silently drop it goes to the Tag Monitor only
}
}
++m_lineCount;
m_lineCountLbl->setText(tr("Lines: %1").arg(m_lineCount));
// Highlight lines that contain a tag like [WDG]
static const QRegularExpression tagRe(R"(\[[A-Z][A-Z0-9_]*\])",
QRegularExpression::CaseInsensitiveOption);
if (tagRe.match(line).hasMatch()) {
// Append as HTML so we can colour it differently
QTextCursor cursor(m_textEdit->document());
cursor.movePosition(QTextCursor::End);
QTextCharFormat fmt;
fmt.setForeground(QColor(0x56, 0xb6, 0xc2)); // cyan-ish
cursor.insertText(line + '\n', fmt);
} else {
m_textEdit->appendPlainText(line);
}
// Prepend timestamp
const QString ts = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
const QString displayLine = QStringLiteral("[%1] %2").arg(ts, line);
// Colour tag lines cyan, everything else default
const bool hasTag = s_tagRe.match(line).hasMatch();
QTextCursor cursor(m_textEdit->document());
cursor.movePosition(QTextCursor::End);
QTextCharFormat fmt;
if (hasTag)
fmt.setForeground(QColor(0x56, 0xb6, 0xc2)); // cyan
else
fmt.setForeground(QColor(0xd4, 0xd4, 0xd4)); // default
// Dim the timestamp portion
QTextCharFormat tsFmt;
tsFmt.setForeground(QColor(0x60, 0x60, 0x60));
cursor.insertText(QStringLiteral("[%1] ").arg(ts), tsFmt);
cursor.insertText(line + '\n', fmt);
if (m_autoScroll)
m_textEdit->verticalScrollBar()->setValue(
@@ -107,9 +131,13 @@ void RawView::clear()
m_lineCountLbl->setText(tr("Lines: 0"));
}
void RawView::copyToClipboard()
{
QApplication::clipboard()->setText(m_textEdit->toPlainText());
}
void RawView::onSearch(const QString &text)
{
// Simple incremental search highlight first match
QTextDocument *doc = m_textEdit->document();
QTextCursor cursor = doc->find(text);
if (!cursor.isNull()) {
@@ -124,9 +152,7 @@ void RawView::onSearch(const QString &text)
void RawView::onScrollValueChanged(int value)
{
const int max = m_textEdit->verticalScrollBar()->maximum();
// If user scrolled away from bottom, disable auto-scroll
if (value < max - 5) {
if (value < m_textEdit->verticalScrollBar()->maximum() - 5) {
m_autoScroll = false;
m_autoScrollCb->setChecked(false);
}