#ifndef DBSTRUCTUREMODEL_H
#define DBSTRUCTUREMODEL_H

#include <QAbstractItemModel>
#include <QTreeWidgetItem>
#include "dbStructureNode.h"
#include "global.h"

class DBStructureModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    explicit DBStructureModel(QObject* parent = nullptr);
    ~DBStructureModel();

    //QAbstractItemModel接口实现
    QModelIndex index(int row, int column, const QModelIndex& parent) const override;
    QModelIndex parent(const QModelIndex& index) 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;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

    //业务功能接口
    void addConnection(const QString& name, const QString& dbType);
    QModelIndex getConnNodeIndex(const QString& name);
    void addDataModel(const QString& connection, Model& model);

signals:
    void errorOccurred(const QString& strConnectionName);

public slots:
    void refreshStructure_Connection(const QString& connection); //刷新某个链接的数据(比如刷新、关闭或者手动刷新时)

private:
    DBStructureNode* getNode(const QModelIndex& index) const;
    DBStructureNode* getConnectionNode(const QString& name) const;

    DBStructureNode* m_rootNode;
};

#endif //DBSTRUCTUREMODEL_H
