diff --git a/windowrace.cpp b/windowrace.cpp index e1e7258..fc85fff 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -26,6 +26,10 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) : res = db->getData("select dauer from renndauer", 1); this->fahrzeit = res[0][0].toInt(); + string statement = "select minimumroundtime from rennen order by id DESC limit 1"; + res = db->getData(statement, 1); + this->minimumTime = res[0][0].toInt(); + firstTimeDea = true; firstTimeShell = true; started = false; @@ -76,7 +80,7 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) : ui->hW11->setVisible(true); ui->hW21->setVisible(true); - string statement; + vector< vector > fahrer, autos, rennid, tableData; statement = "select id_rennen from aktrennen group by id_rennen order by id_rennen DESC limit 1"; rennid = this->db->getData(statement, 1); @@ -260,14 +264,19 @@ void WindowRace::shellSlot(){ if(getMinimum(VecShell) == zeit && VecShell.size() > 1){ item->setBackgroundColor(Qt::green); } + if(zeit < this->minimumTime){ + item->setBackgroundColor(Qt::red); + } item->setText(QString::number((double)zeit/1000)); ui->lWShellTime->addItem(item); QString statement = "insert into Zeiten (id_rennen, id_fahrer, id_auto, id_bahn, zeit) values ("+QString::number(this->renn_id)+ ", "+QString::number(this->shellDriverId)+", "+QString::number(this->shellCarId)+", 1, "+QString::number(zeit)+")"; - cout << statement.toStdString() << endl; + //cout << statement.toStdString() << endl; this->db->setData(statement.toStdString()); ui->lWShellTime->scrollToBottom(); - ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000)); + if(getMinimum(VecShell) > 0){ + ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000)); + } ui->lCurRoundTimeShell->setText(QString::number((double)zeit/1000)); } } @@ -285,27 +294,37 @@ void WindowRace::deaSlot(){ if(getMinimum(VecDea) == zeit && VecDea.size() > 1){ item->setBackgroundColor(Qt::green); } + if(zeit < this->minimumTime){ + item->setBackgroundColor(Qt::red); + } item->setText(QString::number((double)zeit/1000)); ui->lWDeaTime->addItem(item); QString statement = "insert into Zeiten (id_rennen, id_fahrer, id_auto, id_bahn, zeit) values ("+QString::number(this->renn_id)+ ", "+QString::number(this->deaDriverId)+", "+QString::number(this->deaCarId)+", 2, "+QString::number(zeit)+")"; - cout << statement.toStdString() << endl; + //cout << statement.toStdString() << endl; this->db->setData(statement.toStdString()); ui->lWDeaTime->scrollToBottom(); - ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000)); + if(getMinimum(VecDea) > 0){ + ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000)); + } ui->lCurRoundDea->setText(QString::number((double)zeit/1000)); } } } long WindowRace::getMinimum(std::vector a){ - long minimum = a[0]; + long minimum = a[0]; //could be wrong for(unsigned int i = 0; i < a.size(); i++){ - if(a[i] < minimum){ + if(a[i] < minimum && a[i] >= this->minimumTime){ minimum = a[i]; } } - return minimum; + if(minimum >= this->minimumTime){ + return minimum; + } + else{ + return -1; + } } void WindowRace::ampelSlot(){ if(ampelCounter == 5){ diff --git a/windowrace.h b/windowrace.h index d93c44a..98892d3 100644 --- a/windowrace.h +++ b/windowrace.h @@ -57,6 +57,7 @@ private: WindowRennliste *wRennliste; int fahrzeit; int renn_id; + int minimumTime; public slots: void stopClicked();