multiple timers are now officially supported

This commit is contained in:
dorian 2019-09-08 00:50:03 +02:00
parent 1f055931f7
commit 499cd247d4
4 changed files with 30 additions and 10 deletions

View file

@ -13,7 +13,7 @@ class SpeedTimer : public QObject
public: public:
explicit SpeedTimer(QObject *parent = nullptr); explicit SpeedTimer(QObject *parent = nullptr);
enum timerState { IDLE, STARTING, WAITING, RUNNING, STOPPED, FAILED, CANCELLED }; enum timerState { IDLE, STARTING, WAITING, RUNNING, WON, LOST, FAILED, CANCELLED, DISABLED };
timerState state; timerState state;
// variables for capturing the time // variables for capturing the time

View file

@ -187,7 +187,11 @@ Window {
height: parent.height height: parent.height
elide: "ElideRight" elide: "ElideRight"
color: appTheme.style.textColor color: speedBackend.timers[index]["state"] === "WON" ? "green" :
speedBackend.timers[index]["state"] === "LOST" ? "red":
appTheme.style.textColor
enabled: speedBackend.timers[index]["state"] !== "DISABLED"
text: speedBackend.timers[index]["text"] text: speedBackend.timers[index]["text"]

View file

@ -394,7 +394,7 @@ void ClimbingRace::refreshTimerText() {
QVariantList newTimerTextList; QVariantList newTimerTextList;
foreach(SpeedTimer * timer, this->speedTimers){ foreach(SpeedTimer * timer, this->speedTimers){
QVariantMap timerMap = {{"text",timer->getText()}, {"reacttime", timer->reactionTime}}; QVariantMap timerMap = {{"text",timer->getText()}, {"reacttime", timer->reactionTime}, {"state", timer->getState()}};
newTimerTextList.append(timerMap); newTimerTextList.append(timerMap);
} }

View file

@ -47,7 +47,7 @@ bool SpeedTimer::stop(int type, bool force) {
{ {
this->stopTime = this->date->currentMSecsSinceEpoch(); this->stopTime = this->date->currentMSecsSinceEpoch();
this->stoppedTime = this->stopTime - this->startTime; this->stoppedTime = this->stopTime - this->startTime;
this->setState(STOPPED); this->setState(WON);
break; break;
} }
case 1: case 1:
@ -71,7 +71,7 @@ bool SpeedTimer::stop(int type, bool force) {
} }
bool SpeedTimer::reset(bool force){ bool SpeedTimer::reset(bool force){
if( ( this->state != STOPPED && this->state != FAILED && this->state != CANCELLED ) && !force){ if( ( this->state < WON ) && !force){
return false; return false;
} }
@ -103,12 +103,16 @@ QString SpeedTimer::getState(){
return ("WAITING"); return ("WAITING");
case RUNNING: case RUNNING:
return("RUNNING"); return("RUNNING");
case STOPPED: case WON:
return("STOPPED"); return "WON";
case LOST:
return "LOST";
case FAILED: case FAILED:
return("FAILED"); return("FAILED");
case CANCELLED: case CANCELLED:
return("CANCELLED"); return("CANCELLED");
case DISABLED:
return "DISABLED";
} }
return "ERROR"; return "ERROR";
} }
@ -141,7 +145,10 @@ QString SpeedTimer::getText() {
case SpeedTimer::RUNNING: case SpeedTimer::RUNNING:
newText = QString::number( this->getCurrTime() / 1000.0, 'f', 3 ) + " sec"; newText = QString::number( this->getCurrTime() / 1000.0, 'f', 3 ) + " sec";
break; break;
case SpeedTimer::STOPPED: case SpeedTimer::WON:
newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec";
break;
case SpeedTimer::LOST:
newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec"; newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec";
break; break;
case SpeedTimer::FAILED: case SpeedTimer::FAILED:
@ -150,6 +157,9 @@ QString SpeedTimer::getText() {
case SpeedTimer::CANCELLED: case SpeedTimer::CANCELLED:
newText = tr("Cancelled"); newText = tr("Cancelled");
break; break;
case SpeedTimer::DISABLED:
newText = "---";
break;
} }
return newText; return newText;
@ -182,12 +192,18 @@ SpeedTimer::timerState SpeedTimer::stateFromString(QString state){
else if (state == "RUNNING") { else if (state == "RUNNING") {
return RUNNING; return RUNNING;
} }
else if (state == "STOPPED") { else if (state == "WON") {
return STOPPED; return WON;
}
else if (state == "LOST") {
return LOST;
} }
else if (state == "FAILED") { else if (state == "FAILED") {
return FAILED; return FAILED;
} }
else if(state == "DISABLED") {
return DISABLED;
}
else { else {
return CANCELLED; return CANCELLED;
} }