From 7dadd495657a8baa67d26dcd6f961e1c523d2a2e 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: Fri, 6 Sep 2019 12:03:43 +0800 Subject: Task related views using the C++ model --- tasklist.hxx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'tasklist.hxx') diff --git a/tasklist.hxx b/tasklist.hxx index 716c365..adece4d 100644 --- a/tasklist.hxx +++ b/tasklist.hxx @@ -3,14 +3,19 @@ #include -struct Task +class Task { - enum TaskRoles { - IdRole = Qt::UserRole + 1, - SubjectRole - }; - QString id; - QString subject; + public: + Task(unsigned int id, QString subject) : + m_id{id}, + m_subject{subject} + {} + unsigned int id() const { return m_id; } + QString const& subject() const { return m_subject; } + + private: + unsigned int m_id; + QString m_subject; }; class TaskList : public QAbstractListModel @@ -19,7 +24,14 @@ class TaskList : public QAbstractListModel Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) public: - explicit TaskList(QObject* parent = nullptr) : QAbstractListModel{parent} {} + enum TaskRoles { + IdRole = Qt::UserRole + 1, + SubjectRole + }; + explicit TaskList(QObject* parent = nullptr) : QAbstractListModel{parent} + { + addTask(Task{1, "Task 1"}); + } int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; -- cgit v1.2.3