Turn application state into enum

The application state was encoded in a QByteArray. Thus, there was
no compile-time checking. Typos would lead to silent failures.

Turn the application state into an enum. Use the enum-class construct,
so that the values don't polute the global namespace. Moreover,
this makes them strongly typed, i.e. they don't auto-convert to
integers.

A disadvantage is that the enums now have to be cast to int
explicitly when used to index an array.

Replace two hash-maps in MainWindow to arrays of fixed sizes.

Move the application-state details into their own files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-05-10 19:51:43 +02:00 committed by Dirk Hohndel
parent 114b3d9d47
commit 75767c456a
11 changed files with 100 additions and 75 deletions

View file

@ -5,6 +5,7 @@
#include "core/qthelper.h"
#include "core/subsurfacestartup.h"
#include "core/units.h"
#include "core/applicationstate.h"
#include <QDebug>
#define DEBUG 1
@ -469,7 +470,7 @@ void TestPlan::testVpmbMetric45m30minTx()
struct diveplan testPlan = {};
setupPlanVpmb45m30mTx(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -500,7 +501,7 @@ void TestPlan::testVpmbMetric60m10minTx()
struct diveplan testPlan = {};
setupPlanVpmb60m10mTx(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -531,7 +532,7 @@ void TestPlan::testVpmbMetric60m30minAir()
struct diveplan testPlan = {};
setupPlanVpmb60m30minAir(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -562,7 +563,7 @@ void TestPlan::testVpmbMetric60m30minEan50()
struct diveplan testPlan = {};
setupPlanVpmb60m30minEan50(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -599,7 +600,7 @@ void TestPlan::testVpmbMetric60m30minTx()
struct diveplan testPlan = {};
setupPlanVpmb60m30minTx(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -636,7 +637,7 @@ void TestPlan::testVpmbMetric100m60min()
struct diveplan testPlan = {};
setupPlanVpmb100m60min(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -680,7 +681,7 @@ void TestPlan::testMultipleGases()
struct diveplan testPlan = {};
setupPlanSeveralGases(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -706,7 +707,7 @@ void TestPlan::testVpmbMetricMultiLevelAir()
struct diveplan testPlan = {};
setupPlanVpmbMultiLevelAir(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -737,7 +738,7 @@ void TestPlan::testVpmbMetric100m10min()
struct diveplan testPlan = {};
setupPlanVpmb100m10min(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
@ -784,7 +785,7 @@ void TestPlan::testVpmbMetricRepeat()
struct diveplan testPlan = {};
setupPlanVpmb30m20min(&testPlan);
setCurrentAppState("PlanDive");
setAppState(ApplicationState::PlanDive);
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);