some changes to race and settings handling

This commit is contained in:
Dorian Zedler 2020-10-03 18:35:37 +02:00
parent 3ee017104f
commit 3cfee983c2
Signed by: dorian
GPG Key ID: D3B255CB8BC7CD37
5 changed files with 15 additions and 157 deletions

View File

@ -15,7 +15,6 @@ class ScStwAppBackend : public QObject
{
Q_OBJECT
Q_PROPERTY(int mode READ getMode NOTIFY modeChanged)
Q_PROPERTY(ScStwRace* race READ getRace NOTIFY raceChanged)
Q_PROPERTY(ScStwClient *scStwClient READ getScStwClient NOTIFY scStwClientChanged)
Q_PROPERTY(ScStwAppSettings *settings READ getSettings NOTIFY settingsChanged)
@ -23,25 +22,18 @@ class ScStwAppBackend : public QObject
public:
explicit ScStwAppBackend(QObject *parent = nullptr);
enum RaceMode { LOCAL, REMOTE };
private:
RaceMode mode;
ScStwAppSettings * appSettings;
ScStwClient * scStwClient;
QTimer * timerTextRefreshTimer;
ScStwRace * localRace;
ScStwRemoteRace * remoteRace;
ScStwRemoteRace * race;
public slots:
// functions for qml
Q_INVOKABLE ScStwRace *getRace();
Q_INVOKABLE ScStwClient *getScStwClient();
Q_INVOKABLE ScStwAppSettings *getSettings();
Q_INVOKABLE int getMode();
// athlete management
Q_INVOKABLE QVariant getAthletes();
@ -52,20 +44,11 @@ public slots:
private slots:
void refreshTimerText();
void refreshMode();
void reloadRaceSettings();
void reloadBaseStationIpAdress();
void handleSettingChange(int keyInt, int keyLevel, QVariant value);
signals:
void modeChanged();
void raceChanged();
void scStwClientChanged();
void settingsChanged();
void baseStationStateChanged();
void baseStationConnectionsChanged();
void baseStationPropertiesChanged();
};
#endif // SCSTWAPPBACKEND_H

View File

