From 015650a6fadd2592100950c57146fcc5c61764a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Thu, 5 Sep 2019 22:48:01 +0800 Subject: Task List abstract list model --- tasklist.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tasklist.cxx (limited to 'tasklist.cxx') diff --git a/tasklist.cxx b/tasklist.cxx new file mode 100644 index 0000000..5850584 --- /dev/null +++ b/tasklist.cxx @@ -0,0 +1,40 @@ +#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 Task::IdRole: + return task.id; + case Task::SubjectRole: + return task.subject; + default: + return QVariant(); + } +} + +QHash TaskList::roleNames() const +{ + return QHash{ + {Task::IdRole, "id"}, + {Task::SubjectRole, "subject"} + }; +} + +void TaskList::addTask(Task const& task) +{ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + tasks << task; + endInsertRows(); + emit rowCountChanged(); +} -- cgit v1.2.3