230 lines
8.3 KiB
C++
230 lines
8.3 KiB
C++
#include "windowrennliste.h"
|
|
#include "ui_windowrennliste.h"
|
|
#include "windowrace.h"
|
|
#include <QBrush>
|
|
#include <QColor>
|
|
#include <QDebug>
|
|
#include <iostream>
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
WindowRennliste::WindowRennliste(std::shared_ptr<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.at(0).at(0).toStdString();
|
|
|
|
this->tableData = db->getData(statement, 4);
|
|
this->ui->tWRennliste->setRowCount(
|
|
static_cast<int>(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.at(i).at(0).toStdString();
|
|
fahrer = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(
|
|
static_cast<int>(i), 0, new QTableWidgetItem(fahrer.at(0).at(0)));
|
|
this->ui->tWRennliste->item(static_cast<int>(i), 0)
|
|
->setFlags(Qt::ItemIsEnabled);
|
|
|
|
statement = "select name from AutoKonfiguration where id_auto like " +
|
|
tableData.at(i).at(1).toStdString() + " order by seit DESC";
|
|
autos = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(static_cast<int>(i), 1,
|
|
new QTableWidgetItem(autos.at(0).at(0)));
|
|
this->ui->tWRennliste->item(static_cast<int>(i), 1)
|
|
->setFlags(Qt::ItemIsEnabled);
|
|
|
|
this->ui->tWRennliste->setItem(static_cast<int>(i), 2,
|
|
new QTableWidgetItem());
|
|
|
|
statement = "select name from fahrer where id like " +
|
|
tableData.at(i).at(2).toStdString();
|
|
fahrer = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(
|
|
static_cast<int>(i), 3, new QTableWidgetItem(fahrer.at(0).at(0)));
|
|
this->ui->tWRennliste->item(static_cast<int>(i), 3)
|
|
->setFlags(Qt::ItemIsEnabled);
|
|
|
|
statement = "select name from AutoKonfiguration where id_auto like " +
|
|
tableData.at(i).at(3).toStdString() + " order by seit DESC";
|
|
autos = this->db->getData(statement, 1);
|
|
this->ui->tWRennliste->setItem(static_cast<int>(i), 4,
|
|
new QTableWidgetItem(autos.at(0).at(0)));
|
|
this->ui->tWRennliste->item(static_cast<int>(i), 4)
|
|
->setFlags(Qt::ItemIsEnabled);
|
|
|
|
this->ui->tWRennliste->setItem(static_cast<int>(i), 5,
|
|
new QTableWidgetItem());
|
|
}
|
|
for (int i = 0; i < 6; i++) {
|
|
this->ui->tWRennliste->item(0, i)->setBackground(Qt::green);
|
|
}
|
|
}
|
|
void WindowRennliste::setWindowRace(std::shared_ptr<WindowRace> instance) {
|
|
this->instanceWindowRace = instance;
|
|
}
|
|
vector<QString> WindowRennliste::getDriverAndCarSettings() {
|
|
vector<QString> vec;
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow) + 1, 0)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow) + 1, 1)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow) + 1, 3)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow) + 1, 4)
|
|
->text());
|
|
return vec;
|
|
}
|
|
vector<QString> WindowRennliste::getDriverAndCarId() {
|
|
// shellFahrer shellAuto deaFahrer deaAuto
|
|
return this->tableData.at(this->selectedRow);
|
|
}
|
|
|
|
void WindowRennliste::setBesttime(int shell, int dea) {
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 2)
|
|
->setText(QString::number(shell / 1000.0));
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 5)
|
|
->setText(QString::number(dea / 1000.0));
|
|
// std::cout << static_cast<int>(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::closeRaceList() {
|
|
this->windowClose = true;
|
|
this->close();
|
|
// delete this;
|
|
}
|
|
|
|
void WindowRennliste::setSelection(int row) {
|
|
for (int i = 0; i < 6; i++) {
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), i)
|
|
->setBackground(Qt::yellow);
|
|
}
|
|
this->selectedRow = static_cast<unsigned int>(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(static_cast<int>(this->selectedRow), 0)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 1)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 3)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(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(static_cast<int>(this->selectedRow), static_cast<int>(i))
|
|
->setBackground(Qt::gray);
|
|
this->ui->tWRennliste
|
|
->item(static_cast<int>(this->selectedRow) + 1,
|
|
static_cast<int>(i))
|
|
->setBackground(Qt::green);
|
|
}
|
|
this->selectedRow += 1;
|
|
this->sendIds();
|
|
|
|
vector<QString> vec;
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 0)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 1)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 3)
|
|
->text());
|
|
vec.push_back(
|
|
this->ui->tWRennliste->item(static_cast<int>(this->selectedRow), 4)
|
|
->text());
|
|
this->instanceWindowRace->setDriverAndCar(vec);
|
|
}
|
|
}
|
|
|
|
WindowRennliste::~WindowRennliste() {
|
|
delete ui;
|
|
}
|