Made all Classes usable in pure QML
This commit is contained in:
parent
f8cc23646c
commit
ca040a191c
11 changed files with 168 additions and 24 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,9 @@ private slots:
|
|||
void refreshCompetitionMode();
|
||||
RaceMode getMode();
|
||||
bool local();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
@ -146,10 +145,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() {
|
||||
|
@ -328,3 +327,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) {
|
||||
|
@ -76,3 +78,20 @@ 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::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);
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
@ -624,7 +628,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) {
|
||||
|
||||
|
@ -734,6 +741,9 @@ QList<ScStwTimer*> ScStwRace::getTimers() {
|
|||
}
|
||||
|
||||
double ScStwRace::getSoundVolume() {
|
||||
if(this->settings == nullptr)
|
||||
return 1;
|
||||
|
||||
return this->settings->readSetting(ScStwSettings::SoundVolumeSetting).toDouble();
|
||||
}
|
||||
|
||||
|
@ -769,6 +779,9 @@ bool ScStwRace::getSoundEnabledSetting(ScStwSoundPlayer::StartSound sound) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(this->settings == nullptr)
|
||||
return false;
|
||||
|
||||
return this->settings->readSetting(soundEnabledSetting).toBool();
|
||||
}
|
||||
|
||||
|
@ -788,6 +801,9 @@ int ScStwRace::getSoundDelaySetting(ScStwSoundPlayer::StartSound sound) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(this->settings == nullptr)
|
||||
return -1;
|
||||
|
||||
return this->settings->readSetting(soundDelaySetting).toInt();
|
||||
}
|
||||
|
||||
|
@ -836,3 +852,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();
|
||||
}
|
||||
|
|
|
@ -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