diff --git a/evaluation.cpp b/evaluation.cpp index f6b517f..9b2da39 100644 --- a/evaluation.cpp +++ b/evaluation.cpp @@ -10,7 +10,7 @@ using std::cout; using std::endl; -Evaluation::Evaluation(DataBase * db, QWidget * parent) +Evaluation::Evaluation(std::shared_ptr 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(ind.row()); int id = this->result.at(index).at(1).toInt(); - this->interfaceResult = new Result(this->db, id); + this->interfaceResult = std::make_shared(this->db, id); this->interfaceResult->show(); } diff --git a/evaluation.h b/evaluation.h index 5c89172..1d51c6f 100644 --- a/evaluation.h +++ b/evaluation.h @@ -5,6 +5,7 @@ #include "result.h" #include #include +#include #include #include @@ -18,13 +19,14 @@ class Evaluation : public QWidget { Q_OBJECT public: - explicit Evaluation(DataBase * db, QWidget * parent = nullptr); + explicit Evaluation(std::shared_ptr db, + QWidget * parent = nullptr); ~Evaluation(); private: Ui::Evaluation * ui; - Result * interfaceResult; - DataBase * db; + std::shared_ptr interfaceResult; + std::shared_ptr db; vector> result; public slots: diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index 151261a..28f2820 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -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) { diff --git a/mainwindow.cpp b/mainwindow.cpp index 72814a5..e9ff070 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -111,13 +111,13 @@ void MainWindow::WindowRennen() { this->interfaceRace = std::make_shared(this->db, this); this->interfaceRace->show(); this->interfaceRennliste = - std::make_shared(this->db.get(), this); + std::make_shared(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(this->db.get()); + this->interfaceEvaluation = std::make_shared(this->db); this->interfaceEvaluation->show(); } diff --git a/result.cpp b/result.cpp index 2444d29..d1fcfdd 100644 --- a/result.cpp +++ b/result.cpp @@ -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 db, int rennid, QWidget * parent) : QWidget(parent), ui(new Ui::Result) { ui->setupUi(this); this->db = db; diff --git a/result.h b/result.h index 624a2d9..ef48309 100644 --- a/result.h +++ b/result.h @@ -4,6 +4,7 @@ #include "database.h" #include "resultmodel.h" #include +#include #include #include @@ -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 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 model; + std::shared_ptr db; int rennid; int minimumTime; QString renndatum; diff --git a/windowrace.cpp b/windowrace.cpp index 638f3b5..6303935 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -121,29 +121,29 @@ WindowRace::WindowRace(std::shared_ptr 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 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(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(VecShell, minSecTime); + ui->lWShellTime->setModel(timeModelShell.get()); // clear tableview dea - timeModelDea = new TimeModel(VecDea, minSecTime); - ui->lWDeaTime->setModel(timeModelDea); + timeModelDea = std::make_shared(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( + 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(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( + 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( 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( + 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( @@ -507,8 +506,9 @@ void WindowRace::deaSlot(int time, int sector) { VecDea.push_back(QVector()); 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(VecDea, minSecTime, this); + this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lBridgeDea->setText(QString::number( static_cast(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( + VecDea, minSecTime, this); + this->ui->lWDeaTime->setModel(timeModelDea.get()); this->ui->lStraightDea->setText(QString::number( static_cast( 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( + VecDea, minSecTime, this); + this->ui->lWDeaTime->setModel(timeModelDea.get()); } // best time on widget @@ -609,13 +611,13 @@ long WindowRace::getMinimum(std::vector 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); } } } diff --git a/windowrace.h b/windowrace.h index 1e3122f..e5dcf2b 100644 --- a/windowrace.h +++ b/windowrace.h @@ -10,6 +10,7 @@ #include "windowrennliste.h" #include #include +#include #include #include #include @@ -48,8 +49,8 @@ class WindowRace : public QMainWindow { bool firstTimeDea; QVector> VecShell; QVector> VecDea; - TimeModel * timeModelShell; - TimeModel * timeModelDea; + std::shared_ptr timeModelShell; + std::shared_ptr timeModelDea; long getMinimum(std::vector 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 keyReturn; + public slots: void stopClicked(); void prepareNextRace(); diff --git a/windowrennliste.cpp b/windowrennliste.cpp index cbacc81..2a4fec9 100644 --- a/windowrennliste.cpp +++ b/windowrennliste.cpp @@ -5,10 +5,13 @@ #include #include #include + +using std::cout; +using std::endl; using std::string; using std::vector; -WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent) +WindowRennliste::WindowRennliste(std::shared_ptr 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 instance) { this->instanceWindowRace = instance; } vector 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) { diff --git a/windowrennliste.h b/windowrennliste.h index 79af27c..5db444c 100644 --- a/windowrennliste.h +++ b/windowrennliste.h @@ -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 db, + QWidget * parent = nullptr); ~WindowRennliste(); - void setWindowRace(WindowRace * instance); + void closeRaceList(); + void setWindowRace(std::shared_ptr instance); vector getDriverAndCarSettings(); vector 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 instanceWindowRace; unsigned int selectedRow; vector> tableData; - DataBase * db; + std::shared_ptr db; Ui::WindowRennliste * ui; public slots: diff --git a/windowssettings.cpp b/windowssettings.cpp index e8d278c..6d89de5 100644 --- a/windowssettings.cpp +++ b/windowssettings.cpp @@ -140,8 +140,10 @@ WindowsSettings::WindowsSettings(std::shared_ptr 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(); @@ -151,15 +153,17 @@ WindowsSettings::WindowsSettings(std::shared_ptr db, QWidget * parent) [&qDriversList](vector 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 carId : carIds) { @@ -168,6 +172,9 @@ WindowsSettings::WindowsSettings(std::shared_ptr 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 db, QWidget * parent) } carModel = std::make_shared(); - 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(); 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(index.row())) - .at(1) + .at(0) .toInt()); } diff --git a/windowssettings.ui b/windowssettings.ui index 722b2ea..27e8646 100644 --- a/windowssettings.ui +++ b/windowssettings.ui @@ -21,7 +21,7 @@ <html><head/><body><p>Rennliste Erstellen</p></body></html> - 3 + 4