Library migration #36

Merged
dorian merged 62 commits from library_migration into master 2024-10-17 17:52:36 +02:00
5 changed files with 80 additions and 72 deletions
Showing only changes of commit e73d1106be - Show all commits

View file

@ -15,12 +15,9 @@ class ScStwAppBackend : public QObject
//Q_PROPERTY(int state READ getState NOTIFY stateChanged)
Q_PROPERTY(int mode READ getMode NOTIFY modeChanged)
Q_PROPERTY(QVariant timers READ getTimerTextList NOTIFY timerTextChanged)
//Q_PROPERTY(QString baseStationState READ getBaseStationState NOTIFY baseStationStateChanged)
Q_PROPERTY(ScStwRace* race READ getRace NOTIFY raceChanged)
Q_PROPERTY(QVariant baseStationConnections READ getBaseStationConnections NOTIFY baseStationConnectionsChanged)
Q_PROPERTY(double nextStartActionDelayProgress READ getNextStartActionDelayProgress NOTIFY nextStartActionDelayProgressChanged)
Q_PROPERTY(int nextStartAction READ getNextStartAction NOTIFY nextStartActionChanged)
Q_PROPERTY(QVariantMap baseStationProperties READ getBaseStationProperties NOTIFY baseStationPropertiesChanged)
public:
@ -48,9 +45,6 @@ public slots:
Q_INVOKABLE ScStwRace *getRace();
//Q_INVOKABLE int getState();
Q_INVOKABLE int getMode();
Q_INVOKABLE QVariant getTimerTextList();
Q_INVOKABLE double getNextStartActionDelayProgress();
Q_INVOKABLE int getNextStartAction();
Q_INVOKABLE void writeSetting(QString key, QVariant value);
Q_INVOKABLE void writeSetting(ScStw::BaseStationSetting key, QVariant value);
@ -79,15 +73,12 @@ public slots:
private slots:
void refreshTimerText();
void refreshMode();
void reloadRaceSettings();
signals:
void modeChanged();
void raceChanged();
void nextStartActionChanged();
void nextStartActionDelayProgressChanged();
void timerTextChanged();
void baseStationStateChanged();
void baseStationConnectionsChanged();
void baseStationPropertiesChanged();

View file

@ -18,7 +18,7 @@ Column {
function updateSetting(key, val, del){
del.busy = true
speedBackend.writeSetting(key, val)
speedBackend.writeSetting(scStw.baseStationSettingToString(key) , val)
del.busy = false
}
@ -38,10 +38,10 @@ Column {
text: qsTr("say 'ready'")
checked: parent.loadSetting("ReadySoundEnable", ready_del) === "true"
checked: parent.loadSetting(ScStw.ReadySoundEnableSetting, ready_del) === "true"
onCheckedChanged: {
parent.updateSetting("ReadySoundEnable", checked, ready_del)
parent.updateSetting(ScStw.ReadySoundEnableSetting, checked, ready_del)
}
}
@ -59,10 +59,10 @@ Column {
inputHint: qsTr("time")
inputMethodHints: Qt.ImhFormattedNumbersOnly
inputText: control.loadSetting("ReadySoundDelay", ready_delay_del)
inputText: control.loadSetting(ScStw.ReadySoundDelaySetting, ready_delay_del)
onInputFinished: {
control.updateSetting("ReadySoundDelay", inputText, ready_delay_del)
control.updateSetting(ScStw.ReadySoundDelaySetting, inputText, ready_delay_del)
}
}
@ -78,10 +78,10 @@ Column {
text: qsTr("say 'at your marks'")
checked: control.loadSetting("AtYourMarksSoundEnable", ready_del) === "true"
checked: control.loadSetting(ScStw.AtYourMarksSoundEnableSetting , ready_del) === "true"
onCheckedChanged: {
parent.updateSetting("AtYourMarksSoundEnable", at_marks_del.checked, at_marks_del)
parent.updateSetting(ScStw.AtYourMarksSoundEnableSetting, at_marks_del.checked, at_marks_del)
}
}
@ -99,10 +99,10 @@ Column {
enabled: !busy && at_marks_del.checked
inputText: control.loadSetting("AtYourMarksSoundDelay", at_marks_delay_del)
inputText: control.loadSetting(ScStw.AtYourMarksSoundDelaySetting, at_marks_delay_del)
onInputFinished: {
control.updateSetting("AtYourMarksSoundDelay", inputText, at_marks_delay_del)
control.updateSetting(ScStw.AtYourMarksSoundDelaySetting, inputText, at_marks_delay_del)
}
}
}

View file

