Tag-Filter hinzugefügt
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
#include "tagpanel.h"
|
||||
#include <QHeaderView>
|
||||
#include <QRegularExpression>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
|
||||
TagPanel::TagPanel(const QString &tag, QWidget *parent)
|
||||
: QGroupBox(QStringLiteral("[%1]").arg(tag), parent)
|
||||
, m_tag(tag)
|
||||
{
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(6, 12, 6, 6);
|
||||
layout->setContentsMargins(6, 14, 6, 6);
|
||||
layout->setSpacing(4);
|
||||
|
||||
// Timestamp line
|
||||
m_timestampLabel = new QLabel(tr("No data yet"), this);
|
||||
m_timestampLabel->setStyleSheet("color: gray; font-size: 10px;");
|
||||
layout->addWidget(m_timestampLabel);
|
||||
|
||||
// Table for key=value pairs
|
||||
// ── Table for key=value pairs ─────────────────────────────────────────────
|
||||
m_table = new QTableWidget(0, 2, this);
|
||||
m_table->setHorizontalHeaderLabels({tr("Key"), tr("Value")});
|
||||
m_table->horizontalHeader()->setStretchLastSection(true);
|
||||
@@ -26,23 +23,28 @@ TagPanel::TagPanel(const QString &tag, QWidget *parent)
|
||||
m_table->verticalHeader()->setDefaultSectionSize(22);
|
||||
layout->addWidget(m_table);
|
||||
|
||||
// Fallback label for non-kv data
|
||||
// ── Fallback label for non-kv data ────────────────────────────────────────
|
||||
m_rawLabel = new QLabel(this);
|
||||
m_rawLabel->setWordWrap(true);
|
||||
m_rawLabel->setStyleSheet("font-family: monospace;");
|
||||
m_rawLabel->hide();
|
||||
layout->addWidget(m_rawLabel);
|
||||
|
||||
// ── Copy button ───────────────────────────────────────────────────────────
|
||||
auto *btnRow = new QHBoxLayout();
|
||||
btnRow->addStretch();
|
||||
auto *copyBtn = new QPushButton(tr("📋 Copy"), this);
|
||||
copyBtn->setToolTip(tr("Copy current tag values to clipboard"));
|
||||
copyBtn->setMaximumWidth(90);
|
||||
connect(copyBtn, &QPushButton::clicked, this, &TagPanel::copyToClipboard);
|
||||
btnRow->addWidget(copyBtn);
|
||||
layout->addLayout(btnRow);
|
||||
}
|
||||
|
||||
void TagPanel::update(const QString &value)
|
||||
{
|
||||
m_timestampLabel->setText(
|
||||
QDateTime::currentDateTime().toString("hh:mm:ss.zzz"));
|
||||
|
||||
// Detect key=value format: word=anything (space separated)
|
||||
static const QRegularExpression kvRe(R"((\w+)=(\S+))");
|
||||
auto it = kvRe.globalMatch(value);
|
||||
if (it.hasNext()) {
|
||||
if (kvRe.match(value).hasMatch()) {
|
||||
parseKeyValue(value);
|
||||
m_rawLabel->hide();
|
||||
m_table->show();
|
||||
@@ -59,13 +61,10 @@ void TagPanel::parseKeyValue(const QString &value)
|
||||
auto it = kvRe.globalMatch(value);
|
||||
while (it.hasNext()) {
|
||||
const auto match = it.next();
|
||||
const QString key = match.captured(1);
|
||||
const QString val = match.captured(2);
|
||||
ensureRow(key);
|
||||
const int row = m_keys.indexOf(key);
|
||||
m_table->item(row, 1)->setText(val);
|
||||
// Flash highlight
|
||||
m_table->item(row, 1)->setBackground(QColor(0x2d, 0x5a, 0x2d));
|
||||
ensureRow(match.captured(1));
|
||||
const int row = m_keys.indexOf(match.captured(1));
|
||||
m_table->item(row, 1)->setText(match.captured(2));
|
||||
m_table->item(row, 1)->setBackground(QColor(0x2d, 0x5a, 0x2d)); // flash green
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,3 +83,21 @@ void TagPanel::ensureRow(const QString &key)
|
||||
m_table->setItem(row, 0, new QTableWidgetItem(key));
|
||||
m_table->setItem(row, 1, new QTableWidgetItem(QString()));
|
||||
}
|
||||
|
||||
void TagPanel::copyToClipboard()
|
||||
{
|
||||
QStringList lines;
|
||||
lines << QStringLiteral("[%1]").arg(m_tag);
|
||||
|
||||
if (m_table->isVisible()) {
|
||||
for (int r = 0; r < m_table->rowCount(); ++r) {
|
||||
const QString key = m_table->item(r, 0)->text();
|
||||
const QString val = m_table->item(r, 1)->text();
|
||||
lines << QStringLiteral(" %1 = %2").arg(key, val);
|
||||
}
|
||||
} else {
|
||||
lines << QStringLiteral(" %1").arg(m_rawLabel->text());
|
||||
}
|
||||
|
||||
QApplication::clipboard()->setText(lines.join('\n'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user