-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconsolelistmodel.cpp
39 lines (31 loc) · 1.08 KB
/
consolelistmodel.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
#include "consolelistmodel.h"
ConsoleListModel::ConsoleListModel(QObject* parent)
: QAbstractListModel(parent)
{
}
void ConsoleListModel::init() {
connect(this, &ConsoleListModel::appendEvent, this, &ConsoleListModel::doAppend);
}
QVariant ConsoleListModel::data(const QModelIndex &index, int role) const{
const int indexRow = index.row();
QVector<QVariant> vectorRole = _vectors[role];
if (indexRow < 0 || vectorRole.size() <= indexRow) {
return {"No data"};
}
return _vectors[role][indexRow];
}
QHash<int, QByteArray> ConsoleListModel::roleNames() const {
return _roleNames;
}
void ConsoleListModel::doAppend(const QString& time, int category, const QString& data)
{
bool visible = category & _categories;
const int line = rowCount();
beginInsertRows(QModelIndex(), line, line);
_vectors[ConsoleListModel::Visibility].append(visible);
_vectors[ConsoleListModel::Time].append(time);
_vectors[ConsoleListModel::Category].append(category);
_vectors[ConsoleListModel::Payload].append(data);
_size++;
endInsertRows();
}