Files
HPPA/HPPA/LayerTreeModel.h
tangchao0503 631216dc66 初步实现单独的图层管理器。
注意:没有和mapcavas通讯。
2026-02-05 15:32:34 +08:00

48 lines
1.6 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"
/**
* 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, const QString& name, const QIcon& icon = QIcon());
void setCascadeCheckEnabled(bool enabled);
bool cascadeCheckEnabled() const;
private:
LayerTree* m_tree = nullptr; // not owned
bool m_cascadeCheck = true;
private:
LayerTreeNode* nodeFromIndex(const QModelIndex& index) const;
QModelIndex indexFromNode(LayerTreeNode* n) const;
};