Files
HPPA/HPPA/LayerTreeModel.h
2026-04-02 10:34:57 +08:00

53 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <QCoreApplication>
#include <QAbstractItemModel>
#include "LayerTree.h"
class LayerTreeLayer; // forward declare
/**
* LayerTreeModelQt 适配层(不再管理树)
* - 1 列:名称(带图标)+ checkbox
* - 勾选可见性(可选级联勾选)
*/
class LayerTreeModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit LayerTreeModel(LayerTree* tree,
QObject* parent = nullptr,
bool cascadeCheck = true);
~LayerTreeModel() override = default;
// QAbstractItemModel 必须接口
QModelIndex index(int row, int column,
const QModelIndex& parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& child) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
// 对外 API构建树内部会正确调用 begin/endInsertRows
LayerTreeNode* root() const;
LayerTreeNode* addGroup(LayerTreeNode* parent, const QString& name, const QIcon& icon = QIcon());
LayerTreeNode* addLayer(LayerTreeNode* parent, LayerTreeLayer* layerNode, const QIcon& icon = QIcon());
void setCascadeCheckEnabled(bool enabled);
bool cascadeCheckEnabled() const;
// 新增:从父节点移除子节点(包装 LayerTree::removeNode 并发出 model 通知)
LayerTreeNode* removeNode(LayerTreeNode* parent, int row);
private:
LayerTree* m_tree = nullptr; // not owned
bool m_cascadeCheck = true;
private:
LayerTreeNode* nodeFromIndex(const QModelIndex& index) const;
QModelIndex indexFromNode(LayerTreeNode* n) const;
};