mirror of
https://github.com/FAUSheppy/speech-server-client-qt
synced 2025-12-06 00:41:35 +01:00
implement adding new serverconfig
This commit is contained in:
110
serverconfig.cpp
110
serverconfig.cpp
@@ -7,11 +7,14 @@
|
||||
#include <QWidget>
|
||||
#include <QtUiTools>
|
||||
|
||||
#include "multivalueinputdialog.h"
|
||||
#include "urls.h"
|
||||
|
||||
ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(parent) {
|
||||
|
||||
mySettings = settings;
|
||||
|
||||
ServerConnection *sc = new ServerConnection(this, mySettings);
|
||||
sc = new ServerConnection(this, mySettings);
|
||||
connect(sc->getNetworkManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedRequest(QNetworkReply*)), Qt::UniqueConnection);
|
||||
sc->getUnifiedServerConfig();
|
||||
|
||||
@@ -62,6 +65,9 @@ ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(p
|
||||
innerLayoutContext->addWidget(addNewContext);
|
||||
context->setLayout(innerLayoutContext);
|
||||
|
||||
/* connect buttons */
|
||||
connect(addNew, SIGNAL (released()), this, SLOT (addNewPP()));
|
||||
connect(addNewContext, SIGNAL (released()), this, SLOT (addNewContext()));
|
||||
|
||||
/* setup main window */
|
||||
mainLayout = new QGridLayout();
|
||||
@@ -72,6 +78,44 @@ ServerConfig::ServerConfig(QWidget *parent, QSettings *settings) : QMainWindow(p
|
||||
this->setCentralWidget(mainWidget);
|
||||
}
|
||||
|
||||
void ServerConfig::addNewPP(){
|
||||
|
||||
QStringList *sl = new QStringList();
|
||||
sl->append("Schlüsselword");
|
||||
sl->append("Ersetzung");
|
||||
|
||||
QWidgetList *wl = new QWidgetList();
|
||||
wl->append(new QLineEdit());
|
||||
wl->append(new QLineEdit());
|
||||
|
||||
MultiValueInputDialog *dialog = new MultiValueInputDialog(sl, wl);
|
||||
if (dialog->exec() == QDialog::Accepted) {
|
||||
auto keyword = static_cast<QLineEdit*>(wl->at(0));
|
||||
auto replace = static_cast<QLineEdit*>(wl->at(0));
|
||||
|
||||
if(!keyword->text().isEmpty() && !replace->text().isEmpty()){
|
||||
sc->submitPostProcessorChange(keyword->text(), replace->text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerConfig::addNewContext()
|
||||
{
|
||||
QStringList *sl = new QStringList();
|
||||
sl->append("Ausdruck");
|
||||
|
||||
QWidgetList *wl = new QWidgetList();
|
||||
wl->append(new QLineEdit());
|
||||
|
||||
MultiValueInputDialog *dialog = new MultiValueInputDialog(sl, wl);
|
||||
if (dialog->exec() == QDialog::Accepted) {
|
||||
auto lineEdit = static_cast<QLineEdit*>(wl->at(0));
|
||||
if(!lineEdit->text().isEmpty()){
|
||||
sc->submitSpeechContextPhraseChange(lineEdit->text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* ServerConfig::loatListItemUiForm()
|
||||
{
|
||||
QUiLoader loader;
|
||||
@@ -91,29 +135,57 @@ void ServerConfig::finishedRequest(QNetworkReply *reply){
|
||||
return;
|
||||
}
|
||||
|
||||
/* get filename and tracking id from replay */
|
||||
QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object();
|
||||
QString addPP = sc->buildURLFromLocation(PP_EDIT);
|
||||
QString addContext = sc->buildURLFromLocation(CONTEXT_EDIT);
|
||||
if(QString::compare(reply->url().toString(), addPP) == 0){
|
||||
sc->getUnifiedServerConfig();
|
||||
}else if(QString::compare(reply->url().toString(), addContext) == 0){
|
||||
sc->getUnifiedServerConfig();
|
||||
}else{
|
||||
/* this is the unified server config query */
|
||||
/* get filename and tracking id from replay */
|
||||
QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object();
|
||||
|
||||
auto keywordMap = json["keyword-map"].toObject();
|
||||
auto phrases = json["phrases"].toArray();
|
||||
auto keywordMap = json["keyword-map"].toObject();
|
||||
auto phrases = json["phrases"].toArray();
|
||||
|
||||
contextTable->clear();
|
||||
contextTable->clear();
|
||||
contextTable->setRowCount(0);
|
||||
ppTable->clear();
|
||||
ppTable->setRowCount(0);
|
||||
|
||||
for(int i = 0; i < phrases.size(); i++){
|
||||
contextTable->insertRow(i);
|
||||
contextTable->setItem(i, 0, new QTableWidgetItem(phrases.at(i).toString()));
|
||||
auto *deleteButtonLayout = new QGridLayout();
|
||||
auto *deleteCell = new QWidget();
|
||||
auto *deleteButton = new QPushButton("Entfernen");
|
||||
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
deleteButtonLayout->addWidget(deleteButton);
|
||||
deleteButtonLayout->setContentsMargins(0,0,0,0);
|
||||
deleteCell->setLayout(deleteButtonLayout);
|
||||
for(int i = 0; i < phrases.size(); i++){
|
||||
contextTable->insertRow(i);
|
||||
contextTable->setItem(i, 0, new QTableWidgetItem(phrases.at(i).toString()));
|
||||
auto *deleteButtonLayout = new QGridLayout();
|
||||
auto *deleteCell = new QWidget();
|
||||
auto *deleteButton = new QPushButton("Entfernen");
|
||||
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
deleteButtonLayout->addWidget(deleteButton);
|
||||
deleteButtonLayout->setContentsMargins(0,0,0,0);
|
||||
deleteCell->setLayout(deleteButtonLayout);
|
||||
|
||||
contextTable->setCellWidget(i, 1, deleteCell);
|
||||
contextTable->setCellWidget(i, 1, deleteCell);
|
||||
}
|
||||
|
||||
for(int i = 0; i < keywordMap.keys().size(); i++){
|
||||
auto key = keywordMap.keys().at(i);
|
||||
ppTable->insertRow(i);
|
||||
ppTable->setItem(i, 0, new QTableWidgetItem(key));
|
||||
ppTable->setItem(i, 1, new QTableWidgetItem(keywordMap[key].toString()));
|
||||
auto *deleteButtonLayout = new QGridLayout();
|
||||
auto *deleteCell = new QWidget();
|
||||
auto *deleteButton = new QPushButton("Entfernen");
|
||||
deleteButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
deleteButtonLayout->addWidget(deleteButton);
|
||||
deleteButtonLayout->setContentsMargins(0,0,0,0);
|
||||
deleteCell->setLayout(deleteButtonLayout);
|
||||
|
||||
ppTable->setCellWidget(i, 2, deleteCell);
|
||||
}
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
this->repaint();
|
||||
|
||||
}
|
||||
|
||||
ServerConfig::~ServerConfig()
|
||||
|
||||
Reference in New Issue
Block a user