Commit 499cd247 authored by Dorian Zedler's avatar Dorian Zedler

multiple timers are now officially supported

parent 1f055931
......@@ -13,7 +13,7 @@ class SpeedTimer : public QObject
public:
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;
// variables for capturing the time
......
......@@ -187,7 +187,11 @@ Window {
height: parent.height
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"]
......
......@@ -394,7 +394,7 @@ void ClimbingRace::refreshTimerText() {
QVariantList newTimerTextList;
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);
}
......
......@@ -47,7 +47,7 @@ bool SpeedTimer::stop(int type, bool force) {
{
this->stopTime = this->date->currentMSecsSinceEpoch();
this->stoppedTime = this->stopTime - this->startTime;
this->setState(STOPPED);
this->setState(WON);
break;
}
case 1:
......@@ -71,7 +71,7 @@ bool SpeedTimer::stop(int type, 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;
}
......@@ -103,12 +103,16 @@ QString SpeedTimer::getState(){
return ("WAITING");
case RUNNING:
return("RUNNING");
case STOPPED:
return("STOPPED");
case WON:
return "WON";
case LOST:
return "LOST";
case FAILED:
return("FAILED");
case CANCELLED:
return("CANCELLED");
case DISABLED:
return "DISABLED";
}
return "ERROR";
}
......@@ -141,7 +145,10 @@ QString SpeedTimer::getText() {
case SpeedTimer::RUNNING:
newText = QString::number( this->getCurrTime() / 1000.0, 'f', 3 ) + " sec";
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";
break;
case SpeedTimer::FAILED:
......@@ -150,6 +157,9 @@ QString SpeedTimer::getText() {
case SpeedTimer::CANCELLED:
newText = tr("Cancelled");
break;
case SpeedTimer::DISABLED:
newText = "---";
break;
}
return newText;
......@@ -182,12 +192,18 @@ SpeedTimer::timerState SpeedTimer::stateFromString(QString state){
else if (state == "RUNNING") {
return RUNNING;
}
else if (state == "STOPPED") {
return STOPPED;
else if (state == "WON") {
return WON;
}
else if (state == "LOST") {
return LOST;
}
else if (state == "FAILED") {
return FAILED;
}
else if(state == "DISABLED") {
return DISABLED;
}
else {
return CANCELLED;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment