#include "alarmdialog.hpp"
#include "AlarmInfo.h"

extern std::vector<AlarmInfo> g_vec_alarm;

AlarmDialog::AlarmDialog(QWidget * parent) : QDialog(parent) {
	ui.setupUi(this);
	this->setWindowFlags(Qt::FramelessWindowHint);
	ui.tableWidget->setColumnCount(4);
	ui.tableWidget->setRowCount(g_vec_alarm.size());
	QStringList header_list;
	header_list << QStringLiteral("报警开始时间") << QStringLiteral("报警处理时间")
		<< QStringLiteral("报警信息") << QStringLiteral("报警代码");
	ui.tableWidget->setHorizontalHeaderLabels(header_list);
	ui.tableWidget->setColumnWidth(0, 140);
	ui.tableWidget->setColumnWidth(1, 140);
	ui.tableWidget->setColumnWidth(2, 380);
	ui.tableWidget->setColumnWidth(3, 120);
	for (int i = 0; i < g_vec_alarm.size(); i++)
	{
		ui.tableWidget->setItem(i, 0, new QTableWidgetItem(QString(g_vec_alarm[i].alarm_start.c_str())));
		ui.tableWidget->setItem(i, 1, new QTableWidgetItem(QString(g_vec_alarm[i].alarm_handle.c_str())));
		ui.tableWidget->setItem(i, 2, new QTableWidgetItem(QString(g_vec_alarm[i].alarm_msg.c_str())));
		ui.tableWidget->setItem(i, 3, new QTableWidgetItem(QString::number(g_vec_alarm[i].alarm_code)));
	}
}

AlarmDialog::~AlarmDialog() {
	
}

void AlarmDialog::on_pushButton_close_released()
{
	this->close();
}

void AlarmDialog::on_pushButton_clear_released()
{
	int rowNum = ui.tableWidget->rowCount();
	for (int i = rowNum - 1; i >= 0; i--)
	{
		ui.tableWidget->removeRow(i);
	}
	g_vec_alarm.clear();
}
