130 lines
3.9 KiB
C++
130 lines
3.9 KiB
C++
#include "mainwindow.h"
|
|
#include "database.h"
|
|
#include "hardwaresetup.h"
|
|
#include "training.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "unistd.h"
|
|
#include "windowrace.h"
|
|
#include "windowrennliste2.h"
|
|
#include "windowssettings.h"
|
|
#include <QObject>
|
|
#include <QShortcut>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
|
|
#include <boost/asio/read.hpp>
|
|
#include <boost/asio/serial_port.hpp>
|
|
#include <boost/lexical_cast.hpp>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
using std::vector;
|
|
|
|
MainWindow::MainWindow(QWidget * parent)
|
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
ui->setupUi(this);
|
|
this->interfaceTraining = nullptr;
|
|
|
|
this->interfaceRace = nullptr;
|
|
this->interfaceSettings = nullptr;
|
|
this->interfaceRennliste = nullptr;
|
|
|
|
QObject::connect(ui->pushButton, SIGNAL(clicked()), this,
|
|
SLOT(NewWindowSettings()));
|
|
|
|
QObject::connect(ui->pBRennen, SIGNAL(clicked()), this,
|
|
SLOT(WindowRennen()));
|
|
QObject::connect(this->ui->pBTraining, SIGNAL(clicked()), this,
|
|
SLOT(WindowTraining()));
|
|
|
|
QObject::connect(this->ui->pBEvaluation, SIGNAL(clicked()), this,
|
|
SLOT(WindowEvaluation()));
|
|
|
|
startTraining = std::make_shared<QShortcut>(QKeySequence("Ctrl+t"), this);
|
|
startRennen = std::make_shared<QShortcut>(QKeySequence("Ctrl+r"), this);
|
|
|
|
QObject::connect(startTraining.get(), SIGNAL(activated()), this,
|
|
SLOT(WindowTraining()));
|
|
QObject::connect(startRennen.get(), SIGNAL(activated()), this,
|
|
SLOT(WindowRennen()));
|
|
|
|
this->db = std::make_unique<DataBase>();
|
|
}
|
|
void MainWindow::closeEvent(QCloseEvent * event) {
|
|
Q_UNUSED(event);
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::WindowTraining() {
|
|
{
|
|
this->interfaceTraining =
|
|
std::make_unique<Training>(this, this->db.get());
|
|
this->interfaceTraining->show();
|
|
}
|
|
}
|
|
|
|
void MainWindow::NewWindowSettings() {
|
|
this->interfaceSettings =
|
|
std::make_unique<WindowsSettings>(this->db.get(), this);
|
|
this->interfaceSettings->show();
|
|
}
|
|
|
|
void MainWindow::WindowRennen() {
|
|
|
|
// check if a valid racelist has been created
|
|
// get last race id
|
|
string statement = "select aktRennen.id_rennen from aktRennen order by "
|
|
"id_rennen DESC limit 1";
|
|
|
|
try {
|
|
string raceId =
|
|
this->db->getData2(statement, 1).at(0).at(0).toStdString();
|
|
std::stringstream ss;
|
|
ss << "select count(*) from Zeiten where zeiten.id_rennen like "
|
|
<< raceId;
|
|
int res = this->db->getData2(ss.str(), 1).at(0).at(0).toInt();
|
|
if (res > 0) {
|
|
// current race was raced before
|
|
QMessageBox msgBox;
|
|
msgBox.setText(
|
|
"Aktuelles Rennen wurde bereits gefahren! Trotzdem fahren?");
|
|
msgBox.setInformativeText("");
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
msgBox.setDefaultButton(QMessageBox::No);
|
|
int ret = msgBox.exec();
|
|
|
|
switch (ret) {
|
|
case QMessageBox::No:
|
|
return;
|
|
|
|
case QMessageBox::Yes:
|
|
// do nothing
|
|
break;
|
|
default:
|
|
// should never be reached
|
|
break;
|
|
}
|
|
}
|
|
|
|
} catch (std::exception & e) {
|
|
Q_UNUSED(e);
|
|
}
|
|
|
|
this->interfaceRace = std::make_unique<WindowRace>(this->db.get(), this);
|
|
this->interfaceRace->show();
|
|
this->interfaceRennliste =
|
|
std::make_unique<WindowRennliste>(this->db.get(), this);
|
|
this->interfaceRennliste->show();
|
|
this->interfaceRace->setWindowRennliste(this->interfaceRennliste.get());
|
|
this->interfaceRennliste->setWindowRace(this->interfaceRace.get());
|
|
}
|
|
|
|
void MainWindow::WindowEvaluation() {
|
|
this->interfaceEvaluation = std::make_unique<Evaluation>(this->db.get());
|
|
this->interfaceEvaluation->show();
|
|
}
|