@ -55,6 +55,10 @@ Window {
}
}
ScStw {
id: scStw
}
SpeedBackend {
id: speedBackend
}
@ -65,32 +69,31 @@ Window {
var stateString
console.log("race state changed to: " + state)
switch (state){
case 0:
case ScStwRace.IDLE:
stateString = "IDLE"
break;
case 1:
case ScStwRace.STARTING:
stateString = "STARTING"
settingsDialog.close()
profilesDialog.close()
break;
case 2:
case ScStwRace.WAITING:
stateString = "WAITING"
settingsDialog.close()
profilesDialog.close()
break;
case 3:
case ScStwRace.RUNNING:
stateString = "RUNNING"
settingsDialog.close()
profilesDialog.close()
break;
case 4:
case ScStwRace.STOPPED:
stateString = "STOPPED"
settingsDialog.close()
profilesDialog.close()
}
app.state = stateString
}
}
AppTheme {
@ -140,12 +143,13 @@ Window {
anchors.centerIn: parent
opacity: ( speedBackend.state < 3 ) ? 1:0
opacity: ( speedBackend.race.state < ScStwRace.RUNNING ) ? 1:0
width: parent.width * 0.7
height: parent.height * 0.7
text: implicitText === "NEXT_START_ACTION" ? ["at your \nmarks", "ready", "starting...", ""][speedBackend.nextStartAction]:implicitText
text: implicitText === "NEXT_START_ACTION" ?
["", "at your \nmarks", "ready", "starting..."][speedBackend.race.nextStartActionDetails[ScStwRace.NextStartAction]+1]:implicitText
color: appTheme.style.textColor
@ -172,14 +176,14 @@ Window {
anchors.fill: parent
anchors.bottomMargin: app.landscape() ? 0:parent.height * 0.1
opacity: ( speedBackend.state < 3 ) ? 0:1
opacity: ( speedBackend.race.state < ScStwRace.RUNNING ) ? 0:1
spacing: height * 0.05
Repeater {
id: timerRep
model: speedBackend.timers.length
model: speedBackend.race.timers.length
delegate: Item {
id: timerDel
@ -200,9 +204,9 @@ Window {
["LOST", "FAILED"].includes(speedBackend.timers[index]["state"]) ? appTheme.style.errorColor:
appTheme.style.textColor
enabled: speedBackend.timers[index]["state"] !== "DISABLED"
enabled: speedBackend.race.timers[index]["state"] !== ScStwTimer.DISABLED
text: speedBackend.timers[index]["text"]
text: speedBackend.race.timers[index]["text"]
fontSizeMode: Text.Fit
@ -224,7 +228,7 @@ Window {
Label {
id: react_time
property int rtime: speedBackend.timers[index]["reacttime"]
property int rtime: speedBackend.race.timers[index]["reactionTime"]
anchors {
centerIn: parent
@ -408,7 +412,7 @@ Window {
app.start()
break
case "RUNNING":
app.stop(0)
app.stop()
break
case "STOPPED":
app.reset()
@ -479,6 +483,9 @@ Window {
ProgressCircle {
id: prog
property double progress: speedBackend.race.nextStartActionDetails[ScStwRace.NextStartActionDelayProgress]
anchors.fill: startButt
opacity: app.state === "STARTING" ? 1:0
@ -487,7 +494,7 @@ Window {
lineWidth: prog.width * 0.02
arcBegin: 0
arcEnd: 360 * speedBackend.nextStartActionDelayProgress
arcEnd: 360 * (1 - (progress > 0 ? progress:1))
colorCircle: "grey"
@ -521,7 +528,7 @@ Window {
enabled: app.state === "STARTING"
onClicked: {
app.stop(1)
app.cancel()
}
Behavior on scale {
@ -842,23 +849,30 @@ Window {
/*----Functions to control the stopwatch----*/
function start(){
var ret = speedBackend.race.start()
if(!ret){
console.log("+ --- error starting race!")
if(ret !== 200){
console.log("+ --- error starting race: " + ret)
}
}
function stop(type){
function cancel() {
var ret = speedBackend.race.cancelStart(false)
if(ret !== 200){
console.log("+ --- error canellingr race: " + ret)
}
}
var ret = speedBackend.stopRace(type)
function stop(){
if(!ret){
console.log("+ --- error stopping race: ")
var ret = speedBackend.race.stop()
if(ret !== 200){
console.log("+ --- error stopping race: " + ret)
}
}
function reset(){
var ret = speedBackend.resetRace()
var ret = speedBackend.race.reset()
if(ret !== 200){
console.log("+ --- error resetting race: " + ret)

View file

@ -17,6 +17,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QSqlDatabase>
#include <QSqlError>
#include <QDebug>
@ -54,7 +55,9 @@
//#include "headers/climbingrace.h"
#include "headers/apptheme.h"
#include "headers/scstwappbackend.h"
#include <scstwtimer.h>
#include <scstwrace.h>
#include <ScStw.hpp>
#include <QTranslator>
int main(int argc, char *argv[])
@ -86,7 +89,10 @@ int main(int argc, char *argv[])
// setup speed backend and App themes
qmlRegisterType<ScStwAppBackend>("com.itsblue.speedclimbingstopwatch", 2, 0, "SpeedBackend");
qmlRegisterType<ScStwRace>("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStwRace");
qmlRegisterType<ScStwTimer>("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStwTimer");
qmlRegisterType<AppTheme>("com.itsblue.speedclimbingstopwatch", 2, 0, "AppTheme");
//qmlRegisterUncreatableType<ScStw>("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStw", "This is a static class and therefore not instantiable");
qmlRegisterType<ScStw>("com.itsblue.speedclimbingstopwatch", 2, 0, "ScStw");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

View file

@ -13,6 +13,7 @@ ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent)
connect(this, &ScStwAppBackend::baseStationStateChanged, this, &ScStwAppBackend::baseStationPropertiesChanged);
this->localRace->addTimer(new ScStwTimer(this));
this->reloadRaceSettings();
this->timerTextRefreshTimer = new QTimer(this);
this->timerTextRefreshTimer->setInterval(1);
@ -21,11 +22,6 @@ ScStwAppBackend::ScStwAppBackend(QObject *parent) : QObject(parent)
this->refreshTimerText();
}
// --------------------------
// --- Main Functionality ---
// --------------------------
// -------------------------
// --- Base Station sync ---
// -------------------------
@ -124,8 +120,7 @@ void ScStwAppBackend::refreshMode() {
if(newMode == LOCAL){
// if the new mode is local -> connection to base station has been lost
// reset race
// reset state
// reset local race
this->getRace()->reset();
}
@ -138,18 +133,14 @@ void ScStwAppBackend::refreshMode() {
void ScStwAppBackend::refreshTimerText() {
// --- refresh timer text ---
QVariantList newTimerTextList;
newTimerTextList = this->getRace()->getTimerDetailList();
if(this->getRace()->getState() == ScStwRace::RUNNING) {
emit this->getRace()->timersChanged();
}
// --- refresh next start action delay progress ---
double nextStartActionDelayProgress = 0;
nextStartActionDelayProgress = this->getRace()->getNextStartActionDetails()["nextActionDelayProg"].toDouble();
if(nextStartActionDelayProgress < 1.0)
emit this->nextStartActionDelayProgressChanged();
if(this->getRace()->getState() == ScStwRace::STARTING) {
emit this->getRace()->nextStartActionDetailsChanged();
}
this->timerTextRefreshTimer->start();
}
@ -258,18 +249,6 @@ int ScStwAppBackend::getMode() {
return this->mode;
}
QVariant ScStwAppBackend::getTimerTextList() {
return this->getRace()->getTimerDetailList();
}
double ScStwAppBackend::getNextStartActionDelayProgress() {
return this->getRace()->getNextStartActionDetails()["nextActionDelayProg"].toDouble();
}
int ScStwAppBackend::getNextStartAction() {
return this->getRace()->getNextStartActionDetails()["nextAction"].toInt();
}
void ScStwAppBackend::writeSetting(QString key, QVariant value) {
if(this->mode == REMOTE && ScStw::baseStationSettingFromString(key) != ScStw::InvalidSetting ){
this->scStwClient->writeRemoteSetting(ScStw::baseStationSettingFromString(key), value.toString());
@ -277,6 +256,8 @@ void ScStwAppBackend::writeSetting(QString key, QVariant value) {
else {
this->appSettings->writeSetting(key, value);
}
this->reloadRaceSettings();
}
void ScStwAppBackend::writeSetting(ScStw::BaseStationSetting key, QVariant value) {
@ -301,6 +282,22 @@ QString ScStwAppBackend::readSetting(ScStw::BaseStationSetting key) {
return "false";
}
void ScStwAppBackend::reloadRaceSettings() {
this->getRace()->writeStartActionSetting(
ScStwRace::AtYourMarks,
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::AtYourMarksSoundEnableSetting)) == "true",
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::AtYourMarksSoundDelaySetting)).toDouble()
);
this->getRace()->writeStartActionSetting(
ScStwRace::Ready,
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::ReadySoundEnableSetting)) == "true",
this->appSettings->loadSetting(ScStw::baseStationSettingToString(ScStw::ReadySoundDelaySetting)).toDouble()
);
this->getRace()->setSoundVolume(1);
}
void ScStwAppBackend::connectBaseStation() {
this->reloadBaseStationIpAdress();
this->scStwClient->connectToHost();