fixes for usb-support

This commit is contained in:
2017-12-25 08:12:10 +01:00
parent 3b66192591
commit 95b3471f49
19 changed files with 1196 additions and 3580 deletions

24
.clang-format Normal file
View File

@@ -0,0 +1,24 @@
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Middle
AlignTrailingComments: true
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
...

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.o
moc_*

3029
Makefile

File diff suppressed because it is too large Load Diff

View File

@@ -51,8 +51,11 @@ FORMS += mainwindow.ui \
OTHER_FILES += OTHER_FILES +=
INCLUDEPATH += /home/jpaehr/Dokumente/libusb/libusb #INCLUDEPATH += /home/johannes/Dokumente/libusb/libusb
LIBS += -L "/usr/lib" -lusb LIBS += -L "/usr/lib" -lusb
RESOURCES += \ RESOURCES += \
resource.qrc resource.qrc
DISTFILES += \
.clang-format

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.4.0, 2017-09-12T15:10:06. --> <!-- Written by QtCreator 4.3.1, 2017-12-24T15:47:52. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
<value type="QByteArray">{15687edb-7104-42fa-a53c-7d0294bb7338}</value> <value type="QByteArray">{fa7f3dc3-5b46-4468-a19f-ea195cf466a8}</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -54,79 +54,21 @@
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.PluginSettings</variable> <variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/> <valuemap type="QVariantMap">
<valuelist type="QVariantList" key="ClangStaticAnalyzer.SuppressedDiagnostics"/>
</valuemap>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.Target.0</variable> <variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap"> <valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 5.9.1 in PATH (qt5)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 5.9.1 in PATH (qt5)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{e7c8e272-6c95-4fb7-9b69-d295b2ca02f0}</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{48e51839-112c-4842-badf-f2eb9bcf81cb}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_9_1_in_PATH_qt5-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -172,7 +114,7 @@
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Bereinigen</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap> </valuemap>
@@ -185,8 +127,8 @@
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value> <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Profile</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_9_1_in_PATH_qt5-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -196,7 +138,7 @@
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value> <value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">true</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.SeparateDebugInfo">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value> <value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
@@ -232,29 +174,29 @@
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Bereinigen</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Profile</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value> <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">3</value> <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value> <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deployment</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Lokales Deployment</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap> </valuemap>
@@ -304,13 +246,13 @@
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RennbahnZeitmessung</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">RennbahnZeitmessung</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/jpaehr/Dokumente/rennbahnc/RennbahnZeitmessung.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/johannes/Dokumente/rennbahnc/RennbahnZeitmessung.pro</value>
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">RennbahnZeitmessung.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">RennbahnZeitmessung.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/jpaehr/Dokumente/build-RennbahnZeitmessung-Desktop-Debug</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_9_1_in_PATH_qt5-Release</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>

View File

@@ -1,25 +1,23 @@
#include "ampel.h" #include "ampel.h"
#include <unistd.h> #include <unistd.h>
Ampel::Ampel() Ampel::Ampel() {
{
this->running = 1; this->running = 1;
} }
void Ampel::setStop(){ void Ampel::setStop() {
this->running = 0; this->running = 0;
} }
void Ampel::run(){ void Ampel::run() {
int anzahl = 0; int anzahl = 0;
while(this->running){ while (this->running) {
anzahl++; anzahl++;
if(anzahl < 6){ if (anzahl < 6) {
usleep(800000); usleep(800000);
} }
else{ else {
usleep(1400000); usleep(1400000);
} }
emit ampelUpdate(); emit ampelUpdate();
} }
} }

View File

