UI: save and restore ui settings in primary and secondary uis

This commit is contained in:
Carl Philipp Klemm 2026-04-26 17:28:57 +02:00
parent afb2d23173
commit 51193a5d0b
7 changed files with 132 additions and 4 deletions

View file

@ -58,6 +58,8 @@ int main(int argc, char *argv[])
int retVal;
QString uiSettingsPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/smartvos_ui.json";
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
{
QString settingsPath = parser.value(settingsPathOption);
@ -111,11 +113,13 @@ int main(int argc, char *argv[])
microDevice = microPort;
}
PrimaryMainObject mainObject(microDevice, settingsPath, parser.value(hostOption), parser.value(portOption).toInt());
QObject::connect(mainObject.tcpServer, &TcpServer::sigRequestSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);});
MainWindow* w = nullptr;
if(programMode != PROGRAM_MODE_HEADLESS_PRIMARY)
{
w = new MainWindow(&mainObject);
QJsonObject uiSettings = MainObject::getJsonObjectFromDisk(uiSettingsPath);
w->load(uiSettings);
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
QObject::connect(w, &MainWindow::sigSetRgb, &mainObject.micro, &Microcontroller::changeRgbColor);
@ -123,8 +127,16 @@ int main(int argc, char *argv[])
QObject::connect(w, &MainWindow::createdItem, &globalItems, &ItemStore::addItem);
w->show();
}
retVal = a->exec();
if(programMode != PROGRAM_MODE_HEADLESS_PRIMARY)
{
QJsonObject uiSettingsJson;
w->store(uiSettingsJson);
MainObject::storeJsonObjectToDisk(uiSettingsPath, uiSettingsJson);
}
delete w;
delete microDevice;
}
@ -132,11 +144,19 @@ int main(int argc, char *argv[])
{
SecondaryMainObject mainObject(parser.value(hostOption), parser.value(portOption).toInt());
MainWindow w(&mainObject);
QJsonObject uiSettings = MainObject::getJsonObjectFromDisk(uiSettingsPath);
w.load(uiSettings);
QObject::connect(&w, &MainWindow::createdItem, &globalItems, &ItemStore::addItem);
QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems);
w.show();
retVal = a->exec();
QJsonObject uiSettingsJson;
w.store(uiSettingsJson);
MainObject::storeJsonObjectToDisk(uiSettingsPath, uiSettingsJson);
}
delete a;