changed getMin and getCurTime functions to seperatat class to prevent same methods in traing and race mode -> more generic approach
This commit is contained in:
52
training.cpp
52
training.cpp
@@ -8,6 +8,7 @@
|
||||
#include "unistd.h"
|
||||
#include <QListWidgetItem>
|
||||
#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<int> x) const {
|
||||
if(x.size() >= 3){
|
||||
return x.at(0)+ x.at(1) + x.at(2);
|
||||
}
|
||||
else{
|
||||
return 9999;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Training::getMin(const QVector<QVector<int>> 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();
|
||||
|
||||
Reference in New Issue
Block a user