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:
+11
-41
@@ -8,6 +8,7 @@
|
|||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include "timemodel.h"
|
#include "timemodel.h"
|
||||||
|
#include "qvectorhelper.h"
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -150,7 +151,7 @@ void Training::shellSlot(int time, int sector){
|
|||||||
VecShell.last().push_back(time);
|
VecShell.last().push_back(time);
|
||||||
|
|
||||||
// add sum to vector
|
// 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
|
// best time on widget
|
||||||
|
|
||||||
if(getCurTime(VecShell.last()) <= getMin(VecShell)){
|
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){
|
||||||
ui->lBestZeitShell->setText(QString::number((double)getMin(VecShell)/1000));
|
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;
|
break;
|
||||||
@@ -222,7 +223,7 @@ void Training::deaSlot(int time, int sector){
|
|||||||
VecDea.last().push_back(time);
|
VecDea.last().push_back(time);
|
||||||
|
|
||||||
// add sum to vector
|
// 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
|
// best time on widget
|
||||||
cout << "cur time: " << getCurTime(VecDea.last()) << endl;
|
cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl;
|
||||||
cout << "min time: " << getMin(VecDea) << endl;
|
cout << "min time: " << QVectorHelper::getMin(VecDea) << endl;
|
||||||
if(getCurTime(VecDea.last()) <= getMin(VecDea)){
|
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){
|
||||||
ui->lBestZeitDea->setText(QString::number((double)getMin(VecDea)/1000));
|
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;
|
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()
|
Training::~Training()
|
||||||
{
|
{
|
||||||
this->Hardware->setStop();
|
this->Hardware->setStop();
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ private:
|
|||||||
QVector<QVector<int>> VecShell;
|
QVector<QVector<int>> VecShell;
|
||||||
QVector<QVector<int>> VecDea;
|
QVector<QVector<int>> VecDea;
|
||||||
long getMinimum(std::vector<long> a);
|
long getMinimum(std::vector<long> a);
|
||||||
int getCurTime(const QVector<int> x) const;
|
|
||||||
int getMin(const QVector<QVector<int>> x) const;
|
|
||||||
|
|
||||||
|
|
||||||
bool paused;
|
bool paused;
|
||||||
bool finished;
|
bool finished;
|
||||||
|
|||||||
Reference in New Issue
Block a user