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:
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

View file

@ -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"]

View file

@ -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);
}

View file

@ -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;
}