add to indexedTimer single shot and remaining time
This commit is contained in:
@@ -38,6 +38,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setIndexedTimerType(Index index, Qt::TimerType type) { timers[index].type = type; }
|
void setIndexedTimerType(Index index, Qt::TimerType type) { timers[index].type = type; }
|
||||||
|
void setIndexedTimerSingleShot(Index index, bool yes) { timers[index].single_shot = yes; }
|
||||||
void bindIndexedTimer(Index index, std::function<void()> func) { timers[index].func = func; }
|
void bindIndexedTimer(Index index, std::function<void()> func) { timers[index].func = func; }
|
||||||
void stopIndexedTimer(Index index) {
|
void stopIndexedTimer(Index index) {
|
||||||
auto & t(timers[index]);
|
auto & t(timers[index]);
|
||||||
@@ -54,10 +55,18 @@ public:
|
|||||||
}
|
}
|
||||||
t.timer = new QTimer();
|
t.timer = new QTimer();
|
||||||
t.timer->setTimerType(t.type);
|
t.timer->setTimerType(t.type);
|
||||||
|
t.timer->setSingleShot(t.single_shot);
|
||||||
QObject::connect(t.timer, &QTimer::timeout, t.func);
|
QObject::connect(t.timer, &QTimer::timeout, t.func);
|
||||||
t.timer->start(interval.toMilliseconds());
|
t.timer->start(interval.toMilliseconds());
|
||||||
}
|
}
|
||||||
bool isIndexedTimerStarted(Index index) const { return timers.value(index).isValid(); }
|
bool isIndexedTimerStarted(Index index) const { return timers.value(index).isValid(); }
|
||||||
|
PISystemTime indexedTimerRemainingTime(Index index) const {
|
||||||
|
const __TimerSlot & t(timers[index]);
|
||||||
|
if (!t.timer) return {};
|
||||||
|
int ms = t.timer->remainingTime();
|
||||||
|
if (ms < 0) return {};
|
||||||
|
return PISystemTime::fromMilliseconds(ms);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct __TimerSlot {
|
struct __TimerSlot {
|
||||||
@@ -69,6 +78,7 @@ private:
|
|||||||
}
|
}
|
||||||
std::function<void()> func = nullptr;
|
std::function<void()> func = nullptr;
|
||||||
QTimer * timer = nullptr;
|
QTimer * timer = nullptr;
|
||||||
|
bool single_shot = false;
|
||||||
Qt::TimerType type = Qt::CoarseTimer;
|
Qt::TimerType type = Qt::CoarseTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user