Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
92fae09672
12 changed files with 205 additions and 36 deletions
|
@ -28,7 +28,10 @@
|
|||
class ScStwRemoteRace : public ScStwRace
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(ScStwClient* scStwClient READ getScStwClient WRITE setScStwClient NOTIFY scStwClientChanged)
|
||||
|
||||
public:
|
||||
ScStwRemoteRace(QObject *parent = nullptr);
|
||||
ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settings = nullptr, QObject *parent = nullptr);
|
||||
|
||||
enum RaceMode {
|
||||
|
@ -59,6 +62,9 @@ public slots:
|
|||
bool getIsReadyForNextState();
|
||||
bool getReadySoundEnabled();
|
||||
|
||||
ScStwClient *getScStwClient();
|
||||
void setScStwClient(ScStwClient *client);
|
||||
|
||||
private slots:
|
||||
void handleBaseStationSignal(ScStw::SignalKey key, QVariant data);
|
||||
|
||||
|
@ -70,6 +76,11 @@ private slots:
|
|||
void refreshCompetitionMode();
|
||||
RaceMode getMode();
|
||||
bool local();
|
||||
|
||||
void setTimers(QList<ScStwTimer*> timers, bool deleteOldTimers);
|
||||
|
||||
signals:
|
||||
void scStwClientChanged();
|
||||
};
|
||||
|
||||
#endif // SCSTWREMOTEMONITORRACE_H
|
||||
|
|
|
@ -27,7 +27,10 @@
|
|||
class ScStwRemoteSettings : public ScStwSettings
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(ScStwClient* scStwClient READ getScStwClient WRITE setScStwClient NOTIFY scStwClientChanged)
|
||||
|
||||
public:
|
||||
ScStwRemoteSettings(QObject * parent = nullptr);
|
||||
ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent = nullptr);
|
||||
|
||||
enum SettingsMode {
|
||||
|
@ -43,10 +46,17 @@ protected:
|
|||
private:
|
||||
ScStwClient * scStwClient;
|
||||
|
||||
public slots:
|
||||
ScStwClient *getScStwClient();
|
||||
void setScStwClient(ScStwClient *client);
|
||||
|
||||
private slots:
|
||||
void handleClientStateChange();
|
||||
void handleBaseStationSignal(ScStw::SignalKey key, QVariant data);
|
||||
SettingsMode getMode();
|
||||
|
||||
signals:
|
||||
void scStwClientChanged();
|
||||
};
|
||||
|
||||
#endif // SCSTWREMOTESETTINGS_H
|
||||
|
|
|
@ -74,7 +74,6 @@ protected slots:
|
|||
*/
|
||||
void setState(TimerState newState);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SCSTWREMOTETIMER_H
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "scstwsetting.h"
|
||||
#include "scstwremoterace.h"
|
||||
#include "scstwclient.h"
|
||||
#include "scstwremotesettings.h"
|
||||
#endif
|
||||
|
||||
class ScStwLibraries : public QObject
|
||||
|
|
|
@ -59,8 +59,11 @@ class ScStwRace : public QObject
|
|||
Q_PROPERTY(bool competitionMode READ getCompetitionMode NOTIFY competitionModeChanged)
|
||||
Q_PROPERTY(bool readySoundEnabled READ getReadySoundEnabled NOTIFY readySoundEnabledChanged)
|
||||
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:
|
||||
explicit ScStwRace(QObject *parent = nullptr);
|
||||
explicit ScStwRace(ScStwSettings *settings, QObject *parent = nullptr);
|
||||
|
||||
friend class ScStwRemoteRace;
|
||||
|
@ -76,6 +79,7 @@ private:
|
|||
RaceState state;
|
||||
|
||||
QTimer *startDelayTimer;
|
||||
QTimer *timerTextRefreshTimer;
|
||||
QEventLoop *startWaitLoop;
|
||||
|
||||
// sounds
|
||||
|
@ -84,6 +88,7 @@ private:
|
|||
// settings
|
||||
ScStwSettings *settings;
|
||||
bool competitionMode;
|
||||
bool autoRefreshTimerText;
|
||||
|
||||
enum LoopExitTypes {
|
||||
LoopAutomaticExit = 0,
|
||||
|
@ -119,7 +124,7 @@ public slots:
|
|||
|
||||
virtual ScStw::StatusCode setTimerDisabled(int id, bool disabled);
|
||||
|
||||
virtual bool addTimer(ScStwTimer *timer);
|
||||
Q_INVOKABLE virtual bool addTimer(ScStwTimer *timer);
|
||||
|
||||
// getters
|
||||
RaceState getState();
|
||||
|
@ -130,6 +135,12 @@ public slots:
|
|||
bool getCompetitionMode();
|
||||
virtual bool getReadySoundEnabled();
|
||||
|
||||
ScStwSettings* getSettings();
|
||||
void setSettings(ScStwSettings* settings);
|
||||
|
||||
bool getAutoRefreshTimerText();
|
||||
void setAutoRefreshTimerText(bool autoRefresh);
|
||||
|
||||
protected slots:
|
||||
|
||||
private slots:
|
||||
|
@ -171,6 +182,8 @@ signals:
|
|||
void detailsChanged();
|
||||
void competitionModeChanged();
|
||||
void readySoundEnabledChanged();
|
||||
void settingsChanged();
|
||||
void autoRefreshTimerTextChanged();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -65,13 +65,16 @@ class ScStwTimer : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit ScStwTimer(QObject *parent = nullptr);
|
||||
|
||||
/*!
|
||||
* \brief ScStwTimer constructor
|
||||
* \param parent the parent object
|
||||
* \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!)
|
||||
*/
|
||||
explicit ScStwTimer(QObject *parent = nullptr, QString letter = "" );
|
||||
explicit ScStwTimer(QString letter, QObject *parent = nullptr);
|
||||
|
||||
friend class ScStwRace;
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "scstwremoterace.h"
|
||||
|
||||
ScStwRemoteRace::ScStwRemoteRace(QObject* parent) : ScStwRemoteRace(nullptr, nullptr, parent)
|
||||
{
|
||||
}
|
||||
|
||||
ScStwRemoteRace::ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settings, QObject *parent) : ScStwRace(settings, parent)
|
||||
{
|
||||
this->isReadyForNextState = true;
|
||||
|
@ -25,12 +29,7 @@ ScStwRemoteRace::ScStwRemoteRace(ScStwClient *scStwClient, ScStwSettings *settin
|
|||
this->remoteTimers = {};
|
||||
this->localTimers = {};
|
||||
|
||||
this->scStwClient = scStwClient;
|
||||
|
||||
this->scStwClient->addSignalSubscription(ScStw::RaceDetailsChanged);
|
||||
|
||||
connect(this->scStwClient, &ScStwClient::stateChanged, this, &ScStwRemoteRace::handleClientStateChange);
|
||||
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteRace::handleBaseStationSignal);
|
||||
this->setScStwClient(scStwClient);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
@ -120,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();
|
||||
|
@ -146,10 +142,10 @@ void ScStwRemoteRace::handleClientStateChange() {
|
|||
}
|
||||
|
||||
ScStwRemoteRace::RaceMode ScStwRemoteRace::getMode() {
|
||||
if(this->scStwClient->getState() == ScStwClient::CONNECTED)
|
||||
return ScStwRemoteRace::REMOTE;
|
||||
if(this->scStwClient == nullptr || this->scStwClient->getState() != ScStwClient::CONNECTED)
|
||||
return LOCAL;
|
||||
else
|
||||
return ScStwRemoteRace::LOCAL;
|
||||
return REMOTE;
|
||||
}
|
||||
|
||||
bool ScStwRemoteRace::local() {
|
||||
|
@ -285,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();
|
||||
|
@ -328,3 +348,22 @@ void ScStwRemoteRace::refreshCompetitionMode() {
|
|||
if(this->local())
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,19 +18,21 @@
|
|||
|
||||
#include "../../headers/client/scstwremotesettings.h"
|
||||
|
||||
ScStwRemoteSettings::ScStwRemoteSettings(QObject* parent) : ScStwSettings(parent)
|
||||
{
|
||||
this->scStwClient = nullptr;
|
||||
}
|
||||
|
||||
ScStwRemoteSettings::ScStwRemoteSettings(ScStwClient * scStwClient, QObject * parent) : ScStwSettings(parent)
|
||||
{
|
||||
this->scStwClient = scStwClient;
|
||||
this->scStwClient->addSignalSubscription(ScStw::SettingChanged);
|
||||
|
||||
connect(this->scStwClient, &ScStwClient::gotSignal, this, &ScStwRemoteSettings::handleBaseStationSignal);
|
||||
this->setScStwClient(scStwClient);
|
||||
}
|
||||
|
||||
ScStwRemoteSettings::SettingsMode ScStwRemoteSettings::getMode() {
|
||||
if(this->scStwClient->getState() == ScStwClient::CONNECTED)
|
||||
return ScStwRemoteSettings::REMOTE;
|
||||
if(this->scStwClient == nullptr || this->scStwClient->getState() != ScStwClient::CONNECTED)
|
||||
return LOCAL;
|
||||
else
|
||||
return ScStwRemoteSettings::LOCAL;
|
||||
return REMOTE;
|
||||
}
|
||||
|
||||
QVariant ScStwRemoteSettings::readSetting(QString key, int keyInt, int keyLevel) {
|
||||
|
@ -63,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) {
|
||||
|
@ -76,3 +78,21 @@ void ScStwRemoteSettings::handleBaseStationSignal(ScStw::SignalKey key, QVariant
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,15 @@ void ScStwLibraries::init() {
|
|||
qRegisterMetaType<ScStw::SocketCommand>("ScStw::SocketCommand");
|
||||
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");
|
||||
|
||||
#ifdef ScStwLibraries_ClientLibs
|
||||
qmlRegisterType<ScStwClient>("de.itsblue.ScStw", 2, 0, "ScStwClient");
|
||||
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");
|
||||
qmlRegisterType<ScStwRemoteRace>("de.itsblue.ScStw", 2, 0, "ScStwRemoteRace");
|
||||
qmlRegisterType<ScStwRemoteSettings>("de.itsblue.ScStw", 2, 0, "ScStwRemoteSettings");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,10 +18,15 @@
|
|||
|
||||
#include "../headers/scstwrace.h"
|
||||
|
||||
ScStwRace::ScStwRace(QObject* parent) : ScStwRace(nullptr, parent)
|
||||
{
|
||||
}
|
||||
|
||||
ScStwRace::ScStwRace(ScStwSettings *settings, QObject *parent) : QObject(parent)
|
||||
{
|
||||
this->state = IDLE;
|
||||
this->competitionMode = false;
|
||||
this->autoRefreshTimerText = false;
|
||||
|
||||
// configure the loop that waits for the sound effect to finish
|
||||
this->soundPlayer = new ScStwSoundPlayer();
|
||||
|
@ -38,8 +43,7 @@ ScStwRace::ScStwRace(ScStwSettings *settings, QObject *parent) : QObject(parent)
|
|||
connect(this, &ScStwRace::stateChanged, this, &ScStwRace::detailsChanged);
|
||||
|
||||
// init settings
|
||||
this->settings = settings;
|
||||
this->refreshCompetitionMode();
|
||||
this->setSettings(settings);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
@ -631,7 +635,10 @@ void ScStwRace::refreshCompetitionMode() {
|
|||
if(this->state != IDLE)
|
||||
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) {
|
||||
|
||||
|
@ -741,6 +748,9 @@ QList<ScStwTimer*> ScStwRace::getTimers() {
|
|||
}
|
||||
|
||||
double ScStwRace::getSoundVolume() {
|
||||
if(this->settings == nullptr)
|
||||
return 1;
|
||||
|
||||
return this->settings->readSetting(ScStwSettings::SoundVolumeSetting).toDouble();
|
||||
}
|
||||
|
||||
|
@ -776,6 +786,9 @@ bool ScStwRace::getSoundEnabledSetting(ScStwSoundPlayer::StartSound sound) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(this->settings == nullptr)
|
||||
return false;
|
||||
|
||||
return this->settings->readSetting(soundEnabledSetting).toBool();
|
||||
}
|
||||
|
||||
|
@ -795,6 +808,9 @@ int ScStwRace::getSoundDelaySetting(ScStwSoundPlayer::StartSound sound) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(this->settings == nullptr)
|
||||
return -1;
|
||||
|
||||
return this->settings->readSetting(soundDelaySetting).toInt();
|
||||
}
|
||||
|
||||
|
@ -843,3 +859,53 @@ bool ScStwRace::getCompetitionMode() {
|
|||
bool ScStwRace::getReadySoundEnabled() {
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
|
||||
#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)
|
||||
this->letter = letter[0];
|
||||
|
|
Reference in a new issue