From ee5db49e5205409688f58954f76cb446afdd9116 Mon Sep 17 00:00:00 2001 From: Johannes Paehr Date: Tue, 12 Sep 2017 17:17:31 +0200 Subject: [PATCH] added second part of minimum sector times --- timemodel.cpp | 20 ++++++++++++++++++-- timemodel.h | 5 +++-- training.cpp | 24 ++++++++++++++++-------- training.h | 1 + windowrace.cpp | 24 ++++++++++++++++-------- windowrace.h | 1 + 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/timemodel.cpp b/timemodel.cpp index 91b86e2..d05849c 100644 --- a/timemodel.cpp +++ b/timemodel.cpp @@ -4,16 +4,18 @@ #include -TimeModel::TimeModel(QVector> timeData, QObject *parent) +TimeModel::TimeModel(QVector> timeData, QVector minimumTimes, QObject *parent) : QAbstractTableModel(parent) { this->timeData = timeData; + this->minimumTimes = minimumTimes; } -TimeModel::TimeModel(QVector> timeData, QVector topTime, QObject *parent) +TimeModel::TimeModel(QVector> timeData, QVector minimumTimes, QVector topTime, QObject *parent) : QAbstractTableModel(parent) { this->topTime = topTime; this->timeData = timeData; + this->minimumTimes = minimumTimes; } QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -62,6 +64,20 @@ QColor TimeModel::getColor(const QVector> data, const int col, cons } else if(data.size() > row){ // check for enough rows if(data.at(row).size() > col){ // check for enough cols + if(col < 3){ + if(data.at(row).at(col) < this->minimumTimes.at(col)){ + return QColor(Qt::red); + } + } + else{ + // lap time + if( data.at(row).at(0) < this->minimumTimes.at(0) + || data.at(row).at(1) < this->minimumTimes.at(1) + || data.at(row).at(2) < this->minimumTimes.at(2)){ + return QColor(Qt::red); + } + } + QVector compare; for(int i = 0; i <= row; i++){ if(data.at(i).size() > col){ diff --git a/timemodel.h b/timemodel.h index 8dbc6b0..b7811db 100644 --- a/timemodel.h +++ b/timemodel.h @@ -10,8 +10,8 @@ class TimeModel : public QAbstractTableModel Q_OBJECT public: - explicit TimeModel(QVector> timeData, QObject *parent = nullptr); - explicit TimeModel(QVector> timeData, QVector topTime, QObject *parent = nullptr); + explicit TimeModel(QVector> timeData, QVector minimumTimes, QObject *parent = nullptr); + explicit TimeModel(QVector> timeData, QVector minimumTimes, QVector topTime, QObject *parent = nullptr); // Header: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; @@ -32,6 +32,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; + QVector minimumTimes; }; #endif // TIMEMODEL_H diff --git a/training.cpp b/training.cpp index fa509fb..a7050e3 100644 --- a/training.cpp +++ b/training.cpp @@ -55,12 +55,20 @@ Training::Training(QWidget *parent, DataBase *db) : QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this, SLOT(ResetDea())); QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this, SLOT(ResetShell())); + // fill minSecTimes vector + statement = "select minsec1, minsec2, minsec3 from renndauer order by id DESC limit 1"; + vector< vector< QString > > res; + res = db->getData(statement, 3); + this->minSecTime.append(res[0][0].toInt()); + this->minSecTime.append(res[0][1].toInt()); + this->minSecTime.append(res[0][2].toInt()); + } void Training::ResetShell(){ this->VecShell.clear(); // this->ui->lWShellTime->clear(); - timeModelShell = new TimeModel(VecShell, this); + timeModelShell = new TimeModel(VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell); this->ui->lBestZeitShell->setText("∞"); @@ -71,7 +79,7 @@ void Training::ResetDea(){ this->VecDea.clear(); //this->ui->lWDeaTime->clear(); - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lBestZeitDea->setText("∞"); @@ -117,7 +125,7 @@ void Training::shellSlot(int time, int sector){ VecShell.push_back(QVector()); VecShell.last().push_back(time); - timeModelShell = new TimeModel(VecShell, this); + timeModelShell = new TimeModel(VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell); break; @@ -126,7 +134,7 @@ void Training::shellSlot(int time, int sector){ if(VecShell.last().size() == 1){ // cout << time << sector << endl; VecShell.last().push_back(time); - timeModelShell = new TimeModel(VecShell, this); + timeModelShell = new TimeModel(VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell); } } @@ -141,7 +149,7 @@ void Training::shellSlot(int time, int sector){ // add sum to vector VecShell.last().push_back(QVectorHelper::getCurTime(VecShell.last())); - timeModelShell = new TimeModel(VecShell, this); + timeModelShell = new TimeModel(VecShell, minSecTime, this); this->ui->lWShellTime->setModel(timeModelShell); } // best time on widget @@ -183,7 +191,7 @@ void Training::deaSlot(int time, int sector){ VecDea.push_back(QVector()); VecDea.last().push_back(time); // cout << "Dea Sektor 1" << endl; - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); break; @@ -192,7 +200,7 @@ void Training::deaSlot(int time, int sector){ if(VecDea.last().size() == 1){ // cout << time << sector << endl; VecDea[VecDea.size()-1].push_back(time); - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); } else{ @@ -210,7 +218,7 @@ void Training::deaSlot(int time, int sector){ // add sum to vector VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last())); - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); } // best time on widget diff --git a/training.h b/training.h index fb8f294..cf1b045 100644 --- a/training.h +++ b/training.h @@ -45,6 +45,7 @@ private: // timeModel TimeModel *timeModelDea; TimeModel *timeModelShell; + QVector minSecTime; public slots: void ResetShell(); diff --git a/windowrace.cpp b/windowrace.cpp index 9c085cb..acee636 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -35,6 +35,14 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) : res = db->getData(statement, 1); this->minimumTime = res[0][0].toInt(); + // fill minSecTimes vector + statement = "select minsec1, minsec2, minsec3 from renndauer order by id DESC limit 1"; + res = db->getData(statement, 3); + this->minSecTime.append(res[0][0].toInt()); + this->minSecTime.append(res[0][1].toInt()); + this->minSecTime.append(res[0][2].toInt()); + + firstTimeDea = true; firstTimeShell = true; started = false; @@ -169,11 +177,11 @@ void WindowRace::prepareNextRace(){ this->VecDea.clear(); // clear tableview shell - timeModelShell = new TimeModel(VecShell); + timeModelShell = new TimeModel(VecShell, minSecTime); ui->lWShellTime->setModel(timeModelShell); // clear tableview dea - timeModelDea = new TimeModel(VecDea); + timeModelDea = new TimeModel(VecDea, minSecTime); ui->lWDeaTime->setModel(timeModelDea); this->finished = false; @@ -348,7 +356,7 @@ void WindowRace::shellSlot(int time, int sector){ test.append(1); test.append(2); test.append(3); - this->timeModelShell = new TimeModel(VecShell, test, this); + this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); // this->ui->lWShellTime->setModel(this->timeModelShell); ui->lWShellTime->setModel(this->timeModelShell); break; @@ -363,7 +371,7 @@ void WindowRace::shellSlot(int time, int sector){ test.append(1); test.append(2); test.append(3); - this->timeModelShell = new TimeModel(VecShell, test, this); + this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); // timeModelShell = new TimeModel(VecShell, this); this->ui->lWShellTime->setModel(timeModelShell); } @@ -384,7 +392,7 @@ void WindowRace::shellSlot(int time, int sector){ test.append(1); test.append(2); test.append(3); - this->timeModelShell = new TimeModel(VecShell, test, this); + this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); // timeModelShell = new TimeModel(VecShell, this); this->ui->lWShellTime->setModel(timeModelShell); int zeit = QVectorHelper::getMin(VecShell); @@ -424,7 +432,7 @@ void WindowRace::deaSlot(int time, int sector){ VecDea.push_back(QVector()); VecDea.last().push_back(time); cout << "Dea Sektor 1" << endl; - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); break; @@ -433,7 +441,7 @@ void WindowRace::deaSlot(int time, int sector){ if(VecDea.last().size() == 1){ cout << time << sector << endl; VecDea[VecDea.size()-1].push_back(time); - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); } else{ @@ -453,7 +461,7 @@ void WindowRace::deaSlot(int time, int sector){ - timeModelDea = new TimeModel(VecDea, this); + timeModelDea = new TimeModel(VecDea, minSecTime, this); this->ui->lWDeaTime->setModel(timeModelDea); diff --git a/windowrace.h b/windowrace.h index 845c71e..835d3ca 100644 --- a/windowrace.h +++ b/windowrace.h @@ -62,6 +62,7 @@ private: int fahrzeit; int renn_id; int minimumTime; + QVector minSecTime; public slots: void stopClicked();