Fixed issues that ourred when switching between remote and local race mode

This commit is contained in:
Dorian Zedler 2020-10-19 11:15:49 +02:00
parent 35fb805849
commit fdb17bdc3a
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
4 changed files with 37 additions and 12 deletions

View file

@ -77,6 +77,8 @@ private slots:
RaceMode getMode(); RaceMode getMode();
bool local(); bool local();
void setTimers(QList<ScStwTimer*> timers, bool deleteOldTimers);
signals: signals:
void scStwClientChanged(); void scStwClientChanged();
}; };

View file

@ -119,20 +119,17 @@ ScStw::StatusCode ScStwRemoteRace::setTimerDisabled(int timerId, bool disabled)
void ScStwRemoteRace::handleClientStateChange() { void ScStwRemoteRace::handleClientStateChange() {
switch (this->scStwClient->getState()) { switch (this->scStwClient->getState()) {
case ScStwClient::CONNECTED: case ScStwClient::INITIALISING:
this->localTimers.clear(); // disconnect all local timers from race
this->localTimers = this->timers; this->setTimers({}, false);
this->timers.clear(); // delete all obsolete remote timers
for(ScStwRemoteTimer* oldRemoteTimer : this->remoteTimers)
oldRemoteTimer->deleteLater();
this->remoteTimers.clear(); this->remoteTimers.clear();
break; break;
case ScStwClient::DISCONNECTED: case ScStwClient::DISCONNECTED:
foreach(ScStwRemoteTimer *remoteTimer, this->remoteTimers)
remoteTimer->deleteLater();
this->remoteTimers.clear(); this->remoteTimers.clear();
this->setTimers(this->localTimers, true);
this->timers.clear();
this->timers = this->localTimers;
this->localTimers.clear();
emit this->timersChanged(); emit this->timersChanged();
emit this->detailsChanged(); emit this->detailsChanged();
emit this->currentStartDelayChanged(); emit this->currentStartDelayChanged();
@ -284,6 +281,30 @@ bool ScStwRemoteRace::addTimer(ScStwTimer* timer) {
return false; return false;
} }
void ScStwRemoteRace::setTimers(QList<ScStwTimer*> timers, bool deleteOldTimers) {
// disconnect all signals of all current timers
qDebug() << "SETTING TIMERS";
foreach(ScStwTimer *existingTimer, this->timers) {
disconnect(existingTimer, &ScStwTimer::stateChanged, this, &ScStwRace::handleTimerStateChange);
disconnect(existingTimer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged);
disconnect(existingTimer, &ScStwTimer::wantsToBeDisabledChanged, this, &ScStwRace::handleTimerWantsToBeDisabledChange);
disconnect(existingTimer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
disconnect(existingTimer, &ScStwTimer::readyStateChanged, this, &ScStwRace::handleTimerReadyStateChange);
disconnect(existingTimer, &ScStwTimer::readyStateChanged, this, &ScStwRace::isReadyForNextStateChanged);
if(deleteOldTimers)
existingTimer->deleteLater();
}
this->timers.clear();
for(ScStwTimer* timer : timers) {
this->addTimer(timer);
}
}
QVariantMap ScStwRemoteRace::getCurrentStartDelay() { QVariantMap ScStwRemoteRace::getCurrentStartDelay() {
if(this->local()) if(this->local())
return ScStwRace::getCurrentStartDelay(); return ScStwRace::getCurrentStartDelay();

View file

@ -65,9 +65,9 @@ bool ScStwRemoteSettings::setDefaultSetting(QString key, QVariant defaultVariant
void ScStwRemoteSettings::handleClientStateChange() { void ScStwRemoteSettings::handleClientStateChange() {
if(this->scStwClient->getState() == ScStwClient::DISCONNECTED) if(this->scStwClient->getState() == ScStwClient::DISCONNECTED)
emit this->settingChanged(-1, 0, QVariant()); emit this->settingChanged(-1, ScStwSettings::KeyLevel, QVariant());
else if(this->scStwClient->getState() == ScStwClient::CONNECTED) else if(this->scStwClient->getState() == ScStwClient::CONNECTED)
emit this->settingChanged(-1, 0, QVariant()); emit this->settingChanged(-1, ScStwSettings::KeyLevel, QVariant());
} }
void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) { void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
@ -92,6 +92,7 @@ void ScStwRemoteSettings::setScStwClient(ScStwClient* client) {
if(this->scStwClient != nullptr) { if(this->scStwClient != nullptr) {
this->scStwClient->addSignalSubscription(ScStw::SettingChanged); this->scStwClient->addSignalSubscription(ScStw::SettingChanged);
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteSettings::handleClientStateChange);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteSettings::handleBaseStationSignal); connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteSettings::handleBaseStationSignal);
} }
} }

View file

@ -51,6 +51,7 @@ void ScStwSetting::handleSettingChange(int key, int keyLevel, QVariant value) {
emit this->valueChanged(); emit this->valueChanged();
} }
else if(key == -1 && this->key != -1 && this->keyLevel != -1 && this->keyLevel == keyLevel) { else if(key == -1 && this->key != -1 && this->keyLevel != -1 && this->keyLevel == keyLevel) {
qDebug() << "value changed!!! key: " << key << " new value " << value;
this->hasToReload = true; this->hasToReload = true;
emit this->valueChanged(); emit this->valueChanged();
} }