feature: added possibility to change hardware interface from GUI

This commit is contained in:
2019-12-29 17:07:42 +01:00
parent 8443b12937
commit e102dab939
8 changed files with 163 additions and 9 deletions

View File

@@ -4,6 +4,7 @@
#include "ui_windowssettings.h"
#include <QStringListModel>
#include <boost/lexical_cast.hpp>
#include <filesystem>
#include <iostream>
#include <qcolordialog.h>
#include <qmessagebox.h>
@@ -12,6 +13,8 @@
#include <time.h>
#include <vector>
namespace fs = std::filesystem;
using std::cout;
using std::endl;
using std::string;
@@ -21,6 +24,8 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
: QMainWindow(parent), ui(new Ui::WindowsSettings) {
ui->setupUi(this);
QObject::connect(ui->cBInterface, SIGNAL(activated(int)), this,
SLOT(changeInterface()));
QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this,
SLOT(StreckeSpeichernSlot()));
QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this,
@@ -199,7 +204,27 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
// fill listView of cars
this->repaintCars();
// this->ui->wEditCarColor->grab()
// setup Hardware interface
QStringList cbInterfaceList = QStringList();
cbInterfaceList.append("/dev/ttyAMC0");
std::string path = "/dev/pts/";
for (const auto & entry : fs::directory_iterator(path)) {
std::string pathToAppend = entry.path();
cbInterfaceList.append(QString::fromStdString(pathToAppend));
}
this->ui->cBInterface->addItems(cbInterfaceList);
// preset combobox from database
QString dataFromDatabase =
this->db->getData("select interface from interface where id like 1", 1)
.at(0)
.at(0);
int id = this->ui->cBInterface->findText(dataFromDatabase);
if (id > -1) {
this->ui->cBInterface->setCurrentIndex(id);
}
}
void WindowsSettings::saveEditCar() {
@@ -495,6 +520,15 @@ string WindowsSettings::currentDateTime() {
return buf;
}
void WindowsSettings::changeInterface() {
std::string curInterface =
this->ui->cBInterface->currentText().toStdString();
std::string statement = "update interface set interface = '" +
curInterface + "' where id like 1";
cout << statement << endl;
this->db->setData(statement);
}
void WindowsSettings::createRaceListAndClose() {
vector<int> selectedCarIds;
foreach (const QModelIndex & index,