From 827acf840494e62f916299b3e4104b08f4deea3c Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 10 Jul 2020 15:20:41 +0200 Subject: [PATCH] adapted anything to new settings --- ScStwApp.pro | 2 +- headers/scstwappsettings.h | 25 +++++++----- .../SettingsBaseStationPage.qml | 8 ++-- .../SettingsStartSequencePage.qml | 20 +++++----- resources/qml/SettingsDialog/StartPage.qml | 4 +- resources/qml/main.qml | 4 +- shared-libraries | 2 +- sources/main.cpp | 10 ++--- sources/scstwappbackend.cpp | 39 ++++++++++++------- sources/scstwappsettings.cpp | 34 +++++++++++----- 10 files changed, 87 insertions(+), 61 deletions(-) diff --git a/ScStwApp.pro b/ScStwApp.pro index 11a1f76..3281af2 100644 --- a/ScStwApp.pro +++ b/ScStwApp.pro @@ -18,7 +18,7 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -TARGET = speedclimbing_stw +TARGET = ScStwApp # include submodules CONFIG += ScStwLibraries_QML ScStwLibraries_Styling ScStwLibraries_ClientLibs diff --git a/headers/scstwappsettings.h b/headers/scstwappsettings.h index 11e309f..ba98e60 100644 --- a/headers/scstwappsettings.h +++ b/headers/scstwappsettings.h @@ -4,13 +4,13 @@ #include #include #include -#include "scstwsettings.h" +#include "scstwremotesettings.h" -class ScStwAppSettings : public ScStwSettings +class ScStwAppSettings : public ScStwRemoteSettings { Q_OBJECT public: - explicit ScStwAppSettings(QObject *parent = nullptr); + explicit ScStwAppSettings(ScStwClient * scStwClient, QObject *parent = nullptr); ~ScStwAppSettings(); enum AppInternalSetting { @@ -20,14 +20,19 @@ public: }; Q_ENUM(AppInternalSetting) - using ScStwSettings::readSetting; - QVariant readSetting(AppInternalSetting key); - using ScStwSettings::writeSetting; - bool writeSetting(AppInternalSetting key, QVariant value); - using ScStwSettings::setDefaultSetting; - void setDefaultSetting(AppInternalSetting key, QVariant defaultVariant); + enum KeyLevelEnum { + KeyLevel = 1 + }; + Q_ENUM(KeyLevelEnum) - QSettings *settingsManager; + using ScStwSettings::readSetting; + Q_INVOKABLE QVariant readSetting(AppInternalSetting key); + Q_INVOKABLE QVariant readSetting(int key, int level); + using ScStwSettings::writeSetting; + Q_INVOKABLE bool writeSetting(AppInternalSetting key, QVariant value); + Q_INVOKABLE bool writeSetting(int key, QVariant value, int level); + using ScStwSettings::setDefaultSetting; + Q_INVOKABLE void setDefaultSetting(AppInternalSetting key, QVariant defaultVariant); signals: diff --git a/resources/qml/SettingsDialog/SettingsBaseStationPage.qml b/resources/qml/SettingsDialog/SettingsBaseStationPage.qml index 94f2a9f..afeae77 100644 --- a/resources/qml/SettingsDialog/SettingsBaseStationPage.qml +++ b/resources/qml/SettingsDialog/SettingsBaseStationPage.qml @@ -134,11 +134,11 @@ Column { text: qsTr("IP") inputHint: "IP" - inputText: speedBackend.readSetting("baseStationIpAdress") + inputText: speedBackend.settings.readSetting(ScStwAppSettings.BaseStationIpSetting) inputTextFieldWidth: width * 0.7 onInputTextChanged: { - speedBackend.writeSetting("baseStationIpAdress", inputText) + speedBackend.settings.writeSetting(ScStwAppSettings.BaseStationIpSetting, inputText) } width: parent.width @@ -229,12 +229,12 @@ Column { onSliderFinished: { enabled = false - speedBackend.writeSetting("SoundVolume", sliderValue) + speedBackend.settings.writeSetting(ScStwSettings.SoundVolumeSetting, sliderValue, ScStwSettings.KeyLevel) enabled = true } Component.onCompleted: { - var val = speedBackend.readSetting("SoundVolume") + var val = speedBackend.settings.readSetting(ScStwSettings.SoundVolumeSetting, ScStwSettings.KeyLevel) if(val !== "false"){ sliderValue = parseFloat(val) } diff --git a/resources/qml/SettingsDialog/SettingsStartSequencePage.qml b/resources/qml/SettingsDialog/SettingsStartSequencePage.qml index 9950f11..f30280e 100644 --- a/resources/qml/SettingsDialog/SettingsStartSequencePage.qml +++ b/resources/qml/SettingsDialog/SettingsStartSequencePage.qml @@ -23,12 +23,12 @@ Column { function updateSetting(key, val, del){ del.busy = true - speedBackend.writeSetting(scStw.baseStationSettingToString(key) , val) + speedBackend.settings.writeSetting(key, val, ScStwSettings.KeyLevel) del.busy = false } function loadSetting(key, del){ - return speedBackend.readSetting(key) + return speedBackend.settings.readSetting(key, ScStwSettings.KeyLevel) } SmoothSwitchDelegate { @@ -43,10 +43,10 @@ Column { text: qsTr("say 'ready'") - checked: parent.loadSetting(ScStw.ReadySoundEnableSetting, ready_del) === "true" + checked: parent.loadSetting(ScStwSettings.ReadySoundEnableSetting, ready_del) onCheckedChanged: { - parent.updateSetting(ScStw.ReadySoundEnableSetting, checked, ready_del) + parent.updateSetting(ScStwSettings.ReadySoundEnableSetting, checked, ready_del) } } @@ -64,10 +64,10 @@ Column { inputHint: qsTr("time") inputMethodHints: Qt.ImhFormattedNumbersOnly - inputText: control.loadSetting(ScStw.ReadySoundDelaySetting, ready_delay_del) + inputText: control.loadSetting(ScStwSettings.ReadySoundDelaySetting, ready_delay_del) onInputFinished: { - control.updateSetting(ScStw.ReadySoundDelaySetting, inputText, ready_delay_del) + control.updateSetting(ScStwSettings.ReadySoundDelaySetting, inputText, ready_delay_del) } } @@ -83,10 +83,10 @@ Column { text: qsTr("say 'at your marks'") - checked: control.loadSetting(ScStw.AtYourMarksSoundEnableSetting , ready_del) === "true" + checked: control.loadSetting(ScStwSettings.AtYourMarksSoundEnableSetting , ready_del) onCheckedChanged: { - parent.updateSetting(ScStw.AtYourMarksSoundEnableSetting, at_marks_del.checked, at_marks_del) + parent.updateSetting(ScStwSettings.AtYourMarksSoundEnableSetting, at_marks_del.checked, at_marks_del) } } @@ -104,10 +104,10 @@ Column { enabled: !busy && at_marks_del.checked - inputText: control.loadSetting(ScStw.AtYourMarksSoundDelaySetting, at_marks_delay_del) + inputText: control.loadSetting(ScStwSettings.AtYourMarksSoundDelaySetting, at_marks_delay_del) onInputFinished: { - control.updateSetting(ScStw.AtYourMarksSoundDelaySetting, inputText, at_marks_delay_del) + control.updateSetting(ScStwSettings.AtYourMarksSoundDelaySetting, inputText, at_marks_delay_del) } } } diff --git a/resources/qml/SettingsDialog/StartPage.qml b/resources/qml/SettingsDialog/StartPage.qml index 94b592e..708c8cb 100644 --- a/resources/qml/SettingsDialog/StartPage.qml +++ b/resources/qml/SettingsDialog/StartPage.qml @@ -55,11 +55,11 @@ Column { width: parent.width height: parentObj.delegateHeight - checked: speedBackend.readSetting("theme") === "Dark" + checked: speedBackend.settings.readSetting(ScStwAppSettings.AppThemeSetting) === "Dark" onCheckedChanged: { var newTheme = checked ? "Dark":"Light" - speedBackend.writeSetting("theme", newTheme) + speedBackend.settings.writeSetting(ScStwAppSettings.AppThemeSetting, newTheme) appTheme.setTheme(newTheme) } } diff --git a/resources/qml/main.qml b/resources/qml/main.qml index deec2b3..62842dd 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -35,7 +35,7 @@ Window { visible: true width: 540 height: 960 - title: "Speedclimbing stw" + title: "ScStwApp" property date currentTime: new Date() property int millis: 0 @@ -103,7 +103,7 @@ Window { id: appTheme Component.onCompleted: { - appTheme.setTheme(speedBackend.readSetting("theme")) + appTheme.setTheme(speedBackend.settings.readSetting(ScStwAppSettings.AppThemeSetting)) } } diff --git a/shared-libraries b/shared-libraries index 3d18b72..6c1ce8e 160000 --- a/shared-libraries +++ b/shared-libraries @@ -1 +1 @@ -Subproject commit 3d18b72eaf7fc8993ff60f1e087fa0c30516f4b5 +Subproject commit 6c1ce8e65407452ce82f412fdd26d1367bf3ea38 diff --git a/sources/main.cpp b/sources/main.cpp index 5378cd7..60ff056 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -81,10 +81,11 @@ int main(int argc, char *argv[]) }); #endif - ScStwAppSettings * pAppSettings = new ScStwAppSettings(); - // setup speed backend qmlRegisterType("de.itsblue.ScStwApp", 2, 0, "SpeedBackend"); + qmlRegisterUncreatableType("de.itsblue.ScStwApp", 2, 0, "ScStwAppSettings", "The ScStwAppSettings type is not creatable!"); + + qRegisterMetaType("ScStwAppSettings::BaseStationSetting"); QQmlApplicationEngine engine; ScStwLibraries::init(); @@ -92,11 +93,6 @@ int main(int argc, char *argv[]) engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - QQmlContext *context = engine.rootContext(); - - // setup app settings - context->setContextProperty("_cppAppSettings", pAppSettings); - if (engine.rootObjects().isEmpty()) return -1; diff --git a/sources/scstwappbackend.cpp b/sources/scstwappbackend.cpp index 6af90e4..c53d95d 100644 --- a/sources/scstwappbackend.cpp +++ b/sources/scstwappbackend.cpp @@ -2,23 +2,25 @@ ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent) { - this->appSettings = new ScStwAppSettings(this); + this->scStwClient = new ScStwClient(this); + this->appSettings = new ScStwAppSettings(this->scStwClient, this); + this->localRace = new ScStwRace(this); + this->remoteRace = new ScStwRemoteMonitorRace(this->scStwClient, this); + this->mode = LOCAL; - this->appSettings->setDefaultSetting(ScStwSettings::ReadySoundEnableSetting, false); - this->appSettings->setDefaultSetting(ScStwSettings::ReadySoundDelaySetting, 0); - this->appSettings->setDefaultSetting(ScStwSettings::AtYourMarksSoundEnableSetting, false); - this->appSettings->setDefaultSetting(ScStwSettings::AtYourMarksSoundDelaySetting, 0); + connect(this->appSettings, &ScStwAppSettings::settingChanged, this, &ScStwAppBackend::handleSettingChange); + + this->appSettings->setDefaultSetting(ScStwSettings::BaseStationSetting::ReadySoundEnableSetting, false); + this->appSettings->setDefaultSetting(ScStwSettings::BaseStationSetting::ReadySoundDelaySetting, 0); + this->appSettings->setDefaultSetting(ScStwSettings::BaseStationSetting::AtYourMarksSoundEnableSetting, false); + this->appSettings->setDefaultSetting(ScStwSettings::BaseStationSetting::AtYourMarksSoundDelaySetting, 0); this->appSettings->setDefaultSetting(ScStwAppSettings::AppThemeSetting, "Light"); this->appSettings->setDefaultSetting(ScStwAppSettings::BaseStationIpSetting, "192.168.4.1"); - this->scStwClient = new ScStwClient(); - this->localRace = new ScStwRace(this); - this->remoteRace = new ScStwRemoteMonitorRace(this->scStwClient, this); - this->mode = LOCAL; - this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString()); + connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwAppBackend::baseStationStateChanged); connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwAppBackend::refreshMode); connect(this, &ScStwAppBackend::baseStationStateChanged, this, &ScStwAppBackend::baseStationPropertiesChanged); @@ -189,14 +191,14 @@ int ScStwAppBackend::getMode() { void ScStwAppBackend::reloadRaceSettings() { this->getRace()->writeStartActionSetting( ScStwRace::AtYourMarks, - this->appSettings->readSetting(ScStwSettings::AtYourMarksSoundEnableSetting).toBool(), - this->appSettings->readSetting(ScStwSettings::AtYourMarksSoundDelaySetting).toDouble() + this->appSettings->readSetting(ScStwSettings::BaseStationSetting::AtYourMarksSoundEnableSetting).toBool(), + this->appSettings->readSetting(ScStwSettings::BaseStationSetting::AtYourMarksSoundDelaySetting).toDouble() ); this->getRace()->writeStartActionSetting( ScStwRace::Ready, - this->appSettings->readSetting(ScStwSettings::ReadySoundEnableSetting).toBool(), - this->appSettings->readSetting(ScStwSettings::ReadySoundDelaySetting).toDouble() + this->appSettings->readSetting(ScStwSettings::BaseStationSetting::ReadySoundEnableSetting).toBool(), + this->appSettings->readSetting(ScStwSettings::BaseStationSetting::ReadySoundDelaySetting).toDouble() ); this->getRace()->setSoundVolume(1); @@ -208,12 +210,17 @@ void ScStwAppBackend::reloadBaseStationIpAdress() { } void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel) { + if(keyInt == -1) { + emit this->settingsChanged(); + return; + } + switch (keyLevel) { case 0: { // BaseStationSetting!! ScStwSettings::BaseStationSetting key = static_cast(keyInt); switch (key) { - case ScStwSettings::InvalidSetting: + case ScStwSettings::BaseStationSetting::InvalidSetting: return; default: this->reloadRaceSettings(); @@ -236,4 +243,6 @@ void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel) { break; } } + + emit this->settingsChanged(); } diff --git a/sources/scstwappsettings.cpp b/sources/scstwappsettings.cpp index 1616e01..7835652 100644 --- a/sources/scstwappsettings.cpp +++ b/sources/scstwappsettings.cpp @@ -19,30 +19,46 @@ ScStwAppSettings * pGlobalAppSettings = nullptr; -ScStwAppSettings::ScStwAppSettings(QObject* parent) - :ScStwSettings(parent) +ScStwAppSettings::ScStwAppSettings(ScStwClient * client, QObject* parent) + :ScStwRemoteSettings(client, parent) { - QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - - this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat, this); - - pGlobalAppSettings = this; } QVariant ScStwAppSettings::readSetting(AppInternalSetting key) { - return ScStwSettings::readSetting(QMetaEnum::fromType().valueToKey(int(key))); + return ScStwSettings::readSetting(QMetaEnum::fromType().valueToKey(int(key)), int(key), 1); +} + +QVariant ScStwAppSettings::readSetting(int key, int keyLevel) { + switch (keyLevel) { + case ScStwAppSettings::KeyLevel: + return this->readSetting(ScStwAppSettings::AppInternalSetting(key)); + case ScStwSettings::KeyLevel: + return ScStwSettings::readSetting(ScStwSettings::BaseStationSetting(key)); + default: + return QVariant(); + } } bool ScStwAppSettings::writeSetting(AppInternalSetting key, QVariant value) { return ScStwSettings::writeSetting(QMetaEnum::fromType().valueToKey(int(key)), value, int(key), 1); } +bool ScStwAppSettings::writeSetting(int key, QVariant value, int keyLevel) { + switch (keyLevel) { + case ScStwAppSettings::KeyLevel: + return this->writeSetting(ScStwAppSettings::AppInternalSetting(key), value); + case ScStwSettings::KeyLevel: + return ScStwSettings::writeSetting(ScStwSettings::BaseStationSetting(key), value); + default: + return false; + } +} + void ScStwAppSettings::setDefaultSetting(AppInternalSetting key, QVariant defaultVariant) { ScStwSettings::setDefaultSetting(QMetaEnum::fromType().valueToKey(int(key)), defaultVariant, int(key), 1); } ScStwAppSettings::~ScStwAppSettings() { - delete settingsManager; }