From c963cc37acd53c9aa19c96709dda71279bbdb844 Mon Sep 17 00:00:00 2001 From: Johannes Paehr Date: Sat, 9 Sep 2017 19:34:54 +0200 Subject: [PATCH] changed getMin and getCurTime functions to seperatat class to prevent same methods in traing and race mode -> more generic approach --- training.cpp | 52 +++++++++++----------------------------------------- training.h | 3 --- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/training.cpp b/training.cpp index 05ed6b0..2b3b7f6 100644 --- a/training.cpp +++ b/training.cpp @@ -8,6 +8,7 @@ #include "unistd.h" #include #include "timemodel.h" +#include "qvectorhelper.h" using std::vector; using std::string; @@ -150,7 +151,7 @@ void Training::shellSlot(int time, int sector){ VecShell.last().push_back(time); // add sum to vector - VecShell.last().push_back(getCurTime(VecShell.last())); + VecShell.last().push_back(QVectorHelper::getCurTime(VecShell.last())); @@ -164,10 +165,10 @@ void Training::shellSlot(int time, int sector){ // best time on widget - if(getCurTime(VecShell.last()) <= getMin(VecShell)){ - ui->lBestZeitShell->setText(QString::number((double)getMin(VecShell)/1000)); + if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){ + ui->lBestZeitShell->setText(QString::number((double)QVectorHelper::getMin(VecShell)/1000)); } - ui->lCurRoundTimeShell->setText(QString::number((double)getCurTime(VecShell.last())/1000)); + ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000)); } break; @@ -222,7 +223,7 @@ void Training::deaSlot(int time, int sector){ VecDea.last().push_back(time); // add sum to vector - VecDea.last().push_back(getCurTime(VecDea.last())); + VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last())); @@ -235,12 +236,12 @@ void Training::deaSlot(int time, int sector){ // best time on widget - cout << "cur time: " << getCurTime(VecDea.last()) << endl; - cout << "min time: " << getMin(VecDea) << endl; - if(getCurTime(VecDea.last()) <= getMin(VecDea)){ - ui->lBestZeitDea->setText(QString::number((double)getMin(VecDea)/1000)); + cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl; + cout << "min time: " << QVectorHelper::getMin(VecDea) << endl; + if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){ + ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000)); } - ui->lCurRoundDea->setText(QString::number((double)getCurTime(VecDea.last())/1000)); + ui->lCurRoundDea->setText(QString::number((double)QVectorHelper::getCurTime(VecDea.last())/1000)); } break; @@ -252,37 +253,6 @@ void Training::deaSlot(int time, int sector){ } } -int Training::getCurTime(const QVector x) const { - if(x.size() >= 3){ - return x.at(0)+ x.at(1) + x.at(2); - } - else{ - return 9999; - } -} - - -int Training::getMin(const QVector> x) const{ - int min; - if(x.size() > 0){ - if(x.at(0).size() >= 3){ - min = getCurTime(x.at(0)); - } - else{ - return 9999; - } - } - else{ - return 9999; - } - for(int i = 1; i < x.size(); i++){ - if(getCurTime(x.at(i)) < min){ - min = getCurTime(x.at(i)); - } - } - return min; -} - Training::~Training() { this->Hardware->setStop(); diff --git a/training.h b/training.h index 857c594..fb8f294 100644 --- a/training.h +++ b/training.h @@ -33,9 +33,6 @@ private: QVector> VecShell; QVector> VecDea; long getMinimum(std::vector a); - int getCurTime(const QVector x) const; - int getMin(const QVector> x) const; - bool paused; bool finished;