feat(ui): DynamicFormView 动态表单分组键值渲染器

This commit is contained in:
gaozheng 2026-06-10 20:36:03 +08:00
parent 6cf53ab199
commit 5686155faa
3 changed files with 103 additions and 0 deletions

View File

@ -24,6 +24,7 @@ add_executable(geopro_desktop WIN32
panels/AnomalyListPanel.cpp panels/AnomalyListPanel.cpp
panels/DatasetListPanel.cpp panels/DatasetListPanel.cpp
panels/ObjectTreePanel.cpp panels/ObjectTreePanel.cpp
panels/DynamicFormView.cpp
CentralScene.cpp CentralScene.cpp
ProjectListDialog.cpp ProjectListDialog.cpp
SettingsDialog.cpp) SettingsDialog.cpp)

View File

@ -0,0 +1,81 @@
#include "panels/DynamicFormView.hpp"
#include <QFormLayout>
#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>
#include "Theme.hpp"
namespace geopro::app {
DynamicFormView::DynamicFormView(QWidget* parent) : QWidget(parent) {
auto* outer = new QVBoxLayout(this);
outer->setContentsMargins(0, 0, 0, 0);
outer->setSpacing(0);
auto* scroll = new QScrollArea(this);
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
auto* host = new QWidget();
content_ = new QVBoxLayout(host);
content_->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kMd,
geopro::app::space::kLg, geopro::app::space::kMd);
content_->setSpacing(geopro::app::space::kSm);
content_->addStretch();
scroll->setWidget(host);
outer->addWidget(scroll);
showMessage(QStringLiteral("(选中后显示属性详情)"));
}
void DynamicFormView::clear() {
while (content_->count() > 0) {
QLayoutItem* it = content_->takeAt(0);
if (it->widget()) it->widget()->deleteLater();
delete it;
}
}
void DynamicFormView::showMessage(const QString& message) {
clear();
auto* hint = new QLabel(message);
hint->setAlignment(Qt::AlignCenter);
geopro::app::applyTokenizedStyleSheet(hint,
QStringLiteral("color:{{text/disabled}}; padding:16px;"));
content_->addWidget(hint);
content_->addStretch();
}
void DynamicFormView::setForm(const geopro::data::DynamicForm& form) {
clear();
if (form.groups.empty()) {
showMessage(QStringLiteral("(暂无属性)"));
return;
}
for (const auto& group : form.groups) {
auto* title = new QLabel(QString::fromStdString(group.name));
geopro::app::applyTokenizedStyleSheet(
title, QStringLiteral("color:{{text/secondary}}; font-weight:%1; padding-top:6px;")
.arg(geopro::app::type::kWeightSemibold));
content_->addWidget(title);
auto* form_w = new QWidget();
auto* fl = new QFormLayout(form_w);
fl->setContentsMargins(0, 0, 0, 0);
fl->setLabelAlignment(Qt::AlignLeft | Qt::AlignTop);
fl->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
for (const auto& f : group.fields) {
auto* k = new QLabel(QString::fromStdString(f.name));
geopro::app::applyTokenizedStyleSheet(k, QStringLiteral("color:{{text/secondary}};"));
auto* v = new QLabel(QString::fromStdString(f.value));
v->setWordWrap(true);
geopro::app::applyTokenizedStyleSheet(v, QStringLiteral("color:{{text/primary}};"));
fl->addRow(k, v);
}
content_->addWidget(form_w);
}
content_->addStretch();
}
} // namespace geopro::app

View File

@ -0,0 +1,21 @@
#pragma once
#include <QWidget>
#include "repo/RepoTypes.hpp"
class QVBoxLayout;
namespace geopro::app {
// 被动:渲染 DynamicForm分组键值。对象属性 / 数据集属性两面板共用。
class DynamicFormView : public QWidget {
public:
explicit DynamicFormView(QWidget* parent = nullptr);
void setForm(const geopro::data::DynamicForm& form);
void showMessage(const QString& message); // 空/错占位
private:
void clear();
QVBoxLayout* content_ = nullptr; // 滚动区内容布局
};
} // namespace geopro::app