@@ -1,15 +1,14 @@
#include "countdown.h" #include "countdown.h"
#include "unistd.h" #include "unistd.h"
Countdown::Countdown() Countdown::Countdown() {
{
this->running = 1; this->running = 1;
} }
void Countdown::setStop(){ void Countdown::setStop() {
this->running = 0; this->running = 0;
} }
void Countdown::run(){ void Countdown::run() {
while(this->running){ while (this->running) {
sleep(1); sleep(1);
emit CountdownUpdate(); emit CountdownUpdate();
} }

View File

@@ -1,21 +1,19 @@
#include "counter.h" #include "counter.h"
#include <sys/time.h>
#include <iostream>
#include <cstddef> #include <cstddef>
#include <iostream>
#include <sys/time.h>
Counter::Counter() Counter::Counter() {
{
} }
void Counter::start(){ void Counter::start() {
gettimeofday(&startTime, NULL); gettimeofday(&startTime, NULL);
} }
long Counter::getTime(){ long Counter::getTime() {
gettimeofday(&endTime, NULL); gettimeofday(&endTime, NULL);
long back = (endTime.tv_usec-startTime.tv_usec)/1000+(endTime.tv_sec-startTime.tv_sec)*1000; long back = (endTime.tv_usec - startTime.tv_usec) / 1000 +
(endTime.tv_sec - startTime.tv_sec) * 1000;
this->start(); this->start();
return back; return back;
} }

View File

@@ -1,66 +1,65 @@
#include "database.h" #include "database.h"
#include <iostream>
#include <cstring>
#include <QVariant> #include <QVariant>
#include <cstring>
#include <iostream>
using std::vector; using std::vector;
DataBase::DataBase() DataBase::DataBase() {
{
this->db = new QSqlDatabase(); this->db = new QSqlDatabase();
*this->db = QSqlDatabase::addDatabase("QSQLITE"); *this->db = QSqlDatabase::addDatabase("QSQLITE");
this->db->setDatabaseName("Renndatenbank.sqlite"); this->db->setDatabaseName("Renndatenbank.sqlite");
std::cout << "Konstruktor Database" << std::endl; std::cout << "Konstruktor Database" << std::endl;
} }
DataBase::~DataBase(){ DataBase::~DataBase() {
std::cout << "Destruktor aus Datenbank" << std::endl; std::cout << "Destruktor aus Datenbank" << std::endl;
delete this->db; delete this->db;
//delete this; // delete this;
} }
vector< vector<QString> > DataBase::getData2(std::string statement, int cols){ vector<vector<QString>> DataBase::getData2(std::string statement, int cols) {
vector<QString> data; vector<QString> data;
vector< vector<QString> > lines; vector<vector<QString>> lines;
bool ok = this->db->open(); bool ok = this->db->open();
QString qstr; QString qstr;
if(ok){ if (ok) {
QSqlQuery query; QSqlQuery query;
query.exec(QString::fromStdString(statement)); query.exec(QString::fromStdString(statement));
while(query.next()){ while (query.next()) {
for(int i = 0; i < cols; i++){ for (int i = 0; i < cols; i++) {
qstr = query.value(i).toString(); qstr = query.value(i).toString();
data.push_back(qstr); data.push_back(qstr);
} }
lines.push_back(data); lines.push_back(data);
data.erase(data.begin(), data.begin()+cols); data.erase(data.begin(), data.begin() + cols);
} }
} }
this->db->close(); this->db->close();
return lines; return lines;
} }
vector< vector<QString> > DataBase::getData(std::string statement, int cols){ vector<vector<QString>> DataBase::getData(std::string statement, int cols) {
char * buffer = new char[statement.length()+1]; char * buffer = new char[statement.length() + 1];
strcpy(buffer,statement.c_str()); strcpy(buffer, statement.c_str());
vector<QString> data; vector<QString> data;
vector< vector<QString> > lines; vector<vector<QString>> lines;
bool ok = this->db->open(); bool ok = this->db->open();
QString qstr; QString qstr;
if(ok){ if (ok) {
QSqlQuery query(buffer); QSqlQuery query(buffer);
while(query.next()){ while (query.next()) {
for(int i = 0; i < cols; i++){ for (int i = 0; i < cols; i++) {
qstr = query.value(i).toString(); qstr = query.value(i).toString();
data.push_back(qstr); data.push_back(qstr);
} }
lines.push_back(data); lines.push_back(data);
data.erase(data.begin(), data.begin()+cols); data.erase(data.begin(), data.begin() + cols);
} }
} }
this->db->close(); this->db->close();
@@ -68,11 +67,11 @@ vector< vector<QString> > DataBase::getData(std::string statement, int cols){
return lines; return lines;
} }
void DataBase::setData(std::string statement){ void DataBase::setData(std::string statement) {
char * buffer = new char[statement.length()+1]; char * buffer = new char[statement.length() + 1];
strcpy(buffer,statement.c_str()); strcpy(buffer, statement.c_str());
bool ok = this->db->open(); bool ok = this->db->open();
if(ok){ if (ok) {
QSqlQuery query(buffer); QSqlQuery query(buffer);
} }
this->db->close(); this->db->close();

View File

@@ -4,7 +4,7 @@
#include <QtSql/QSqlDatabase> #include <QtSql/QSqlDatabase>
#include <QDir> #include <QDir>
#include <QtSql/QSqlQuery> #include <QtSql/QSqlQuery>
#include<vector> #include <vector>
#include <string> #include <string>
using std::vector; using std::vector;

View File

@@ -1,93 +1,89 @@
#include "hardwaresetup.h" #include "hardwaresetup.h"
#include <unistd.h>
#include "sys/io.h" #include "sys/io.h"
#include <iostream> #include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <usb.h> #include <usb.h>
#define USB_LED_ON 1 #define USB_LED_ON 1
#define USB_LED_OFF 0 #define USB_LED_OFF 0
#define USB_DATA_OUT 2 #define USB_DATA_OUT 2
using namespace std; using namespace std;
// not needed anymore -> usb // not needed anymore -> usb
// #define BASEPORT 0xe050 /* lp1 */ // #define BASEPORT 0xe050 /* lp1 */
// #define BASEPORT 0x378 // #define BASEPORT 0x378
// #define BASEPORT 0xd000 // #define BASEPORT 0xd000
HardwareSetup::HardwareSetup() HardwareSetup::HardwareSetup() {
{ // if (ioperm(BASEPORT, 3, 1)) {
// if (ioperm(BASEPORT, 3, 1)) { // //perror("ioperm");
// //perror("ioperm"); // }
// }
this->stop = 0; this->stop = 0;
this->handle = NULL; this->handle = NULL;
} }
void HardwareSetup::setStop(){ void HardwareSetup::setStop() {
this->stop = 1; this->stop = 1;
} }
HardwareSetup::~HardwareSetup(){ HardwareSetup::~HardwareSetup() {
/*if (ioperm(BASEPORT, 3, 0)) { /*if (ioperm(BASEPORT, 3, 0)) {
//perror("ioperm"); //perror("ioperm");
}*/ }*/
std::cout << "Hardware beendet" << std::endl; std::cout << "Hardware beendet" << std::endl;
this->stop = 1; this->stop = 1;
if(this->handle){ if (this->handle) {
usb_close(this->handle); usb_close(this->handle);
} }
this->handle = NULL; this->handle = NULL;
} }
/* Used to get descriptor strings for device identification */ /* Used to get descriptor strings for device identification */
int HardwareSetup::usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, int HardwareSetup::usbGetDescriptorString(usb_dev_handle * dev, int index,
char *buf, int buflen) { int langid, char * buf, int buflen) {
char buffer[256]; char buffer[256];
int rval, i; int rval, i;
// make standard request GET_DESCRIPTOR, type string and given index // make standard request GET_DESCRIPTOR, type string and given index
// (e.g. dev->iProduct) // (e.g. dev->iProduct)
rval = usb_control_msg(dev, rval = usb_control_msg(
USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_ENDPOINT_IN, dev, USB_TYPE_STANDARD | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, buffer,
buffer, sizeof(buffer), 1000); sizeof(buffer), 1000);
if(rval < 0) // error if (rval < 0) // error
return rval; return rval;
// rval should be bytes read, but buffer[0] contains the actual response size // rval should be bytes read, but buffer[0] contains the actual response
if((unsigned char)buffer[0] < rval) // size
if ((unsigned char)buffer[0] < rval)
rval = (unsigned char)buffer[0]; // string is shorter than bytes read rval = (unsigned char)buffer[0]; // string is shorter than bytes read
if(buffer[1] != USB_DT_STRING) // second byte is the data type if (buffer[1] != USB_DT_STRING) // second byte is the data type
return 0; // invalid return type return 0; // invalid return type
// we're dealing with UTF-16LE here so actual chars is half of rval, // we're dealing with UTF-16LE here so actual chars is half of rval,
// and index 0 doesn't count // and index 0 doesn't count
rval /= 2; rval /= 2;
/* lossy conversion to ISO Latin1 */ /* lossy conversion to ISO Latin1 */
for(i = 1; i < rval && i < buflen; i++) { for (i = 1; i < rval && i < buflen; i++) {
if(buffer[2 * i + 1] == 0) if (buffer[2 * i + 1] == 0)
buf[i-1] = buffer[2 * i]; buf[i - 1] = buffer[2 * i];
else else
buf[i-1] = '?'; /* outside of ISO Latin1 range */ buf[i - 1] = '?'; /* outside of ISO Latin1 range */
} }
buf[i-1] = 0; buf[i - 1] = 0;
return i-1; return i - 1;
} }
usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char * vendorName,
int product, char * productName) {
usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName, struct usb_bus * bus;
int product, char *productName) { struct usb_device * dev;
struct usb_bus *bus;
struct usb_device *dev;
char devVendor[256], devProduct[256]; char devVendor[256], devProduct[256];
usb_dev_handle * handle = NULL; usb_dev_handle * handle = NULL;
@@ -96,22 +92,23 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
usb_find_busses(); usb_find_busses();
usb_find_devices(); usb_find_devices();
for(bus=usb_get_busses(); bus; bus=bus->next) { for (bus = usb_get_busses(); bus; bus = bus->next) {
for(dev=bus->devices; dev; dev=dev->next) { for (dev = bus->devices; dev; dev = dev->next) {
if(dev->descriptor.idVendor != vendor || if (dev->descriptor.idVendor != vendor ||
dev->descriptor.idProduct != product) dev->descriptor.idProduct != product)
continue; continue;
/* we need to open the device in order to query strings */ /* we need to open the device in order to query strings */
if(!(handle = usb_open(dev))) { if (!(handle = usb_open(dev))) {
fprintf(stderr, "Warning: cannot open USB device: %sn", fprintf(stderr, "Warning: cannot open USB device: %sn",
usb_strerror()); usb_strerror());
continue; continue;
} }
/* get vendor name */ /* get vendor name */
if(usbGetDescriptorString(handle, dev->descriptor.iManufacturer, if (usbGetDescriptorString(handle, dev->descriptor.iManufacturer,
0x0409, devVendor, sizeof(devVendor)) < 0) { 0x0409, devVendor,
sizeof(devVendor)) < 0) {
fprintf(stderr, fprintf(stderr,
"Warning: cannot query manufacturer for device: %sn", "Warning: cannot query manufacturer for device: %sn",
usb_strerror()); usb_strerror());
@@ -120,17 +117,16 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
} }
/* get product name */ /* get product name */
if(usbGetDescriptorString(handle, dev->descriptor.iProduct, if (usbGetDescriptorString(handle, dev->descriptor.iProduct, 0x0409,
0x0409, devProduct, sizeof(devVendor)) < 0) { devProduct, sizeof(devVendor)) < 0) {
fprintf(stderr, fprintf(stderr, "Warning: cannot query product for device: %sn",
"Warning: cannot query product for device: %sn",
usb_strerror()); usb_strerror());
usb_close(handle); usb_close(handle);
continue; continue;
} }
if(strcmp(devVendor, vendorName) == 0 && if (strcmp(devVendor, vendorName) == 0 &&
strcmp(devProduct, productName) == 0) strcmp(devProduct, productName) == 0)
return handle; return handle;
else else
usb_close(handle); usb_close(handle);
@@ -139,135 +135,129 @@ usb_dev_handle * HardwareSetup::usbOpenDevice(int vendor, char *vendorName,
return NULL; return NULL;
} }
void HardwareSetup::run() {
void HardwareSetup::run(){
int nBytes = 0; int nBytes = 0;
//char buffer[256]; // char buffer[256];
struct TransStruct buffer[2]; struct TransStruct buffer[6];
//struct TransStruct *buffer = buffer1; // struct TransStruct *buffer = buffer1;
//cout << "thread started" << endl; // cout << "thread started" << endl;
// if(argc < 2) { // if(argc < 2) {
// printf("Usage:\n"); // printf("Usage:\n");
// printf("usbtext.exe on\n"); // printf("usbtext.exe on\n");
// printf("usbtext.exe off\n"); // printf("usbtext.exe off\n");
// exit(1); // exit(1);
// } // }
while(!this->handle){ while (!this->handle) {
this->handle = usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample"); this->handle = usbOpenDevice(0x16C0, "test01", 0x05DC, "USBExample");
if(this->handle == NULL) { if (this->handle == NULL) {
fprintf(stderr, "Could not find USB device!\n"); fprintf(stderr, "Could not find USB device!\n");
} }
sleep(1); sleep(1);
} }
int index; int index;
while(!this->stop){ while (!this->stop) {
usleep(100000); // 100ms usleep(100000); // 100ms
//while(1){ // while(1){
nBytes = usb_control_msg(this->handle, nBytes = usb_control_msg(
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, this->handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000); USB_DATA_OUT, 0, 0, (char *)buffer, sizeof(buffer), 5000);
for(int i = 0; i < 2; i++){ for (int i = 0; i < 6; i++) {
if(buffer[i].update != 0){ if (buffer[i].update != 0) {
switch(buffer[i].id){ switch (buffer[i].id) {
case 0: case 0:
cout << "Shell Zeit 1: " << (int)buffer[i].time << endl; cout << "Shell Zeit 1: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 1); emit Shell((int)buffer[i].time, 1);
break; break;
case 1: case 1:
cout << "Dea Zeit 1: " << (int)buffer[i].time << endl; cout << "Dea Zeit 1: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 1); emit Dea((int)buffer[i].time, 1);
break; break;
case 2: case 2:
cout << "Shell Zeit 2: " << (int)buffer[i].time << endl; cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 2); emit Shell((int)buffer[i].time, 2);
break; break;
case 3: case 3:
cout << "Dea Zeit 2: " << (int)buffer[i].time << endl; cout << "Dea Zeit 2: " << (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 << "Shell Zeit 2: " << (int)buffer[i].time << endl; cout << "Shell Zeit 2: " << (int)buffer[i].time << endl;
emit Shell((int)buffer[i].time, 3); emit Shell((int)buffer[i].time, 3);
break; break;
case 5: case 5:
cout << "Dea Zeit 3: " << (int)buffer[i].time << endl; cout << "Dea Zeit 3: " << (int)buffer[i].time << endl;
emit Dea((int)buffer[i].time, 3); emit Dea((int)buffer[i].time, 3);
break; break;
}
} }
} }
if(buffer[0].update != 0){ }
cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time << ", " << (int)buffer[2].id << endl; if (buffer[0].update != 0) {
} cout << "Got " << nBytes << " bytes: " << (int)buffer[2].time
<< ", " << (int)buffer[2].id << endl;
}
//} //}
if(nBytes < 0) if (nBytes < 0)
fprintf(stderr, "USB error: %sn", usb_strerror()); fprintf(stderr, "USB error: %sn", usb_strerror());
} }
} }
bool HardwareSetup::getShell() {
bool HardwareSetup::getShell(){ // int zahl[8] = {0};
// int zahl[8] = {0}; // if(findBit(zahl, inb(BASEPORT + 1))[7] == 1){
// if(findBit(zahl, inb(BASEPORT + 1))[7] == 1){ // return true;
// }
// return true;
// }
return false; return false;
} }
bool HardwareSetup::getDea(){ bool HardwareSetup::getDea() {
// int zahl[8] = {0}; // int zahl[8] = {0};
// if(findBit(zahl, inb(BASEPORT + 1))[6] == 0 ){ // if(findBit(zahl, inb(BASEPORT + 1))[6] == 0 ){
// return true; // return true;
// } // }
return false; return false;
} }
int* HardwareSetup::findBit(int *array, int zahl){ int * HardwareSetup::findBit(int * array, int zahl) {
if(zahl >=128){ if (zahl >= 128) {
array[7] = 1; array[7] = 1;
zahl -= 128; zahl -= 128;
} }
if(zahl >=64){ if (zahl >= 64) {
array[6] = 1; array[6] = 1;
zahl -= 64; zahl -= 64;
} }
if(zahl >=32){ if (zahl >= 32) {
array[5] = 1; array[5] = 1;
zahl -= 32; zahl -= 32;
} }
if(zahl >=16){ if (zahl >= 16) {
array[4] = 1; array[4] = 1;
zahl -= 16; zahl -= 16;
} }
if(zahl >=8){ if (zahl >= 8) {
array[3] = 1; array[3] = 1;
zahl -= 8; zahl -= 8;
} }
if(zahl >=4){ if (zahl >= 4) {
array[2] = 1; array[2] = 1;
zahl -= 4; zahl -= 4;
} }
if(zahl >=2){ if (zahl >= 2) {
array[1] = 1; array[1] = 1;
zahl -= 2; zahl -= 2;
} }
if(zahl >=1){ if (zahl >= 1) {
array[0] = 1; array[0] = 1;
zahl -= 1; zahl -= 1;
} }

View File

@@ -1,8 +1,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QApplication> #include <QApplication>
int main(int argc, char *argv[]) int main(int argc, char * argv[]) {
{
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.show(); w.show();

View File

@@ -1,22 +1,20 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "database.h"
#include "hardwaresetup.h"
#include "training.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "unistd.h"
#include "windowrace.h"
#include "windowrennliste2.h"
#include "windowssettings.h"
#include <QObject> #include <QObject>
#include <QShortcut> #include <QShortcut>
#include "windowssettings.h"
#include <iostream> #include <iostream>
#include "hardwaresetup.h"
#include "windowrace.h"
#include "database.h"
#include <vector> #include <vector>
#include "windowrennliste2.h"
#include "training.h"
#include "unistd.h"
using std::vector; using std::vector;
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::MainWindow) {
ui(new Ui::MainWindow)
{
ui->setupUi(this); ui->setupUi(this);
this->interfaceTraining = NULL; this->interfaceTraining = NULL;
@@ -24,50 +22,48 @@ MainWindow::MainWindow(QWidget *parent) :
this->interfaceSettings = NULL; this->interfaceSettings = NULL;
this->interfaceRennliste = NULL; this->interfaceRennliste = NULL;
//test = new HardwareSetup; // test = new HardwareSetup;
//this->test->start(); // this->test->start();
QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(NewWindowSettings())); QObject::connect(ui->pushButton, SIGNAL(clicked()), this,
SLOT(NewWindowSettings()));
QObject::connect(ui->pBRennen, SIGNAL(clicked()), this, SLOT(WindowRennen())); QObject::connect(ui->pBRennen, SIGNAL(clicked()), this,
QObject::connect(this->ui->pBTraining, SIGNAL(clicked()), this, SLOT(WindowTraining())); SLOT(WindowRennen()));
QObject::connect(this->ui->pBTraining, SIGNAL(clicked()), this,
QShortcut *startTraining = new QShortcut(QKeySequence("Ctrl+t"), this); SLOT(WindowTraining()));
QShortcut *startRennen = new QShortcut(QKeySequence("Ctrl+r"), this);
QObject::connect(startTraining, SIGNAL(activated()), this, SLOT(WindowTraining()));
QObject::connect(startRennen, SIGNAL(activated()), this, SLOT(WindowRennen()));
QShortcut * startTraining = new QShortcut(QKeySequence("Ctrl+t"), this);
QShortcut * startRennen = new QShortcut(QKeySequence("Ctrl+r"), this);
QObject::connect(startTraining, SIGNAL(activated()), this,
SLOT(WindowTraining()));
QObject::connect(startRennen, SIGNAL(activated()), this,
SLOT(WindowRennen()));
this->db = new DataBase; this->db = new DataBase;
vector< vector <QString> > daten = db->getData("select * from Fahrer", 2); vector<vector<QString>> daten = db->getData("select * from Fahrer", 2);
} }
void MainWindow::closeEvent(QCloseEvent *event){ void MainWindow::closeEvent(QCloseEvent * event) {
} }
MainWindow::~MainWindow() MainWindow::~MainWindow() {
{
delete this->db; delete this->db;
delete ui; delete ui;
} }
void MainWindow::WindowTraining(){ void MainWindow::WindowTraining() {
this->interfaceTraining = new Training(this, this->db); this->interfaceTraining = new Training(this, this->db);
this->interfaceTraining->show(); this->interfaceTraining->show();
} }
void MainWindow::NewWindowSettings(){ void MainWindow::NewWindowSettings() {
this->interfaceSettings = new WindowsSettings(this->db, this); this->interfaceSettings = new WindowsSettings(this->db, this);
this->interfaceSettings->show(); this->interfaceSettings->show();
} }
void MainWindow::WindowRennen(){ void MainWindow::WindowRennen() {
this->interfaceRace = new WindowRace(this->db, this); this->interfaceRace = new WindowRace(this->db, this);
this->interfaceRace->show(); this->interfaceRace->show();
this->interfaceRennliste = new WindowRennliste(this->db, this); this->interfaceRennliste = new WindowRennliste(this->db, this);

View File

@@ -1,35 +1,33 @@
#include "qvectorhelper.h" #include "qvectorhelper.h"
#include <qvector.h> #include <qvector.h>
QVectorHelper::QVectorHelper() QVectorHelper::QVectorHelper() {
{
} }
int QVectorHelper::getCurTime(const QVector<int> x) { int QVectorHelper::getCurTime(const QVector<int> x) {
if(x.size() >= 3){ if (x.size() >= 3) {
return x.at(0)+ x.at(1) + x.at(2); return x.at(0) + x.at(1) + x.at(2);
} }
else{ else {
return 9999; return 9999;
} }
} }
int QVectorHelper::getMin(const QVector<QVector<int>> x){ int QVectorHelper::getMin(const QVector<QVector<int>> x) {
int min; int min;
if(x.size() > 0){ if (x.size() > 0) {
if(x.at(0).size() >= 3){ if (x.at(0).size() >= 3) {
min = getCurTime(x.at(0)); min = getCurTime(x.at(0));
} }
else{ else {
return 9999; return 9999;
} }
} }
else{ else {
return 9999; return 9999;
} }
for(int i = 1; i < x.size(); i++){ for (int i = 1; i < x.size(); i++) {
if(getCurTime(x.at(i)) < min){ if (getCurTime(x.at(i)) < min) {
min = getCurTime(x.at(i)); min = getCurTime(x.at(i));
} }
} }

View File

@@ -1,165 +1,170 @@
#include "timemodel.h" #include "timemodel.h"
#include<qvector.h>
#include <iostream> #include <iostream>
#include <qcolor.h> #include <qcolor.h>
#include <qvector.h>
TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes,
TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes, QObject *parent) QObject * parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent) {
{
this->timeData = timeData; this->timeData = timeData;
this->minimumTimes = minimumTimes; this->minimumTimes = minimumTimes;
} }
TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes, QVector<int> topTime, QObject *parent) TimeModel::TimeModel(QVector<QVector<int>> timeData, QVector<int> minimumTimes,
: QAbstractTableModel(parent) QVector<int> topTime, QObject * parent)
{ : QAbstractTableModel(parent) {
this->topTime = topTime; this->topTime = topTime;
this->timeData = timeData; this->timeData = timeData;
this->minimumTimes = minimumTimes; this->minimumTimes = minimumTimes;
} }
QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant TimeModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return QString("Sektor 1");
case 1:
return QString("Sektor 2");
case 2:
return QString("Sektor 3");
case 3:
return QString("Runde");
default:
return QVariant();
}
}
return QVariant(); return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return QString("Sektor 1");
case 1:
return QString("Sektor 2");
case 2:
return QString("Sektor 3");
case 3:
return QString("Runde");
default:
return QVariant();
}
}
return QVariant();
} }
int TimeModel::rowCount(const QModelIndex &parent) const int TimeModel::rowCount(const QModelIndex & parent) const {
{
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
return this->timeData.size(); return this->timeData.size();
} }
int TimeModel::columnCount(const QModelIndex &parent) const int TimeModel::columnCount(const QModelIndex & parent) const {
{
if (parent.isValid()) if (parent.isValid())
return 0; return 0;
return 4; return 4;
} }
QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, const int row) const{ QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col,
if(row == 0){ const int row) const {
if (row == 0) {
return QColor(Qt::gray); return QColor(Qt::gray);
} }
else if(data.size() > row){ // check for enough rows else if (data.size() > row) { // check for enough rows
if(data.at(row).size() > col){ // check for enough cols if (data.at(row).size() > col) { // check for enough cols
if(col < 3){ if (col < 3) {
if(data.at(row).at(col) < this->minimumTimes.at(col)){ if (data.at(row).at(col) < this->minimumTimes.at(col)) {
return QColor(Qt::red); return QColor(Qt::red);
} }
} }
else{ else {
// lap time // lap time
if( data.at(row).at(0) < this->minimumTimes.at(0) if (data.at(row).at(0) < this->minimumTimes.at(0) ||
|| data.at(row).at(1) < this->minimumTimes.at(1) data.at(row).at(1) < this->minimumTimes.at(1) ||
|| data.at(row).at(2) < this->minimumTimes.at(2)){ data.at(row).at(2) < this->minimumTimes.at(2)) {
return QColor(Qt::red); return QColor(Qt::red);
} }
} }
QVector<int> compare; QVector<int> compare;
for(int i = 0; i <= row; i++){ for (int i = 0; i <= row; i++) {
if(data.at(i).size() > col){ if (data.at(i).size() > col) {
compare.append(data.at(i).at(col)); compare.append(data.at(i).at(col));
} }
} }
if(data.at(row).at(col) == getMin(compare)){ // at least personal best time if (data.at(row).at(col) ==
if(col < 3){ // sector time getMin(compare)) { // at least personal best time
// std::cout << this->topTime.size() << std::endl; if (col < 3) { // sector time
if(this->topTime.size() > col){ // absolute top time exists // std::cout << this->topTime.size() <<
// std::cout << "local besttime" << std::endl; // std::endl;
if(this->topTime.at(col) >= data.at(row).at(col)){ if (this->topTime.size() >
col) { // absolute top time exists
// std::cout << "local besttime"
// << std::endl;
if (this->topTime.at(col) >= data.at(row).at(col)) {
return QColor(Qt::magenta); return QColor(Qt::magenta);
} }
} }
} }
else{ // lap time else { // lap time
if(this->topTime.size() == 3){ if (this->topTime.size() == 3) {
if(this->topTime.at(0) + this->topTime.at(1) + this->topTime.at(2) >= data.at(row).at(col)){ if (this->topTime.at(0) + this->topTime.at(1) +
this->topTime.at(2) >=
data.at(row).at(col)) {
return QColor(Qt::magenta); return QColor(Qt::magenta);
} }
} }
} }
return QColor(Qt::green); return QColor(Qt::green);
} }
else{ else {
return QColor(Qt::gray); return QColor(Qt::gray);
} }
} }
else{ else {
return QColor(Qt::white); return QColor(Qt::white);
} }
} }
else{ else {
return QColor(Qt::white); return QColor(Qt::white);
} }
} }
int TimeModel::getMin(const QVector<int> x) const{ int TimeModel::getMin(const QVector<int> x) const {
int min; int min;
if(x.size() > 0){ if (x.size() > 0) {
min = x.at(0); min = x.at(0);
} }
for(int i = 1; i < x.size(); i++){ for (int i = 1; i < x.size(); i++) {
if(x.at(i) < min){ if (x.at(i) < min) {
min = x.at(i); min = x.at(i);
} }
} }
return min; return min;
} }
QVariant TimeModel::data(const QModelIndex &index, int role) const QVariant TimeModel::data(const QModelIndex & index, int role) const {
{ // std::cout << "data called" << std::endl;
//std::cout << "data called" << std::endl;
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
if(role == Qt::DisplayRole){ if (role == Qt::DisplayRole) {
if(timeData.at(index.row()).size() > index.column()){ if (timeData.at(index.row()).size() > index.column()) {
return QString::number((double)timeData.at(index.row()).at(index.column())/1000); return QString::number(
(double)timeData.at(index.row()).at(index.column()) / 1000);
} }
else{ else {
return QString(""); return QString("");
} }
} }
else if(role == Qt::BackgroundColorRole){ else if (role == Qt::BackgroundColorRole) {
return getColor(timeData, index.column(), index.row()); return getColor(timeData, index.column(), index.row());
} }
return QVariant(); return QVariant();
} }
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();
return true;
} }
bool TimeModel::insertColumns(int column, int count, const QModelIndex &parent) bool TimeModel::insertColumns(int column, int count,
{ const QModelIndex & parent) {
beginInsertColumns(parent, column, column + count - 1); beginInsertColumns(parent, column, column + count - 1);
// FIXME: Implement me! // FIXME: Implement me!
endInsertColumns(); endInsertColumns();
return true;
} }

