Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dorian Zedler 2020-12-28 14:27:20 +01:00
commit 92fae09672
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
12 changed files with 205 additions and 36 deletions

View file

@ -28,7 +28,10 @@
class ScStwRemoteRace : public ScStwRace class ScStwRemoteRace : public ScStwRace
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(ScStwClient* scStwClient READ getScStwClient WRITE setScStwClient NOTIFY scStwClientChanged)
public: public:
ScStwRemoteRace(QObject *parent = nullptr);
ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settings = nullptr, QObject *parent = nullptr); ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settings = nullptr, QObject *parent = nullptr);
enum RaceMode { enum RaceMode {
@ -59,6 +62,9 @@ public slots:
bool getIsReadyForNextState(); bool getIsReadyForNextState();
bool getReadySoundEnabled(); bool getReadySoundEnabled();
ScStwClient *getScStwClient();
void setScStwClient(ScStwClient *client);
private slots: private slots:
void handleBaseStationSignal(ScStw::SignalKey key, QVariant data); void handleBaseStationSignal(ScStw::SignalKey key, QVariant data);
@ -70,6 +76,11 @@ private slots:
void refreshCompetitionMode(); void refreshCompetitionMode();
RaceMode getMode(); RaceMode getMode();
bool local(); bool local();
void setTimers(QList<ScStwTimer*> timers, bool deleteOldTimers);
signals:
void scStwClientChanged();
}; };
#endif // SCSTWREMOTEMONITORRACE_H #endif // SCSTWREMOTEMONITORRACE_H

View file

@ -27,7 +27,10 @@
class ScStwRemoteSettings : public ScStwSettings class ScStwRemoteSettings : public ScStwSettings
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(ScStwClient* scStwClient READ getScStwClient WRITE setScStwClient NOTIFY scStwClientChanged)
public: public:
ScStwRemoteSettings(QObject * parent = nullptr);
ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent = nullptr); ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent = nullptr);
enum SettingsMode { enum SettingsMode {
@ -43,10 +46,17 @@ protected:
private: private:
ScStwClient * scStwClient; ScStwClient * scStwClient;
public slots:
ScStwClient *getScStwClient();
void setScStwClient(ScStwClient *client);
private slots: private slots:
void handleClientStateChange(); void handleClientStateChange();
void handleBaseStationSignal(ScStw::SignalKey key, QVariant data); void handleBaseStationSignal(ScStw::SignalKey key, QVariant data);
SettingsMode getMode(); SettingsMode getMode();
signals:
void scStwClientChanged();
}; };
#endif // SCSTWREMOTESETTINGS_H #endif // SCSTWREMOTESETTINGS_H

View file

@ -74,7 +74,6 @@ protected slots:
*/ */
void setState(TimerState newState); void setState(TimerState newState);
}; };
#endif // SCSTWREMOTETIMER_H #endif // SCSTWREMOTETIMER_H

View file

@ -36,6 +36,7 @@
#include "scstwsetting.h" #include "scstwsetting.h"
#include "scstwremoterace.h" #include "scstwremoterace.h"
#include "scstwclient.h" #include "scstwclient.h"
#include "scstwremotesettings.h"
#endif #endif
class ScStwLibraries : public QObject class ScStwLibraries : public QObject

View file

