-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_errorslistmodel.cpp
86 lines (67 loc) · 1.62 KB
/
ui_errorslistmodel.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "ui_errorslistmodel.h"
#include <QDebug>
#include <QSize>
UIErrorsListModel::UIErrorsListModel(QObject *parent, QList<ParseError*>& errors) :
QAbstractTableModel(parent),
_errors()
{
// We need to make a deep copy of all the stuff in the error list
for(int i=0; i<errors.size(); i++)
{
_errors.append(new ParseError(errors.at(i)));
}
}
UIErrorsListModel::~UIErrorsListModel()
{
qDeleteAll(_errors);
_errors.clear();
}
int
UIErrorsListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return _errors.size();
}
int
UIErrorsListModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
}
QVariant
UIErrorsListModel::data(const QModelIndex &index, int role) const
{
ParseError* error = _errors.at(index.row());
if (role == Qt::UserRole)
{
return QVariant::fromValue(error);
}
return error->data(index, role);
}
QVariant
UIErrorsListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(orientation);
Q_UNUSED(role);
// if (role == Qt::SizeHintRole)
// {
// qDebug() << "Size hint for" << section;
// }
if (role != Qt::DisplayRole && role != Qt::SizeHintRole)
{
// qDebug() << role;
return QVariant();
}
switch(section)
{
case 0:
if (role == Qt::SizeHintRole) return QSize(30,1);
return tr("Line");
case 1:
if (role == Qt::SizeHintRole) return QSize(30,1);
return tr("Col");
default:
if (role == Qt::SizeHintRole) return QVariant();
return tr("Error");
}
}