View File

@@ -1,27 +1,26 @@
#include "training.h" #include "training.h"
#include "qvectorhelper.h"
#include "timemodel.h"
#include "ui_training.h" #include "ui_training.h"
#include <QObject>
#include <string>
#include <sstream>
#include <iostream>
#include <QShortcut>
#include "unistd.h" #include "unistd.h"
#include <QListWidgetItem> #include <QListWidgetItem>
#include "timemodel.h" #include <QObject>
#include "qvectorhelper.h" #include <QShortcut>
#include <iostream>
#include <sstream>
#include <string>
using std::vector;
using std::string;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::string;
using std::vector;
Training::Training(QWidget *parent, DataBase *db) : Training::Training(QWidget * parent, DataBase * db)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::Training) {
ui(new Ui::Training)
{
ui->setupUi(this); ui->setupUi(this);
this->db = db; this->db = db;
string statement = "select mindestrundendauer from renndauer where id like 1"; string statement =
"select mindestrundendauer from renndauer where id like 1";
this->minimumTime = this->db->getData(statement, 1)[0][0].toInt(); this->minimumTime = this->db->getData(statement, 1)[0][0].toInt();
this->finished = false; this->finished = false;
@@ -35,36 +34,38 @@ Training::Training(QWidget *parent, DataBase *db) :
this->Hardware = new HardwareSetup; this->Hardware = new HardwareSetup;
Hardware->start(); Hardware->start();
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this,
SLOT(deaSlot(int, int)));
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this,
SLOT(shellSlot(int, int)));
// 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);
QShortcut * shellReset = new QShortcut(QKeySequence("Ctrl+s"), this);
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this, SLOT(deaSlot(int, int))); QShortcut * deaReset = new QShortcut(QKeySequence("Ctrl+d"), this);
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this, SLOT(shellSlot(int, int)));
//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);
QShortcut *shellReset = new QShortcut(QKeySequence("Ctrl+s"), this);
QShortcut *deaReset = new QShortcut(QKeySequence("Ctrl+d"), this);
QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close())); QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));
QObject::connect(shellReset, SIGNAL(activated()), this, SLOT(ResetShell())); QObject::connect(shellReset, SIGNAL(activated()), this, SLOT(ResetShell()));
QObject::connect(deaReset, SIGNAL(activated()), this, SLOT(ResetDea())); QObject::connect(deaReset, SIGNAL(activated()), this, SLOT(ResetDea()));
QObject::connect(this->ui->pBReset, SIGNAL(clicked()), this, SLOT(Reset())); QObject::connect(this->ui->pBReset, SIGNAL(clicked()), this, SLOT(Reset()));
QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this, SLOT(ResetDea())); QObject::connect(this->ui->pBResetDea, SIGNAL(clicked()), this,
QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this, SLOT(ResetShell())); SLOT(ResetDea()));
QObject::connect(this->ui->pBResetShell, SIGNAL(clicked()), this,
SLOT(ResetShell()));
// fill minSecTimes vector // fill minSecTimes vector
statement = "select minsec1, minsec2, minsec3 from renndauer order by id DESC limit 1"; statement = "select minsec1, minsec2, minsec3 from renndauer order by id "
vector< vector< QString > > res; "DESC limit 1";
vector<vector<QString>> res;
res = db->getData(statement, 3); res = db->getData(statement, 3);
this->minSecTime.append(res[0][0].toInt()); this->minSecTime.append(res[0][0].toInt());
this->minSecTime.append(res[0][1].toInt()); this->minSecTime.append(res[0][1].toInt());
this->minSecTime.append(res[0][2].toInt()); this->minSecTime.append(res[0][2].toInt());
} }
void Training::ResetShell(){ void Training::ResetShell() {
this->VecShell.clear(); this->VecShell.clear();
// this->ui->lWShellTime->clear(); // this->ui->lWShellTime->clear();
@@ -75,10 +76,10 @@ void Training::ResetShell(){
this->ui->lCurRoundTimeShell->setText(""); this->ui->lCurRoundTimeShell->setText("");
this->firstTimeShell = true; this->firstTimeShell = true;
} }
void Training::ResetDea(){ void Training::ResetDea() {
this->VecDea.clear(); this->VecDea.clear();
//this->ui->lWDeaTime->clear(); // this->ui->lWDeaTime->clear();
timeModelDea = new TimeModel(VecDea, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
@@ -87,11 +88,11 @@ void Training::ResetDea(){
this->ui->lCurRoundDea->setText(""); this->ui->lCurRoundDea->setText("");
this->firstTimeDea = true; this->firstTimeDea = true;
} }
void Training::Reset(){ void Training::Reset() {
this->ResetDea(); this->ResetDea();
this->ResetShell(); this->ResetShell();
} }
void Training::prepareNextRace(){ void Training::prepareNextRace() {
this->firstTimeShell = true; this->firstTimeShell = true;
this->firstTimeDea = true; this->firstTimeDea = true;
@@ -108,137 +109,155 @@ void Training::prepareNextRace(){
this->started = true; this->started = true;
} }
void Training::shellSlot(int time, int sector){ void Training::shellSlot(int time, int sector) {
// 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
cout << "received Shelltime: " << time << sector << endl; cout << "received Shelltime: " << time << sector << endl;
if(started && !paused && !this->finished){ if (started && !paused && !this->finished) {
if(firstTimeShell){ if (firstTimeShell) {
firstTimeShell = false; firstTimeShell = false;
} }
else{ else {
switch(sector){ switch (sector) {
case 1: case 1:
VecShell.push_back(QVector<int>()); VecShell.push_back(QVector<int>());
VecShell.last().push_back(time); VecShell.last().push_back(time);
timeModelShell = new TimeModel(VecShell, minSecTime, this); timeModelShell = new TimeModel(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
break; break;
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 <<
VecShell.last().push_back(time); // endl;
timeModelShell = new TimeModel(VecShell, minSecTime, this); VecShell.last().push_back(time);
this->ui->lWShellTime->setModel(timeModelShell); timeModelShell =
} new TimeModel(VecShell, minSecTime, this);
this->ui->lWShellTime->setModel(timeModelShell);
} }
break; }
case 3: break;
if(VecShell.size() > 0){ case 3:
//cout << "Time sec 3: " << time << endl; if (VecShell.size() > 0) {
if(VecShell.last().size() == 2){ // cout << "Time sec 3: " << time << endl;
// cout << time << sector << endl; if (VecShell.last().size() == 2) {
VecShell.last().push_back(time); // cout << time << sector <<
// endl;
VecShell.last().push_back(time);
// 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, minSecTime, this); timeModelShell =
this->ui->lWShellTime->setModel(timeModelShell); new TimeModel(VecShell, minSecTime, this);
} this->ui->lWShellTime->setModel(timeModelShell);
// best time on widget
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){
ui->lBestZeitShell->setText(QString::number((double)QVectorHelper::getMin(VecShell)/1000));
}
ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000));
} }
// best time on widget
break; if (QVectorHelper::getCurTime(VecShell.last()) <=
QVectorHelper::getMin(VecShell)) {
ui->lBestZeitShell->setText(QString::number(
(double)QVectorHelper::getMin(VecShell) / 1000));
}
ui->lCurRoundTimeShell->setText(QString::number(
(double)QVectorHelper::getCurTime(VecShell.last()) /
1000));
}
break;
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWShellTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
} }
} }
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) {
// 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
cout << "received Deatime: " << time << sector << endl; cout << "received Deatime: " << time << sector << endl;
if (started && !paused && !this->finished) {
if(started && !paused && !this->finished){ if (firstTimeDea) {
if(firstTimeDea){
firstTimeDea = false; firstTimeDea = false;
} }
else{ else {
switch(sector){ switch (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, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
break; break;
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 <<
VecDea[VecDea.size()-1].push_back(time); // endl;
timeModelDea = new TimeModel(VecDea, minSecTime, this); VecDea[VecDea.size() - 1].push_back(time);
this->ui->lWDeaTime->setModel(timeModelDea); timeModelDea = new TimeModel(VecDea, minSecTime, this);
} this->ui->lWDeaTime->setModel(timeModelDea);
else{
//VecDea[VecDea.size()-1].append(9999);
}
} }
break; else {
case 3: // VecDea[VecDea.size()-1].append(9999);
if(VecDea.size() > 0){
//cout << "Time sec 3: " << time << endl;
if(VecDea.last().size() == 2){
// cout << time << sector << endl;
VecDea.last().push_back(time);
// add sum to vector
VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
}
// best time on widget
// cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl;
// cout << "min time: " << QVectorHelper::getMin(VecDea) << endl;
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){
ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000));
}
ui->lCurRoundDea->setText(QString::number((double)QVectorHelper::getCurTime(VecDea.last())/1000));
} }
break; }
break;
case 3:
if (VecDea.size() > 0) {
// cout << "Time sec 3: " << time << endl;
if (VecDea.last().size() == 2) {
// cout << time << sector <<
// endl;
VecDea.last().push_back(time);
// add sum to vector
VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
}
// best time on widget
// cout << "cur time: " <<
// QVectorHelper::getCurTime(VecDea.last())
// << endl; cout << "min time: " <<
// QVectorHelper::getMin(VecDea) <<
// endl;
if (QVectorHelper::getCurTime(VecDea.last()) <=
QVectorHelper::getMin(VecDea)) {
ui->lBestZeitDea->setText(QString::number(
(double)QVectorHelper::getMin(VecDea) / 1000));
}
ui->lCurRoundDea->setText(QString::number(
(double)QVectorHelper::getCurTime(VecDea.last()) /
1000));
}
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; cout << "destr Training" << endl;
this->Hardware->setStop(); this->Hardware->setStop();
usleep(1000000); usleep(1000000);

