#pragma once
#include "AllHead.h"
#include <QAbstractTableModel>
#include <QObject>
#include <QStringList>
#include <QVector>

class AbstractTableModel :public QAbstractTableModel {
    Q_OBJECT;
public:
    virtual void loadFilePath(QString csvPath); // 加载csv数据
    virtual void saveFilePath();
    virtual void saveAsFilePath(QString csvpath);
    virtual QString getCSVPath();
};


// FKEOResult.csv 表格对应类 2023.07.25 重写类
class FEKOResultCsvTableModel :public AbstractTableModel {
	Q_OBJECT;

private:
    QStringList m_hor_hedlbls;                      // headerlabels
    QStringList m_vec_hedlbls;                      // oids - map.keys()
    QVector<QVector<QVariant>> m_data_map;
    QVector<QPair<int, int> > m_highlight_indexs;   // 背景高亮的indexs
    QVector<QVector<QColor>> colorData;
    QString csvPath;

public:

	explicit FEKOResultCsvTableModel(QObject* parent = NULL);
	~FEKOResultCsvTableModel();
    
    virtual void loadFilePath(QString csvPath); // 加载csv数据
    virtual void saveFilePath();
    virtual void saveAsFilePath(QString csvpath);

    void loadCSVFilePath(QString csvPath); // 加载csv数据
    void saveCSVFilePath(QString csvpath);

    QStringList getColumnNames();
    QStringList getItemDataByColumn(int colidx);
    int getColumnIdxByColumName(QString ColumnName);
    virtual QString getCSVPath();

    // tableview 表格模型操作
    void SetData(const QVector<QVector<QVariant>>& map, QStringList& colnames, QStringList& rowIds);

    void setHignlightIndex(QVector< QPair<int, int> > vec_index);

    virtual Qt::ItemFlags flags(const QModelIndex& index) const;
    virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    virtual int rowCount(const QModelIndex& parent) const;
    virtual int columnCount(const QModelIndex& parent) const;

    virtual QVariant data(const QModelIndex& index, int role) const;
    virtual bool setData(const QModelIndex& index, const QVariant& value, int role=2);

    QString itemText(int row, int column) const;
    QString itemText(const QModelIndex& index) const;
    void setItemText(const QModelIndex& index, const QString& str);
    void setItemText(int row, int column, const QString& str);

    QVariant ItemData(const QModelIndex& index) const;
    QVariant ItemData(int row, int column) const;
    void SetItemData(const QModelIndex& index, const QVariant& data);
    void SetItemData(int row, int column, const QVariant& data);

    size_t rowCount();
    size_t colCount();

    void isNeedExtendTable(size_t row, size_t col);

    void clear();

    QVariant* getVariantPtr(size_t row, size_t col);

signals:
    void itemChanged(const QModelIndex& index, const QVariant& value);

};

