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();
bool local();
void setTimers(QList<ScStwTimer*> timers, bool deleteOldTimers);
signals:
void scStwClientChanged();
};

View file

@ -119,20 +119,17 @@ ScStw::StatusCode ScStwRemoteRace::setTimerDisabled(int timerId, bool disabled)
void ScStwRemoteRace::handleClientStateChange() {
switch (this->scStwClient->getState()) {
case ScStwClient::CONNECTED:
this->localTimers.clear();
this->localTimers = this->timers;
this->timers.clear();
case ScStwClient::INITIALISING:
// disconnect all local timers from race
this->setTimers({}, false);
// delete all obsolete remote timers
for(ScStwRemoteTimer* oldRemoteTimer : this->remoteTimers)
oldRemoteTimer->deleteLater();
this->remoteTimers.clear();
break;
case ScStwClient::DISCONNECTED:
foreach(ScStwRemoteTimer *remoteTimer, this->remoteTimers)
remoteTimer->deleteLater();
this->remoteTimers.clear();
this->timers.clear();
this->timers = this->localTimers;
this->localTimers.clear();
this->setTimers(this->localTimers, true);
emit this->timersChanged();
emit this->detailsChanged();
emit this->currentStartDelayChanged();
@ -284,6 +281,30 @@ bool ScStwRemoteRace::addTimer(ScStwTimer* timer) {
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() {
if(this->local())
return ScStwRace::getCurrentStartDelay();

View file

@ -65,9 +65,9 @@ bool ScStwRemoteSettings::setDefaultSetting(QString key, QVariant defaultVariant
void ScStwRemoteSettings::handleClientStateChange() {
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)
emit this->settingChanged(-1, 0, QVariant());
emit this->settingChanged(-1, ScStwSettings::KeyLevel, QVariant());
}
void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant data) {
@ -92,6 +92,7 @@ void ScStwRemoteSettings::setScStwClient(ScStwClient* client) {
if(this->scStwClient != nullptr) {
this->scStwClient->addSignalSubscription(ScStw::SettingChanged);
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteSettings::handleClientStateChange);
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();
}
else if(key == -1 && this->key != -1 && this->keyLevel != -1 && this->keyLevel == keyLevel) {
qDebug() << "value changed!!! key: " << key << " new value " << value;
this->hasToReload = true;
emit this->valueChanged();
}