diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-06 12:03:43 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-06 12:03:43 +0800 |
commit | 7dadd495657a8baa67d26dcd6f961e1c523d2a2e (patch) | |
tree | 4e530d4b80be89a8fe4c6bbdb96405cfc96ae86c /tasklist.hxx | |
parent | 015650a6fadd2592100950c57146fcc5c61764a2 (diff) |
Task related views using the C++ model
Diffstat (limited to 'tasklist.hxx')
-rw-r--r-- | tasklist.hxx | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tasklist.hxx b/tasklist.hxx index 716c365..adece4d 100644 --- a/tasklist.hxx +++ b/tasklist.hxx @@ -3,14 +3,19 @@ #include <QAbstractListModel> -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; |