@ -59,8 +59,11 @@ class ScStwRace : public QObject
Q_PROPERTY(bool competitionMode READ getCompetitionMode NOTIFY competitionModeChanged) Q_PROPERTY(bool competitionMode READ getCompetitionMode NOTIFY competitionModeChanged)
Q_PROPERTY(bool readySoundEnabled READ getReadySoundEnabled NOTIFY readySoundEnabledChanged) Q_PROPERTY(bool readySoundEnabled READ getReadySoundEnabled NOTIFY readySoundEnabledChanged)
Q_PROPERTY(QVariantMap details READ getDetails NOTIFY detailsChanged) Q_PROPERTY(QVariantMap details READ getDetails NOTIFY detailsChanged)
Q_PROPERTY(ScStwSettings* settings READ getSettings WRITE setSettings NOTIFY settingsChanged)
Q_PROPERTY(bool autoRefreshTimerText READ getAutoRefreshTimerText WRITE setAutoRefreshTimerText NOTIFY autoRefreshTimerTextChanged)
public: public:
explicit ScStwRace(QObject *parent = nullptr);
explicit ScStwRace(ScStwSettings *settings, QObject *parent = nullptr); explicit ScStwRace(ScStwSettings *settings, QObject *parent = nullptr);
friend class ScStwRemoteRace; friend class ScStwRemoteRace;
@ -76,6 +79,7 @@ private:
RaceState state; RaceState state;
QTimer *startDelayTimer; QTimer *startDelayTimer;
QTimer *timerTextRefreshTimer;
QEventLoop *startWaitLoop; QEventLoop *startWaitLoop;
// sounds // sounds
@ -84,6 +88,7 @@ private:
// settings // settings
ScStwSettings *settings; ScStwSettings *settings;
bool competitionMode; bool competitionMode;
bool autoRefreshTimerText;
enum LoopExitTypes { enum LoopExitTypes {
LoopAutomaticExit = 0, LoopAutomaticExit = 0,
@ -119,7 +124,7 @@ public slots:
virtual ScStw::StatusCode setTimerDisabled(int id, bool disabled); virtual ScStw::StatusCode setTimerDisabled(int id, bool disabled);
virtual bool addTimer(ScStwTimer *timer); Q_INVOKABLE virtual bool addTimer(ScStwTimer *timer);
// getters // getters
RaceState getState(); RaceState getState();
@ -130,6 +135,12 @@ public slots:
bool getCompetitionMode(); bool getCompetitionMode();
virtual bool getReadySoundEnabled(); virtual bool getReadySoundEnabled();
ScStwSettings* getSettings();
void setSettings(ScStwSettings* settings);
bool getAutoRefreshTimerText();
void setAutoRefreshTimerText(bool autoRefresh);
protected slots: protected slots:
private slots: private slots:
@ -171,6 +182,8 @@ signals:
void detailsChanged(); void detailsChanged();
void competitionModeChanged(); void competitionModeChanged();
void readySoundEnabledChanged(); void readySoundEnabledChanged();
void settingsChanged();
void autoRefreshTimerTextChanged();
}; };

View file

@ -65,13 +65,16 @@ class ScStwTimer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ScStwTimer(QObject *parent = nullptr);
/*! /*!
* \brief ScStwTimer constructor * \brief ScStwTimer constructor
* \param parent the parent object * \param parent the parent object
* \param directControlEnabled Defines if protected properties (startTimer, stopTime, reactionTime and state) can be directly set from outside. * \param directControlEnabled Defines if protected properties (startTimer, stopTime, reactionTime and state) can be directly set from outside.
* \param letter the letter of the timer (only first char will be used!) * \param letter the letter of the timer (only first char will be used!)
*/ */
explicit ScStwTimer(QObject *parent = nullptr, QString letter = "" ); explicit ScStwTimer(QString letter, QObject *parent = nullptr);
friend class ScStwRace; friend class ScStwRace;

View file

@ -18,6 +18,10 @@
#include "scstwremoterace.h" #include "scstwremoterace.h"
ScStwRemoteRace::ScStwRemoteRace(QObject* parent) : ScStwRemoteRace(nullptr, nullptr, parent)
{
}
ScStwRemoteRace::ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settings, QObject *parent) : ScStwRace(settings, parent) ScStwRemoteRace::ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settings, QObject *parent) : ScStwRace(settings, parent)
{ {
this->isReadyForNextState = true; this->isReadyForNextState = true;
@ -25,12 +29,7 @@ ScStwRemoteRace::ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settin
this->remoteTimers = {}; this->remoteTimers = {};
this->localTimers = {}; this->localTimers = {};
this->scStwClient = scStwClient; this->setScStwClient(scStwClient);
this->scStwClient->addSignalSubscription(ScStw::RaceDetailsChanged);
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteRace::handleClientStateChange);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteRace::handleBaseStationSignal);
} }
// -------------------------- // --------------------------
@ -120,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();
@ -146,10 +142,10 @@ void ScStwRemoteRace::handleClientStateChange() {
} }
ScStwRemoteRace::RaceMode ScStwRemoteRace::getMode() { ScStwRemoteRace::RaceMode ScStwRemoteRace::getMode() {
if(this->scStwClient->getState() == ScStwClient::CONNECTED) if(this->scStwClient == nullptr || this->scStwClient->getState() != ScStwClient::CONNECTED)
return ScStwRemoteRace::REMOTE; return LOCAL;
else else
return ScStwRemoteRace::LOCAL; return REMOTE;
} }
bool ScStwRemoteRace::local() { bool ScStwRemoteRace::local() {
@ -285,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();
@ -328,3 +348,22 @@ void ScStwRemoteRace::refreshCompetitionMode() {
if(this->local()) if(this->local())
return ScStwRace::refreshCompetitionMode(); return ScStwRace::refreshCompetitionMode();
} }
ScStwClient* ScStwRemoteRace::getScStwClient() {
return this->scStwClient;
}
void ScStwRemoteRace::setScStwClient(ScStwClient* client) {
if(client == this->scStwClient)
return;
this->scStwClient = client;
if(this->scStwClient != nullptr) {
this->scStwClient->addSignalSubscription(ScStw::RaceDetailsChanged);
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteRace::handleClientStateChange);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteRace::handleBaseStationSignal);
}
}