View File

@@ -1,24 +1,22 @@
#include "windowrace.h" #include "windowrace.h"
#include "ui_windowrace.h"
#include <QObject>
#include <string>
#include <QShortcut>
#include <sstream>
#include <iostream>
#include "unistd.h"
#include <QKeySequence>
#include "qvectorhelper.h" #include "qvectorhelper.h"
#include "timemodel.h" #include "timemodel.h"
#include "ui_windowrace.h"
#include "unistd.h"
#include <QKeySequence>
#include <QObject>
#include <QShortcut>
#include <iostream>
#include <sstream>
#include <string>
using std::vector;
using std::string;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::string;
using std::vector;
WindowRace::WindowRace(DataBase *db, QWidget *parent) : WindowRace::WindowRace(DataBase * db, QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::WindowRace) {
ui(new Ui::WindowRace)
{
ui->setupUi(this); ui->setupUi(this);
this->ui->pBNextRace->setEnabled(false); this->ui->pBNextRace->setEnabled(false);
this->finished = false; this->finished = false;
@@ -27,22 +25,23 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
this->db = db; this->db = db;
vector< vector< QString > > res; vector<vector<QString>> res;
res = db->getData("select dauer from renndauer", 1); res = db->getData("select dauer from renndauer", 1);
this->fahrzeit = res[0][0].toInt(); this->fahrzeit = res[0][0].toInt();
string statement = "select minimumroundtime from rennen order by id DESC limit 1"; string statement =
"select minimumroundtime from rennen order by id DESC limit 1";
res = db->getData(statement, 1); res = db->getData(statement, 1);
this->minimumTime = res[0][0].toInt(); this->minimumTime = res[0][0].toInt();
// fill minSecTimes vector // fill minSecTimes vector
statement = "select minsec1, minsec2, minsec3 from renndauer order by id DESC limit 1"; statement = "select minsec1, minsec2, minsec3 from renndauer order by id "
"DESC limit 1";
res = db->getData(statement, 3); res = db->getData(statement, 3);
this->minSecTime.append(res[0][0].toInt()); this->minSecTime.append(res[0][0].toInt());
this->minSecTime.append(res[0][1].toInt()); this->minSecTime.append(res[0][1].toInt());
this->minSecTime.append(res[0][2].toInt()); this->minSecTime.append(res[0][2].toInt());
firstTimeDea = true; firstTimeDea = true;
firstTimeShell = true; firstTimeShell = true;
started = false; started = false;
@@ -59,20 +58,27 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
Hardware = new HardwareSetup; Hardware = new HardwareSetup;
Hardware->start(); Hardware->start();
QObject::connect(Hardware, SIGNAL(Dea(int, int)), this, SLOT(deaSlot(int, int))); QObject::connect(Hardware, SIGNAL(Dea(int, int)), this,
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this, SLOT(shellSlot(int, int))); SLOT(deaSlot(int, int)));
QObject::connect(Hardware, SIGNAL(Shell(int, int)), this,
SLOT(shellSlot(int, int)));
QObject::connect(ui->pBStart, SIGNAL(clicked()), this, SLOT(go())); QObject::connect(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));
QObject::connect(countdown, SIGNAL(CountdownUpdate()), this, SLOT(countdownUpdate())); QObject::connect(countdown, SIGNAL(CountdownUpdate()), this,
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(ampelSlot())); SLOT(countdownUpdate()));
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(laufcheck())); QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this,
QObject::connect(ui->pBBreak, SIGNAL(clicked()), this, SLOT(breakCounter())); SLOT(ampelSlot()));
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace())); QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this,
QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this, SLOT(stopClicked())); SLOT(laufcheck()));
QObject::connect(ui->pBBreak, SIGNAL(clicked()), this,
SLOT(breakCounter()));
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this,
SLOT(prepareNextRace()));
QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this,
SLOT(stopClicked()));
ui->lCountdown->setText(timeWrapper(countdownValue)); ui->lCountdown->setText(timeWrapper(countdownValue));
//Ampelsetup // Ampelsetup
ui->WAmpel15->hide(); ui->WAmpel15->hide();
ui->WAmpel25->hide(); ui->WAmpel25->hide();
ui->hW15->setVisible(true); ui->hW15->setVisible(true);
@@ -94,38 +100,43 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
ui->hW11->setVisible(true); ui->hW11->setVisible(true);
ui->hW21->setVisible(true); ui->hW21->setVisible(true);
vector<vector<QString>> fahrer, autos, rennid, tableData;
vector< vector<QString> > fahrer, autos, rennid, tableData; statement = "select id_rennen from aktrennen group by id_rennen order by "
statement = "select id_rennen from aktrennen group by id_rennen order by id_rennen DESC limit 1"; "id_rennen DESC limit 1";
rennid = this->db->getData(statement, 1); rennid = this->db->getData(statement, 1);
this->renn_id = rennid[0][0].toInt(); this->renn_id = rennid[0][0].toInt();
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid from aktrennen where id_rennen like "+rennid[0][0].toStdString()+" limit 1"; statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
"from aktrennen where id_rennen like " +
rennid[0][0].toStdString() + " limit 1";
tableData = db->getData2(statement, 4); tableData = db->getData2(statement, 4);
statement = "select name from fahrer where id like " +
statement = "select name from fahrer where id like " + tableData[0][0].toStdString(); tableData[0][0].toStdString();
fahrer = this->db->getData2(statement, 1); fahrer = this->db->getData2(statement, 1);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[0][1].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[0][1].toStdString() + " order by seit DESC";
autos = this->db->getData2(statement, 1); autos = this->db->getData2(statement, 1);
this->ui->gbShell->setTitle("Shell, "+fahrer[0][0]+", "+autos[0][0]); this->ui->gbShell->setTitle("Shell, " + fahrer[0][0] + ", " + autos[0][0]);
statement = "select name from fahrer where id like " + tableData[0][2].toStdString(); statement = "select name from fahrer where id like " +
tableData[0][2].toStdString();
fahrer = this->db->getData2(statement, 1); fahrer = this->db->getData2(statement, 1);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[0][3].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[0][3].toStdString() + " order by seit DESC";
autos = this->db->getData2(statement, 1); autos = this->db->getData2(statement, 1);
this->ui->gbDea->setTitle("Dea, "+fahrer[0][0]+", "+autos[0][0]); this->ui->gbDea->setTitle("Dea, " + fahrer[0][0] + ", " + autos[0][0]);
this->shellDriverId = tableData[0][0].toInt(); this->shellDriverId = tableData[0][0].toInt();
this->shellCarId = tableData[0][1].toInt(); this->shellCarId = tableData[0][1].toInt();
this->deaDriverId = tableData[0][2].toInt(); this->deaDriverId = tableData[0][2].toInt();
this->deaCarId = tableData[0][3].toInt(); this->deaCarId = tableData[0][3].toInt();
//progressbar // progressbar
this->ui->pbTime->setMaximum(this->fahrzeit); this->ui->pbTime->setMaximum(this->fahrzeit);
this->ui->pbTime->setMinimum(0); this->ui->pbTime->setMinimum(0);
this->ui->pbTime->setTextVisible(false); this->ui->pbTime->setTextVisible(false);
@@ -133,35 +144,34 @@ WindowRace::WindowRace(DataBase *db, QWidget *parent) :
this->ui->pbTime->setValue(0); this->ui->pbTime->setValue(0);
QKeySequence ks(Qt::Key_Return); // btw, this is numpad enter QKeySequence ks(Qt::Key_Return); // btw, this is numpad enter
QShortcut *keyReturn = new QShortcut(ks, this); QShortcut * keyReturn = new QShortcut(ks, this);
QObject::connect(keyReturn, SIGNAL(activated()), this, SLOT(ReturnPress())); QObject::connect(keyReturn, SIGNAL(activated()), this, SLOT(ReturnPress()));
//QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close())); // QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));
} }
void WindowRace::ReturnPress(){ void WindowRace::ReturnPress() {
//cout << "Return pressed" << endl; // cout << "Return pressed" << endl;
if(this->ui->pBNextRace->isEnabled()){ if (this->ui->pBNextRace->isEnabled()) {
this->prepareNextRace(); this->prepareNextRace();
if(this->wRennlisteSeted){ if (this->wRennlisteSeted) {
this->wRennliste->changeSelection(); this->wRennliste->changeSelection();
} }
else{ else {
cout << "Problem with racelist" << endl; cout << "Problem with racelist" << endl;
} }
} }
else{ else {
if(started){ if (started) {
this->breakCounter(); this->breakCounter();
} }
else{ else {
this->go(); this->go();
} }
} }
} }
void WindowRace::prepareNextRace(){ void WindowRace::prepareNextRace() {
this->firstTimeShell = true; this->firstTimeShell = true;
this->firstTimeDea = true; this->firstTimeDea = true;
@@ -194,14 +204,14 @@ void WindowRace::prepareNextRace(){
this->ui->pBNextRace->setEnabled(false); this->ui->pBNextRace->setEnabled(false);
this->ui->lCountdown->setText(timeWrapper(countdownValue)); this->ui->lCountdown->setText(timeWrapper(countdownValue));
//progressbar // progressbar
this->ui->pbTime->setStyleSheet("QProgressBar::chunk { color: #05B8CC;}"); this->ui->pbTime->setStyleSheet("QProgressBar::chunk { color: #05B8CC;}");
this->ui->pbTime->setValue(0); this->ui->pbTime->setValue(0);
//countdown // countdown
this->ui->lCountdown->setStyleSheet("QLabel { color: black; }"); this->ui->lCountdown->setStyleSheet("QLabel { color: black; }");
//Ampel Setup // Ampel Setup
ui->WAmpel15->hide(); ui->WAmpel15->hide();
ui->WAmpel25->hide(); ui->WAmpel25->hide();
ui->hW15->setVisible(true); ui->hW15->setVisible(true);
@@ -223,29 +233,28 @@ void WindowRace::prepareNextRace(){
ui->hW11->setVisible(true); ui->hW11->setVisible(true);
ui->hW21->setVisible(true); ui->hW21->setVisible(true);
} }
void WindowRace::setDriverAndCar(vector<QString> vec){ void WindowRace::setDriverAndCar(vector<QString> vec) {
this->ui->gbShell->setTitle("Shell, "+vec[0]+", "+vec[1]); this->ui->gbShell->setTitle("Shell, " + vec[0] + ", " + vec[1]);
this->ui->gbDea->setTitle("Dea, "+vec[2]+", "+vec[3]); this->ui->gbDea->setTitle("Dea, " + vec[2] + ", " + vec[3]);
} }
void WindowRace::stopClicked(){ void WindowRace::stopClicked() {
this->prepareNextRace(); this->prepareNextRace();
} }
void WindowRace::setWindowRennliste(WindowRennliste *ptrInstance){ void WindowRace::setWindowRennliste(WindowRennliste * ptrInstance) {
this->wRennliste = ptrInstance; this->wRennliste = ptrInstance;
this->wRennlisteSeted = true; this->wRennlisteSeted = true;
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste, SLOT(changeSelection())); QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste,
SLOT(changeSelection()));
} }
void WindowRace::setDriverAndCarId(vector<QString> vec){ void WindowRace::setDriverAndCarId(vector<QString> vec) {
this->shellDriverId = vec[0].toInt(); this->shellDriverId = vec[0].toInt();
this->shellCarId = vec[1].toInt(); this->shellCarId = vec[1].toInt();
this->deaDriverId = vec[2].toInt(); this->deaDriverId = vec[2].toInt();
this->deaCarId = vec[3].toInt(); this->deaCarId = vec[3].toInt();
} }
void WindowRace::closeEvent(QCloseEvent *event){ void WindowRace::closeEvent(QCloseEvent * event) {
countdown->setStop(); countdown->setStop();
QMessageBox msgBox; QMessageBox msgBox;
@@ -256,261 +265,279 @@ void WindowRace::closeEvent(QCloseEvent *event){
int ret = msgBox.exec(); int ret = msgBox.exec();
switch (ret) { switch (ret) {
case QMessageBox::No: case QMessageBox::No:
event->ignore(); event->ignore();
break; break;
case QMessageBox::Yes: case QMessageBox::Yes:
this->wRennliste->schliessen(); this->wRennliste->schliessen();
this->Hardware->setStop(); this->Hardware->setStop();
event->accept(); event->accept();
break; break;
default: default:
// should never be reached // should never be reached
break; break;
} }
} }
void WindowRace::breakCounter(){ void WindowRace::breakCounter() {
if(!paused){ if (!paused) {
paused = true; paused = true;
ui->pBBreak->setText("Weiter"); ui->pBBreak->setText("Weiter");
} }
else{ else {
ui->pBBreak->setText("Pause"); ui->pBBreak->setText("Pause");
paused = false; paused = false;
} }
} }
void WindowRace::laufcheck(){ void WindowRace::laufcheck() {
//std::cout << "thread lauft noch" << std::endl; // std::cout << "thread lauft noch" << std::endl;
} }
QString WindowRace::timeWrapper(long zahl){ QString WindowRace::timeWrapper(long zahl) {
long min = zahl / 60; long min = zahl / 60;
int sec = zahl % 60; int sec = zahl % 60;
QString sec_q; QString sec_q;
if(sec < 10){ if (sec < 10) {
sec_q = "0"+QString::number(sec); sec_q = "0" + QString::number(sec);
} }
else{ else {
sec_q = QString::number(sec); sec_q = QString::number(sec);
} }
QString min_q = QString::number(min); QString min_q = QString::number(min);
return min_q+":"+sec_q; return min_q + ":" + sec_q;
} }
void WindowRace::countdownUpdate(){ void WindowRace::countdownUpdate() {
if(!paused){ if (!paused) {
countdownValue -= 1; countdownValue -= 1;
if(countdownValue <= 15){ if (countdownValue <= 15) {
this->ui->lCountdown->setStyleSheet("QLabel { color: red; }"); this->ui->lCountdown->setStyleSheet("QLabel { color: red; }");
this->ui->pbTime->setStyleSheet( "QProgressBar::chunk { background-color: orange; }"); this->ui->pbTime->setStyleSheet(
//this->ui->pbTime-> "QProgressBar::chunk { background-color: orange; }");
// this->ui->pbTime->
} }
if(countdownValue <= -1){ if (countdownValue <= -1) {
this->finished = true; this->finished = true;
this->wRennliste->setBesttime(QVectorHelper::getMin(VecShell),QVectorHelper::getMin(this->VecDea)); this->wRennliste->setBesttime(QVectorHelper::getMin(VecShell),
QVectorHelper::getMin(this->VecDea));
this->ui->pBNextRace->setEnabled(true); this->ui->pBNextRace->setEnabled(true);
} }
else{ else {
ui->lCountdown->setText(timeWrapper(countdownValue)); ui->lCountdown->setText(timeWrapper(countdownValue));
this->ui->pbTime->setValue(this->fahrzeit-countdownValue); this->ui->pbTime->setValue(this->fahrzeit - countdownValue);
} }
} }
} }
WindowRace::~WindowRace() {
WindowRace::~WindowRace()
{
this->startAmpelThread->setStop(); this->startAmpelThread->setStop();
this->countdown->setStop(); this->countdown->setStop();
this->Hardware->setStop(); this->Hardware->setStop();
usleep(1000010); //eine Sekunde usleep(1000010); // eine Sekunde
delete this->countdown; delete this->countdown;
delete this->Hardware; delete this->Hardware;
delete this->startAmpelThread; delete this->startAmpelThread;
//delete this->db; // delete this->db;
delete ui; delete ui;
} }
void WindowRace::shellSlot(int time, int sector){ void WindowRace::shellSlot(int time, int sector) {
if(started && !paused && !this->finished){ if (started && !paused && !this->finished) {
if(firstTimeShell){ if (firstTimeShell) {
firstTimeShell = false; firstTimeShell = false;
// counterShell.start(); // counterShell.start();
} }
else{ else {
// long zeit = counterShell.getTime(); // long zeit = counterShell.getTime();
QVector<int> test; QVector<int> test;
switch(sector){ switch (sector) {
case 1: case 1:
VecShell.append(QVector<int>()); VecShell.append(QVector<int>());
VecShell.last().append(time); VecShell.last().append(time);
// update tableview
test.append(1);
test.append(2);
test.append(3);
this->timeModelShell =
new TimeModel(VecShell, minSecTime, test, this);
// this->ui->lWShellTime->setModel(this->timeModelShell);
ui->lWShellTime->setModel(this->timeModelShell);
break;
case 2:
if (VecShell.size() > 0) {
if (VecShell.last().size() == 1) {
VecShell.last().append(time);
}
// update tableview // update tableview
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); this->timeModelShell =
// this->ui->lWShellTime->setModel(this->timeModelShell); new TimeModel(VecShell, minSecTime, test, this);
ui->lWShellTime->setModel(this->timeModelShell); // timeModelShell = new
break; // TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell);
}
break;
case 3:
if (VecShell.size() > 0) {
if (VecShell.last().size() == 2) {
VecShell.last().append(time);
VecShell.last().append(
QVectorHelper::getCurTime(VecShell.last()));
case 2: if (QVectorHelper::getCurTime(VecShell.last()) <=
if(VecShell.size() > 0){ QVectorHelper::getMin(VecShell)) {
if(VecShell.last().size() == 1){ ui->lBestZeitShell->setText(QString::number(
VecShell.last().append(time); (double)QVectorHelper::getMin(VecShell) /
1000));
} }
ui->lCurRoundTimeShell->setText(QString::number(
(double)QVectorHelper::getCurTime(VecShell.last()) /
1000));
// update tableview // update tableview
test.append(1); test.append(1);
test.append(2); test.append(2);
test.append(3); test.append(3);
this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this); this->timeModelShell =
// timeModelShell = new TimeModel(VecShell, this); new TimeModel(VecShell, minSecTime, test, this);
// timeModelShell = new
// TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell); this->ui->lWShellTime->setModel(timeModelShell);
int zeit = QVectorHelper::getMin(VecShell);
QString statement =
"insert into Zeiten (id_rennen, id_fahrer, "
"id_auto, id_bahn, zeit) values (" +
QString::number(this->renn_id) + ", " +
QString::number(this->shellDriverId) + ", " +
QString::number(this->shellCarId) + ", 1, " +
QString::number(zeit) + ")";
cout << statement.toStdString() << endl;
// this->db->setData(statement.toStdString());
} }
break; }
case 3:
if(VecShell.size() > 0){
if(VecShell.last().size() == 2){
VecShell.last().append(time);
VecShell.last().append(QVectorHelper::getCurTime(VecShell.last()));
if(QVectorHelper::getCurTime(VecShell.last()) <= QVectorHelper::getMin(VecShell)){
ui->lBestZeitShell->setText(QString::number((double)QVectorHelper::getMin(VecShell)/1000));
}
ui->lCurRoundTimeShell->setText(QString::number((double)QVectorHelper::getCurTime(VecShell.last())/1000));
// update tableview
test.append(1);
test.append(2);
test.append(3);
this->timeModelShell = new TimeModel(VecShell, minSecTime, test, this);
// timeModelShell = new TimeModel(VecShell, this);
this->ui->lWShellTime->setModel(timeModelShell);
int zeit = QVectorHelper::getMin(VecShell);
QString statement = "insert into Zeiten (id_rennen, id_fahrer, id_auto, id_bahn, zeit) values ("+QString::number(this->renn_id)+
", "+QString::number(this->shellDriverId)+", "+QString::number(this->shellCarId)+", 1, "+QString::number(zeit)+")";
cout << statement.toStdString() << endl;
//this->db->setData(statement.toStdString());
}
}
break;
break;
} }
if(sector == 3){ if (sector == 3) {
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
} }
} }
ui->lWShellTime->scrollToBottom(); ui->lWShellTime->scrollToBottom();
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWShellTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
void WindowRace::deaSlot(int time, int sector){ void WindowRace::deaSlot(int time, int sector) {
if(started && !paused && !this->finished){ if (started && !paused && !this->finished) {
if(firstTimeDea){ if (firstTimeDea) {
firstTimeDea = false; firstTimeDea = false;
counterDea.start(); counterDea.start();
} }
else{ else {
switch(sector){ switch (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, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
break; break;
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, minSecTime, this); timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea); this->ui->lWDeaTime->setModel(timeModelDea);
}
else{
//VecDea[VecDea.size()-1].append(9999);
}
} }
break; else {
case 3: // VecDea[VecDea.size()-1].append(9999);
if(VecDea.size() > 0){
//cout << "Time sec 3: " << time << endl;
if(VecDea.last().size() == 2){
// cout << time << sector << endl;
VecDea.last().push_back(time);
// add sum to vector
VecDea.last().push_back(QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
}
// best time on widget
cout << "cur time: " << QVectorHelper::getCurTime(VecDea.last()) << endl;
cout << "min time: " << QVectorHelper::getMin(VecDea) << endl;
if(QVectorHelper::getCurTime(VecDea.last()) <= QVectorHelper::getMin(VecDea)){
ui->lBestZeitDea->setText(QString::number((double)QVectorHelper::getMin(VecDea)/1000));
}
ui->lCurRoundDea->setText(QString::number((double)QVectorHelper::getCurTime(VecDea.last())/1000));
} }
int zeit = QVectorHelper::getMin(VecDea); }
QString statement = "insert into Zeiten (id_rennen, id_fahrer, id_auto, id_bahn, zeit) values ("+QString::number(this->renn_id)+ break;
", "+QString::number(this->deaDriverId)+", "+QString::number(this->deaCarId)+", 2, "+QString::number(zeit)+")"; case 3:
cout << statement.toStdString() << endl; if (VecDea.size() > 0) {
//this->db->setData(statement.toStdString()); // cout << "Time sec 3: " << time << endl;
ui->lWDeaTime->scrollToBottom(); if (VecDea.last().size() == 2) {
// cout << time << sector <<
// endl;
VecDea.last().push_back(time);
break; // add sum to vector
VecDea.last().push_back(
QVectorHelper::getCurTime(VecDea.last()));
timeModelDea = new TimeModel(VecDea, minSecTime, this);
this->ui->lWDeaTime->setModel(timeModelDea);
}
// best time on widget
cout << "cur time: "
<< QVectorHelper::getCurTime(VecDea.last()) << endl;
cout << "min time: " << QVectorHelper::getMin(VecDea)
<< endl;
if (QVectorHelper::getCurTime(VecDea.last()) <=
QVectorHelper::getMin(VecDea)) {
ui->lBestZeitDea->setText(QString::number(
(double)QVectorHelper::getMin(VecDea) / 1000));
}
ui->lCurRoundDea->setText(QString::number(
(double)QVectorHelper::getCurTime(VecDea.last()) /
1000));
}
int zeit = QVectorHelper::getMin(VecDea);
QString statement = "insert into Zeiten (id_rennen, id_fahrer, "
"id_auto, id_bahn, zeit) values (" +
QString::number(this->renn_id) + ", " +
QString::number(this->deaDriverId) + ", " +
QString::number(this->deaCarId) + ", 2, " +
QString::number(zeit) + ")";
cout << statement.toStdString() << endl;
// this->db->setData(statement.toStdString());
ui->lWDeaTime->scrollToBottom();
break;
} }
} }
} }
ui->lWDeaTime->scrollToBottom(); ui->lWDeaTime->scrollToBottom();
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(
QHeaderView::Stretch);
} }
long WindowRace::getMinimum(std::vector<long> a){ long WindowRace::getMinimum(std::vector<long> a) {
long minimum = -1; long minimum = -1;
for(unsigned int i = 0; i < a.size(); i++){ for (unsigned int i = 0; i < a.size(); i++) {
if(minimum < 0){ if (minimum < 0) {
if(a[i] >= this->minimumTime){ if (a[i] >= this->minimumTime) {
minimum = a[i]; minimum = a[i];
} }
} }
else{ else {
if(a[i] < minimum && a[i] >= this->minimumTime){ if (a[i] < minimum && a[i] >= this->minimumTime) {
minimum = a[i]; minimum = a[i];
} }
} }
} }
return minimum; return minimum;
} }
void WindowRace::ampelSlot(){ void WindowRace::ampelSlot() {
if(ampelCounter == 5){ if (ampelCounter == 5) {
ui->WAmpel15->hide(); ui->WAmpel15->hide();
ui->WAmpel25->hide(); ui->WAmpel25->hide();
ui->hW15->setVisible(true); ui->hW15->setVisible(true);
@@ -535,35 +562,35 @@ void WindowRace::ampelSlot(){
started = true; started = true;
countdown->start(); countdown->start();
} }
if(ampelCounter == 4){ if (ampelCounter == 4) {
ampelCounter = 5; ampelCounter = 5;
ui->WAmpel15->setVisible(true); ui->WAmpel15->setVisible(true);
ui->WAmpel25->setVisible(true); ui->WAmpel25->setVisible(true);
ui->hW15->hide(); ui->hW15->hide();
ui->hW25->hide(); ui->hW25->hide();
} }
if(ampelCounter == 3){ if (ampelCounter == 3) {
ampelCounter = 4; ampelCounter = 4;
ui->WAmpel14->setVisible(true); ui->WAmpel14->setVisible(true);
ui->WAmpel24->setVisible(true); ui->WAmpel24->setVisible(true);
ui->hW14->hide(); ui->hW14->hide();
ui->hW24->hide(); ui->hW24->hide();
} }
if(ampelCounter == 2){ if (ampelCounter == 2) {
ampelCounter = 3; ampelCounter = 3;
ui->WAmpel13->setVisible(true); ui->WAmpel13->setVisible(true);
ui->WAmpel23->setVisible(true); ui->WAmpel23->setVisible(true);
ui->hW13->hide(); ui->hW13->hide();
ui->hW23->hide(); ui->hW23->hide();
} }
if(ampelCounter == 1){ if (ampelCounter == 1) {
ampelCounter = 2; ampelCounter = 2;
ui->WAmpel12->setVisible(true); ui->WAmpel12->setVisible(true);
ui->WAmpel22->setVisible(true); ui->WAmpel22->setVisible(true);
ui->hW12->hide(); ui->hW12->hide();
ui->hw22->hide(); ui->hw22->hide();
} }
if(ampelCounter == 0){ if (ampelCounter == 0) {
ampelCounter = 1; ampelCounter = 1;
ui->WAmpel11->setVisible(true); ui->WAmpel11->setVisible(true);
ui->WAmpel21->setVisible(true); ui->WAmpel21->setVisible(true);
@@ -572,6 +599,6 @@ void WindowRace::ampelSlot(){
} }
} }
void WindowRace::go(){ void WindowRace::go() {
startAmpelThread->start(); startAmpelThread->start();
} }

View File

@@ -1,17 +1,15 @@
#include "windowrennliste.h" #include "windowrennliste.h"
#include "ui_windowrennliste.h" #include "ui_windowrennliste.h"
#include <QColor>
#include <QBrush>
#include <iostream>
#include <QDebug>
#include "windowrace.h" #include "windowrace.h"
using std::vector; #include <QBrush>
#include <QColor>
#include <QDebug>
#include <iostream>
using std::string; using std::string;
using std::vector;
WindowRennliste::WindowRennliste(DataBase *db, QWidget *parent) : WindowRennliste::WindowRennliste(DataBase * db, QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::WindowRennliste) {
ui(new Ui::WindowRennliste)
{
ui->setupUi(this); ui->setupUi(this);
this->windowClose = false; this->windowClose = false;
@@ -21,81 +19,103 @@ WindowRennliste::WindowRennliste(DataBase *db, QWidget *parent) :
this->ui->tWRennliste->setSelectionBehavior(QAbstractItemView::SelectRows); this->ui->tWRennliste->setSelectionBehavior(QAbstractItemView::SelectRows);
this->ui->tWRennliste->setSelectionMode(QAbstractItemView::SingleSelection); this->ui->tWRennliste->setSelectionMode(QAbstractItemView::SingleSelection);
QObject::connect(this->ui->tWRennliste, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(listClick(const QModelIndex&))); QObject::connect(this->ui->tWRennliste,
SIGNAL(doubleClicked(const QModelIndex &)), this,
SLOT(listClick(const QModelIndex &)));
this->db = db; this->db = db;
string statement; string statement;
vector< vector<QString> > fahrer, autos, rennid; vector<vector<QString>> fahrer, autos, rennid;
statement = "select id_rennen from aktrennen group by id_rennen order by id_rennen DESC limit 1"; statement = "select id_rennen from aktrennen group by id_rennen order by "
"id_rennen DESC limit 1";
rennid = this->db->getData(statement, 1); rennid = this->db->getData(statement, 1);
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid from aktrennen where id_rennen like "+rennid[0][0].toStdString(); statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
"from aktrennen where id_rennen like " +
rennid[0][0].toStdString();
this->tableData = db->getData(statement, 4); this->tableData = db->getData(statement, 4);
this->ui->tWRennliste->setRowCount(this->tableData.size()); this->ui->tWRennliste->setRowCount(this->tableData.size());
this->ui->tWRennliste->setColumnCount(6); this->ui->tWRennliste->setColumnCount(6);
QStringList header; QStringList header;
header<< "Fahrer" << "Auto"<< "Zeit"<< "Fahrer"<< "Auto"<< "Zeit"; header << "Fahrer"
<< "Auto"
<< "Zeit"
<< "Fahrer"
<< "Auto"
<< "Zeit";
this->ui->tWRennliste->setHorizontalHeaderLabels(header); this->ui->tWRennliste->setHorizontalHeaderLabels(header);
for (int i = 0; i < this->ui->tWRennliste->horizontalHeader()->count();
for(int i = 0; i < this->ui->tWRennliste->horizontalHeader()->count();i++){ i++) {
this->ui->tWRennliste->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch); this->ui->tWRennliste->horizontalHeader()->setSectionResizeMode(
i, QHeaderView::Stretch);
} }
for (unsigned int i = 0; i < tableData.size(); i++) {
for(unsigned int i = 0; i < tableData.size(); i++){ statement = "select name from fahrer where id like " +
statement = "select name from fahrer where id like " + tableData[i][0].toStdString(); tableData[i][0].toStdString();
fahrer = this->db->getData(statement, 1); fahrer = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 0, new QTableWidgetItem(fahrer[0][0])); this->ui->tWRennliste->setItem(i, 0,
this->ui->tWRennliste->item(i,0)->setFlags(Qt::ItemIsEnabled); new QTableWidgetItem(fahrer[0][0]));
this->ui->tWRennliste->item(i, 0)->setFlags(Qt::ItemIsEnabled);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[i][1].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[i][1].toStdString() + " order by seit DESC";
autos = this->db->getData(statement, 1); autos = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 1, new QTableWidgetItem(autos[0][0])); this->ui->tWRennliste->setItem(i, 1, new QTableWidgetItem(autos[0][0]));
this->ui->tWRennliste->item(i,1)->setFlags(Qt::ItemIsEnabled); this->ui->tWRennliste->item(i, 1)->setFlags(Qt::ItemIsEnabled);
this->ui->tWRennliste->setItem(i, 2, new QTableWidgetItem()); this->ui->tWRennliste->setItem(i, 2, new QTableWidgetItem());
statement = "select name from fahrer where id like " + tableData[i][2].toStdString(); statement = "select name from fahrer where id like " +
tableData[i][2].toStdString();
fahrer = this->db->getData(statement, 1); fahrer = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 3, new QTableWidgetItem(fahrer[0][0])); this->ui->tWRennliste->setItem(i, 3,
this->ui->tWRennliste->item(i,3)->setFlags(Qt::ItemIsEnabled); new QTableWidgetItem(fahrer[0][0]));
this->ui->tWRennliste->item(i, 3)->setFlags(Qt::ItemIsEnabled);
statement = "select name from AutoKonfiguration where id_auto like " + tableData[i][3].toStdString()+" order by seit DESC"; statement = "select name from AutoKonfiguration where id_auto like " +
tableData[i][3].toStdString() + " order by seit DESC";
autos = this->db->getData(statement, 1); autos = this->db->getData(statement, 1);
this->ui->tWRennliste->setItem(i, 4, new QTableWidgetItem(autos[0][0])); this->ui->tWRennliste->setItem(i, 4, new QTableWidgetItem(autos[0][0]));
this->ui->tWRennliste->item(i,4)->setFlags(Qt::ItemIsEnabled); this->ui->tWRennliste->item(i, 4)->setFlags(Qt::ItemIsEnabled);
this->ui->tWRennliste->setItem(i, 5, new QTableWidgetItem()); this->ui->tWRennliste->setItem(i, 5, new QTableWidgetItem());
} }
for(int i = 0; i < 6; i++){ for (int i = 0; i < 6; i++) {
this->ui->tWRennliste->item(0, i)->setBackground(Qt::green); this->ui->tWRennliste->item(0, i)->setBackground(Qt::green);
} }
} }
void WindowRennliste::setWindowRace(WindowRace *instance){ void WindowRennliste::setWindowRace(WindowRace * instance) {
this->instanceWindowRace = instance; this->instanceWindowRace = instance;
} }
vector<QString> WindowRennliste::getDriverAndCarSettings(){ vector<QString> WindowRennliste::getDriverAndCarSettings() {
vector<QString> vec; vector<QString> vec;
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 0)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 1)->text()); this->ui->tWRennliste->item(this->selectedRow + 1, 0)->text());
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 3)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow+1, 4)->text()); this->ui->tWRennliste->item(this->selectedRow + 1, 1)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow + 1, 3)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow + 1, 4)->text());
return vec; return vec;
} }
vector<QString> WindowRennliste::getDriverAndCarId(){ vector<QString> WindowRennliste::getDriverAndCarId() {
//shellFahrer shellAuto deaFahrer deaAuto // shellFahrer shellAuto deaFahrer deaAuto
return this->tableData[this->selectedRow]; return this->tableData[this->selectedRow];
} }
void WindowRennliste::setBesttime(int shell, int dea){ void WindowRennliste::setBesttime(int shell, int dea) {
this->ui->tWRennliste->item(this->selectedRow, 2)->setText(QString::number(shell/1000.0)); this->ui->tWRennliste->item(this->selectedRow, 2)
this->ui->tWRennliste->item(this->selectedRow, 5)->setText(QString::number(dea/1000.0)); ->setText(QString::number(shell / 1000.0));
//std::cout << this->selectedRow << std::endl; this->ui->tWRennliste->item(this->selectedRow, 5)
->setText(QString::number(dea / 1000.0));
// std::cout << this->selectedRow << std::endl;
} }
void WindowRennliste::listClick(const QModelIndex & index){ void WindowRennliste::listClick(const QModelIndex & index) {
QString driverShell = this->ui->tWRennliste->item(index.row(), 0)->text(); QString driverShell = this->ui->tWRennliste->item(index.row(), 0)->text();
QString carShell = this->ui->tWRennliste->item(index.row(), 1)->text(); QString carShell = this->ui->tWRennliste->item(index.row(), 1)->text();
@@ -112,30 +132,29 @@ void WindowRennliste::listClick(const QModelIndex & index){
this->instanceWindowRace->prepareNextRace(); this->instanceWindowRace->prepareNextRace();
this->setSelection(index.row()); this->setSelection(index.row());
this->sendIds(); this->sendIds();
} }
void WindowRennliste::closeEvent(QCloseEvent *event){ void WindowRennliste::closeEvent(QCloseEvent * event) {
if(!this->windowClose){ if (!this->windowClose) {
this->setWindowState(Qt::WindowMinimized); this->setWindowState(Qt::WindowMinimized);
event->ignore(); event->ignore();
} }
else{ else {
event->accept(); event->accept();
} }
} }
void WindowRennliste::schliessen(){ void WindowRennliste::schliessen() {
this->windowClose = true; this->windowClose = true;
this->close(); this->close();
delete this; delete this;
} }
void WindowRennliste::setSelection(int row){ void WindowRennliste::setSelection(int row) {
for(int i = 0; i < 6; i++){ for (int i = 0; i < 6; i++) {
this->ui->tWRennliste->item(this->selectedRow, i)->setBackground(Qt::yellow); this->ui->tWRennliste->item(this->selectedRow, i)
->setBackground(Qt::yellow);
} }
this->selectedRow = row; this->selectedRow = row;
for(int i = 0; i < 6; i++){ for (int i = 0; i < 6; i++) {
this->ui->tWRennliste->item(row, i)->setBackground(Qt::green); this->ui->tWRennliste->item(row, i)->setBackground(Qt::green);
} }
this->sendIds(); this->sendIds();
@@ -145,32 +164,35 @@ void WindowRennliste::setSelection(int row){
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text()); vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text());
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text()); vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text());
this->instanceWindowRace->setDriverAndCar(vec); this->instanceWindowRace->setDriverAndCar(vec);
} }
void WindowRennliste::sendIds(){ void WindowRennliste::sendIds() {
this->instanceWindowRace->setDriverAndCarId(this->getDriverAndCarId()); this->instanceWindowRace->setDriverAndCarId(this->getDriverAndCarId());
} }
void WindowRennliste::changeSelection(){ void WindowRennliste::changeSelection() {
if(this->selectedRow + 1 < this->tableData.size()){ if (this->selectedRow + 1 < this->tableData.size()) {
for(unsigned int i = 0; i < 6; i++){ for (unsigned int i = 0; i < 6; i++) {
this->ui->tWRennliste->item(this->selectedRow, i)->setBackground(Qt::gray); this->ui->tWRennliste->item(this->selectedRow, i)
this->ui->tWRennliste->item(this->selectedRow+1, i)->setBackground(Qt::green); ->setBackground(Qt::gray);
this->ui->tWRennliste->item(this->selectedRow + 1, i)
->setBackground(Qt::green);
} }
this->selectedRow += 1; this->selectedRow += 1;
this->sendIds(); this->sendIds();
vector<QString> vec; vector<QString> vec;
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 0)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 1)->text()); this->ui->tWRennliste->item(this->selectedRow, 0)->text());
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 3)->text()); vec.push_back(
vec.push_back(this->ui->tWRennliste->item(this->selectedRow, 4)->text()); this->ui->tWRennliste->item(this->selectedRow, 1)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow, 3)->text());
vec.push_back(
this->ui->tWRennliste->item(this->selectedRow, 4)->text());
this->instanceWindowRace->setDriverAndCar(vec); this->instanceWindowRace->setDriverAndCar(vec);
} }
} }
WindowRennliste::~WindowRennliste() WindowRennliste::~WindowRennliste() {
{
delete ui; delete ui;
} }

