feat(3d): 异常对话框加样式预览(选中类型 legend 可视化)

应用户要求,在异常类型下拉下方加「样式」预览行:据选中类型的平台 legend 按形态画——
点=实心色球 / 线=按线宽·虚实的线 / 面=描边矩形+淡填充。选类型变化或样式拉到后实时刷新;
未取到时显占位「—」。

构建:app 链接通过
This commit is contained in:
gaozheng 2026-06-26 12:07:11 +08:00
parent 4ae8286bb0
commit 1a70ca0072
2 changed files with 45 additions and 1 deletions

View File

@ -8,9 +8,12 @@
#include <QJsonObject> #include <QJsonObject>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QPainter>
#include <QPen>
#include <QPixmap> #include <QPixmap>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QPointer> #include <QPointer>
#include <algorithm>
#include "FormKit.hpp" #include "FormKit.hpp"
#include "Theme.hpp" #include "Theme.hpp"
@ -40,7 +43,11 @@ AnomalySaveDialog::AnomalySaveDialog(const QString& screenshotPath, int shotW, i
type_->setPlaceholderText(QStringLiteral("请选择异常类型")); // 空(如该形态平台无类型)时显灰占位+「暂无数据」 type_->setPlaceholderText(QStringLiteral("请选择异常类型")); // 空(如该形态平台无类型)时显灰占位+「暂无数据」
formkit::capField(type_); formkit::capField(type_);
form->addRow(formkit::editLabel(QStringLiteral("异常类型")), 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<int>(&QComboBox::currentIndexChanged), this, connect(type_, qOverload<int>(&QComboBox::currentIndexChanged), this,
[this](int) { loadStyleForCurrent(); }); [this](int) { loadStyleForCurrent(); });
loadTypes(cmdRepo, projectId, remarkSourceType); // 异步拉平台异常类型填充(与平台一致) loadTypes(cmdRepo, projectId, remarkSourceType); // 异步拉平台异常类型填充(与平台一致)
@ -102,9 +109,43 @@ void AnomalySaveDialog::loadStyleForCurrent() {
self->styleDashed_ = self->styleDashed_ =
lg.value(QStringLiteral("polylineShape")).toString().contains(QStringLiteral("dash")); 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 { QString AnomalySaveDialog::anomalyName() const {
const QString n = name_->text().trimmed(); const QString n = name_->text().trimmed();
return n.isEmpty() ? QStringLiteral("异常") : n; return n.isEmpty() ? QStringLiteral("异常") : n;

View File

@ -41,6 +41,8 @@ private:
int remarkSourceType); int remarkSourceType);
// 拉当前选中类型的详情 legend → 按形态(点/线/面)派生 styleColor/Width/Dashed。 // 拉当前选中类型的详情 legend → 按形态(点/线/面)派生 styleColor/Width/Dashed。
void loadStyleForCurrent(); void loadStyleForCurrent();
// 据当前样式按形态画预览(点=色球/线=线型/面=描边矩形),画到 stylePreview_。
void updateStylePreview();
geopro::data::IDatasetCommandRepository* cmdRepo_ = nullptr; geopro::data::IDatasetCommandRepository* cmdRepo_ = nullptr;
int remarkSourceType_ = 3; int remarkSourceType_ = 3;
@ -50,6 +52,7 @@ private:
QLineEdit* name_ = nullptr; QLineEdit* name_ = nullptr;
QComboBox* type_ = nullptr; QComboBox* type_ = nullptr;
QLabel* stylePreview_ = nullptr; // 选中类型样式预览(色块/线型)
QPlainTextEdit* remark_ = nullptr; QPlainTextEdit* remark_ = nullptr;
}; };