some changes, settings are now working correctly

This commit is contained in:
Dorian Zedler 2020-07-11 20:30:50 +02:00
parent 342dde38ad
commit 2826dc6195
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
9 changed files with 46 additions and 73 deletions

View file

@ -55,7 +55,7 @@ private slots:
void refreshMode(); void refreshMode();
void reloadRaceSettings(); void reloadRaceSettings();
void reloadBaseStationIpAdress(); void reloadBaseStationIpAdress();
void handleSettingChange(int keyInt, int keyLevel); void handleSettingChange(int keyInt, int keyLevel, QVariant value);
signals: signals:
void modeChanged(); void modeChanged();

View file

@ -11,7 +11,6 @@ class ScStwAppSettings : public ScStwRemoteSettings
Q_OBJECT Q_OBJECT
public: public:
explicit ScStwAppSettings(ScStwClient * scStwClient, QObject *parent = nullptr); explicit ScStwAppSettings(ScStwClient * scStwClient, QObject *parent = nullptr);
~ScStwAppSettings();
enum AppInternalSetting { enum AppInternalSetting {
InvalidSetting = -1, InvalidSetting = -1,
@ -27,12 +26,14 @@ public:
using ScStwSettings::readSetting; using ScStwSettings::readSetting;
Q_INVOKABLE QVariant readSetting(AppInternalSetting key); Q_INVOKABLE QVariant readSetting(AppInternalSetting key);
Q_INVOKABLE QVariant readSetting(int key, int level);
using ScStwSettings::writeSetting; using ScStwSettings::writeSetting;
Q_INVOKABLE bool writeSetting(AppInternalSetting key, QVariant value); Q_INVOKABLE bool writeSetting(AppInternalSetting key, QVariant value);
Q_INVOKABLE bool writeSetting(int key, QVariant value, int level);
using ScStwSettings::setDefaultSetting; using ScStwSettings::setDefaultSetting;
Q_INVOKABLE void setDefaultSetting(AppInternalSetting key, QVariant defaultVariant); Q_INVOKABLE bool setDefaultSetting(AppInternalSetting key, QVariant defaultValue);
static QString keyToString(int key) {
return QMetaEnum::fromType<AppInternalSetting>().valueToKey(key);
}
signals: signals:

View file

@ -220,25 +220,21 @@ Column {
SmoothSliderDelegate { SmoothSliderDelegate {
id: baseStationVolumeDel id: baseStationVolumeDel
property ScStwSetting setting: speedBackend.settings.getSetting(ScStwSettings.SoundVolumeSetting, ScStwSettings.KeyLevel)
text: qsTr("volume") text: qsTr("volume")
width: parent.width width: parent.width
height: parentObj.delegateHeight height: parentObj.delegateHeight
sliderValue: 0 sliderValue: setting.value
onSliderFinished: { onSliderFinished: {
enabled = false enabled = false
speedBackend.settings.writeSetting(ScStwSettings.SoundVolumeSetting, sliderValue, ScStwSettings.KeyLevel) setting.value = sliderValue
enabled = true enabled = true
} }
Component.onCompleted: {
var val = speedBackend.settings.readSetting(ScStwSettings.SoundVolumeSetting, ScStwSettings.KeyLevel)
if(val !== "false"){
sliderValue = parseFloat(val)
}
}
} }
} }
} }

View file

