added Traimode

This commit is contained in:
2014-09-24 22:35:51 +02:00
parent ff954eced0
commit 0d51efea63
6 changed files with 155 additions and 382 deletions

View File

@@ -45,7 +45,8 @@ MainWindow::~MainWindow()
}
void MainWindow::WindowTraining(){
this->interfaceTraining = new Training(this, this->db);
this->interfaceTraining->show();
}
void MainWindow::NewWindowSettings(){

View File

@@ -9,6 +9,7 @@
#include "windowssettings.h"
#include "windowrennliste.h"
#include "windowrennliste2.h"
#include "training.h"
namespace Ui {
class MainWindow;
@@ -31,6 +32,7 @@ public slots:
private:
Training *interfaceTraining;
void closeEvent(QCloseEvent *event);
DataBase *db;
Ui::MainWindow *ui;

View File

@@ -1,14 +1,130 @@
#include "training.h"
#include "ui_training.h"
#include <QObject>
#include <string>
#include <sstream>
#include <iostream>
#include <QShortcut>
#include "unistd.h"
Training::Training(QWidget *parent) :
using std::vector;
using std::string;
using std::cout;
using std::endl;
Training::Training(QWidget *parent, DataBase *db) :
QMainWindow(parent),
ui(new Ui::Training)
{
ui->setupUi(this);
this->db = db;
string statement = "select mindestrundendauer from renndauer where id like 1";
this->minTimeOneRound = this->db->getData(statement, 1)[0][0].toInt();
this->finished = false;
firstTimeDea = true;
firstTimeShell = true;
started = true;
paused = false;
this->Hardware = new HardwareSetup;
Hardware->start();
QObject::connect(Hardware, SIGNAL(Dea()), this, SLOT(deaSlot()));
QObject::connect(Hardware, SIGNAL(Shell()), this, SLOT(shellSlot()));
//QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace()));
//QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this, SLOT(stopClicked()));
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+Q"), this);
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));
}
void Training::prepareNextRace(){
this->firstTimeShell = true;
this->firstTimeDea = true;
this->ui->lWShellTime->clear();
this->ui->lWDeaTime->clear();
this->ui->lBestZeitDea->setText("");
this->ui->lBestZeitShell->setText("");
this->ui->lCurRoundTimeShell->setText("");
this->ui->lCurRoundDea->setText("");
this->finished = false;
this->paused = false;
this->started = false;
}
void Training::stopClicked(){
cout << "Shortcut" << endl;
}
void Training::shellSlot(){
if(started && !paused && !this->finished){
if(firstTimeShell){
firstTimeShell = false;
counterShell.start();
}
else{
long zeit = counterShell.getTime();
VecShell.push_back(zeit);
QListWidgetItem *item = new QListWidgetItem;
if(getMinimum(VecShell) == zeit && VecShell.size() > 1){
item->setBackgroundColor(Qt::green);
}
item->setText(QString::number((double)zeit/1000));
ui->lWShellTime->addItem(item);
ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000));
ui->lCurRoundTimeShell->setText(QString::number((double)zeit/1000));
}
}
}
void Training::closeEvent(QCloseEvent *event){
}
void Training::deaSlot(){
if(started && !paused && !this->finished){
if(firstTimeDea){
firstTimeDea = false;
counterDea.start();
}
else{
long zeit = counterDea.getTime();
VecDea.push_back(zeit);
QListWidgetItem *item = new QListWidgetItem;
if(getMinimum(VecDea) == zeit && VecDea.size() > 1){
item->setBackgroundColor(Qt::green);
}
item->setText(QString::number((double)zeit/1000));
ui->lWDeaTime->addItem(item);
ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000));
ui->lCurRoundDea->setText(QString::number((double)zeit/1000));
}
}
}
long Training::getMinimum(std::vector<long> a){
long minimum = a[0];
for(unsigned int i = 0; i < a.size(); i++){
if(a[i] < minimum){
minimum = a[i];
}
}
return minimum;
}
Training::~Training()
{
this->Hardware->setStop();
usleep(1000);
delete this->Hardware;
delete ui;
}

View File

@@ -1,7 +1,11 @@
#ifndef TRAINING_H
#define TRAINING_H
#include "hardwaresetup.h"
#include <vector>
#include <string>
#include "counter.h"
#include <QMainWindow>
#include "database.h"
namespace Ui {
class Training;
@@ -12,11 +16,33 @@ class Training : public QMainWindow
Q_OBJECT
public:
explicit Training(QWidget *parent = 0);
explicit Training(QWidget *parent, DataBase *db);
~Training();
private:
void prepareNextRace();
Ui::Training *ui;
void closeEvent(QCloseEvent *event);
bool started;
HardwareSetup *Hardware;
bool firstTimeShell;
bool firstTimeDea;
std::vector<long> VecShell;
std::vector<long> VecDea;
long getMinimum(std::vector<long> a);
bool paused;
bool finished;
Counter counterShell;
Counter counterDea;
DataBase *db;
long minTimeOneRound;
public slots:
void deaSlot();
void shellSlot();
void stopClicked();
};
#endif // TRAINING_H

View File

@@ -108,25 +108,7 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6" stretch="0,0,1">
<item alignment="Qt::AlignHCenter|Qt::AlignTop">
<widget class="QLabel" name="lCountdown">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>17</pointsize>
</font>
</property>
<property name="text">
<string>Verbleibende Zeit</string>
</property>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout_6" stretch="0,1">
<item alignment="Qt::AlignHCenter">
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
@@ -135,362 +117,7 @@
<height>100</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QWidget" name="hW11" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel11" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QWidget" name="hW21" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel21" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QWidget" name="hW12" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel12" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QWidget" name="hw22" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel22" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QWidget" name="hW13" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel13" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QWidget" name="hW23" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel23" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QWidget" name="hW14" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel14" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QWidget" name="hW24" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel24" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QWidget" name="hW15" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel15" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QWidget" name="hW25" native="true">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="WAmpel25" native="true">
<property name="maximumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-image: url(:/new/prefix1/ampel.png);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
<layout class="QVBoxLayout" name="verticalLayout_5"/>
</widget>
</item>
<item>

View File

@@ -53,9 +53,10 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
ui->lEDeaSteilkurveAussen->setText(res[0][4]);
//duration prepare
statement = "select dauer from renndauer";
res = db->getData(statement, 1);
statement = "select dauer, mindestrundendauer from renndauer";
res = db->getData(statement, 2);
this->ui->leRenndauer->setText(res[0][0]);
this->ui->lEMinRundenzeit->setText(res[0][1]);
}
void WindowsSettings::AbbrechenSlot(){
@@ -63,7 +64,7 @@ void WindowsSettings::AbbrechenSlot(){
delete this;
}
void WindowsSettings::SaveDauerSlot(){
string statement = "update renndauer set dauer="+this->ui->leRenndauer->text().toStdString()+" where id like 1";
string statement = "update renndauer set dauer="+this->ui->leRenndauer->text().toStdString()+", mindestrundendauer="+this->ui->lEMinRundenzeit->text().toStdString()+" where id like 1";
this->db->setData(statement);
}
void WindowsSettings::SaveDauerAndExitSlot(){