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; };