#include "CBTableViewModel.h"

#include <QIcon>

CBTableViewModel::CBTableViewModel(QObject *parent) : QAbstractTableModel{parent} {
    _header << "内容" << "时间";
    QStringList data0;
    QStringList data1;
    QStringList data2;
    QStringList data3;
    QStringList data4;
    QStringList data5;
    QStringList data6;
    QStringList data7;
    QStringList data8;
    data0 << "夜航星(Night Voyager)" << "05:03";
    data1 << "玫瑰少年" << "03:55";
    data2 << "Collapsing World(Original Mix)" << "03:10";
    data3 << "RAIN MAN (雨人)" << "05:37";
    data4 << "黑暗森林" << "05:47";
    data5 << "轻(我的三体第四季主题曲)" << "01:59";
    data6 << "STYX HELIX" << "04:51";
    data7 << "LAST STARDUST" << "05:18";
    data8 << "Running In The Dark" << "03:40";
    _dataList.append(data0);
    _dataList.append(data1);
    _dataList.append(data2);
    _dataList.append(data3);
    _dataList.append(data4);
    _dataList.append(data5);
    _dataList.append(data6);
    _dataList.append(data7);
    _dataList.append(data8);
}

CBTableViewModel::~CBTableViewModel() {}

int CBTableViewModel::rowCount(const QModelIndex &parent) const { return 100; }

int CBTableViewModel::columnCount(const QModelIndex &parent) const { return _header.count(); }

QVariant CBTableViewModel::data(const QModelIndex &index, int role) const {
    if (role == Qt::DisplayRole) {
        return _dataList[index.row() % 9][index.column()];
    } else if (role == Qt::DecorationPropertyRole) {
        return Qt::AlignCenter;
    } else if (role == Qt::TextAlignmentRole && index.column() == 1) {
        return Qt::AlignCenter;
    }
    return QVariant();
}

QVariant CBTableViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
        return _header[section];
    }
    return QAbstractTableModel::headerData(section, orientation, role);
}
