summaryrefslogtreecommitdiff
path: root/tasklist.cxx
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-05 22:48:01 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-05 22:48:01 +0800
commit015650a6fadd2592100950c57146fcc5c61764a2 (patch)
tree94b58691f4f7a85560c6a706b9578746b7b6a98f /tasklist.cxx
parent89bff3fa5d58aeb0d507d633aa058d781f06a8c0 (diff)
Task List abstract list model
Diffstat (limited to 'tasklist.cxx')
-rw-r--r--tasklist.cxx40
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();
+}