diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-05 22:48:01 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-05 22:48:01 +0800 |
commit | 015650a6fadd2592100950c57146fcc5c61764a2 (patch) | |
tree | 94b58691f4f7a85560c6a706b9578746b7b6a98f /tasklist.cxx | |
parent | 89bff3fa5d58aeb0d507d633aa058d781f06a8c0 (diff) |
Task List abstract list model
Diffstat (limited to 'tasklist.cxx')
-rw-r--r-- | tasklist.cxx | 40 |
1 files changed, 40 insertions, 0 deletions
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<int, QByteArray> TaskList::roleNames() const +{ + return QHash<int, QByteArray>{ + {Task::IdRole, "id"}, + {Task::SubjectRole, "subject"} + }; +} + +void TaskList::addTask(Task const& task) +{ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + tasks << task; + endInsertRows(); + emit rowCountChanged(); +} |