fix crash on close, some code cleanup

This commit is contained in:
2017-09-09 19:45:47 +02:00
parent c963cc37ac
commit 032e354152
3 changed files with 12 additions and 31 deletions
+2 -2
View File
@@ -187,11 +187,11 @@ void HardwareSetup::run(){
emit Shell((int)buffer[i].time, 2); emit Shell((int)buffer[i].time, 2);
break; break;
case 3: case 3:
cout << "Time: vor emit" << (int)buffer[i].time << endl; // cout << "Time: vor emit" << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 2); emit Dea((int)buffer[i].time, 2);
break; break;
case 4: case 4:
cout << "emit shell" << endl; // cout << "emit shell" << endl;
emit Shell((int)buffer[i].time, 3); emit Shell((int)buffer[i].time, 3);
break; break;
case 5: case 5:
+1 -1
View File
@@ -113,7 +113,7 @@ QVariant TimeModel::data(const QModelIndex &index, int role) const
bool TimeModel::insertRows(int row, int count, const QModelIndex &parent) bool TimeModel::insertRows(int row, int count, const QModelIndex &parent)
{ {
std::cout << "insert triggert" << std::endl; //std::cout << "insert triggert" << std::endl;
beginInsertRows(parent, row, row + count - 1); beginInsertRows(parent, row, row + count - 1);
// FIXME: Implement me! // FIXME: Implement me!
endInsertRows(); endInsertRows();
+9 -28
View File
@@ -104,14 +104,13 @@ void Training::prepareNextRace(){
this->ui->lCurRoundTimeShell->setText(""); this->ui->lCurRoundTimeShell->setText("");
this->ui->lCurRoundDea->setText(""); this->ui->lCurRoundDea->setText("");
this->finished = false; this->finished = false;
this->paused = false; this->paused = false;
this->started = true; this->started = true;
} }
void Training::shellSlot(int time, int sector){ void Training::shellSlot(int time, int sector){
cout << "Shell slot" << endl; // cout << "Shell slot" << endl;
// slot is called when a sector is finished // slot is called when a sector is finished
// time is given in ms // time is given in ms
// counting of sector beginns at 1 // counting of sector beginns at 1
@@ -133,14 +132,11 @@ void Training::shellSlot(int time, int sector){
case 2: case 2:
if(VecShell.size() > 0){ if(VecShell.size() > 0){
if(VecShell.last().size() == 1){ if(VecShell.last().size() == 1){
cout << time << sector << endl; // cout << time << sector << endl;
VecShell.last().push_back(time); VecShell.last().push_back(time);
timeModelShell = new TimeModel(VecShell, this); timeModelShell = new TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
} }
else{
}
} }
break; break;
case 3: case 3:
@@ -153,16 +149,9 @@ void Training::shellSlot(int time, int sector){
// add sum to vector // add sum to vector
VecShell.last().push_back(QVectorHelper::getCurTime(VecShell.last())); VecShell.last().push_back(QVectorHelper::getCurTime(VecShell.last()));
timeModelShell = new TimeModel(VecShell, this); timeModelShell = new TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
} }
// best time on widget // best time on widget
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){ if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){
@@ -181,7 +170,7 @@ void Training::shellSlot(int time, int sector){
} }
void Training::closeEvent(QCloseEvent *event){ void Training::closeEvent(QCloseEvent *event){
Hardware->setStop(); Hardware->setStop();
delete this->Hardware; //delete this->Hardware;
} }
void Training::deaSlot(int time, int sector){ void Training::deaSlot(int time, int sector){
@@ -197,7 +186,7 @@ void Training::deaSlot(int time, int sector){
case 1: case 1:
VecDea.push_back(QVector<int>()); VecDea.push_back(QVector<int>());
VecDea.last().push_back(time); VecDea.last().push_back(time);
cout << "Dea Sektor 1" << endl; // cout << "Dea Sektor 1" << endl;
timeModelDea = new TimeModel(VecDea, this); timeModelDea = new TimeModel(VecDea, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
@@ -205,7 +194,7 @@ void Training::deaSlot(int time, int sector){
case 2: case 2:
if(VecDea.size() > 0){ if(VecDea.size() > 0){
if(VecDea.last().size() == 1){ if(VecDea.last().size() == 1){
cout << time << sector << endl; // cout << time << sector << endl;
VecDea[VecDea.size()-1].push_back(time); VecDea[VecDea.size()-1].push_back(time);
timeModelDea = new TimeModel(VecDea, this); timeModelDea = new TimeModel(VecDea, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
@@ -225,38 +214,30 @@ void Training::deaSlot(int time, int sector){
// add sum to vector // add sum to vector
VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last())); VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, this); timeModelDea = new TimeModel(VecDea, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
} }
// best time on widget // best time on widget
cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl; // cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl;
cout << "min time: " << QVectorHelper::getMin(VecDea) << endl; // cout << "min time: " << QVectorHelper::getMin(VecDea) << endl;
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){ if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){
ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000)); ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000));
} }
ui->lCurRoundDea->setText(QString::number((double)QVectorHelper::getCurTime(VecDea.last())/1000)); ui->lCurRoundDea->setText(QString::number((double)QVectorHelper::getCurTime(VecDea.last())/1000));
} }
break; break;
} }
ui->lWDeaTime->scrollToBottom(); ui->lWDeaTime->scrollToBottom();
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
} }
} }
} }
Training::~Training() Training::~Training()
{ {
cout << "destr Training" << endl;
this->Hardware->setStop(); this->Hardware->setStop();
usleep(1000); usleep(1000000);
delete this->Hardware; delete this->Hardware;
delete ui; delete ui;
} }