From 88bbb96199f944925063d7ef96eb055da063a776 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: Thu, 26 Sep 2019 21:05:42 +0800 Subject: Use new signal slot syntax and lambda --- controller.cxx | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'controller.cxx') diff --git a/controller.cxx b/controller.cxx index df10b20..40eee0d 100644 --- a/controller.cxx +++ b/controller.cxx @@ -16,7 +16,8 @@ Controller::Controller(QObject* parent) : QObject{parent} QFile file{"assets:/certs/ca-certificates.crt"}; file.copy(path); #endif - auto client = new RTClient::Client{"https://darapsa.co.id/rt" + using RTClient::Client; + auto client = new Client{"https://darapsa.co.id/rt" #ifdef ANDROID , path.toLatin1().constData() #endif @@ -27,6 +28,7 @@ Controller::Controller(QObject* parent) : QObject{parent} auto engine = static_cast(parent); auto rootObjects = engine->rootObjects(); auto appWindow = rootObjects[0]; + using RTClient::User; auto typeId = qmlRegisterSingletonType("KelakonUser", 0, 1, "User" , [](QQmlEngine *engine @@ -36,27 +38,37 @@ Controller::Controller(QObject* parent) : QObject{parent} return new User; }); auto user = engine->singletonInstance(typeId); - taskList = new RTClient::TicketList; + + using RTClient::TicketList; + taskList = new TicketList; engine->rootContext()->setContextProperty("taskList", taskList); connect(appWindow, SIGNAL(logIn(QString, QString)) , client, SLOT(logIn(QString, QString))); - connect(client, SIGNAL(loggedIn(QString)) - , client, SLOT(userShow(QString))); + connect(client, &Client::loggedIn + , client, static_cast + (&Client::userShow)); - connect(client, SIGNAL(userShown(rtclient_user*)) - , this, SLOT(check(rtclient_user*))); + connect(client, &Client::userShown, [this](rtclient_user* user) { + if (user) { + emit checked(QString{user->name}); + emit checked(user); + } + }); - connect(this, SIGNAL(checked(rtclient_user*)) - , user, SLOT(update(rtclient_user*))); - connect(this, SIGNAL(checked(QString)) - , client, SLOT(ticketSearch(QString))); + connect(this, static_cast + (&Controller::checked) + , user, &User::update); + connect(this, static_cast + (&Controller::checked) + , client, &Client::ticketSearch); - connect(client, SIGNAL(ticketSearched(rtclient_ticketlist*)) - , taskList, SLOT(update(rtclient_ticketlist*))); + connect(client, &Client::ticketSearched, taskList, &TicketList::update); - connect(taskList, SIGNAL(updated()), appWindow, SLOT(pushHome())); + connect(taskList, &TicketList::updated, [appWindow]() { + QMetaObject::invokeMethod(appWindow, "pushHome"); + }); connect(appWindow, SIGNAL(ticketHistory(int)) , client, SLOT(ticketHistory(int))); @@ -67,14 +79,6 @@ Controller::Controller(QObject* parent) : QObject{parent} thread.start(); } -void Controller::check(rtclient_user* user) -{ - if (user) { - emit checked(QString{user->name}); - emit checked(user); - } -} - Controller::~Controller() { thread.quit(); -- cgit v1.2.3