From e84be938aaae682369083520faeccd92944e76fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sat, 6 Jan 2024 00:47:07 +0100 Subject: [PATCH 1/3] typo --- libosmscout/include/osmscout/async/CancelableFuture.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libosmscout/include/osmscout/async/CancelableFuture.h b/libosmscout/include/osmscout/async/CancelableFuture.h index 56e1101bb..976f266a0 100644 --- a/libosmscout/include/osmscout/async/CancelableFuture.h +++ b/libosmscout/include/osmscout/async/CancelableFuture.h @@ -180,7 +180,7 @@ namespace osmscout { /** * Callback triggered on future complete. - * When future is calceled, it is never called. + * When future is canceled, it is never called. * It is called from thread of value producer. * When future is completed already, callback is called immediately in thread of caller. * From 96b9263d0088977f1fdcadfdcb1601e07d34fdf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sat, 6 Jan 2024 00:47:36 +0100 Subject: [PATCH 2/3] log spaces --- libosmscout-client/src/osmscoutclient/DBThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libosmscout-client/src/osmscoutclient/DBThread.cpp b/libosmscout-client/src/osmscoutclient/DBThread.cpp index 16f085a7d..aeb1d6b97 100644 --- a/libosmscout-client/src/osmscoutclient/DBThread.cpp +++ b/libosmscout-client/src/osmscoutclient/DBThread.cpp @@ -393,7 +393,7 @@ CancelableFuture DBThread::OnMapDPIChange(double dpi) CancelableFuture DBThread::SetStyleFlag(const std::string &key, bool value) { return Async([this, key, value](const Breaker&) -> bool{ - log.Debug() << "SetStyleFlag" << key << "to" << value; + log.Debug() << "SetStyleFlag " << key << " to " << value; std::unique_lock locker(lock); if (!isInitializedInternal()) { From 481fc9cc8cb67c054281360666dad915514e2f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sat, 6 Jan 2024 00:50:30 +0100 Subject: [PATCH 3/3] emit flagSet signal in Future callback --- .../include/osmscoutclientqt/StyleModule.h | 2 ++ .../src/osmscoutclientqt/StyleModule.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h b/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h index aae660fee..f14c26a8b 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h @@ -42,6 +42,8 @@ class OSMSCOUT_CLIENT_QT_API StyleModule:public QObject { QThread *thread; DBThreadRef dbThread; + std::shared_ptr alive=std::make_shared(true); + Slot dbLoadedSlot{ [this](const osmscout::GeoBox &b) { emit initialisationFinished(b); diff --git a/libosmscout-client-qt/src/osmscoutclientqt/StyleModule.cpp b/libosmscout-client-qt/src/osmscoutclientqt/StyleModule.cpp index 4baf9ece0..24db56747 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/StyleModule.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/StyleModule.cpp @@ -43,6 +43,7 @@ StyleModule::~StyleModule() if (thread!=nullptr){ thread->quit(); } + *alive=false; } void StyleModule::loadStyle(QString stylesheetFilename, @@ -69,7 +70,14 @@ void StyleModule::onStyleChanged() void StyleModule::onSetFlagRequest(QString key, bool value) { - dbThread->SetStyleFlag(key.toStdString(), value); - emit flagSet(key, value); + qDebug() << "Setting flag" << key << "to" << value; + auto thisAlive=alive; + dbThread->SetStyleFlag(key.toStdString(), value) + .OnComplete([this, key, value, thisAlive](const bool &){ + if (*thisAlive) { // avoid to call slot with deleted object + emit flagSet(key, value); + } + qDebug() << "Flag" << key << "setup done (" << value << ")"; + }); } }