@ -34,26 +34,27 @@ Column {
SmoothSwitchDelegate { SmoothSwitchDelegate {
id: ready_del id: ready_del
property bool busy: false property ScStwSetting setting: speedBackend.settings.getSetting(ScStwSettings.ReadySoundEnableSetting, ScStwSettings.KeyLevel)
width: parent.width width: parent.width
height: parentObj.delegateHeight height: parentObj.delegateHeight
enabled: !busy checked: setting.value
text: qsTr("say 'ready'")
checked: parent.loadSetting(ScStwSettings.ReadySoundEnableSetting, ready_del)
onCheckedChanged: { onCheckedChanged: {
parent.updateSetting(ScStwSettings.ReadySoundEnableSetting, checked, ready_del) enabled = false
setting.value = checked
enabled = true
} }
text: qsTr("say 'ready'")
} }
InputDelegate { InputDelegate {
id: ready_delay_del id: ready_delay_del
property bool busy: false property bool busy: false
property ScStwSetting setting: speedBackend.settings.getSetting(ScStwSettings.ReadySoundDelaySetting, ScStwSettings.KeyLevel)
width: parent.width width: parent.width
height: parentObj.delegateHeight height: parentObj.delegateHeight
@ -64,29 +65,32 @@ Column {
inputHint: qsTr("time") inputHint: qsTr("time")
inputMethodHints: Qt.ImhFormattedNumbersOnly inputMethodHints: Qt.ImhFormattedNumbersOnly
inputText: control.loadSetting(ScStwSettings.ReadySoundDelaySetting, ready_delay_del) inputText: setting.value
onInputFinished: { onInputFinished: {
control.updateSetting(ScStwSettings.ReadySoundDelaySetting, inputText, ready_delay_del) console.log("input finished")
busy = true
setting.value = inputText
busy = false
} }
} }
SmoothSwitchDelegate { SmoothSwitchDelegate {
id: at_marks_del id: at_marks_del
property bool busy: false property ScStwSetting setting: speedBackend.settings.getSetting(ScStwSettings.AtYourMarksSoundEnableSetting, ScStwSettings.KeyLevel)
width: parent.width width: parent.width
height: parentObj.delegateHeight height: parentObj.delegateHeight
enabled: !busy
text: qsTr("say 'at your marks'") text: qsTr("say 'at your marks'")
checked: control.loadSetting(ScStwSettings.AtYourMarksSoundEnableSetting , ready_del) checked: setting.value
onCheckedChanged: { onCheckedChanged: {
parent.updateSetting(ScStwSettings.AtYourMarksSoundEnableSetting, at_marks_del.checked, at_marks_del) enabled = false
setting.value = checked
enabled = true
} }
} }
@ -94,6 +98,7 @@ Column {
id: at_marks_delay_del id: at_marks_delay_del
property bool busy: false property bool busy: false
property ScStwSetting setting: speedBackend.settings.getSetting(ScStwSettings.AtYourMarksSoundDelaySetting, ScStwSettings.KeyLevel)
width: parent.width width: parent.width
height: parentObj.delegateHeight height: parentObj.delegateHeight
@ -102,12 +107,14 @@ Column {
inputHint: qsTr("time") inputHint: qsTr("time")
inputMethodHints: Qt.ImhFormattedNumbersOnly inputMethodHints: Qt.ImhFormattedNumbersOnly
enabled: !busy && at_marks_del.checked enabled: !busy && at_marks_del.checked
inputText: control.loadSetting(ScStwSettings.AtYourMarksSoundDelaySetting, at_marks_delay_del) inputText: setting.value
onInputFinished: { onInputFinished: {
control.updateSetting(ScStwSettings.AtYourMarksSoundDelaySetting, inputText, at_marks_delay_del) busy = true
setting.setValue(inputText)
busy = false
} }
} }
} }

View file

