#include "messagespresent.h"

using namespace Components;
using namespace Parse;
using namespace Parse::Result;

MessagesPresent::MessagesPresent(MakeTools::StoryTool *tool, QWidget *parent)
    : QTableView(parent), core_ins(tool), items_present(new QStandardItemModel(this)) {
    setModel(items_present);
}

void MessagesPresent::refresh() {
    items_present->clear();

    QList<ErrorMessage> errors;
    core_ins->checkPass(errors);

    for(auto &err : errors){
        QList<QStandardItem*> row;
        row << new QStandardItem(err.Reason);
        row << new QStandardItem(err.Text);
        row << new QStandardItem(err.FilePath);
        row << new QStandardItem(QString("%1").arg(err.CodeRow + 1));
        row << new QStandardItem(QString("%1").arg(err.CodeCol));

        for(auto &ins : row)
            ins->setEditable(false);
        items_present->appendRow(row);
    }
    items_present->setHorizontalHeaderLabels(QStringList() << "错误原因"<<"源文本"<<"磁盘路径"<<"代码行"<<"代码列");

    this->resizeColumnsToContents();
    this->resizeRowsToContents();
}

QWidget *MessagesPresent::widget() const { return (QWidget *)this; }

QString MessagesPresent::name() const { return NAME(MessagesPresent); }
