|
|
|
@ -1,15 +1,11 @@
|
|
|
|
#include "panels/ObjectTreePanel.hpp"
|
|
|
|
#include "panels/ObjectTreePanel.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QModelIndex>
|
|
|
|
|
|
|
|
#include <QSignalBlocker>
|
|
|
|
#include <QSignalBlocker>
|
|
|
|
#include <QStandardItem>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QTreeView>
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
|
|
#include <ElaTreeView.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Theme.hpp"
|
|
|
|
#include "Theme.hpp"
|
|
|
|
#include "dto/NavDto.hpp"
|
|
|
|
#include "dto/NavDto.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,16 +15,15 @@ namespace {
|
|
|
|
// TM 节点把 tmObjectId 存在该角色;GS/项目根节点为空。
|
|
|
|
// TM 节点把 tmObjectId 存在该角色;GS/项目根节点为空。
|
|
|
|
constexpr int kRoleTmId = Qt::UserRole + 2;
|
|
|
|
constexpr int kRoleTmId = Qt::UserRole + 2;
|
|
|
|
|
|
|
|
|
|
|
|
void addNodes(QStandardItem* parent, const std::vector<data::dto::StructTreeNode>& nodes) {
|
|
|
|
void addNodes(QTreeWidgetItem* parent, const std::vector<data::dto::StructTreeNode>& nodes) {
|
|
|
|
for (const auto& n : nodes) {
|
|
|
|
for (const auto& n : nodes) {
|
|
|
|
auto* item = new QStandardItem(QString::fromStdString(n.node.name));
|
|
|
|
auto* item = new QTreeWidgetItem(parent);
|
|
|
|
item->setEditable(false);
|
|
|
|
item->setText(0, QString::fromStdString(n.node.name));
|
|
|
|
if (n.isTm) {
|
|
|
|
if (n.isTm) {
|
|
|
|
item->setData(QString::fromStdString(n.node.id), kRoleTmId);
|
|
|
|
item->setData(0, kRoleTmId, QString::fromStdString(n.node.id));
|
|
|
|
item->setCheckable(true);
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
|
item->setCheckState(Qt::Unchecked); // 真实数据渲染下一轮接入,默认不勾
|
|
|
|
item->setCheckState(0, Qt::Unchecked); // 真实数据渲染下一轮接入,默认不勾
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent->appendRow(item);
|
|
|
|
|
|
|
|
addNodes(item, n.children);
|
|
|
|
addNodes(item, n.children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -39,11 +34,10 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(0);
|
|
|
|
lay->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
|
|
tree_ = new ElaTreeView(this); // Fluent 树视图(自绘展开/折叠指示,随主题)
|
|
|
|
// Qt 原生标准树:复选框/展开箭头由 Fusion 绘制(明暗都清晰);配色取自全局主题 QSS。
|
|
|
|
|
|
|
|
tree_ = new QTreeWidget(this);
|
|
|
|
tree_->setHeaderHidden(true);
|
|
|
|
tree_->setHeaderHidden(true);
|
|
|
|
tree_->setIndentation(14); // 默认缩进偏大,收紧更紧凑协调
|
|
|
|
tree_->setIndentation(14); // 收紧缩进
|
|
|
|
model_ = new QStandardItemModel(tree_);
|
|
|
|
|
|
|
|
tree_->setModel(model_);
|
|
|
|
|
|
|
|
lay->addWidget(tree_, 1);
|
|
|
|
lay->addWidget(tree_, 1);
|
|
|
|
|
|
|
|
|
|
|
|
hint_ = new QLabel(QStringLiteral("正在加载对象…"), this);
|
|
|
|
hint_ = new QLabel(QStringLiteral("正在加载对象…"), this);
|
|
|
|
@ -52,22 +46,20 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|
|
|
hint_->setVisible(false);
|
|
|
|
hint_->setVisible(false);
|
|
|
|
lay->addWidget(hint_);
|
|
|
|
lay->addWidget(hint_);
|
|
|
|
|
|
|
|
|
|
|
|
// 单击 TM → tmClicked(按 index 取 tmId)。
|
|
|
|
QObject::connect(tree_, &QTreeWidget::itemClicked, this, [this](QTreeWidgetItem* item, int) {
|
|
|
|
QObject::connect(tree_, &QTreeView::clicked, this, [this](const QModelIndex& idx) {
|
|
|
|
const QString tmId = item->data(0, kRoleTmId).toString();
|
|
|
|
const QString tmId = idx.data(kRoleTmId).toString();
|
|
|
|
|
|
|
|
if (!tmId.isEmpty()) emit tmClicked(tmId);
|
|
|
|
if (!tmId.isEmpty()) emit tmClicked(tmId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// 勾选变化 → tmCheckToggled。
|
|
|
|
QObject::connect(tree_, &QTreeWidget::itemChanged, this, [this](QTreeWidgetItem* item, int) {
|
|
|
|
QObject::connect(model_, &QStandardItemModel::itemChanged, this, [this](QStandardItem* item) {
|
|
|
|
const QString tmId = item->data(0, kRoleTmId).toString();
|
|
|
|
const QString tmId = item->data(kRoleTmId).toString();
|
|
|
|
if (!tmId.isEmpty()) emit tmCheckToggled(tmId, item->checkState(0) == Qt::Checked);
|
|
|
|
if (!tmId.isEmpty()) emit tmCheckToggled(tmId, item->checkState() == Qt::Checked);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ObjectTreePanel::setStructure(const QString& projectName,
|
|
|
|
void ObjectTreePanel::setStructure(const QString& projectName,
|
|
|
|
const std::vector<data::StructNode>& nodes) {
|
|
|
|
const std::vector<data::StructNode>& nodes) {
|
|
|
|
const QSignalBlocker block(model_); // 重建触发 itemChanged,先屏蔽
|
|
|
|
const QSignalBlocker block(tree_); // 重建触发 itemChanged,先屏蔽
|
|
|
|
model_->clear();
|
|
|
|
tree_->clear();
|
|
|
|
const auto roots = data::dto::buildStructTree(nodes);
|
|
|
|
const auto roots = data::dto::buildStructTree(nodes);
|
|
|
|
if (roots.empty()) {
|
|
|
|
if (roots.empty()) {
|
|
|
|
showMessage(projectName.isEmpty() ? QStringLiteral("(暂无项目)")
|
|
|
|
showMessage(projectName.isEmpty() ? QStringLiteral("(暂无项目)")
|
|
|
|
@ -76,12 +68,12 @@ void ObjectTreePanel::setStructure(const QString& projectName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hint_->setVisible(false);
|
|
|
|
hint_->setVisible(false);
|
|
|
|
tree_->setVisible(true);
|
|
|
|
tree_->setVisible(true);
|
|
|
|
addNodes(model_->invisibleRootItem(), roots); // 结构已含项目根节点,直接渲染
|
|
|
|
addNodes(tree_->invisibleRootItem(), roots); // 结构已含项目根节点,直接渲染
|
|
|
|
tree_->expandAll();
|
|
|
|
tree_->expandAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ObjectTreePanel::showMessage(const QString& message) {
|
|
|
|
void ObjectTreePanel::showMessage(const QString& message) {
|
|
|
|
model_->clear();
|
|
|
|
tree_->clear();
|
|
|
|
tree_->setVisible(false);
|
|
|
|
tree_->setVisible(false);
|
|
|
|
hint_->setText(message);
|
|
|
|
hint_->setText(message);
|
|
|
|
hint_->setVisible(true);
|
|
|
|
hint_->setVisible(true);
|
|
|
|
|