40 lines
652 B
C++
40 lines
652 B
C++
#pragma once
|
|
|
|
#include <qtimer.h>
|
|
|
|
#include "service.hpp"
|
|
|
|
namespace ZShell::services {
|
|
|
|
class TickingService : public Service {
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(
|
|
int updateInterval READ updateInterval NOTIFY updateIntervalChanged)
|
|
|
|
public:
|
|
explicit TickingService(QObject* parent = nullptr);
|
|
|
|
[[nodiscard]] int updateInterval() const;
|
|
|
|
signals:
|
|
void updateIntervalChanged();
|
|
void updateTriggered();
|
|
|
|
protected:
|
|
void start() final;
|
|
void stop() final;
|
|
|
|
virtual void tick() = 0;
|
|
virtual void onStopped() {}
|
|
|
|
private:
|
|
void applyInterval(int ms);
|
|
|
|
QTimer* m_timer;
|
|
int m_interval = 1000;
|
|
bool m_running = false;
|
|
};
|
|
|
|
} // namespace ZShell::services
|