fix: crash of closeEvent in racewindow and settingsmenu + code cleanup

This commit is contained in:
2018-12-29 23:15:30 +01:00
parent a811514b04
commit 50ab4dffef
12 changed files with 96 additions and 73 deletions

View File

@@ -10,7 +10,7 @@
using std::cout;
using std::endl;
Evaluation::Evaluation(DataBase * db, QWidget * parent)
Evaluation::Evaluation(std::shared_ptr<DataBase> db, QWidget * parent)
: QWidget(parent), ui(new Ui::Evaluation) {
ui->setupUi(this);
this->db = db;
@@ -43,7 +43,7 @@ void Evaluation::listClick(const QModelIndex & ind) {
unsigned long index = static_cast<unsigned long>(ind.row());
int id = this->result.at(index).at(1).toInt();
this->interfaceResult = new Result(this->db, id);
this->interfaceResult = std::make_shared<Result>(this->db, id);
this->interfaceResult->show();
}

View File

@@ -5,6 +5,7 @@
#include "result.h"
#include <QListWidgetItem>
#include <QWidget>
#include <memory>
#include <qstring.h>
#include <vector>
@@ -18,13 +19,14 @@ class Evaluation : public QWidget {
Q_OBJECT
public:
explicit Evaluation(DataBase * db, QWidget * parent = nullptr);
explicit Evaluation(std::shared_ptr<DataBase> db,
QWidget * parent = nullptr);
~Evaluation();
private:
Ui::Evaluation * ui;
Result * interfaceResult;
DataBase * db;
std::shared_ptr<Result> interfaceResult;
std::shared_ptr<DataBase> db;
vector<vector<QString>> result;
public slots:

View File

@@ -49,7 +49,7 @@ HardwareSetup::~HardwareSetup() {
//perror("ioperm");
}*/
std::cout << "Hardware beendet" << std::endl;
std::cout << "Destructor of Hardware" << std::endl;
this->stop = 1;
if (HARDWARE_VERSION == 2) {

View File

@@ -111,13 +111,13 @@ void MainWindow::WindowRennen() {
this->interfaceRace = std::make_shared<WindowRace>(this->db, this);
this->interfaceRace->show();
this->interfaceRennliste =
std::make_shared<WindowRennliste>(this->db.get(), this);
std::make_shared<WindowRennliste>(this->db, this);
this->interfaceRennliste->show();
this->interfaceRace->setWindowRennliste(this->interfaceRennliste);
this->interfaceRennliste->setWindowRace(this->interfaceRace.get());
this->interfaceRennliste->setWindowRace(this->interfaceRace);
}
void MainWindow::WindowEvaluation() {
this->interfaceEvaluation = std::make_shared<Evaluation>(this->db.get());
this->interfaceEvaluation = std::make_shared<Evaluation>(this->db);
this->interfaceEvaluation->show();
}

View File

@@ -22,7 +22,7 @@ using std::endl;
using std::string;
using std::vector;
Result::Result(DataBase * db, int rennid, QWidget * parent)
Result::Result(std::shared_ptr<DataBase> db, int rennid, QWidget * parent)
: QWidget(parent), ui(new Ui::Result) {
ui->setupUi(this);
this->db = db;

View File

@@ -4,6 +4,7 @@
#include "database.h"
#include "resultmodel.h"
#include <QWidget>
#include <memory>
#include <string>
#include <vector>
@@ -23,7 +24,8 @@ class Result : public QWidget {
Q_OBJECT
public:
explicit Result(DataBase * db, int rennid, QWidget * parent = nullptr);
explicit Result(std::shared_ptr<DataBase> db, int rennid,
QWidget * parent = nullptr);
~Result();
public slots:
void closeWindow();
@@ -46,8 +48,8 @@ class Result : public QWidget {
void drawPlots(int rennid);
Ui::Result * ui;
ResultModel * model;
DataBase * db;
std::shared_ptr<ResultModel> model;
std::shared_ptr<DataBase> db;
int rennid;
int minimumTime;
QString renndatum;

View File

@@ -121,29 +121,29 @@ WindowRace::WindowRace(std::shared_ptr<DataBase> db, QWidget * parent)
tableData = db->getData2(statement, 4);
statement = "select name from fahrer where id like " +
tableData[0][0].toStdString();
tableData.at(0).at(0).toStdString();
fahrer = this->db->getData2(statement, 1);
statement = "select name from AutoKonfiguration where id_auto like " +
tableData[0][1].toStdString() + " order by seit DESC";
tableData.at(0).at(1).toStdString() + " order by seit DESC";
autos = this->db->getData2(statement, 1);
this->ui->gbShell->setTitle("Shell, " + fahrer[0][0] + ", " + autos[0][0]);
statement = "select name from fahrer where id like " +
tableData[0][2].toStdString();
tableData.at(0).at(2).toStdString();
fahrer = this->db->getData2(statement, 1);
statement = "select name from AutoKonfiguration where id_auto like " +
tableData[0][3].toStdString() + " order by seit DESC";
tableData.at(0).at(3).toStdString() + " order by seit DESC";
autos = this->db->getData2(statement, 1);
this->ui->gbDea->setTitle("Dea, " + fahrer[0][0] + ", " + autos[0][0]);
this->shellDriverId = tableData[0][0].toInt();
this->shellCarId = tableData[0][1].toInt();
this->deaDriverId = tableData[0][2].toInt();
this->deaCarId = tableData[0][3].toInt();
this->shellDriverId = tableData.at(0).at(0).toInt();
this->shellCarId = tableData.at(0).at(1).toInt();
this->deaDriverId = tableData.at(0).at(2).toInt();
this->deaCarId = tableData.at(0).at(3).toInt();
// progressbar
this->ui->pbTime->setMaximum(this->fahrzeit);
@@ -153,8 +153,9 @@ WindowRace::WindowRace(std::shared_ptr<DataBase> db, QWidget * parent)
this->ui->pbTime->setValue(0);
QKeySequence ks(Qt::Key_Return); // btw, this is numpad enter
QShortcut * keyReturn = new QShortcut(ks, this);
QObject::connect(keyReturn, SIGNAL(activated()), this, SLOT(ReturnPress()));
this->keyReturn = std::make_shared<QShortcut>(ks, this);
QObject::connect(keyReturn.get(), SIGNAL(activated()), this,
SLOT(ReturnPress()));
// QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));
}
@@ -210,12 +211,12 @@ void WindowRace::prepareNextRace() {
this->VecDea.clear();
// clear tableview shell
timeModelShell = new TimeModel(VecShell, minSecTime);
ui->lWShellTime->setModel(timeModelShell);
timeModelShell = std::make_shared<TimeModel>(VecShell, minSecTime);
ui->lWShellTime->setModel(timeModelShell.get());
// clear tableview dea
timeModelDea = new TimeModel(VecDea, minSecTime);
ui->lWDeaTime->setModel(timeModelDea);
timeModelDea = std::make_shared<TimeModel>(VecDea, minSecTime);
ui->lWDeaTime->setModel(timeModelDea.get());
this->finished = false;
this->paused = false;
@@ -293,7 +294,7 @@ void WindowRace::closeEvent(QCloseEvent * event) {
event->ignore();
break;
case QMessageBox::Yes:
this->wRennliste->schliessen();
this->wRennliste->closeRaceList();
this->Hardware->setStop();
event->accept();
break;
@@ -362,8 +363,6 @@ WindowRace::~WindowRace() {
this->Hardware->setStop();
usleep(1000000); // 1 second
// delete this->db;
delete ui;
}
void WindowRace::shellSlot(int time, int sector) {
@@ -385,10 +384,10 @@ void WindowRace::shellSlot(int time, int sector) {
test.append(1);
test.append(2);
test.append(3);
this->timeModelShell =
new TimeModel(VecShell, minSecTime, test, this);
this->timeModelShell = std::make_shared<TimeModel>(
VecShell, minSecTime, test, this);
// this->ui->lWShellTime->setModel(this->timeModelShell);
ui->lWShellTime->setModel(this->timeModelShell);
ui->lWShellTime->setModel(this->timeModelShell.get());
this->ui->lBridgeShell->setText(QString::number(
static_cast<double>(QVectorHelper::getMinSec1(VecShell)) /
@@ -405,11 +404,11 @@ void WindowRace::shellSlot(int time, int sector) {
test.append(1);
test.append(2);
test.append(3);
this->timeModelShell =
new TimeModel(VecShell, minSecTime, test, this);
this->timeModelShell = std::make_shared<TimeModel>(
VecShell, minSecTime, test, this);
// timeModelShell = new
// TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell);
this->ui->lWShellTime->setModel(timeModelShell.get());
this->ui->lStraightShell->setText(QString::number(
static_cast<double>(
QVectorHelper::getMinSec2(VecShell)) /
@@ -440,11 +439,11 @@ void WindowRace::shellSlot(int time, int sector) {
test.append(1);
test.append(2);
test.append(3);
this->timeModelShell =
new TimeModel(VecShell, minSecTime, test, this);
this->timeModelShell = std::make_shared<TimeModel>(
VecShell, minSecTime, test, this);
// timeModelShell = new
// TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell);
this->ui->lWShellTime->setModel(timeModelShell.get());
this->ui->lCurvesShell->setText(QString::number(
static_cast<double>(
@@ -507,8 +506,9 @@ void WindowRace::deaSlot(int time, int sector) {
VecDea.push_back(QVector<int>());
VecDea.last().push_back(time);
cout << "Dea Sektor 1" << endl;
timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
timeModelDea =
std::make_shared<TimeModel>(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lBridgeDea->setText(QString::number(
static_cast<double>(QVectorHelper::getMinSec1(VecDea)) /
@@ -520,8 +520,9 @@ 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, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
timeModelDea = std::make_shared<TimeModel>(
VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get());
this->ui->lStraightDea->setText(QString::number(
static_cast<double>(
QVectorHelper::getMinSec2(VecDea)) /
@@ -544,8 +545,9 @@ void WindowRace::deaSlot(int time, int sector) {
VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
timeModelDea = std::make_shared<TimeModel>(
VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea.get());
}
// best time on widget
@@ -609,13 +611,13 @@ long WindowRace::getMinimum(std::vector<long> a) {
long minimum = -1;
for (unsigned int i = 0; i < a.size(); i++) {
if (minimum < 0) {
if (a[i] >= this->minimumTime) {
minimum = a[i];
if (a.at(i) >= this->minimumTime) {
minimum = a.at(i);
}
}
else {
if (a[i] < minimum && a[i] >= this->minimumTime) {
minimum = a[i];
if (a.at(i) < minimum && a.at(i) >= this->minimumTime) {
minimum = a.at(i);
}
}
}

View File

@@ -10,6 +10,7 @@
#include "windowrennliste.h"
#include <QMainWindow>
#include <QMessageBox>
#include <QShortcut>
#include <memory>
#include <string>
#include <vector>
@@ -48,8 +49,8 @@ class WindowRace : public QMainWindow {
bool firstTimeDea;
QVector<QVector<int>> VecShell;
QVector<QVector<int>> VecDea;
TimeModel * timeModelShell;
TimeModel * timeModelDea;
std::shared_ptr<TimeModel> timeModelShell;
std::shared_ptr<TimeModel> timeModelDea;
long getMinimum(std::vector<long> a);
QString timeWrapper(long zahl);
long countdownValue; // in sec
@@ -72,6 +73,9 @@ class WindowRace : public QMainWindow {
int theoreticalMinDea;
int deltaDea;
// shortcuts
std::shared_ptr<QShortcut> keyReturn;
public slots:
void stopClicked();
void prepareNextRace();

View File

@@ -5,10 +5,13 @@
#include <QColor>
#include <QDebug>
#include <iostream>
using std::cout;
using std::endl;
using std::string;
using std::vector;
WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent)
WindowRennliste::WindowRennliste(std::shared_ptr<DataBase> db, QWidget * parent)
: QMainWindow(parent), ui(new Ui::WindowRennliste) {
ui->setupUi(this);
@@ -96,7 +99,7 @@ WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent)
this->ui->tWRennliste->item(0, i)->setBackground(Qt::green);
}
}
void WindowRennliste::setWindowRace(WindowRace * instance) {
void WindowRennliste::setWindowRace(std::shared_ptr<WindowRace> instance) {
this->instanceWindowRace = instance;
}
vector<QString> WindowRennliste::getDriverAndCarSettings() {
@@ -155,10 +158,10 @@ void WindowRennliste::closeEvent(QCloseEvent * event) {
event->accept();
}
}
void WindowRennliste::schliessen() {
void WindowRennliste::closeRaceList() {
this->windowClose = true;
this->close();
delete this;
// delete this;
}
void WindowRennliste::setSelection(int row) {

View File

@@ -19,10 +19,11 @@ class WindowRennliste : public QMainWindow {
Q_OBJECT
public:
void schliessen();
explicit WindowRennliste(DataBase * db, QWidget * parent = 0);
explicit WindowRennliste(std::shared_ptr<DataBase> db,
QWidget * parent = nullptr);
~WindowRennliste();
void setWindowRace(WindowRace * instance);
void closeRaceList();
void setWindowRace(std::shared_ptr<WindowRace> instance);
vector<QString> getDriverAndCarSettings();
vector<QString> getDriverAndCarId();
void sendIds();
@@ -32,10 +33,10 @@ class WindowRennliste : public QMainWindow {
bool windowClose;
void closeEvent(QCloseEvent * event);
void setSelection(int row);
WindowRace * instanceWindowRace;
std::shared_ptr<WindowRace> instanceWindowRace;
unsigned int selectedRow;
vector<vector<QString>> tableData;
DataBase * db;
std::shared_ptr<DataBase> db;
Ui::WindowRennliste * ui;
public slots:

View File

@@ -140,8 +140,10 @@ WindowsSettings::WindowsSettings(std::shared_ptr<DataBase> db, QWidget * parent)
// setup Rennliste
// setup drivers
this->ui->lVDrivers->setSelectionMode(
QAbstractItemView::ExtendedSelection);
/*
statement = "select name, id from fahrer";
driversList = this->db->getData2(statement, 2);
driversModel = std::make_shared<QStringListModel>();
@@ -151,15 +153,17 @@ WindowsSettings::WindowsSettings(std::shared_ptr<DataBase> db, QWidget * parent)
[&qDriversList](vector<QString> i) { qDriversList << i.at(0); });
driversModel->setStringList(qDriversList);
this->ui->lVDrivers->setModel(driversModel.get());
*/
// setup cars
this->ui->lVCars->setSelectionMode(
QAbstractItemView::ExtendedSelection);
/*
QStringList carNames;
std::stringstream ss;
try {
statement = "select id from autos";
cout << "hier gehts noch" << endl;
this->carIds = this->db->getData2(statement, 1);
for (vector<QString> carId : carIds) {
@@ -168,6 +172,9 @@ WindowsSettings::WindowsSettings(std::shared_ptr<DataBase> db, QWidget * parent)
<< carId.at(0).toStdString()
<< " order by seit DESC limit 1";
carNames << this->db->getData2(ss.str(), 1).at(0).at(0);
cout
<< this->db->getData2(ss.str(), 1).at(0).at(0).toStdString()
<< endl;
ss.str(std::string());
}
@@ -177,10 +184,9 @@ WindowsSettings::WindowsSettings(std::shared_ptr<DataBase> db, QWidget * parent)
}
carModel = std::make_shared<QStringListModel>();
carModel->setStringList(carNames);
this->ui->lVCars->setModel(carModel.get());
*/
} catch (std::exception & e) {
Q_UNUSED(e);
cout << "missing database :(" << endl;
@@ -324,13 +330,17 @@ void WindowsSettings::listClickEditCar(const QModelIndex & index) {
void WindowsSettings::repaintDrivers() {
string statement = "select id, name from fahrer";
this->driversLV = this->db->getData2(statement, 2);
QStringListModel * driverModel = new QStringListModel();
// this->driversLV;
this->driversList = this->db->getData2(statement, 2);
// driversList = this->driversLV;
// QStringListModel *
this->driversModel = std::make_shared<QStringListModel>();
QStringList driverList =
DataHelper::vectorListToQstringList(this->driversLV, 1);
driverModel->setStringList(driverList);
this->ui->lVDriverEditSavedDrivers->setModel(driverModel);
this->ui->lVNewDriverSavedDrivers->setModel(driverModel);
DataHelper::vectorListToQstringList(this->driversList, 1);
this->driversModel->setStringList(driverList);
this->ui->lVDriverEditSavedDrivers->setModel(this->driversModel.get());
this->ui->lVNewDriverSavedDrivers->setModel(this->driversModel.get());
this->ui->lVDrivers->setModel(this->driversModel.get());
}
void WindowsSettings::repaintCars() {
QStringList carNames;
@@ -351,7 +361,7 @@ void WindowsSettings::repaintCars() {
this->carModel->setStringList(carNames);
this->ui->lVCarSavedCars->setModel(this->carModel.get());
this->ui->lvNewCar->setModel(this->carModel.get());
this->ui->lVCars->setModel(this->carModel.get());
} catch (std::exception & e) {
Q_UNUSED(e);
cout << "Error on repainting cars" << endl;
@@ -470,7 +480,6 @@ void WindowsSettings::StreckeSpeichernSlot() {
WindowsSettings::~WindowsSettings() {
delete ui;
std::cout << "Destruktor einstellungen" << std::endl;
}
// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
@@ -501,7 +510,7 @@ void WindowsSettings::createRaceListAndClose() {
this->ui->lVDrivers->selectionModel()->selectedIndexes()) {
selectedDriverIds.push_back(
this->driversList.at(static_cast<unsigned long>(index.row()))
.at(1)
.at(0)
.toInt());
}

View File

@@ -21,7 +21,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Rennliste Erstellen&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="currentIndex">
<number>3</number>
<number>4</number>
</property>
<widget class="QWidget" name="Dauer">
<attribute name="title">