199 lines
7.2 KiB
C++
199 lines
7.2 KiB
C++
#include "windowrennliste.h"
|
|
#include "ui_windowrennliste.h"
|
|
#include "windowrace.h"
|
|
#include <QBrush>
|
|
#include <QColor>
|
|
#include <QDebug>
|
|
#include <iostream>
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent)
|
|
: QMainWindow(parent), ui(new Ui::WindowRennliste) {
|
|
ui->setupUi(this);
|
|
|
|
this->windowClose = false;
|
|
|
|
this->selectedRow = 0;
|
|
|
|
this->ui->tWRennliste->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
this->ui->tWRennliste->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
QObject::connect(this->ui->tWRennliste,
|
|
SIGNAL(doubleClicked(const QModelIndex &)), this,
|
|
SLOT(listClick(const QModelIndex &)));
|
|
this->db = db;
|
|
|
|
string statement;
|
|
vector<vector<QString>> fahrer, autos, rennid;
|
|
statement = "select id_rennen from aktrennen group by id_rennen order by "
|
|
"id_rennen DESC limit 1";
|
|
rennid = this->db->getData(statement, 1);
|
|
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
|
|
"from aktrennen where id_rennen like " +
|
|
rennid[0][0].toStdString();
|
|
|
|
this->tableData = db->getData(statement, 4);
|
|
this->ui->tWRennliste->setRowCount(this->tableData.size());
|
|
this->ui->tWRennliste->setColumnCount(6);
|
|
QStringList header;
|
|
header << "Fahrer"
|
|
<< "Auto"
|
|
<< "Zeit"
|
|
<< "Fahrer"
|
|
<< "Auto"
|
|
<< "Zeit";
|
|
|
|
this->ui->tWRennliste->setHorizontalHeaderLabels(header);
|
|
|
|
for (int i = 0; i < this->ui->tWRennliste->horizontalHeader()->count();
|
|
i++) {
|
|
this->ui->tWRennliste->horizontalHeader()->setSectionResizeMode(
|
|
i, QHeaderView::Stretch);
|
|
}
|
|
|
|
for (unsigned int i = 0; i < tableData.size(); i++) {
|
|
statement = "select name from fahrer where id like " +
|
|
tableData[i][0].toStdString();
|
|
fahrer = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(i, 0,
|
|
new QTableWidgetItem(fahrer[0][0]));
|
|
this->ui->tWRennliste->item(i, 0)->setFlags(Qt::ItemIsEnabled);
|
|
|
|
statement = "select name from AutoKonfiguration where id_auto like " +
|
|
tableData[i][1].toStdString() + " order by seit DESC";
|
|
autos = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(i, 1, new QTableWidgetItem(autos[0][0]));
|
|
this->ui->tWRennliste->item(i, 1)->setFlags(Qt::ItemIsEnabled);
|
|
|
|
this->ui->tWRennliste->setItem(i, 2, new QTableWidgetItem());
|
|
|
|
statement = "select name from fahrer where id like " +
|
|
tableData[i][2].toStdString();
|
|
fahrer = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(i, 3,
|
|
new QTableWidgetItem(fahrer[0][0]));
|
|
this->ui->tWRennliste->item(i, 3)->setFlags(Qt::ItemIsEnabled);
|
|
|
|
statement = "select name from AutoKonfiguration where id_auto like " +
|
|
tableData[i][3].toStdString() + " order by seit DESC";
|
|
autos = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(i, 4, new QTableWidgetItem(autos[0][0]));
|
|
this->ui->tWRennliste->item(i, 4)->setFlags(Qt::ItemIsEnabled);
|
|
|
|
this->ui->tWRennliste->setItem(i, 5, new QTableWidgetItem());
|
|
}
|
|
for (int i = 0; i < 6; i++) {
|
|
this->ui->tWRennliste->item(0, i)->setBackground(Qt::green);
|
|
}
|
|
}
|
|
void WindowRennliste::setWindowRace(WindowRace * instance) {
|
|
this->instanceWindowRace = instance;
|
|
}
|
|
vector<QString> WindowRennliste::getDriverAndCarSettings() {
|
|
vector<QString> vec;
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow + 1, 0)->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow + 1, 1)->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow + 1, 3)->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow + 1, 4)->text());
|
|
return vec;
|
|
}
|
|
vector<QString> WindowRennliste::getDriverAndCarId() {
|
|
// shellFahrer shellAuto deaFahrer deaAuto
|
|
return this->tableData[this->selectedRow];
|
|
}
|
|
|
|
void WindowRennliste::setBesttime(int shell, int dea) {
|
|
this->ui->tWRennliste->item(this->selectedRow, 2)
|
|
->setText(QString::number(shell / 1000.0));
|
|
this->ui->tWRennliste->item(this->selectedRow, 5)
|
|
->setText(QString::number(dea / 1000.0));
|
|
// std::cout << this->selectedRow << std::endl;
|
|
}
|
|
|
|
void WindowRennliste::listClick(const QModelIndex & index) {
|
|
|
|
QString driverShell = this->ui->tWRennliste->item(index.row(), 0)->text();
|
|
QString carShell = this->ui->tWRennliste->item(index.row(), 1)->text();
|
|
QString driverDea = this->ui->tWRennliste->item(index.row(), 3)->text();
|
|
QString carDea = this->ui->tWRennliste->item(index.row(), 4)->text();
|
|
|
|
vector<QString> vec;
|
|
vec.push_back(driverShell);
|
|
vec.push_back(carShell);
|
|
vec.push_back(driverDea);
|
|
vec.push_back(carDea);
|
|
|
|
this->instanceWindowRace->setDriverAndCar(vec);
|
|
this->instanceWindowRace->prepareNextRace();
|
|
this->setSelection(index.row());
|
|
this->sendIds();
|
|
}
|
|
void WindowRennliste::closeEvent(QCloseEvent * event) {
|
|
if (!this->windowClose) {
|
|
this->setWindowState(Qt::WindowMinimized);
|
|
event->ignore();
|
|
}
|
|
else {
|
|
event->accept();
|
|
}
|
|
}
|
|
void WindowRennliste::schliessen() {
|
|
this->windowClose = true;
|
|
this->close();
|
|
delete this;
|
|
}
|
|
|
|
void WindowRennliste::setSelection(int row) {
|
|
for (int i = 0; i < 6; i++) {
|
|
this->ui->tWRennliste->item(this->selectedRow, i)
|
|
->setBackground(Qt::yellow);
|
|
}
|
|
this->selectedRow = row;
|
|
for (int i = 0; i < 6; i++) {
|
|
this->ui->tWRennliste->item(row, i)->setBackground(Qt::green);
|
|
}
|
|
this->sendIds();
|
|
vector<QString> vec;
|
|
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 0)->text());
|
|
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 1)->text());
|
|
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text());
|
|
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text());
|
|
this->instanceWindowRace->setDriverAndCar(vec);
|
|
}
|
|
void WindowRennliste::sendIds() {
|
|
this->instanceWindowRace->setDriverAndCarId(this->getDriverAndCarId());
|
|
}
|
|
|
|
void WindowRennliste::changeSelection() {
|
|
if (this->selectedRow + 1 < this->tableData.size()) {
|
|
for (unsigned int i = 0; i < 6; i++) {
|
|
this->ui->tWRennliste->item(this->selectedRow, i)
|
|
->setBackground(Qt::gray);
|
|
this->ui->tWRennliste->item(this->selectedRow + 1, i)
|
|
->setBackground(Qt::green);
|
|
}
|
|
this->selectedRow += 1;
|
|
this->sendIds();
|
|
|
|
vector<QString> vec;
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow, 0)->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow, 1)->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow, 3)->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(this->selectedRow, 4)->text());
|
|
this->instanceWindowRace->setDriverAndCar(vec);
|
|
}
|
|
}
|
|
|
|
WindowRennliste::~WindowRennliste() {
|
|
delete ui;
|
|
}
|