geopro/src/app/panels/AnomalyTablePanel.cpp

73 lines
3.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "panels/AnomalyTablePanel.hpp"
#include <QHBoxLayout>
#include <QHeaderView>
#include <QMessageBox>
#include <QTableWidget>
#include <QToolButton>
#include <QVBoxLayout>
namespace geopro::app {
static QString markName(int t) {
return t == 1 ? "" : t == 3 ? "多边形" : t == 4 ? "文字" : "多段线";
}
AnomalyTablePanel::AnomalyTablePanel(QWidget* parent) : QWidget(parent) {
auto* lay = new QVBoxLayout(this); lay->setContentsMargins(0, 0, 0, 0);
table_ = new QTableWidget(this);
table_->setColumnCount(6);
table_->setHorizontalHeaderLabels({"名称", "异常类型", "几何类型", "创建时间", "备注", "操作"});
table_->horizontalHeader()->setStretchLastSection(true);
table_->setEditTriggers(QAbstractItemView::NoEditTriggers);
lay->addWidget(table_);
}
void AnomalyTablePanel::setAnomalies(const std::vector<geopro::core::Anomaly>& list,
const std::vector<QString>& createTimes,
const std::vector<QString>& remarks) {
hidden_.clear();
table_->setRowCount(static_cast<int>(list.size()));
for (int i = 0; i < static_cast<int>(list.size()); ++i) {
const auto& a = list[i];
// 创建时间/备注:优先用形参(兼容),否则回退 Anomaly 字段DTO 已解析)。
const QString ct = i < (int)createTimes.size() && !createTimes[i].isEmpty()
? createTimes[i] : QString::fromStdString(a.createTime);
const QString rm = i < (int)remarks.size() && !remarks[i].isEmpty()
? remarks[i] : QString::fromStdString(a.remark);
table_->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(a.name)));
table_->setItem(i, 1, new QTableWidgetItem(QString::fromStdString(a.typeName)));
table_->setItem(i, 2, new QTableWidgetItem(markName(static_cast<int>(a.markType))));
table_->setItem(i, 3, new QTableWidgetItem(ct));
table_->setItem(i, 4, new QTableWidgetItem(rm));
// 操作列:定位 / 详情 / 删除(对照原版 contourPage 操作列),保留眼睛显隐。
auto* ops = new QWidget(table_);
auto* opLay = new QHBoxLayout(ops);
opLay->setContentsMargins(2, 0, 2, 0);
opLay->setSpacing(2);
auto* eye = new QToolButton(ops); eye->setCheckable(true); eye->setChecked(true);
eye->setText("👁"); eye->setToolTip(QStringLiteral("显示/隐藏"));
connect(eye, &QToolButton::toggled, this, [this, i](bool on) {
if (on) hidden_.erase(i); else hidden_.insert(i);
emit hiddenChanged(hidden_);
});
auto* btnLocate = new QToolButton(ops); btnLocate->setText(QStringLiteral("定位"));
connect(btnLocate, &QToolButton::clicked, this, [this, i]() { emit locateRequested(i); });
auto* btnDetail = new QToolButton(ops); btnDetail->setText(QStringLiteral("详情"));
connect(btnDetail, &QToolButton::clicked, this, [this, i]() { emit detailRequested(i); });
auto* btnDelete = new QToolButton(ops); btnDelete->setText(QStringLiteral("删除"));
connect(btnDelete, &QToolButton::clicked, this, [this, i]() {
// 原版 a-popconfirm 二次确认contourContentDelete→ 这里用 QMessageBox文案对齐原版。
if (QMessageBox::question(this, QStringLiteral("提示"),
QStringLiteral("该操作会删除该异常标注数据,确认?")) ==
QMessageBox::Yes)
emit deleteRequested(i);
});
opLay->addWidget(eye);
opLay->addWidget(btnLocate);
opLay->addWidget(btnDetail);
opLay->addWidget(btnDelete);
opLay->addStretch();
table_->setCellWidget(i, 5, ops);
}
}
} // namespace geopro::app