View file

@ -18,19 +18,21 @@
#include "../../headers/client/scstwremotesettings.h" #include "../../headers/client/scstwremotesettings.h"
ScStwRemoteSettings::ScStwRemoteSettings(QObject* parent) : ScStwSettings(parent)
{
this->scStwClient = nullptr;
}
ScStwRemoteSettings::ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent) : ScStwSettings(parent) ScStwRemoteSettings::ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent) : ScStwSettings(parent)
{ {
this->scStwClient = scStwClient; this->setScStwClient(scStwClient);
this->scStwClient->addSignalSubscription(ScStw::SettingChanged);
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteSettings::handleBaseStationSignal);
} }
ScStwRemoteSettings::SettingsMode ScStwRemoteSettings::getMode() { ScStwRemoteSettings::SettingsMode ScStwRemoteSettings::getMode() {
if(this->scStwClient->getState() == ScStwClient::CONNECTED) if(this->scStwClient == nullptr || this->scStwClient->getState() != ScStwClient::CONNECTED)
return ScStwRemoteSettings::REMOTE; return LOCAL;
else else
return ScStwRemoteSettings::LOCAL; return REMOTE;
} }
QVariant ScStwRemoteSettings::readSetting(QString key, int keyInt, int keyLevel) { QVariant ScStwRemoteSettings::readSetting(QString key, int keyInt, int keyLevel) {
@ -63,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) {
@ -76,3 +78,21 @@ void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant
break; break;
} }
} }
ScStwClient* ScStwRemoteSettings::getScStwClient() {
return this->scStwClient;
}
void ScStwRemoteSettings::setScStwClient(ScStwClient* client) {
if(client == this->scStwClient)
return;
this->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

@ -30,13 +30,15 @@ void ScStwLibraries::init() {
qRegisterMetaType<ScStw::SocketCommand>("ScStw::SocketCommand"); qRegisterMetaType<ScStw::SocketCommand>("ScStw::SocketCommand");
qRegisterMetaType<ScStw::StatusCode>("ScStw::StatusCode"); qRegisterMetaType<ScStw::StatusCode>("ScStw::StatusCode");
qmlRegisterUncreatableType<ScStwRace>("de.itsblue.ScStw", 2, 0, "ScStwRace", "ScStwRace is not creatable"); qmlRegisterType<ScStwRace>("de.itsblue.ScStw", 2, 0, "ScStwRace");
qmlRegisterType<ScStwTimer>("de.itsblue.ScStw", 2, 0, "ScStwTimer"); qmlRegisterType<ScStwTimer>("de.itsblue.ScStw", 2, 0, "ScStwTimer");
#ifdef ScStwLibraries_ClientLibs #ifdef ScStwLibraries_ClientLibs
qmlRegisterType<ScStwClient>("de.itsblue.ScStw", 2, 0, "ScStwClient"); qmlRegisterType<ScStwClient>("de.itsblue.ScStw", 2, 0, "ScStwClient");
qmlRegisterType<ScStwSettings>("de.itsblue.ScStw", 2, 0, "ScStwSettings"); qmlRegisterType<ScStwSettings>("de.itsblue.ScStw", 2, 0, "ScStwSettings");
qmlRegisterUncreatableType<ScStwSetting>("de.itsblue.ScStw", 2, 0, "ScStwSetting", "The ScStwSetting is manage by a ScStwSettings instance and therefore not creatable"); qmlRegisterUncreatableType<ScStwSetting>("de.itsblue.ScStw", 2, 0, "ScStwSetting", "The ScStwSetting is manage by a ScStwSettings instance and therefore not creatable");
qmlRegisterType<ScStwRemoteRace>("de.itsblue.ScStw", 2, 0, "ScStwRemoteRace");
qmlRegisterType<ScStwRemoteSettings>("de.itsblue.ScStw", 2, 0, "ScStwRemoteSettings");
#endif #endif
#endif #endif

View file

@ -18,10 +18,15 @@
#include "../headers/scstwrace.h" #include "../headers/scstwrace.h"
ScStwRace::ScStwRace(QObject* parent) : ScStwRace(nullptr, parent)
{
}
ScStwRace::ScStwRace(ScStwSettings *settings, QObject *parent) : QObject(parent) ScStwRace::ScStwRace(ScStwSettings *settings, QObject *parent) : QObject(parent)
{ {
this->state = IDLE; this->state = IDLE;
this->competitionMode = false; this->competitionMode = false;
this->autoRefreshTimerText = false;
// configure the loop that waits for the sound effect to finish // configure the loop that waits for the sound effect to finish
this->soundPlayer = new ScStwSoundPlayer(); this->soundPlayer = new ScStwSoundPlayer();
@ -38,8 +43,7 @@ ScStwRace::ScStwRace(ScStwSettings *settings, QObject *parent) : QObject(parent)
connect(this, &ScStwRace::stateChanged, this, &ScStwRace::detailsChanged); connect(this, &ScStwRace::stateChanged, this, &ScStwRace::detailsChanged);
// init settings // init settings
this->settings = settings; this->setSettings(settings);
this->refreshCompetitionMode();
} }
// -------------------------- // --------------------------
@ -631,7 +635,10 @@ void ScStwRace::refreshCompetitionMode() {
if(this->state != IDLE) if(this->state != IDLE)
return; return;
bool currentCompetitionMode = this->settings->readSetting(ScStwSettings::CompetitionModeSetting).toBool(); bool currentCompetitionMode = false;
if(this->settings != nullptr)
currentCompetitionMode = this->settings->readSetting(ScStwSettings::CompetitionModeSetting).toBool();
if(this->competitionMode != currentCompetitionMode) { if(this->competitionMode != currentCompetitionMode) {
@ -741,6 +748,9 @@ QList<ScStwTimer*> ScStwRace::getTimers() {
} }
double ScStwRace::getSoundVolume() { double ScStwRace::getSoundVolume() {
if(this->settings == nullptr)
return 1;
return this->settings->readSetting(ScStwSettings::SoundVolumeSetting).toDouble(); return this->settings->readSetting(ScStwSettings::SoundVolumeSetting).toDouble();
} }
@ -776,6 +786,9 @@ bool ScStwRace::getSoundEnabledSetting(ScStwSoundPlayer::StartSound sound) {
return false; return false;
} }
if(this->settings == nullptr)
return false;
return this->settings->readSetting(soundEnabledSetting).toBool(); return this->settings->readSetting(soundEnabledSetting).toBool();
} }
@ -795,6 +808,9 @@ int ScStwRace::getSoundDelaySetting(ScStwSoundPlayer::StartSound sound) {
return -1; return -1;
} }
if(this->settings == nullptr)
return -1;
return this->settings->readSetting(soundDelaySetting).toInt(); return this->settings->readSetting(soundDelaySetting).toInt();
} }
@ -843,3 +859,53 @@ bool ScStwRace::getCompetitionMode() {
bool ScStwRace::getReadySoundEnabled() { bool ScStwRace::getReadySoundEnabled() {
return this->getSoundEnabledSetting(ScStwSoundPlayer::Ready); return this->getSoundEnabledSetting(ScStwSoundPlayer::Ready);
} }
ScStwSettings* ScStwRace::getSettings() {
return this->settings;
}
void ScStwRace::setSettings(ScStwSettings* settings) {
if(settings == this->settings)
return;
this->settings = settings;
this->refreshCompetitionMode();
emit this->settingsChanged();
}
bool ScStwRace::getAutoRefreshTimerText() {
return this->autoRefreshTimerText;
}
void ScStwRace::setAutoRefreshTimerText(bool autoRefresh) {
if(autoRefresh == this->autoRefreshTimerText)
return;
this->autoRefreshTimerText = autoRefresh;
if(this->autoRefreshTimerText) {
this->timerTextRefreshTimer = new QTimer(this);
this->timerTextRefreshTimer->setInterval(1);
this->timerTextRefreshTimer->connect(
this->timerTextRefreshTimer,
&QTimer::timeout,
[=]{
// refresh timer text
if(this->getState() == ScStwRace::RUNNING) {
emit this->timersChanged();
}
// refresh next start action delay progress
if(this->getState() == ScStwRace::WAITING || this->getState() == ScStwRace::PREPAIRING) {
emit this->currentStartDelayChanged();
}
}
);
this->timerTextRefreshTimer->start();
}
else if(this->timerTextRefreshTimer != nullptr) {
this->timerTextRefreshTimer->deleteLater();
}
emit this->autoRefreshTimerTextChanged();
}

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();
} }

View file

@ -18,7 +18,11 @@
#include "../headers/scstwtimer.h" #include "../headers/scstwtimer.h"
ScStwTimer::ScStwTimer(QObject *parent, QString letter) : QObject(parent) ScStwTimer::ScStwTimer(QObject* parent) : ScStwTimer("", parent)
{
}
ScStwTimer::ScStwTimer(QString letter, QObject *parent) : QObject(parent)
{ {
if(letter.length() > 1) if(letter.length() > 1)
this->letter = letter[0]; this->letter = letter[0];