mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 16:31:31 +00:00
Ensures proper thread confinement for updateStatusBarText
.
This commit is contained in:
parent
a2db6ddea5
commit
7c05b1788e
@ -1338,24 +1338,25 @@ void MainWindow::addActivityObserver() {
|
||||
}
|
||||
|
||||
void MainWindow::register_led(const std::string &name) {
|
||||
std::lock_guard guard(ledStatusesLock);
|
||||
ledStatuses[name] = false;
|
||||
updateStatusBarText();
|
||||
QMetaObject::invokeMethod(this, "updateStatusBarText");
|
||||
}
|
||||
|
||||
void MainWindow::set_led_status(const std::string &name, bool isLit) {
|
||||
std::lock_guard guard(ledStatusesLock);
|
||||
ledStatuses[name] = isLit;
|
||||
updateStatusBarText(); // Assumption here: Qt's attempt at automatic thread confinement will work here.
|
||||
QMetaObject::invokeMethod(this, "updateStatusBarText");
|
||||
}
|
||||
|
||||
void MainWindow::updateStatusBarText() {
|
||||
QString fullText;
|
||||
bool isFirst = true;
|
||||
std::lock_guard guard(ledStatusesLock);
|
||||
for(const auto &pair: ledStatuses) {
|
||||
if(!isFirst) fullText += " | ";
|
||||
if(!fullText.isEmpty()) fullText += " | ";
|
||||
fullText += QString::fromStdString(pair.first);
|
||||
fullText += " ";
|
||||
fullText += pair.second ? "■" : "□";
|
||||
isFirst = false;
|
||||
}
|
||||
statusBar()->showMessage(fullText);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
#include "audiobuffer.h"
|
||||
@ -80,6 +81,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
||||
|
||||
private slots:
|
||||
void startMachine();
|
||||
void updateStatusBarText();
|
||||
|
||||
private:
|
||||
void start_appleII();
|
||||
@ -144,9 +146,11 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
||||
|
||||
void register_led(const std::string &) override;
|
||||
void set_led_status(const std::string &, bool) override;
|
||||
|
||||
std::recursive_mutex ledStatusesLock;
|
||||
std::map<std::string, bool> ledStatuses;
|
||||
|
||||
void addActivityObserver();
|
||||
void updateStatusBarText();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
Loading…
Reference in New Issue
Block a user