summaryrefslogtreecommitdiff
path: root/ticket.cxx
blob: 461e5540563a06279d1b6ca844bb67f19a47e27a (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
#include <rtclient/client.h>
#include "qrtclient/ticket.hxx"

namespace RTClient {

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

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

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

		auto ticket = tickets[row];
		switch (role) {
			case SubjectRole:
				return ticket.subject();
			default:
				return QVariant();
		}
	}

	QHash<int, QByteArray> TicketList::roleNames() const
	{
		return QHash<int, QByteArray>{
			{SubjectRole, "subject"}
		};
	}

	void TicketList::addTicket(Ticket const& ticket)
	{
		beginInsertRows(QModelIndex(), rowCount(), rowCount());
		tickets << ticket;
		endInsertRows();
		emit rowCountChanged();
	}

	void TicketList::update(rtclient_ticketlist* ticketList)
	{
		for (unsigned int i = 0; i < ticketList->length; i++)
			addTicket(Ticket{ticketList->tickets[i]});
		rtclient_ticket_freelist(ticketList);
		emit updated();
	}

}