/
DemienMedich
/
BodyweightBase
Обзор
Документация
Войти
/
DemienMedich
/
BodyweightBase
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
app/session_controller.h
374 строки
19 KB
DemienMedich
feat: continue quick workouts into full sessions
23 июл 2026, 16:34
23 июл 2026, 16:34
a2ccab1
Код
Авторство
О чём код?
#pragma once #include <memory> #include <optional> #include <QDateTime> #include <QJsonArray> #include <QJsonObject> #include <QObject> #include <QVariantList> #include <QVariantMap> #include <QTimer> #include "bodyweight/state_importer.h" #include "bodyweight/state_store.h" #include "bodyweight/workout_session_runner.h" class SessionController : public QObject { Q_OBJECT Q_PROPERTY(bool ready READ ready NOTIFY changed) Q_PROPERTY(bool active READ active NOTIFY changed) Q_PROPERTY(bool paused READ paused NOTIFY changed) Q_PROPERTY(bool quickDecisionPending READ quickDecisionPending NOTIFY changed) Q_PROPERTY(bool needsSave READ needsSave NOTIFY changed) Q_PROPERTY(bool hasRecoverableDraft READ hasRecoverableDraft NOTIFY changed) Q_PROPERTY(QString status READ status NOTIFY changed) Q_PROPERTY(QString pendingResultSummary READ pendingResultSummary NOTIFY changed) Q_PROPERTY(QString recoverableDraftSummary READ recoverableDraftSummary NOTIFY changed) Q_PROPERTY(QString planName READ planName NOTIFY changed) Q_PROPERTY(QString planGoal READ planGoal NOTIFY changed) Q_PROPERTY(QVariantList profiles READ profiles NOTIFY changed) Q_PROPERTY(QString selectedProfileId READ selectedProfileId NOTIFY changed) Q_PROPERTY(QString selectedProfileName READ selectedProfileName NOTIFY changed) Q_PROPERTY(QVariantMap preWorkoutRecommendation READ preWorkoutRecommendation NOTIFY changed) Q_PROPERTY(QString phaseTitle READ phaseTitle NOTIFY changed) Q_PROPERTY(QString exerciseName READ exerciseName NOTIFY changed) Q_PROPERTY(QString nextExerciseName READ nextExerciseName NOTIFY changed) Q_PROPERTY(QString currentCoachNote READ currentCoachNote NOTIFY changed) Q_PROPERTY(QString currentStepSummary READ currentStepSummary NOTIFY changed) Q_PROPERTY(QVariantMap currentExerciseTechnique READ currentExerciseTechnique NOTIFY changed) Q_PROPERTY(QString progressText READ progressText NOTIFY changed) Q_PROPERTY(QString completedStepText READ completedStepText NOTIFY changed) Q_PROPERTY(QString counterText READ counterText NOTIFY changed) Q_PROPERTY(double phaseProgress READ phaseProgress NOTIFY changed) Q_PROPERTY(QString phaseProgressText READ phaseProgressText NOTIFY changed) Q_PROPERTY(QString phaseColor READ phaseColor NOTIFY changed) Q_PROPERTY(QVariantMap currentWorkoutPosition READ currentWorkoutPosition NOTIFY changed) Q_PROPERTY(int currentStepIndex READ currentStepIndex NOTIFY changed) Q_PROPERTY(int currentSet READ currentSet NOTIFY changed) Q_PROPERTY(int totalSets READ totalSets NOTIFY changed) Q_PROPERTY(int selectedPlanDayOfWeek READ selectedPlanDayOfWeek NOTIFY changed) Q_PROPERTY(bool hasScheduledPlanToday READ hasScheduledPlanToday NOTIFY changed) Q_PROPERTY(QString scheduledPlanTodayName READ scheduledPlanTodayName NOTIFY changed) Q_PROPERTY(QVariantList currentExerciseFrameUrls READ currentExerciseFrameUrls NOTIFY changed) Q_PROPERTY(int currentExerciseFrameDurationMs READ currentExerciseFrameDurationMs NOTIFY changed) Q_PROPERTY(QString currentExerciseFramePlayback READ currentExerciseFramePlayback NOTIFY changed) Q_PROPERTY(QVariantList currentExerciseFrameDurationsMs READ currentExerciseFrameDurationsMs NOTIFY changed) Q_PROPERTY(QString currentLoadNote READ currentLoadNote WRITE setCurrentLoadNote NOTIFY changed) Q_PROPERTY(QVariantMap currentSetLog READ currentSetLog NOTIFY changed) Q_PROPERTY(QVariantMap lastCompletedSetLog READ lastCompletedSetLog NOTIFY changed) Q_PROPERTY(QVariantList plans READ plans NOTIFY changed) Q_PROPERTY(QString selectedPlanId READ selectedPlanId NOTIFY changed) Q_PROPERTY(QVariantMap selectedPlanOptions READ selectedPlanOptions NOTIFY changed) Q_PROPERTY(QVariantList selectedPlanSteps READ selectedPlanSteps NOTIFY changed) Q_PROPERTY(QVariantList workoutQueueSteps READ workoutQueueSteps NOTIFY changed) Q_PROPERTY(QVariantList workoutReplacementExercises READ workoutReplacementExercises NOTIFY changed) Q_PROPERTY(int totalSessions READ totalSessions NOTIFY changed) Q_PROPERTY(int totalWorkMinutes READ totalWorkMinutes NOTIFY changed) Q_PROPERTY(QString completionRateText READ completionRateText NOTIFY changed) Q_PROPERTY(QVariantList recentSessions READ recentSessions NOTIFY changed) Q_PROPERTY(QVariantList latestSessionSteps READ latestSessionSteps NOTIFY changed) Q_PROPERTY(QVariantList loadJournalEntries READ loadJournalEntries NOTIFY changed) Q_PROPERTY(QString progressPlanFilter READ progressPlanFilter WRITE setProgressPlanFilter NOTIFY changed) Q_PROPERTY(QVariantList progressDayBuckets READ progressDayBuckets NOTIFY changed) Q_PROPERTY(QVariantList progressExerciseBuckets READ progressExerciseBuckets NOTIFY changed) Q_PROPERTY(QVariantList exerciseLibrary READ exerciseLibrary NOTIFY changed) Q_PROPERTY(QString exerciseSearch READ exerciseSearch WRITE setExerciseSearch NOTIFY changed) Q_PROPERTY(QString exerciseMetricFilter READ exerciseMetricFilter WRITE setExerciseMetricFilter NOTIFY changed) Q_PROPERTY(QVariantMap nutritionSummary READ nutritionSummary NOTIFY changed) Q_PROPERTY(QVariantList nutritionMeals READ nutritionMeals NOTIFY changed) Q_PROPERTY(QVariantList nutritionWeightEntries READ nutritionWeightEntries NOTIFY changed) Q_PROPERTY(QVariantList weightChartData READ weightChartData NOTIFY changed) Q_PROPERTY(QVariantList nutritionMeasurementEntries READ nutritionMeasurementEntries NOTIFY changed) Q_PROPERTY(QVariantList nutritionAdherenceDays READ nutritionAdherenceDays NOTIFY changed) Q_PROPERTY(QVariantList nutritionPhotoEntries READ nutritionPhotoEntries NOTIFY changed) Q_PROPERTY(QVariantList recoveryCheckIns READ recoveryCheckIns NOTIFY changed) Q_PROPERTY(QVariantMap wearableSummary READ wearableSummary NOTIFY changed) Q_PROPERTY(QVariantMap wearableStatistics READ wearableStatistics NOTIFY changed) Q_PROPERTY(QVariantList wearableDays READ wearableDays NOTIFY changed) Q_PROPERTY(QString healthSyncStatusText READ healthSyncStatusText NOTIFY changed) Q_PROPERTY(QString healthSyncLastSuccessText READ healthSyncLastSuccessText NOTIFY changed) Q_PROPERTY(bool healthSyncInProgress READ healthSyncInProgress NOTIFY changed) Q_PROPERTY(QString healthActivitySource READ healthActivitySource NOTIFY changed) Q_PROPERTY(QString healthWeightSource READ healthWeightSource NOTIFY changed) Q_PROPERTY(QString healthConnectOwnerProfileId READ healthConnectOwnerProfileId NOTIFY changed) Q_PROPERTY(QString healthConnectOwnerProfileName READ healthConnectOwnerProfileName NOTIFY changed) Q_PROPERTY(bool workoutReminderEnabled READ workoutReminderEnabled NOTIFY changed) Q_PROPERTY(QString workoutReminderTime READ workoutReminderTime NOTIFY changed) Q_PROPERTY(QVariantList completedStepsForCurrentExercise READ completedStepsForCurrentExercise NOTIFY changed) Q_PROPERTY(QVariantList workoutCalendar READ workoutCalendar NOTIFY changed) Q_PROPERTY(QVariantMap weeklySummary READ weeklySummary NOTIFY changed) Q_PROPERTY(QVariantMap trainingCycle READ trainingCycle NOTIFY changed) Q_PROPERTY(QVariantMap trainingContinuity READ trainingContinuity NOTIFY changed) Q_PROPERTY(QVariantMap cycleReview READ cycleReview NOTIFY changed) Q_PROPERTY(QVariantList trainingCycleWeeks READ trainingCycleWeeks NOTIFY changed) Q_PROPERTY(QVariantList undertrainedExercises READ undertrainedExercises NOTIFY changed) Q_PROPERTY(QString recommendedRestText READ recommendedRestText NOTIFY changed) Q_PROPERTY(bool soundsEnabled READ soundsEnabled WRITE setSoundsEnabled NOTIFY changed) Q_PROPERTY(double uiScale READ uiScale WRITE setUiScale NOTIFY changed) Q_PROPERTY(bool darkMode READ darkMode WRITE setDarkMode NOTIFY changed) Q_PROPERTY(QVariantMap applicationInfo READ applicationInfo CONSTANT) public: explicit SessionController(QObject *parent = nullptr); SessionController( QString storageDirectory, QString exerciseCatalogPath, QString legacyStatePath = {}, QString exerciseFrameDirectory = {}, QObject *parent = nullptr); bool ready() const; bool active() const; bool paused() const; bool quickDecisionPending() const; bool needsSave() const; bool hasRecoverableDraft() const; QString status() const; QString pendingResultSummary() const; QString recoverableDraftSummary() const; QString planName() const; QString planGoal() const; QVariantList profiles() const; QString selectedProfileId() const; QString selectedProfileName() const; QVariantMap preWorkoutRecommendation() const; QString phaseTitle() const; QString exerciseName() const; QString nextExerciseName() const; QString currentCoachNote() const; QString currentStepSummary() const; QVariantMap currentExerciseTechnique() const; QString progressText() const; QString completedStepText() const; QString counterText() const; double phaseProgress() const; QString phaseProgressText() const; QString phaseColor() const; QVariantMap currentWorkoutPosition() const; int currentStepIndex() const; QVariantList currentExerciseFrameUrls() const; int currentExerciseFrameDurationMs() const; QString currentExerciseFramePlayback() const; QVariantList currentExerciseFrameDurationsMs() const; QString currentLoadNote() const; QVariantMap currentSetLog() const; QVariantMap lastCompletedSetLog() const; QVariantList plans() const; QString selectedPlanId() const; QVariantMap selectedPlanOptions() const; QVariantList selectedPlanSteps() const; QVariantList workoutQueueSteps() const; QVariantList workoutReplacementExercises() const; int totalSessions() const; int currentSet() const; int totalSets() const; int selectedPlanDayOfWeek() const; bool hasScheduledPlanToday() const; QString scheduledPlanTodayName() const; int totalWorkMinutes() const; QString completionRateText() const; QVariantList recentSessions() const; QVariantList latestSessionSteps() const; QVariantList loadJournalEntries() const; QString progressPlanFilter() const; QVariantList progressDayBuckets() const; QVariantList progressExerciseBuckets() const; QVariantList exerciseLibrary() const; QString exerciseSearch() const; QString exerciseMetricFilter() const; QVariantMap nutritionSummary() const; QVariantList nutritionMeals() const; QVariantList nutritionWeightEntries() const; QVariantList weightChartData() const; QVariantList nutritionMeasurementEntries() const; QVariantList nutritionAdherenceDays() const; QVariantList nutritionPhotoEntries() const; QVariantList recoveryCheckIns() const; QVariantMap wearableSummary() const; QVariantMap wearableStatistics() const; QVariantList wearableDays() const; QString healthSyncStatusText() const; QString healthSyncLastSuccessText() const; bool healthSyncInProgress() const; QString healthActivitySource() const; QString healthWeightSource() const; QString healthConnectOwnerProfileId() const; QString healthConnectOwnerProfileName() const; bool workoutReminderEnabled() const; QString workoutReminderTime() const; QVariantList completedStepsForCurrentExercise() const; QVariantList workoutCalendar() const; QVariantMap weeklySummary() const; QVariantMap trainingCycle() const; QVariantMap trainingContinuity() const; QVariantMap cycleReview() const; QVariantList trainingCycleWeeks() const; QVariantList undertrainedExercises() const; QString recommendedRestText() const; bool soundsEnabled() const; void setSoundsEnabled(bool enabled); double uiScale() const; void setUiScale(double scale); bool darkMode() const; void setDarkMode(bool dark); QVariantMap applicationInfo() const; void setExerciseSearch(const QString &value); void setExerciseMetricFilter(const QString &value); void setProgressPlanFilter(const QString &value); void setCurrentLoadNote(const QString &value); Q_INVOKABLE bool updateCurrentSetLog( const QString &loadKgText, int effortRating, int discomfortRating, const QString ¬e); Q_INVOKABLE bool updateLastCompletedSetLog( const QString &loadKgText, int effortRating, int discomfortRating, const QString ¬e); Q_INVOKABLE void start(); Q_INVOKABLE void startWithRoundCount(int roundCount); Q_INVOKABLE void startQuickWorkout(int roundCount = 0); Q_INVOKABLE void continueQuickWorkout(); Q_INVOKABLE void finishQuickWorkout(); Q_INVOKABLE void advanceOneSecond(); Q_INVOKABLE void skipCountdown(); Q_INVOKABLE void completeCurrent(); Q_INVOKABLE void skipCurrentExercise(); Q_INVOKABLE void finishActiveWorkout(); Q_INVOKABLE void replaceCurrentExercise(const QString &exerciseId); Q_INVOKABLE void addRep(); Q_INVOKABLE void removeRep(); Q_INVOKABLE void togglePause(); Q_INVOKABLE void suspendWorkoutClock(); Q_INVOKABLE void resumeWorkoutClock(); Q_INVOKABLE void prepareForExit(); Q_INVOKABLE void saveFinishedSession(const QString &feedbackLabel, bool applyAdaptation = false); Q_INVOKABLE QVariantMap pendingResultDetails() const; Q_INVOKABLE QString adaptationPreview(const QString &feedbackLabel) const; Q_INVOKABLE void discardFinishedSession(); Q_INVOKABLE void abortActiveWorkout(); Q_INVOKABLE void restoreDraft(); Q_INVOKABLE void discardDraft(); Q_INVOKABLE void selectProfile(const QString &profileId); Q_INVOKABLE void createProfile(const QString &name); Q_INVOKABLE void createNastyaStarterCourse(); Q_INVOKABLE void selectPlan(const QString &planId); Q_INVOKABLE void duplicateSelectedPlan(const QString &name); Q_INVOKABLE void deleteSelectedPlan(); Q_INVOKABLE void renameSelectedPlan(const QString &name, const QString &goal); Q_INVOKABLE void updateSelectedPlanStep( int stepIndex, const QString &exerciseId, const QString &targetText, const QString &restSecondsText, const QString &coachNote); Q_INVOKABLE void updateSelectedPlanStepSets(int stepIndex, int sets); Q_INVOKABLE void updateSelectedPlanFlowOptions( bool warmupIncluded, int warmupStepCount, bool cooldownIncluded, int cooldownStepCount); Q_INVOKABLE void setSelectedPlanDayOfWeek(int dayOfWeek); Q_INVOKABLE void appendSelectedPlanStep(const QString &exerciseId, const QString &coachNote); Q_INVOKABLE void duplicateSelectedPlanStep(int stepIndex); Q_INVOKABLE void removeSelectedPlanStep(int stepIndex); Q_INVOKABLE void moveSelectedPlanStep(int stepIndex, int delta); Q_INVOKABLE void undoLastPlanEdit(); Q_INVOKABLE bool canUndo() const; Q_INVOKABLE QString lastSessionPlanId() const; Q_INVOKABLE void repeatLastSession(); Q_INVOKABLE void playBeep(int frequencyHz, int durationMs); Q_INVOKABLE void logBodyWeight(const QString &weightText); Q_INVOKABLE void logBodyMeasurements( const QString &waistText, const QString &shouldersText, const QString &chestText, const QString &armText); Q_INVOKABLE void selectNutritionPreset(const QString &presetId); Q_INVOKABLE void markNutritionAdherence(const QString &statusId); Q_INVOKABLE void logPhotoProgress(const QString &imagePath); Q_INVOKABLE void logRecoveryCheckIn(int energyScore, int sleepScore, int jointScore, const QString ¬e); Q_INVOKABLE void importHealthConnectData(const QString &sourcePath); Q_INVOKABLE void syncHealthConnect(); Q_INVOKABLE void autoSyncHealthConnect(); Q_INVOKABLE void refreshForCurrentDay(); Q_INVOKABLE void setHealthSourcePreferences(const QString &activitySource, const QString &weightSource); Q_INVOKABLE void setHealthConnectOwnerProfile(const QString &profileId); Q_INVOKABLE void setWorkoutReminderSettings(bool enabled, const QString &timeText); Q_INVOKABLE void configureTrainingCycle(int durationWeeks); Q_INVOKABLE void completeCycleReview(const QString &decision); Q_INVOKABLE void clearTrainingCycle(); Q_INVOKABLE void exportLocalData(const QString &destinationPath); Q_INVOKABLE void exportCsv(const QString &destinationPath); Q_INVOKABLE void exportSelectedPlan(const QString &destinationPath); Q_INVOKABLE void importPlan(const QString &sourcePath); Q_INVOKABLE void createLocalBackup(); Q_INVOKABLE void restoreLatestBackup(); Q_INVOKABLE void openAndroidDataTransfer(); Q_INVOKABLE void clearPersonalData(); signals: void changed(); private: const bodyweight::WorkoutPlan *selectedPlan() const; const bodyweight::WorkoutPlan *displayPlan() const; bodyweight::WorkoutPlan cycleAdjustedPlan(const bodyweight::WorkoutPlan &plan) const; void startAdjustedPlan(bodyweight::WorkoutPlan plan); QVariantList planStepsFor(const bodyweight::WorkoutPlan *plan) const; const bodyweight::WorkoutPlan *scheduledPlanForDate(const QDate &date) const; QVariantMap trainingContinuityForDate(const QDate &today) const; QString exerciseNameForStep(int index) const; QVariantList exerciseFrameUrls(const QString &exerciseId) const; bodyweight::SessionSnapshot snapshot() const; QJsonArray sessionsArray() const; void clearCurrentSetLog(); void clearCurrentSetLogAfterTransition(const bodyweight::SessionSnapshot &before); void captureFinishedSession(); void persistDraft(); bool persistPendingResult(); void playPhaseFeedback(bodyweight::SessionPhase before, bodyweight::SessionPhase after); void setKeepScreenOn(bool enabled); QString resolvedHealthConnectOwnerForRoot(const QJsonObject &candidateRoot) const; void applyAndroidDevicePreferences(); void notify(); bodyweight::StateSnapshot state_; QVector<bodyweight::ExerciseDefinition> exercises_; std::unique_ptr<bodyweight::WorkoutSessionRunner> runner_; std::unique_ptr<bodyweight::StateStore> store_; QJsonObject root_; std::optional<bodyweight::FinishedSession> pendingFinishedSession_; QString pendingFinishedSessionProfileId_; std::optional<bodyweight::StoredSessionDraft> recoverableDraft_; QDateTime sessionStartedAtLocal_; QDateTime sessionEndedAtLocal_; int secondsSinceDraftSave_ = 0; QString exerciseSearch_; QString exerciseMetricFilter_ = QStringLiteral("all"); QString progressPlanFilter_ = QStringLiteral("all"); QString currentLoadNote_; double currentExternalLoadKg_ = 0.0; int currentEffortRating_ = 0; int currentDiscomfortRating_ = 0; QString storageDirectory_; QDate scheduleDate_; QString exerciseFrameDirectory_; QString status_; bool soundsEnabled_ = true; double uiScale_ = 1.0; bool darkMode_ = true; bool workoutLifecycleSuspended_ = false; bool workoutPausedForBackground_ = false; QJsonArray planUndoStack_; QTimer healthSyncTimer_; QTimer dataTransferTimer_; QString healthSyncFilePath_; QString dataTransferImportPath_; QDateTime lastHealthSyncRequest_; int healthSyncPollsRemaining_ = 0; int dataTransferPollsRemaining_ = 0; QString healthSyncStatusText_ = QStringLiteral("Готово к синхронизации"); bool healthSyncInProgress_ = false; QString healthConnectOwnerProfileId_; static constexpr int maxPlanUndoSteps = 20; };