From 1a70ca007275581f06d0711eba3a2abfcd42bb25 Mon Sep 17 00:00:00 2001 From: gaozheng Date: Fri, 26 Jun 2026 12:07:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(3d):=20=E5=BC=82=E5=B8=B8=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=A1=86=E5=8A=A0=E6=A0=B7=E5=BC=8F=E9=A2=84=E8=A7=88?= =?UTF-8?q?(=E9=80=89=E4=B8=AD=E7=B1=BB=E5=9E=8B=20legend=20=E5=8F=AF?= =?UTF-8?q?=E8=A7=86=E5=8C=96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 应用户要求,在异常类型下拉下方加「样式」预览行:据选中类型的平台 legend 按形态画—— 点=实心色球 / 线=按线宽·虚实的线 / 面=描边矩形+淡填充。选类型变化或样式拉到后实时刷新; 未取到时显占位「—」。 构建:app 链接通过 --- src/app/AnomalySaveDialog.cpp | 43 ++++++++++++++++++++++++++++++++++- src/app/AnomalySaveDialog.hpp | 3 +++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/app/AnomalySaveDialog.cpp b/src/app/AnomalySaveDialog.cpp index fd10f34..3b68b16 100644 --- a/src/app/AnomalySaveDialog.cpp +++ b/src/app/AnomalySaveDialog.cpp @@ -8,9 +8,12 @@ #include #include #include +#include +#include #include #include #include +#include #include "FormKit.hpp" #include "Theme.hpp" @@ -40,7 +43,11 @@ AnomalySaveDialog::AnomalySaveDialog(const QString& screenshotPath, int shotW, i type_->setPlaceholderText(QStringLiteral("请选择异常类型")); // 空(如该形态平台无类型)时显灰占位+「暂无数据」 formkit::capField(type_); form->addRow(formkit::editLabel(QStringLiteral("异常类型")), type_); - // 选中类型变化 → 拉其平台样式(legend),使保存的异常按平台类型样式渲染。 + // 样式预览:选中类型的 legend 派生样式可视化(点=色球/线=线型/面=描边矩形)。 + stylePreview_ = new QLabel(QStringLiteral("—")); + stylePreview_->setMinimumWidth(geopro::app::scaledPx(92)); + form->addRow(formkit::editLabel(QStringLiteral("样式")), stylePreview_); + // 选中类型变化 → 拉其平台样式(legend),使保存的异常按平台类型样式渲染 + 刷新预览。 connect(type_, qOverload(&QComboBox::currentIndexChanged), this, [this](int) { loadStyleForCurrent(); }); loadTypes(cmdRepo, projectId, remarkSourceType); // 异步拉平台异常类型填充(与平台一致) @@ -102,9 +109,43 @@ void AnomalySaveDialog::loadStyleForCurrent() { self->styleDashed_ = lg.value(QStringLiteral("polylineShape")).toString().contains(QStringLiteral("dash")); } + self->updateStylePreview(); }); } +void AnomalySaveDialog::updateStylePreview() { + if (stylePreview_ == nullptr) return; + const QColor col(styleColor_); + if (!col.isValid()) { // 未取到样式 → 占位 + stylePreview_->setPixmap(QPixmap()); + stylePreview_->setText(QStringLiteral("—")); + return; + } + const int w = geopro::app::scaledPx(92), h = geopro::app::scaledPx(22); + QPixmap pm(w, h); + pm.fill(Qt::transparent); + QPainter p(&pm); + p.setRenderHint(QPainter::Antialiasing, true); + QPen pen(col); + pen.setWidthF(std::clamp(styleWidth_ > 0.0 ? styleWidth_ : 2.0, 1.0, 4.0)); + if (styleDashed_) pen.setStyle(Qt::DashLine); + if (remarkSourceType_ == 1) { // 点:实心色球 + p.setPen(Qt::NoPen); + p.setBrush(col); + p.drawEllipse(QPointF(w / 2.0, h / 2.0), h * 0.3, h * 0.3); + } else if (remarkSourceType_ == 2) { // 线:按线宽/虚实画线 + p.setPen(pen); + p.drawLine(QPointF(w * 0.1, h / 2.0), QPointF(w * 0.9, h / 2.0)); + } else { // 面:描边矩形 + 淡填充 + p.setPen(pen); + p.setBrush(QColor(col.red(), col.green(), col.blue(), 40)); + p.drawRect(QRectF(w * 0.12, h * 0.22, w * 0.76, h * 0.56)); + } + p.end(); + stylePreview_->setText(QString()); + stylePreview_->setPixmap(pm); +} + QString AnomalySaveDialog::anomalyName() const { const QString n = name_->text().trimmed(); return n.isEmpty() ? QStringLiteral("异常") : n; diff --git a/src/app/AnomalySaveDialog.hpp b/src/app/AnomalySaveDialog.hpp index c32d2ba..1e97c30 100644 --- a/src/app/AnomalySaveDialog.hpp +++ b/src/app/AnomalySaveDialog.hpp @@ -41,6 +41,8 @@ private: int remarkSourceType); // 拉当前选中类型的详情 legend → 按形态(点/线/面)派生 styleColor/Width/Dashed。 void loadStyleForCurrent(); + // 据当前样式按形态画预览(点=色球/线=线型/面=描边矩形),画到 stylePreview_。 + void updateStylePreview(); geopro::data::IDatasetCommandRepository* cmdRepo_ = nullptr; int remarkSourceType_ = 3; @@ -50,6 +52,7 @@ private: QLineEdit* name_ = nullptr; QComboBox* type_ = nullptr; + QLabel* stylePreview_ = nullptr; // 选中类型样式预览(色块/线型) QPlainTextEdit* remark_ = nullptr; };