#ifndef DBSTRUCTURENODE_H
#define DBSTRUCTURENODE_H

#include <QList>
#include <QVariant>
#include <QIcon>

enum NodeType //节点类型
{
    RootNode, //根节点
    ConnectionNode, //链接（名称）节点
    DatabaseNode, //数据库节点
    TableNode, //表节点
    GroupNode //属性组节点
};

enum NodeStatus //节点状态(主要是ConnectionNode)
{
    Connect,
    Disconnect,
    NoStatus
};

enum NodeDataRole
{
    ID = 1
};

class DBStructureNode
{
public:
    enum ColumnRole
    {
        ColumnName = 0,
        //ColumnStatus = 1,
        ColumnCount = 1 //用来表示属性列的数量
    };

    explicit DBStructureNode(NodeType type, const QString& name, DBStructureNode* parent = nullptr);
    ~DBStructureNode();

    //节点操作
    void appendChild(DBStructureNode* child);
    DBStructureNode* child(int row);
    int childCount() const;
    int row() const;
    void removeAllChildren();

    //数据访问
    NodeType type() const;
    QString name() const;
    QIcon icon() const;
    void setStatus(NodeStatus);
    NodeStatus status() const;
    QVariant columnData(int column) const;
    //QVariant icon() const;
    DBStructureNode* parentNode();
    //模仿QTreeWidgetItem的数据接口
    void setData(int, const QVariant&);
    QVariant data(int) const;

private:
    NodeType m_type;
    QString  m_name;
    QIcon    m_icon;
    NodeStatus m_status;
    QHash<int, QVariant> m_roleData;
    QList<DBStructureNode*> m_children;
    DBStructureNode* m_parent;
};

#endif //DBSTRUCTURENODE_H
