Skip to content

Commit

Permalink
Merge pull request #1554 from Karry/style-module-fix
Browse files Browse the repository at this point in the history
Style module fix
  • Loading branch information
Framstag authored Jan 6, 2024
2 parents e4d9131 + 481fc9c commit 7e7378e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions libosmscout-client-qt/include/osmscoutclientqt/StyleModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class OSMSCOUT_CLIENT_QT_API StyleModule:public QObject {
QThread *thread;
DBThreadRef dbThread;

std::shared_ptr<bool> alive=std::make_shared<bool>(true);

Slot<osmscout::GeoBox> dbLoadedSlot{
[this](const osmscout::GeoBox &b) {
emit initialisationFinished(b);
Expand Down
12 changes: 10 additions & 2 deletions libosmscout-client-qt/src/osmscoutclientqt/StyleModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ StyleModule::~StyleModule()
if (thread!=nullptr){
thread->quit();
}
*alive=false;
}

void StyleModule::loadStyle(QString stylesheetFilename,
Expand All @@ -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 << ")";
});
}
}
2 changes: 1 addition & 1 deletion libosmscout-client/src/osmscoutclient/DBThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ CancelableFuture<bool> DBThread::OnMapDPIChange(double dpi)
CancelableFuture<bool> DBThread::SetStyleFlag(const std::string &key, bool value)
{
return Async<bool>([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()) {
Expand Down
2 changes: 1 addition & 1 deletion libosmscout/include/osmscout/async/CancelableFuture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 7e7378e

Please sign in to comment.