View File

@@ -1,43 +1,47 @@
#include "windowssettings.h" #include "windowssettings.h"
#include "ui_windowssettings.h" #include "ui_windowssettings.h"
#include <iostream> #include <iostream>
#include <string>
#include <stdio.h> #include <stdio.h>
#include <string>
#include <time.h> #include <time.h>
#include <vector> #include <vector>
using std::vector;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::string; using std::string;
using std::vector;
WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) : WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
QMainWindow(parent), : QMainWindow(parent), ui(new Ui::WindowsSettings) {
ui(new Ui::WindowsSettings)
{
ui->setupUi(this); ui->setupUi(this);
QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this, SLOT(StreckeSpeichernSlot())); QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this,
QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this, SLOT(AbbrechenSlot())); SLOT(StreckeSpeichernSlot()));
QObject::connect(this->ui->pbAbbrechenDauer, SIGNAL(clicked()), this, SLOT(AbbrechenSlot())); QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this,
QObject::connect(this->ui->pbSaveDauer, SIGNAL(clicked()), this, SLOT(SaveDauerSlot())); SLOT(AbbrechenSlot()));
QObject::connect(this->ui->pbSaveAndExitDauer, SIGNAL(clicked()), this, SLOT(SaveDauerAndExitSlot())); QObject::connect(this->ui->pbAbbrechenDauer, SIGNAL(clicked()), this,
SLOT(AbbrechenSlot()));
QObject::connect(this->ui->pbSaveDauer, SIGNAL(clicked()), this,
SLOT(SaveDauerSlot()));
QObject::connect(this->ui->pbSaveAndExitDauer, SIGNAL(clicked()), this,
SLOT(SaveDauerAndExitSlot()));
// update minimal lap time on changeing minimal sector time // update minimal lap time on changeing minimal sector time
QObject::connect(this->ui->lEMinTimeSec1, SIGNAL(textChanged(QString)), this, SLOT(repaintMinLapTime())); QObject::connect(this->ui->lEMinTimeSec1, SIGNAL(textChanged(QString)),
QObject::connect(this->ui->lEMinTimeSec2, SIGNAL(textChanged(QString)), this, SLOT(repaintMinLapTime())); this, SLOT(repaintMinLapTime()));
QObject::connect(this->ui->lEMinTimeSec3, SIGNAL(textChanged(QString)), this, SLOT(repaintMinLapTime())); QObject::connect(this->ui->lEMinTimeSec2, SIGNAL(textChanged(QString)),
this, SLOT(repaintMinLapTime()));
QObject::connect(this->ui->lEMinTimeSec3, SIGNAL(textChanged(QString)),
this, SLOT(repaintMinLapTime()));
this->db = db; this->db = db;
//Shell prepare // Shell prepare
string statement = "select geraden, kurven_aussen, " string statement =
"kurven_innen, steilkurve_innen, steilkurve_aussen, seit " "select geraden, kurven_aussen, "
"from Strecke where id_bahn like 1 order by seit DESC limit 1"; "kurven_innen, steilkurve_innen, steilkurve_aussen, seit "
vector< vector<QString> > res; "from Strecke where id_bahn like 1 order by seit DESC limit 1";
vector<vector<QString>> res;
res = db->getData(statement, 6); res = db->getData(statement, 6);
ui->lEShellGeraden->setText(res[0][0]); ui->lEShellGeraden->setText(res[0][0]);
@@ -46,11 +50,10 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
ui->lEShellSteilkurveInnen->setText(res[0][3]); ui->lEShellSteilkurveInnen->setText(res[0][3]);
ui->lEShellSteilkurveaussen->setText(res[0][4]); ui->lEShellSteilkurveaussen->setText(res[0][4]);
//Dea prepare // Dea prepare
statement = "select geraden, kurven_aussen, " statement = "select geraden, kurven_aussen, "
"kurven_innen, steilkurve_innen, steilkurve_aussen, seit " "kurven_innen, steilkurve_innen, steilkurve_aussen, seit "
"from Strecke where id_bahn like 2 order by seit DESC limit 1"; "from Strecke where id_bahn like 2 order by seit DESC limit 1";
res = db->getData(statement, 6); res = db->getData(statement, 6);
ui->lEDeaGeraden->setText(res[0][0]); ui->lEDeaGeraden->setText(res[0][0]);
@@ -59,8 +62,9 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
ui->lEDeaSteilkurveInnen->setText(res[0][3]); ui->lEDeaSteilkurveInnen->setText(res[0][3]);
ui->lEDeaSteilkurveAussen->setText(res[0][4]); ui->lEDeaSteilkurveAussen->setText(res[0][4]);
//duration prepare // duration prepare
statement = "select dauer, mindestrundendauer, minsec1, minsec2, minsec3 from renndauer"; statement = "select dauer, mindestrundendauer, minsec1, minsec2, minsec3 "
"from renndauer";
res = db->getData(statement, 5); res = db->getData(statement, 5);
this->ui->leRenndauer->setText(res[0][0]); this->ui->leRenndauer->setText(res[0][0]);
this->ui->lEMinTimeSec1->setText(res[0][2]); this->ui->lEMinTimeSec1->setText(res[0][2]);
@@ -69,13 +73,13 @@ WindowsSettings::WindowsSettings(DataBase *db, QWidget *parent) :
int minLapTime = res[0][2].toInt() + res[0][3].toInt() + res[0][4].toInt(); int minLapTime = res[0][2].toInt() + res[0][3].toInt() + res[0][4].toInt();
this->ui->lEMinRundenzeit->setText(QString::number(minLapTime)); this->ui->lEMinRundenzeit->setText(QString::number(minLapTime));
statement = "SELECT id, minimumroundtime FROM rennen order by id DESC limit 1"; statement =
"SELECT id, minimumroundtime FROM rennen order by id DESC limit 1";
res = this->db->getData(statement, 2); res = this->db->getData(statement, 2);
this->rennId = res[0][0].toInt(); this->rennId = res[0][0].toInt();
this->ui->lEMinRundenzeitAktRennen->setText(res[0][1]); this->ui->lEMinRundenzeitAktRennen->setText(res[0][1]);
} }
void WindowsSettings::repaintMinLapTime(){ void WindowsSettings::repaintMinLapTime() {
int minlapTime = 0; int minlapTime = 0;
minlapTime += this->ui->lEMinTimeSec1->text().toInt(); minlapTime += this->ui->lEMinTimeSec1->text().toInt();
minlapTime += this->ui->lEMinTimeSec2->text().toInt(); minlapTime += this->ui->lEMinTimeSec2->text().toInt();
@@ -83,41 +87,51 @@ void WindowsSettings::repaintMinLapTime(){
this->ui->lEMinRundenzeit->setText(QString::number(minlapTime)); this->ui->lEMinRundenzeit->setText(QString::number(minlapTime));
this->ui->lEMinRundenzeitAktRennen->setText(QString::number(minlapTime)); this->ui->lEMinRundenzeitAktRennen->setText(QString::number(minlapTime));
} }
void WindowsSettings::AbbrechenSlot(){ void WindowsSettings::AbbrechenSlot() {
this->close(); this->close();
delete this; delete this;
} }
void WindowsSettings::SaveDauerSlot(){ void WindowsSettings::SaveDauerSlot() {
string statement = "update renndauer set " string statement =
"dauer="+this->ui->leRenndauer->text().toStdString()+", "+ "update renndauer set "
"mindestrundendauer="+this->ui->lEMinRundenzeit->text().toStdString()+", "+ "dauer=" +
"minsec1="+this->ui->lEMinTimeSec1->text().toStdString()+", "+ this->ui->leRenndauer->text().toStdString() + ", " +
"minsec2="+this->ui->lEMinTimeSec2->text().toStdString()+", "+ "mindestrundendauer=" +
"minsec3="+this->ui->lEMinTimeSec3->text().toStdString()+" "+ this->ui->lEMinRundenzeit->text().toStdString() + ", " +
" where id like 1"; "minsec1=" + this->ui->lEMinTimeSec1->text().toStdString() + ", " +
"minsec2=" + this->ui->lEMinTimeSec2->text().toStdString() + ", " +
"minsec3=" + this->ui->lEMinTimeSec3->text().toStdString() + " " +
" where id like 1";
cout << statement << endl; cout << statement << endl;
this->db->setData(statement); this->db->setData(statement);
statement = "update rennen set minimumroundtime="+this->ui->lEMinRundenzeitAktRennen->text().toStdString()+ statement = "update rennen set minimumroundtime=" +
" where id like "+QString::number(this->rennId).toStdString(); this->ui->lEMinRundenzeitAktRennen->text().toStdString() +
" where id like " + QString::number(this->rennId).toStdString();
this->db->setData(statement); this->db->setData(statement);
} }
void WindowsSettings::SaveDauerAndExitSlot(){ void WindowsSettings::SaveDauerAndExitSlot() {
this->SaveDauerSlot(); this->SaveDauerSlot();
this->AbbrechenSlot(); this->AbbrechenSlot();
} }
void WindowsSettings::StreckeSpeichernSlot() {
void WindowsSettings::StreckeSpeichernSlot(){ QString shellGeraden, shellKurvenAussen, shellKurvenInnen, shellSteilAussen,
QString shellGeraden, shellKurvenAussen, shellKurvenInnen, shellSteilAussen, shellSteilInnen; shellSteilInnen;
QString deaGeraden, deaKurvenAussen, deaKurvenInnen, deaSteilAussen, deaSteilInnen; QString deaGeraden, deaKurvenAussen, deaKurvenInnen, deaSteilAussen,
deaSteilInnen;
shellGeraden = ui->lEShellGeraden->text(); shellGeraden = ui->lEShellGeraden->text();
shellKurvenAussen = ui->lEShellKurvenAussen->text(); shellKurvenAussen = ui->lEShellKurvenAussen->text();
shellKurvenInnen = ui->lEShellKurvenInnen->text(); shellKurvenInnen = ui->lEShellKurvenInnen->text();
shellSteilAussen = ui->lEShellSteilkurveaussen->text(); shellSteilAussen = ui->lEShellSteilkurveaussen->text();
shellSteilInnen = ui->lEShellSteilkurveInnen->text(); shellSteilInnen = ui->lEShellSteilkurveInnen->text();
QString statement = QString("insert into strecke (geraden, kurven_aussen, kurven_innen, steilkurve_innen, steilkurve_aussen, seit, id_bahn)" QString statement = QString(
" values ("+shellGeraden+", "+shellKurvenAussen+", "+shellKurvenInnen+", "+shellSteilInnen+", "+shellSteilAussen+", '"+QString::fromStdString(currentDateTime())+"', 1)"); "insert into strecke (geraden, kurven_aussen, kurven_innen, "
//cout << statement.toStdString() << endl; "steilkurve_innen, steilkurve_aussen, seit, id_bahn)"
" values (" +
shellGeraden + ", " + shellKurvenAussen + ", " + shellKurvenInnen +
", " + shellSteilInnen + ", " + shellSteilAussen + ", '" +
QString::fromStdString(currentDateTime()) + "', 1)");
// cout << statement.toStdString() << endl;
db->setData(statement.toStdString()); db->setData(statement.toStdString());
deaGeraden = ui->lEDeaGeraden->text(); deaGeraden = ui->lEDeaGeraden->text();
@@ -125,23 +139,27 @@ void WindowsSettings::StreckeSpeichernSlot(){
deaKurvenInnen = ui->lEDeaKurvenInnen->text(); deaKurvenInnen = ui->lEDeaKurvenInnen->text();
deaSteilAussen = ui->lEDeaSteilkurveAussen->text(); deaSteilAussen = ui->lEDeaSteilkurveAussen->text();
deaSteilInnen = ui->lEDeaSteilkurveInnen->text(); deaSteilInnen = ui->lEDeaSteilkurveInnen->text();
statement = QString("insert into strecke (geraden, kurven_aussen, kurven_innen, steilkurve_innen, steilkurve_aussen, seit, id_bahn)" statement =
" values ("+deaGeraden+", "+deaKurvenAussen+", "+deaKurvenInnen+", "+deaSteilInnen+", "+deaSteilAussen+", '"+QString::fromStdString(currentDateTime())+"', 2)"); QString("insert into strecke (geraden, kurven_aussen, kurven_innen, "
//cout << statement.toStdString() << endl; "steilkurve_innen, steilkurve_aussen, seit, id_bahn)"
" values (" +
deaGeraden + ", " + deaKurvenAussen + ", " + deaKurvenInnen +
", " + deaSteilInnen + ", " + deaSteilAussen + ", '" +
QString::fromStdString(currentDateTime()) + "', 2)");
// cout << statement.toStdString() << endl;
db->setData(statement.toStdString()); db->setData(statement.toStdString());
} }
WindowsSettings::~WindowsSettings() WindowsSettings::~WindowsSettings() {
{
delete ui; delete ui;
std::cout << "Destruktor einstellungen" << std::endl; std::cout << "Destruktor einstellungen" << std::endl;
} }
// Get current date/time, format is YYYY-MM-DD.HH:mm:ss // Get current date/time, format is YYYY-MM-DD.HH:mm:ss
string WindowsSettings::currentDateTime() { string WindowsSettings::currentDateTime() {
time_t now = time(0); time_t now = time(0);
struct tm tstruct; struct tm tstruct;
char buf[80]; char buf[80];
tstruct = *localtime(&now); tstruct = *localtime(&now);
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
// for more information about date/time format // for more information about date/time format