@ -55,7 +55,7 @@ Column {
width: parent.width width: parent.width
height: parentObj.delegateHeight height: parentObj.delegateHeight
checked: appThemeSetting.value === "Dark" checked: appTheme.setting === "Dark"
onCheckedChanged: { onCheckedChanged: {
appThemeSetting.value = checked ? "Dark":"Light" appThemeSetting.value = checked ? "Dark":"Light"

View file

@ -101,23 +101,13 @@ Window {
ScStwAppThemeManager { ScStwAppThemeManager {
id: appTheme id: appTheme
property ScStwSetting setting: speedBackend.settings.getSetting(ScStwAppSettings.AppThemeSetting, ScStwAppSettings.KeyLevel)
Component.onCompleted: { Component.onCompleted: {
appTheme.setTheme(speedBackend.settings.readSetting(ScStwAppSettings.AppThemeSetting)) appTheme.setTheme(speedBackend.settings.readSetting(ScStwAppSettings.AppThemeSetting))
} }
} }
ScStwSetting {
id: appThemeSetting
scStwSettings: speedBackend.settings
key: ScStwAppSettings.AppThemeSetting
keyLevel: ScStwAppSettings.KeyLevel
onValueChanged: {
appTheme.setTheme(appThemeSetting.value)
}
}
/*------------------------ /*------------------------
Timer text an upper line Timer text an upper line
------------------------*/ ------------------------*/

@ -1 +1 @@
Subproject commit ad3f8318c709653863058fc234469bd0ff006042 Subproject commit f336e953eb86f1a47f6376a6e94c30f82982e606

View file

@ -209,14 +209,14 @@ void ScStwAppBackend::reloadBaseStationIpAdress() {
this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString()); this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString());
} }
void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel) { void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel, QVariant value) {
Q_UNUSED(value)
if(keyInt == -1) { if(keyInt == -1) {
emit this->settingsChanged(); emit this->settingsChanged();
return; return;
} }
qDebug() << "setting changed: " << keyInt;
switch (keyLevel) { switch (keyLevel) {
case 0: { case 0: {
// BaseStationSetting!! // BaseStationSetting!!
@ -227,8 +227,6 @@ void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel) {
default: default:
if(this->mode == LOCAL) if(this->mode == LOCAL)
this->reloadRaceSettings(); this->reloadRaceSettings();
else
emit this->settingsChanged();
return; return;
} }
break; break;
@ -248,6 +246,4 @@ void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel) {
break; break;
} }
} }
emit this->settingsChanged();
} }

View file

@ -22,35 +22,18 @@ ScStwAppSettings * pGlobalAppSettings = nullptr;
ScStwAppSettings::ScStwAppSettings(ScStwClient * client, QObject* parent) ScStwAppSettings::ScStwAppSettings(ScStwClient * client, QObject* parent)
:ScStwRemoteSettings(client, parent) :ScStwRemoteSettings(client, parent)
{ {
this->registerKeyLevelHandler(ScStwAppSettings::KeyLevel, &ScStwAppSettings::keyToString);
} }
QVariant ScStwAppSettings::readSetting(AppInternalSetting key) { QVariant ScStwAppSettings::readSetting(AppInternalSetting key) {
return ScStwSettings::readSetting(QMetaEnum::fromType<AppInternalSetting>().valueToKey(int(key)), int(key), 1); return this->readSetting(key, 1);
}
QVariant ScStwAppSettings::readSetting(int key, int keyLevel) {
if(keyLevel == ScStwAppSettings::KeyLevel)
return this->readSetting(ScStwAppSettings::AppInternalSetting(key));
else
return ScStwSettings::readSetting(key, keyLevel);
} }
bool ScStwAppSettings::writeSetting(AppInternalSetting key, QVariant value) { bool ScStwAppSettings::writeSetting(AppInternalSetting key, QVariant value) {
return ScStwSettings::writeSetting(QMetaEnum::fromType<AppInternalSetting>().valueToKey(int(key)), value, int(key), 1); return this->writeSetting(key, 1, value);
} }
bool ScStwAppSettings::writeSetting(int key, QVariant value, int keyLevel) { bool ScStwAppSettings::setDefaultSetting(AppInternalSetting key, QVariant defaultValue) {
if(keyLevel == ScStwAppSettings::KeyLevel) return this->setDefaultSetting(key, 1, defaultValue);
return this->writeSetting(ScStwAppSettings::AppInternalSetting(key), value);
else
return ScStwSettings::writeSetting(key, value, keyLevel);
}
void ScStwAppSettings::setDefaultSetting(AppInternalSetting key, QVariant defaultVariant) {
ScStwSettings::setDefaultSetting(QMetaEnum::fromType<AppInternalSetting>().valueToKey(int(key)), defaultVariant, int(key), 1);
}
ScStwAppSettings::~ScStwAppSettings()
{
} }