-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathOutputView.cpp
54 lines (47 loc) · 1.17 KB
/
OutputView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by System Administrator on 16/8/18.
//
#include "OutputView.h"
#include "EventDispatcher.h"
OutputModel::OutputModel(QObject *parent)
: QStandardItemModel(parent)
{
setHorizontalHeaderLabels(QStringList() << "级别" << "信息");
QObject::connect(EventDispatcher::instance(), &EventDispatcher::addLog, this, &OutputModel::addLog);
}
void OutputModel::addLog(QString msg, LogType t)
{
QString level;
QColor color;
switch (t)
{
case LogType::Info:
level = "Info";
color = Qt::white;
break;
case LogType::Warning:
level = "Warning";
color = Qt::yellow;
break;
case LogType::Error:
level = "Error";
color = Qt::red;
break;
}
auto item1 = new QStandardItem(level);
item1->setBackground(color);
auto item2 = new QStandardItem(msg);
item2->setBackground(color);
appendRow(QList<QStandardItem*>() << item1 << item2);
}
OutputView::OutputView(QWidget *parent)
: QTableView(parent)
{
setSelectionBehavior(QAbstractItemView::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void OutputView::rowsInserted(const QModelIndex &parent, int start, int end)
{
scrollToBottom();
QAbstractItemView::rowsInserted(parent, start, end);
}