@ -13,10 +13,6 @@ import de.itsblue.ScStw.Styling.Components 1.0
Item {
id: control
property ScStwSetting competitionModeSetting: speedBackend.settings.getSetting(ScStwSettings.CompetitionModeSetting, ScStwSettings.KeyLevel)
property ScStwSetting readySoundEnableSetting: speedBackend.settings.getSetting(ScStwSettings.ReadySoundEnableSetting, ScStwSettings.KeyLevel)
GridLayout {
id: centerLayout
@ -44,16 +40,7 @@ Item {
id: mainActionButton
property double size
startProgress: speedBackend.race.currentStartDelay[ScStwRace.CurrentStartStateDelayProgress]
/*Connections {
target: mainActionButton.setting
onValueChanged: {
console.log("comp mode is " + mainActionButton.setting.value)
}
}*/
startProgress: speedBackend.race.currentStartDelay["progress"]
Layout.alignment: Layout.Center
@ -72,7 +59,7 @@ Item {
ret = speedBackend.race.start()
break;
case ScStwRace.WAITING:
if(!control.readySoundEnableSetting.value)
if(!speedBackend.race.readySoundEnabled)
ret = speedBackend.race.start()
else
ret = speedBackend.race.cancel()
@ -136,8 +123,8 @@ Item {
PropertyChanges {
target: mainActionButton
size: 0.9
text: control.readySoundEnableSetting.value ? "cancel":"ready"
enabled: control.readySoundEnableSetting.value ? true:speedBackend.race.isReadyForNextState
text: speedBackend.race.readySoundEnabled ? "cancel":"ready"
enabled: speedBackend.race.readySoundEnabled ? true:speedBackend.race.isReadyForNextState
}
},
@ -155,8 +142,8 @@ Item {
PropertyChanges {
target: mainActionButton
size: 0.9
text: "stop"
progressControlActivated: speedBackend.scStwClient.state === ScStwClient.CONNECTED && control.competitionModeSetting.value
text: speedBackend.race.competitionMode ? "cancel":"stop"
progressControlActivated: speedBackend.scStwClient.state === ScStwClient.CONNECTED && speedBackend.race.competitionMode
}
},

@ -1 +1 @@
Subproject commit 3c626b82da8373a2a69b6b7979ecf17d962076dd
Subproject commit 9c736234183e6751a9a4d29f34246469357d6887

View File

@ -3,31 +3,14 @@
ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent)
{
this->scStwClient = new ScStwClient(this);
this->appSettings = new ScStwAppSettings(this->scStwClient, this);
this->localRace = new ScStwRace(this);
this->remoteRace = new ScStwRemoteRace(this->scStwClient, this);
this->mode = LOCAL;
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->race = new ScStwRemoteRace(this->scStwClient, this->appSettings, this);
this->race->addTimer(new ScStwTimer(this));
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);
this->localRace->addTimer(new ScStwTimer(this));
this->reloadRaceSettings();
this->timerTextRefreshTimer = new QTimer(this);
this->timerTextRefreshTimer->setInterval(1);
this->timerTextRefreshTimer->setSingleShot(true);
@ -39,32 +22,6 @@ ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent)
// --- helper functions ---
// ------------------------
void ScStwAppBackend::refreshMode() {
RaceMode newMode;
if(this->scStwClient->getState() == ScStwClient::CONNECTED){
newMode = REMOTE;
}
else {
newMode = LOCAL;
}
if(this->mode != newMode){
if(newMode == LOCAL){
// if the new mode is local -> connection to base station has been lost
// reset local race
this->getRace()->reset();
}
this->mode = newMode;
emit this->modeChanged();
emit this->raceChanged();
emit this->getRace()->stateChanged(this->getRace()->getState());
}
}
void ScStwAppBackend::refreshTimerText() {
// --- refresh timer text ---
@ -167,13 +124,7 @@ QVariant ScStwAppBackend::getResults( QString userName ){
// -------------------------
ScStwRace* ScStwAppBackend::getRace() {
switch (this->mode) {
case LOCAL:
return this->localRace;
case REMOTE:
return this->remoteRace;
}
return nullptr;
return this->race;
}
ScStwAppSettings * ScStwAppBackend::getSettings() {
@ -183,69 +134,3 @@ ScStwAppSettings * ScStwAppBackend::getSettings() {
ScStwClient* ScStwAppBackend::getScStwClient() {
return this->scStwClient;
}
int ScStwAppBackend::getMode() {
return this->mode;
}
void ScStwAppBackend::reloadRaceSettings() {
this->getRace()->writeStartSoundSetting(
ScStwSoundPlayer::AtYourMarks,
this->appSettings->readSetting(ScStwSettings::BaseStationSetting::AtYourMarksSoundEnableSetting).toBool(),
this->appSettings->readSetting(ScStwSettings::BaseStationSetting::AtYourMarksSoundDelaySetting).toDouble()
);
this->getRace()->writeStartSoundSetting(
ScStwSoundPlayer::Ready,
this->appSettings->readSetting(ScStwSettings::BaseStationSetting::ReadySoundEnableSetting).toBool(),
this->appSettings->readSetting(ScStwSettings::BaseStationSetting::ReadySoundDelaySetting).toDouble()
);
this->getRace()->setSoundVolume(1);
this->getRace()->setCompetitionMode(false);
}
void ScStwAppBackend::reloadBaseStationIpAdress() {
this->scStwClient->setIP(this->appSettings->readSetting(ScStwAppSettings::BaseStationIpSetting).toString());
}
void ScStwAppBackend::handleSettingChange(int keyInt, int keyLevel, QVariant value) {
Q_UNUSED(value)
if(keyInt == -1) {
emit this->settingsChanged();
return;
}
switch (keyLevel) {
case 0: {
// BaseStationSetting!!
ScStwSettings::BaseStationSetting key = static_cast<ScStwSettings::BaseStationSetting>(keyInt);
switch (key) {
case ScStwSettings::BaseStationSetting::InvalidSetting:
return;
default:
if(this->mode == LOCAL)
this->reloadRaceSettings();
return;
}
break;
}
case 1: {
// BaseStationInternalSetting!!
ScStwAppSettings::AppInternalSetting key = static_cast<ScStwAppSettings::AppInternalSetting>(keyInt);
switch (key) {
case ScStwAppSettings::InvalidSetting:
return;
case ScStwAppSettings::BaseStationIpSetting:
this->reloadBaseStationIpAdress();
break;
default:
break;
}
break;
}
}
}

View File

@ -23,6 +23,9 @@ ScStwAppSettings::ScStwAppSettings(ScStwClient * client, QObject* parent)
:ScStwRemoteSettings(client, parent)
{
this->registerKeyLevelConverters(ScStwAppSettings::KeyLevel, &ScStwAppSettings::keyToString, &ScStwAppSettings::keyToType);
this->setDefaultSetting(ScStwAppSettings::AppThemeSetting, "Light");
this->setDefaultSetting(ScStwAppSettings::BaseStationIpSetting, "192.168.4.1");
}
QVariant ScStwAppSettings::readSetting(AppInternalSetting key) {