some fixes for timer letter

This commit is contained in:
Dorian Zedler 2020-06-13 15:57:27 +02:00
parent f7629352dd
commit 190a231a7b
Signed by: dorian
GPG key ID: 989DE36109AFA354
3 changed files with 37 additions and 8 deletions

View file

@ -284,6 +284,16 @@ public slots:
*/ */
bool setReactionTime(double rectionTime); bool setReactionTime(double rectionTime);
/*!
* \brief Function to dircetly change the letter
*
* Only works when directControlEnabled is set to true!
*
* \param newLetter the letter to change to
* \return false when directControlEnabled is set to false and the letter was therefore not modified, true otherwise
*/
bool setLetter(QString newLetter);
protected slots: protected slots:
/*! /*!

View file

@ -207,6 +207,8 @@ bool ScStwRemoteMonitorRace::refreshRemoteTimers(QVariantList remoteTimers) {
this->timers[currId]->setReactionTime(remoteTimer.toMap()["reactionTime"].toDouble()); this->timers[currId]->setReactionTime(remoteTimer.toMap()["reactionTime"].toDouble());
this->timers[currId]->setState(newState, true); this->timers[currId]->setState(newState, true);
this->timers[currId]->setLetter(remoteTimer.toMap()["letter"].toString());
} }
return true; return true;

View file

@ -21,7 +21,12 @@
ScStwTimer::ScStwTimer(QObject *parent, bool directControlEnabled, QString letter) : QObject(parent) ScStwTimer::ScStwTimer(QObject *parent, bool directControlEnabled, QString letter) : QObject(parent)
{ {
this->directControlEnabled = directControlEnabled; this->directControlEnabled = directControlEnabled;
this->letter = letter;
if(letter.length() > 1)
this->letter = letter[0];
else
this->letter = letter;
this->startTime = 0; this->startTime = 0;
this->stopTime = 0; this->stopTime = 0;
this->reactionTime = 0; this->reactionTime = 0;
@ -199,6 +204,14 @@ void ScStwTimer::setState(TimerState newState){
} }
} }
bool ScStwTimer::setLetter(QString newLetter) {
if(!this->directControlEnabled)
return false;
this->letter = newLetter;
return true;
}
ScStwTimer::TimerState ScStwTimer::getState() { ScStwTimer::TimerState ScStwTimer::getState() {
return this->state; return this->state;
} }
@ -225,26 +238,27 @@ QString ScStwTimer::getLetter() {
} }
QString ScStwTimer::getText() { QString ScStwTimer::getText() {
//qDebug() << this->getState();
QString newText; QString newText = "";
int newTime = 0;
switch (this->state) { switch (this->state) {
case ScStwTimer::IDLE: case ScStwTimer::IDLE:
newText = "0.000 sec"; newTime = 0;
break; break;
case ScStwTimer::STARTING: case ScStwTimer::STARTING:
newText = "0.000 sec"; newTime = 0;
break; break;
case ScStwTimer::WAITING: case ScStwTimer::WAITING:
newText = "please wait..."; newText = "please wait...";
break; break;
case ScStwTimer::RUNNING: case ScStwTimer::RUNNING:
newText = QString::number( this->getCurrentTime() / 1000.0, 'f', 3 ) + " sec"; newTime = this->getCurrentTime();
break; break;
case ScStwTimer::WON: case ScStwTimer::WON:
newText = QString::number( this->getCurrentTime() / 1000.0, 'f', 3 ) + " sec"; newTime = this->getCurrentTime();
break; break;
case ScStwTimer::LOST: case ScStwTimer::LOST:
newText = QString::number( this->getCurrentTime() / 1000.0, 'f', 3 ) + " sec"; newTime = this->getCurrentTime();
break; break;
case ScStwTimer::FAILED: case ScStwTimer::FAILED:
newText = "false start"; newText = "false start";
@ -257,6 +271,9 @@ QString ScStwTimer::getText() {
break; break;
} }
if(newText == "")
newText = QString::number( newTime / 1000.0, 'f', 3 ).rightJustified(6, '0');
return newText; return newText;
} }