diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-26 21:05:42 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-26 21:05:42 +0800 |
commit | 88bbb96199f944925063d7ef96eb055da063a776 (patch) | |
tree | 8c06031f460634cbdd8ceb9913661aa8d1f57607 /controller.cxx | |
parent | 9e238e0768530bab6a91742db806a0214e5dcbc3 (diff) |
Use new signal slot syntax and lambda
Diffstat (limited to 'controller.cxx')
-rw-r--r-- | controller.cxx | 46 |
1 files changed, 25 insertions, 21 deletions
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<QQmlApplicationEngine*>(parent); auto rootObjects = engine->rootObjects(); auto appWindow = rootObjects[0]; + using RTClient::User; auto typeId = qmlRegisterSingletonType<User>("KelakonUser", 0, 1, "User" , [](QQmlEngine *engine @@ -36,27 +38,37 @@ Controller::Controller(QObject* parent) : QObject{parent} return new User; }); auto user = engine->singletonInstance<User*>(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<void (Client::*)(QString const&)> + (&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<void (Controller::*)(rtclient_user*)> + (&Controller::checked) + , user, &User::update); + connect(this, static_cast<void (Controller::*)(QString const&)> + (&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(); |