mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2024-11-28 02:43:49 -06:00
qt: add ReadableObsevable
This commit is contained in:
parent
587475e81b
commit
05b437e454
15
src/modules/interface/qt/data/ReadableObservable.cpp
Normal file
15
src/modules/interface/qt/data/ReadableObservable.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "ReadableObservable.h"
|
||||
|
||||
ReadableObservable::ReadableObservable(ReadableData *data, QObject *parent) : QObject(parent) {
|
||||
m_readableData = data;
|
||||
|
||||
m_emitTimer = new QTimer;
|
||||
}
|
||||
|
||||
void ReadableObservable::setInterval(std::chrono::milliseconds msecs) {
|
||||
m_emitTimer->start(msecs);
|
||||
|
||||
connect(m_emitTimer, &QTimer::timeout, [=]() {
|
||||
emit valueUpdated(m_latestValue);
|
||||
});
|
||||
}
|
20
src/modules/interface/qt/data/ReadableObservable.h
Normal file
20
src/modules/interface/qt/data/ReadableObservable.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include "ReadableData.h"
|
||||
|
||||
class ReadableObservable : public QObject {
|
||||
public:
|
||||
ReadableObservable(ReadableData *data, QObject *parent = nullptr);
|
||||
void setInterval(std::chrono::milliseconds msecs); // Set the emission interval
|
||||
signals:
|
||||
void valueUpdated(tc_readable_result_t value);
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
ReadableData *m_readableData;
|
||||
QTimer *m_emitTimer;
|
||||
tc_readable_result_t m_latestValue;
|
||||
};
|
Loading…
Reference in New Issue
Block a user