From 5255b40e7854b0221af9fd3e0af6fd303531867a Mon Sep 17 00:00:00 2001 From: Johannes Paehr Date: Tue, 12 Sep 2017 13:48:10 +0200 Subject: [PATCH] fix not termintated thread in windowrace + added preparation for highlighting absolute best times --- RennbahnZeitmessung.pro.user | 2 +- hardwaresetup.cpp | 14 +++++++++----- timemodel.cpp | 24 +++++++++++++++++++++++- timemodel.h | 2 ++ training.cpp | 20 ++++++++------------ windowrace.cpp | 23 +++++++++++++++++++---- 6 files changed, 62 insertions(+), 23 deletions(-) diff --git a/RennbahnZeitmessung.pro.user b/RennbahnZeitmessung.pro.user index 415f167..12e51c9 100644 --- a/RennbahnZeitmessung.pro.user +++ b/RennbahnZeitmessung.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index 7e27257..e774a52 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -178,31 +178,35 @@ void HardwareSetup::run(){ if(buffer[i].update != 0){ switch(buffer[i].id){ case 0: + cout << "Shell Zeit 1: " << (int)buffer[i].time << endl; emit Shell((int)buffer[i].time, 1); break; case 1: + cout << "Dea Zeit 1: " << (int)buffer[i].time << endl; emit Dea((int)buffer[i].time, 1); break; case 2: + cout << "Shell Zeit 2: " << (int)buffer[i].time << endl; emit Shell((int)buffer[i].time, 2); break; case 3: -// cout << "Time: vor emit" << (int)buffer[i].time << endl; + cout << "Dea Zeit 2: " << (int)buffer[i].time << endl; emit Dea((int)buffer[i].time, 2); break; case 4: -// cout << "emit shell" << endl; + cout << "Shell Zeit 2: " << (int)buffer[i].time << endl; emit Shell((int)buffer[i].time, 3); break; case 5: + cout << "Dea Zeit 3: " << (int)buffer[i].time << endl; emit Dea((int)buffer[i].time, 3); break; } } } -// if(buffer[0].update != 0){ -// cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time << ", " << (int)buffer[2].id << endl; -// } + if(buffer[0].update != 0){ + cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time << ", " << (int)buffer[2].id << endl; + } //} if(nBytes < 0) diff --git a/timemodel.cpp b/timemodel.cpp index 3084403..91b86e2 100644 --- a/timemodel.cpp +++ b/timemodel.cpp @@ -9,6 +9,12 @@ TimeModel::TimeModel(QVector> timeData, QObject *parent) { this->timeData = timeData; } +TimeModel::TimeModel(QVector> timeData, QVector topTime, QObject *parent) + : QAbstractTableModel(parent) +{ + this->topTime = topTime; + this->timeData = timeData; +} QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -62,7 +68,23 @@ QColor TimeModel::getColor(const QVector> data, const int col, cons compare.append(data.at(i).at(col)); } } - if(data.at(row).at(col) == getMin(compare)){ + if(data.at(row).at(col) == getMin(compare)){ // at least personal best time + if(col < 3){ // sector time +// std::cout << this->topTime.size() << std::endl; + if(this->topTime.size() > col){ // absolute top time exists +// std::cout << "local besttime" << std::endl; + if(this->topTime.at(col) >= data.at(row).at(col)){ + return QColor(Qt::magenta); + } + } + } + else{ // lap time + if(this->topTime.size() == 3){ + if(this->topTime.at(0) + this->topTime.at(1) + this->topTime.at(2) >= data.at(row).at(col)){ + return QColor(Qt::magenta); + } + } + } return QColor(Qt::green); } else{ diff --git a/timemodel.h b/timemodel.h index cedf1e0..8dbc6b0 100644 --- a/timemodel.h +++ b/timemodel.h @@ -11,6 +11,7 @@ class TimeModel : public QAbstractTableModel public: explicit TimeModel(QVector> timeData, QObject *parent = nullptr); + explicit TimeModel(QVector> timeData, QVector topTime, QObject *parent = nullptr); // Header: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; @@ -30,6 +31,7 @@ private: QColor getColor(const QVector> data, const int col, const int row) const; // row and col starts counting at 0 QVector> timeData; + QVector topTime; }; #endif // TIMEMODEL_H diff --git a/training.cpp b/training.cpp index f3e8298..fa509fb 100644 --- a/training.cpp +++ b/training.cpp @@ -80,17 +80,8 @@ void Training::ResetDea(){ this->firstTimeDea = true; } void Training::Reset(){ - this->VecShell.clear(); - this->VecDea.clear(); - // this->ui->lWDeaTime->clear(); - // this->ui->lWShellTime->clear(); - - this->ui->lBestZeitDea->setText("∞"); - this->ui->lBestZeitShell->setText("∞"); - this->ui->lCurRoundTimeShell->setText("∞"); - this->ui->lCurRoundDea->setText("∞"); - this->firstTimeShell = true; - this->firstTimeDea = true; + this->ResetDea(); + this->ResetShell(); } void Training::prepareNextRace(){ this->firstTimeShell = true; @@ -110,11 +101,12 @@ void Training::prepareNextRace(){ } void Training::shellSlot(int time, int sector){ - // cout << "Shell slot" << endl; // slot is called when a sector is finished // time is given in ms // counting of sector beginns at 1 + cout << "received Shelltime: " << time << sector << endl; + if(started && !paused && !this->finished){ if(firstTimeShell){ firstTimeShell = false; @@ -177,6 +169,10 @@ void Training::deaSlot(int time, int sector){ // slot is called when a sector is finished // time is given in ms // counting of sector beginns at 1 + + cout << "received Deatime: " << time << sector << endl; + + if(started && !paused && !this->finished){ if(firstTimeDea){ firstTimeDea = false; diff --git a/windowrace.cpp b/windowrace.cpp index 4b325a4..4019c56 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -25,7 +25,6 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) : this->wRennlisteSeted = false; - this->db = db; vector< vector< QString > > res; @@ -240,6 +239,7 @@ void WindowRace::setDriverAndCarId(vector vec){ } void WindowRace::closeEvent(QCloseEvent *event){ countdown->setStop(); + this->Hardware->setStop(); QMessageBox msgBox; msgBox.setText("Wirklich schliessen?"); @@ -337,13 +337,18 @@ void WindowRace::shellSlot(int time, int sector){ } else{ // long zeit = counterShell.getTime(); + QVector test; switch(sector){ case 1: VecShell.append(QVector()); VecShell.last().append(time); // update tableview - this->timeModelShell = new TimeModel(VecShell, this); + + test.append(1); + test.append(2); + test.append(3); + this->timeModelShell = new TimeModel(VecShell, test, this); // this->ui->lWShellTime->setModel(this->timeModelShell); ui->lWShellTime->setModel(this->timeModelShell); break; @@ -354,7 +359,12 @@ void WindowRace::shellSlot(int time, int sector){ VecShell.last().append(time); } // update tableview - timeModelShell = new TimeModel(VecShell, this); + + test.append(1); + test.append(2); + test.append(3); + this->timeModelShell = new TimeModel(VecShell, test, this); +// timeModelShell = new TimeModel(VecShell, this); this->ui->lWShellTime->setModel(timeModelShell); } break; @@ -370,7 +380,12 @@ void WindowRace::shellSlot(int time, int sector){ ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000)); // update tableview - timeModelShell = new TimeModel(VecShell, this); + + test.append(1); + test.append(2); + test.append(3); + this->timeModelShell = new TimeModel(VecShell, test, this); +// timeModelShell = new TimeModel(VecShell, this); this->ui->lWShellTime->setModel(timeModelShell); int zeit = QVectorHelper::getMin(VecShell); QString statement = "insert into Zeiten (id_rennen, id_fahrer, id_auto, id_bahn, zeit) values ("+QString::number(this->renn_id)+