|
|
|
|
@ -1,13 +1,15 @@
|
|
|
|
|
#include "panels/ObjectTreePanel.hpp"
|
|
|
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QModelIndex>
|
|
|
|
|
#include <QSignalBlocker>
|
|
|
|
|
#include <QTreeWidget>
|
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
#include "Glyphs.hpp"
|
|
|
|
|
#include <ElaTreeView.h>
|
|
|
|
|
|
|
|
|
|
#include "Theme.hpp"
|
|
|
|
|
#include "dto/NavDto.hpp"
|
|
|
|
|
|
|
|
|
|
@ -17,15 +19,16 @@ namespace {
|
|
|
|
|
// TM 节点把 tmObjectId 存在该角色;GS/项目根节点为空。
|
|
|
|
|
constexpr int kRoleTmId = Qt::UserRole + 2;
|
|
|
|
|
|
|
|
|
|
void addNodes(QTreeWidgetItem* parent, const std::vector<data::dto::StructTreeNode>& nodes) {
|
|
|
|
|
void addNodes(QStandardItem* parent, const std::vector<data::dto::StructTreeNode>& nodes) {
|
|
|
|
|
for (const auto& n : nodes) {
|
|
|
|
|
auto* item = new QTreeWidgetItem(parent);
|
|
|
|
|
item->setText(0, QString::fromStdString(n.node.name));
|
|
|
|
|
auto* item = new QStandardItem(QString::fromStdString(n.node.name));
|
|
|
|
|
item->setEditable(false);
|
|
|
|
|
if (n.isTm) {
|
|
|
|
|
item->setData(0, kRoleTmId, QString::fromStdString(n.node.id));
|
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
|
|
item->setCheckState(0, Qt::Unchecked); // 真实数据渲染下一轮接入,默认不勾
|
|
|
|
|
item->setData(QString::fromStdString(n.node.id), kRoleTmId);
|
|
|
|
|
item->setCheckable(true);
|
|
|
|
|
item->setCheckState(Qt::Unchecked); // 真实数据渲染下一轮接入,默认不勾
|
|
|
|
|
}
|
|
|
|
|
parent->appendRow(item);
|
|
|
|
|
addNodes(item, n.children);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -36,19 +39,10 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
lay->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
tree_ = new QTreeWidget(this);
|
|
|
|
|
tree_ = new ElaTreeView(this); // Fluent 树视图(自绘展开/折叠指示,随主题)
|
|
|
|
|
tree_->setHeaderHidden(true);
|
|
|
|
|
{
|
|
|
|
|
const QString openArrow = writeChevronIcon(true, QColor("#8A93A3"));
|
|
|
|
|
const QString closedArrow = writeChevronIcon(false, QColor("#8A93A3"));
|
|
|
|
|
geopro::app::applyThemedStyleSheet(
|
|
|
|
|
tree_, QStringLiteral("QTreeView::branch { background: #FFFFFF; }"
|
|
|
|
|
"QTreeView::branch:has-children:!has-siblings:closed,"
|
|
|
|
|
"QTreeView::branch:closed:has-children:has-siblings { image: url(%1); }"
|
|
|
|
|
"QTreeView::branch:open:has-children:!has-siblings,"
|
|
|
|
|
"QTreeView::branch:open:has-children:has-siblings { image: url(%2); }")
|
|
|
|
|
.arg(closedArrow, openArrow));
|
|
|
|
|
}
|
|
|
|
|
model_ = new QStandardItemModel(tree_);
|
|
|
|
|
tree_->setModel(model_);
|
|
|
|
|
lay->addWidget(tree_, 1);
|
|
|
|
|
|
|
|
|
|
hint_ = new QLabel(QStringLiteral("正在加载对象…"), this);
|
|
|
|
|
@ -57,21 +51,22 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|
|
|
|
hint_->setVisible(false);
|
|
|
|
|
lay->addWidget(hint_);
|
|
|
|
|
|
|
|
|
|
QObject::connect(tree_, &QTreeWidget::itemClicked, this, [this](QTreeWidgetItem* item, int) {
|
|
|
|
|
const QString tmId = item->data(0, kRoleTmId).toString();
|
|
|
|
|
// 单击 TM → tmClicked(按 index 取 tmId)。
|
|
|
|
|
QObject::connect(tree_, &QTreeView::clicked, this, [this](const QModelIndex& idx) {
|
|
|
|
|
const QString tmId = idx.data(kRoleTmId).toString();
|
|
|
|
|
if (!tmId.isEmpty()) emit tmClicked(tmId);
|
|
|
|
|
});
|
|
|
|
|
QObject::connect(tree_, &QTreeWidget::itemChanged, this, [this](QTreeWidgetItem* item, int) {
|
|
|
|
|
const QString tmId = item->data(0, kRoleTmId).toString();
|
|
|
|
|
if (!tmId.isEmpty())
|
|
|
|
|
emit tmCheckToggled(tmId, item->checkState(0) == Qt::Checked);
|
|
|
|
|
// 勾选变化 → tmCheckToggled。
|
|
|
|
|
QObject::connect(model_, &QStandardItemModel::itemChanged, this, [this](QStandardItem* item) {
|
|
|
|
|
const QString tmId = item->data(kRoleTmId).toString();
|
|
|
|
|
if (!tmId.isEmpty()) emit tmCheckToggled(tmId, item->checkState() == Qt::Checked);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectTreePanel::setStructure(const QString& projectName,
|
|
|
|
|
const std::vector<data::StructNode>& nodes) {
|
|
|
|
|
const QSignalBlocker block(tree_); // 重建触发 itemChanged,先屏蔽
|
|
|
|
|
tree_->clear();
|
|
|
|
|
const QSignalBlocker block(model_); // 重建触发 itemChanged,先屏蔽
|
|
|
|
|
model_->clear();
|
|
|
|
|
const auto roots = data::dto::buildStructTree(nodes);
|
|
|
|
|
if (roots.empty()) {
|
|
|
|
|
showMessage(projectName.isEmpty() ? QStringLiteral("(暂无项目)")
|
|
|
|
|
@ -80,12 +75,12 @@ void ObjectTreePanel::setStructure(const QString& projectName,
|
|
|
|
|
}
|
|
|
|
|
hint_->setVisible(false);
|
|
|
|
|
tree_->setVisible(true);
|
|
|
|
|
addNodes(tree_->invisibleRootItem(), roots); // 结构已含项目根节点,直接渲染
|
|
|
|
|
addNodes(model_->invisibleRootItem(), roots); // 结构已含项目根节点,直接渲染
|
|
|
|
|
tree_->expandAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectTreePanel::showMessage(const QString& message) {
|
|
|
|
|
tree_->clear();
|
|
|
|
|
model_->clear();
|
|
|
|
|
tree_->setVisible(false);
|
|
|
|
|
hint_->setText(message);
|
|
|
|
|
hint_->setVisible(true);
|
|
|
|
|
|