summaryrefslogtreecommitdiff
path: root/tasklist.cxx
blob: 863ae23920cafdd3dd41f7b69d5c5d016c7565f2 (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
#include "tasklist.hxx"

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

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

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

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

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

void TaskList::addTask(Task const& task)
{
	beginInsertRows(QModelIndex(), rowCount(), rowCount());
	tasks << task;
	endInsertRows();
	emit rowCountChanged();
}

void TaskList::addTasks(rt_ticketlist* taskList)
{
	for (unsigned int i = 0; i < taskList->length; i++) {
		auto task = taskList->tickets[i];
		addTask(Task{task});
		free(task);
	}
	free(taskList);
}