summaryrefslogtreecommitdiff
path: root/tickethistory.cxx
blob: ae0e2d712c79c90c6f8ee71bffa95a353c7eec6a (plain)
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
#include <cstddef>
#include "qrtclient/tickethistory.hxx"

namespace RTClient {

TicketHistoryList::TicketHistoryList(struct rtclient_ticket_history** list,
		QObject* parent)
	: QAbstractListModel{parent}
{
	size_t i = 0;
	while (list[i]) {
		beginInsertRows(QModelIndex(), rowCount(), rowCount());
		histories << TicketHistory{list[i++]};
		endInsertRows();
	}
}

int TicketHistoryList::rowCount(QModelIndex const& parent) const
{
	Q_UNUSED(parent)
	return histories.count();
}

QVariant TicketHistoryList::data(QModelIndex const& index, int role) const
{
	auto row = index.row();

	if (row < 0 || row >= histories.count()) return QVariant();

	auto history = histories[row];
	switch (role) {
		case IdRole:
			return history.id();
		case TicketRole:
			return history.ticket();
		case TimeTakenRole:
			return history.timeTaken();
		case TypeRole:
			return history.type();
		case FieldRole:
			return history.field();
		case OldValueRole:
			return history.oldValue();
		case NewValueRole:
			return history.newValue();
		case DataRole:
			return history.data();
		case DescriptionRole:
			return history.description();
		case ContentRole:
			return history.content();
		case CreatorRole:
			return history.creator();
		case CreatedRole:
			return history.created();/*
		case AttachmentsRole:
			return history.attachments();*/
		default:
			return QVariant();
	}
}

QHash<int, QByteArray> TicketHistoryList::roleNames() const
{
	return QHash<int, QByteArray>{{IdRole, "id"},
		{TicketRole, "ticket"},
		{TimeTakenRole, "timeTaken"},
		{TypeRole, "type"},
		{FieldRole, "field"},
		{OldValueRole, "oldValue"},
		{NewValueRole, "newValue"},
		{DataRole, "data"},
		{DescriptionRole, "description"},
		{ContentRole, "content"},
		{CreatorRole, "creator"},
		{CreatedRole, "created"}/*,
		{AttachmentsRole, "attachments"}*/
	};
}

}