changed more raw pointers to smart pointers
This commit is contained in:
19
database.cpp
19
database.cpp
@@ -7,15 +7,13 @@
|
||||
using std::vector;
|
||||
|
||||
DataBase::DataBase() {
|
||||
this->db = new QSqlDatabase();
|
||||
this->db = std::make_shared<QSqlDatabase>();
|
||||
*this->db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
this->db->setDatabaseName("Renndatenbank.sqlite");
|
||||
// std::cout << "Konstruktor Database" << std::endl;
|
||||
}
|
||||
DataBase::~DataBase() {
|
||||
// std::cout << "Destruktor aus Datenbank" << std::endl;
|
||||
delete this->db;
|
||||
// delete this;
|
||||
}
|
||||
|
||||
vector<vector<QString>> DataBase::getData2(std::string statement, int cols) {
|
||||
@@ -58,14 +56,15 @@ QStringList DataBase::getDataQStringList(std::string statement) {
|
||||
|
||||
vector<vector<QString>> DataBase::getData(std::string statement, int cols) {
|
||||
|
||||
char * buffer = new char[statement.length() + 1];
|
||||
strcpy(buffer, statement.c_str());
|
||||
// char * buffer = new char[statement.length() + 1];
|
||||
std::shared_ptr<char> buffer(new char[statement.length() + 1]);
|
||||
strcpy(buffer.get(), statement.c_str());
|
||||
vector<QString> data;
|
||||
vector<vector<QString>> lines;
|
||||
bool ok = this->db->open();
|
||||
QString qstr;
|
||||
if (ok) {
|
||||
QSqlQuery query(buffer);
|
||||
QSqlQuery query(buffer.get());
|
||||
|
||||
while (query.next()) {
|
||||
|
||||
@@ -78,16 +77,16 @@ vector<vector<QString>> DataBase::getData(std::string statement, int cols) {
|
||||
}
|
||||
}
|
||||
this->db->close();
|
||||
delete[] buffer;
|
||||
// delete[] buffer;
|
||||
return lines;
|
||||
}
|
||||
|
||||
void DataBase::setData(std::string statement) {
|
||||
char * buffer = new char[statement.length() + 1];
|
||||
strcpy(buffer, statement.c_str());
|
||||
std::shared_ptr<char> buffer(new char[statement.length() + 1]);
|
||||
strcpy(buffer.get(), statement.c_str());
|
||||
bool ok = this->db->open();
|
||||
if (ok) {
|
||||
QSqlQuery query(buffer);
|
||||
QSqlQuery query(buffer.get());
|
||||
}
|
||||
this->db->close();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QtSql/QSql>
|
||||
#include <QtSql/QSqlDatabase>
|
||||
#include <QtSql/QSqlQuery>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -19,7 +20,7 @@ class DataBase {
|
||||
QStringList getDataQStringList(std::string statement);
|
||||
|
||||
private:
|
||||
QSqlDatabase * db;
|
||||
std::shared_ptr<QSqlDatabase> db;
|
||||
};
|
||||
|
||||
#endif // DATABASE_H
|
||||
|
||||
@@ -63,8 +63,7 @@ void MainWindow::WindowTraining() {
|
||||
}
|
||||
|
||||
void MainWindow::NewWindowSettings() {
|
||||
this->interfaceSettings =
|
||||
std::make_shared<WindowsSettings>(this->db.get(), this);
|
||||
this->interfaceSettings = std::make_shared<WindowsSettings>(this->db, this);
|
||||
this->interfaceSettings->show();
|
||||
}
|
||||
|
||||
|
||||
40
training.cpp
40
training.cpp
@@ -93,8 +93,8 @@ void Training::ResetShell() {
|
||||
this->VecShell.clear();
|
||||
|
||||
// this->ui->lWShellTime->clear();
|
||||
timeModelShell = new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
timeModelShell = std::make_shared<TimeModel>(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell.get());
|
||||
|
||||
this->ui->lBestZeitShell->setText("∞");
|
||||
this->ui->lCurRoundTimeShell->setText("∞");
|
||||
@@ -111,8 +111,8 @@ void Training::ResetDea() {
|
||||
this->VecDea.clear();
|
||||
|
||||
// this->ui->lWDeaTime->clear();
|
||||
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->lBestZeitDea->setText("∞");
|
||||
|
||||
@@ -174,8 +174,9 @@ void Training::shellSlot(int time, int sector) {
|
||||
VecShell.push_back(QVector<int>());
|
||||
VecShell.last().push_back(time);
|
||||
|
||||
timeModelShell = new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
timeModelShell =
|
||||
std::make_shared<TimeModel>(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell.get());
|
||||
|
||||
this->ui->lBridgeShellTop->setText(QString::number(
|
||||
static_cast<double>(QVectorHelper::getMinSec1(VecShell)) /
|
||||
@@ -188,9 +189,9 @@ void Training::shellSlot(int time, int sector) {
|
||||
// cout << time << sector <<
|
||||
// endl;
|
||||
VecShell.last().push_back(time);
|
||||
timeModelShell =
|
||||
new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
timeModelShell = std::make_shared<TimeModel>(
|
||||
VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,9 +211,9 @@ void Training::shellSlot(int time, int sector) {
|
||||
VecShell.last().push_back(
|
||||
QVectorHelper::getCurTime(VecShell.last()));
|
||||
|
||||
timeModelShell =
|
||||
new TimeModel(VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell);
|
||||
timeModelShell = std::make_shared<TimeModel>(
|
||||
VecShell, minSecTime, this);
|
||||
this->ui->lWShellTime->setModel(timeModelShell.get());
|
||||
}
|
||||
// best time on widget
|
||||
|
||||
@@ -279,8 +280,9 @@ void Training::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->lBridgeDeaTop->setText(QString::number(
|
||||
static_cast<double>(QVectorHelper::getMinSec1(VecDea)) /
|
||||
1000));
|
||||
@@ -291,8 +293,9 @@ void Training::deaSlot(int time, int sector) {
|
||||
// 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());
|
||||
}
|
||||
else {
|
||||
// VecDea[VecDea.size()-1].append(9999);
|
||||
@@ -314,8 +317,9 @@ void Training::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
|
||||
// cout << "cur time: " <<
|
||||
|
||||
@@ -50,8 +50,8 @@ class Training : public QMainWindow {
|
||||
int deltaDea;
|
||||
|
||||
// timeModel
|
||||
TimeModel * timeModelDea;
|
||||
TimeModel * timeModelShell;
|
||||
std::shared_ptr<TimeModel> timeModelDea;
|
||||
std::shared_ptr<TimeModel> timeModelShell;
|
||||
QVector<int> minSecTime;
|
||||
|
||||
// shortcuts
|
||||
|
||||
@@ -17,7 +17,7 @@ using std::endl;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
|
||||
WindowsSettings::WindowsSettings(std::shared_ptr<DataBase> db, QWidget * parent)
|
||||
: QMainWindow(parent), ui(new Ui::WindowsSettings) {
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -66,6 +66,15 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
|
||||
QObject::connect(this->ui->pBNewCarSave, SIGNAL(clicked()), this,
|
||||
SLOT(saveNewCar()));
|
||||
|
||||
QObject::connect(this->ui->pBCarClose, SIGNAL(clicked()), this,
|
||||
SLOT(closeWindow()));
|
||||
|
||||
QObject::connect(this->ui->pBNewDriverClose, SIGNAL(clicked()), this,
|
||||
SLOT(closeWindow()));
|
||||
|
||||
QObject::connect(this->ui->pBDriverEditClose, SIGNAL(clicked()), this,
|
||||
SLOT(closeWindow()));
|
||||
|
||||
this->ui->wNewCarColor->setAutoFillBackground(true);
|
||||
// update minimal lap time on changeing minimal sector time
|
||||
// QObject::connect(this->ui->lEMinTimeSec1,
|
||||
@@ -135,13 +144,13 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
|
||||
QAbstractItemView::ExtendedSelection);
|
||||
statement = "select name, id from fahrer";
|
||||
driversList = this->db->getData2(statement, 2);
|
||||
driversModel = new QStringListModel();
|
||||
driversModel = std::make_shared<QStringListModel>();
|
||||
QStringList qDriversList;
|
||||
std::for_each(
|
||||
driversList.begin(), driversList.end(),
|
||||
[&qDriversList](vector<QString> i) { qDriversList << i.at(0); });
|
||||
driversModel->setStringList(qDriversList);
|
||||
this->ui->lVDrivers->setModel(driversModel);
|
||||
this->ui->lVDrivers->setModel(driversModel.get());
|
||||
|
||||
// setup cars
|
||||
this->ui->lVCars->setSelectionMode(
|
||||
@@ -167,10 +176,10 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
|
||||
cout << "cars could not be read from database" << endl;
|
||||
}
|
||||
|
||||
carModel = new QStringListModel();
|
||||
carModel = std::make_shared<QStringListModel>();
|
||||
|
||||
carModel->setStringList(carNames);
|
||||
this->ui->lVCars->setModel(carModel);
|
||||
this->ui->lVCars->setModel(carModel.get());
|
||||
|
||||
} catch (std::exception & e) {
|
||||
Q_UNUSED(e);
|
||||
@@ -212,7 +221,7 @@ void WindowsSettings::saveEditCar() {
|
||||
|
||||
void WindowsSettings::openEditColor() {
|
||||
// cout << "hello from slot" << endl;
|
||||
this->colorDialogEditCar = new QColorDialog();
|
||||
this->colorDialogEditCar = std::make_shared<QColorDialog>();
|
||||
this->colorDialogEditCar->show();
|
||||
this->colorDialogEditCar->setCurrentColor(QColor(this->curCarColor));
|
||||
this->colorDialogEditCar->open(this, SLOT(changeColorEdit()));
|
||||
@@ -220,7 +229,7 @@ void WindowsSettings::openEditColor() {
|
||||
|
||||
void WindowsSettings::openNewColor() {
|
||||
// cout << "hello from slot" << endl;
|
||||
this->colorDialogNewCar = new QColorDialog();
|
||||
this->colorDialogNewCar = std::make_shared<QColorDialog>();
|
||||
this->colorDialogNewCar->show();
|
||||
|
||||
this->colorDialogNewCar->open(this, SLOT(changeColorNew()));
|
||||
@@ -338,10 +347,10 @@ void WindowsSettings::repaintCars() {
|
||||
<< id.at(0).toStdString() << " order by id DESC limit 1";
|
||||
carNames << this->db->getData2(ss.str(), 6).at(0).at(2);
|
||||
}
|
||||
this->carModel = new QStringListModel();
|
||||
this->carModel = std::make_shared<QStringListModel>();
|
||||
this->carModel->setStringList(carNames);
|
||||
this->ui->lVCarSavedCars->setModel(this->carModel);
|
||||
this->ui->lvNewCar->setModel(this->carModel);
|
||||
this->ui->lVCarSavedCars->setModel(this->carModel.get());
|
||||
this->ui->lvNewCar->setModel(this->carModel.get());
|
||||
|
||||
} catch (std::exception & e) {
|
||||
Q_UNUSED(e);
|
||||
@@ -399,7 +408,6 @@ void WindowsSettings::repaintMinCurLapTime() {
|
||||
}
|
||||
void WindowsSettings::AbbrechenSlot() {
|
||||
this->close();
|
||||
delete this;
|
||||
}
|
||||
void WindowsSettings::SaveDauerSlot() {
|
||||
string statement =
|
||||
|
||||
@@ -17,21 +17,22 @@ class WindowsSettings : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WindowsSettings(DataBase * db, QWidget * parent = 0);
|
||||
explicit WindowsSettings(std::shared_ptr<DataBase> db,
|
||||
QWidget * parent = nullptr);
|
||||
~WindowsSettings();
|
||||
|
||||
private:
|
||||
Ui::WindowsSettings * ui;
|
||||
string currentDateTime();
|
||||
DataBase * db;
|
||||
std::shared_ptr<DataBase> db;
|
||||
int rennId;
|
||||
vector<vector<QString>> carIds;
|
||||
vector<vector<QString>> driversList;
|
||||
QStringListModel * carModel;
|
||||
QStringListModel * driversModel;
|
||||
std::shared_ptr<QStringListModel> carModel;
|
||||
std::shared_ptr<QStringListModel> driversModel;
|
||||
vector<vector<QString>> driversLV;
|
||||
QColorDialog * colorDialogEditCar;
|
||||
QColorDialog * colorDialogNewCar;
|
||||
std::shared_ptr<QColorDialog> colorDialogEditCar;
|
||||
std::shared_ptr<QColorDialog> colorDialogNewCar;
|
||||
QString curCarColor;
|
||||
QString curCarId;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<string><html><head/><body><p>Rennliste Erstellen</p></body></html></string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="Dauer">
|
||||
<attribute name="title">
|
||||
@@ -559,7 +559,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget_2">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_6">
|
||||
<attribute name="title">
|
||||
|
||||
Reference in New Issue
Block a user