From 9ec42c7e9c4a96d54bbf526cbd93f07c78e2415e 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, 13 Sep 2019 18:29:31 +0800 Subject: Manage to show tasks but the view is widened vertically yet. --- controller.cxx | 7 +++++++ librtclient | 2 +- main.cxx | 12 ++++++++---- tasklist.cxx | 13 ++++++++++--- tasklist.hxx | 18 +++++++++++------- worker.cxx | 20 ++++---------------- worker.hxx | 1 + 7 files changed, 42 insertions(+), 31 deletions(-) diff --git a/controller.cxx b/controller.cxx index b9bdf5e..42b1ece 100644 --- a/controller.cxx +++ b/controller.cxx @@ -1,6 +1,8 @@ #include +#include #include "worker.hxx" #include "user.hxx" +#include "tasklist.hxx" #include "controller.hxx" Controller::Controller(QObject* parent) : QObject{parent} @@ -22,6 +24,11 @@ Controller::Controller(QObject* parent) : QObject{parent} auto user = engine->singletonInstance(User::typeId); connect(worker, SIGNAL(logged(rt_user*)), user, SLOT(update(rt_user*))); + auto taskList = engine->singletonInstance(TaskList::typeId); + engine->rootContext()->setContextProperty("taskList", taskList); + connect(worker, SIGNAL(foundTasks(rt_ticketlist*)) + , taskList, SLOT(addTasks(rt_ticketlist*))); + thread.start(); } diff --git a/librtclient b/librtclient index 2e207d0..e9561a9 160000 --- a/librtclient +++ b/librtclient @@ -1 +1 @@ -Subproject commit 2e207d07a6416d7ccb32040c3f9e43c3a48aeed2 +Subproject commit e9561a9bd14469edab70886d98e050bfe054a3eb diff --git a/main.cxx b/main.cxx index c9e8691..ff184e7 100644 --- a/main.cxx +++ b/main.cxx @@ -1,6 +1,5 @@ #include #include -#include #include "user.hxx" #include "tasklist.hxx" #include "controller.hxx" @@ -16,11 +15,16 @@ int main(int argc, char* argv[]) QJSEngine *scriptEngine) -> QObject* { Q_UNUSED(engine) Q_UNUSED(scriptEngine) - return new User{}; + return new User; }); - TaskList taskList; - engine.rootContext()->setContextProperty("taskList", &taskList); + TaskList::typeId = qmlRegisterSingletonType("KelakonUser", 0, 1, "TaskList" + , [](QQmlEngine *engine, + QJSEngine *scriptEngine) -> QObject* { + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + return new TaskList; + }); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); Controller controller{&engine}; diff --git a/tasklist.cxx b/tasklist.cxx index 4810c5b..863ae23 100644 --- a/tasklist.cxx +++ b/tasklist.cxx @@ -14,8 +14,6 @@ QVariant TaskList::data(QModelIndex const& index, int role) const auto task = tasks[row]; switch (role) { - case IdRole: - return task.id(); case SubjectRole: return task.subject(); default: @@ -26,7 +24,6 @@ QVariant TaskList::data(QModelIndex const& index, int role) const QHash TaskList::roleNames() const { return QHash{ - {IdRole, "id"}, {SubjectRole, "subject"} }; } @@ -38,3 +35,13 @@ void TaskList::addTask(Task const& task) endInsertRows(); emit rowCountChanged(); } + +void TaskList::addTasks(rt_ticketlist* taskList) +{ + for (unsigned int i = 0; i < taskList->length; i++) { + auto task = taskList->tickets[i]; + addTask(Task{task}); + free(task); + } + free(taskList); +} diff --git a/tasklist.hxx b/tasklist.hxx index a632d86..68cc3ff 100644 --- a/tasklist.hxx +++ b/tasklist.hxx @@ -2,19 +2,16 @@ #define TASKLIST_HXX #include +#include "rtticket.h" class Task { public: - Task(unsigned int id, QString subject) - : m_id{id} - , m_subject{subject} + Task(QString subject) : 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; }; @@ -25,11 +22,14 @@ class TaskList : public QAbstractListModel public: enum TaskRoles { - IdRole = Qt::UserRole + 1, - SubjectRole + SubjectRole = Qt::UserRole + 1, }; + explicit TaskList(QObject* parent = nullptr) : QAbstractListModel{parent} {} + ~TaskList() {} + inline static int typeId; + int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; @@ -37,11 +37,15 @@ class TaskList : public QAbstractListModel QHash roleNames() const Q_DECL_OVERRIDE; signals: + void didAddProducts(); void rowCountChanged(); private: QList tasks; void addTask(Task const& task); + + private slots: + void addTasks(rt_ticketlist* taskList); }; #endif // TASKLIST_HXX diff --git a/worker.cxx b/worker.cxx index e21ef6b..c472212 100644 --- a/worker.cxx +++ b/worker.cxx @@ -1,6 +1,3 @@ -#ifdef DEBUG -#include -#endif // DEBUG #include "rtclient.h" #include "worker.hxx" @@ -12,7 +9,7 @@ Worker::Worker() void Worker::logIn(QString const& name, QString const& password) { rtclient_login(name.toLatin1().constData(), password.toLatin1().constData()); - struct rt_user *user = NULL; + struct rt_user* user = NULL; rtclient_userget(&user, name.toLatin1().constData()); if (user) emit logged(user); } @@ -22,18 +19,9 @@ void Worker::search(QString const& owner) QString query{"Owner='"}; query.append(owner); query.append("'"); - rt_ticketlist *tasks = NULL; - rtclient_search(&tasks, query.toLatin1().constData()); - if (tasks) { -#ifdef DEBUG - for (unsigned short i = 0; i < tasks->length; i++) { - auto task = tasks->tickets[i]; - qDebug() << "Task: " << task; - if (task) free(task); - } -#endif // DEBUG - free(tasks); - } + rt_ticketlist* taskList = NULL; + rtclient_search(&taskList, query.toLatin1().constData()); + if (taskList) emit foundTasks(taskList); } Worker::~Worker() diff --git a/worker.hxx b/worker.hxx index c406db9..878c2ba 100644 --- a/worker.hxx +++ b/worker.hxx @@ -17,6 +17,7 @@ class Worker : public QObject signals: void logged(struct rt_user* user); + void foundTasks(struct rt_ticketlist* list); }; #endif // WORKER_HXX -- cgit v1.2.3