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

@ -12,6 +12,7 @@
#include "divecomputer.h"
#include "time.h"
#include "gettextfromc.h"
#include "applicationstate.h"
#include "metadata.h"
#include <sys/time.h>
#include "exif.h"
@ -1362,21 +1363,9 @@ extern "C" void parse_display_units(char *line)
qDebug() << line;
}
static QByteArray currentApplicationState;
QByteArray getCurrentAppState()
{
return currentApplicationState;
}
void setCurrentAppState(const QByteArray &state)
{
currentApplicationState = state;
}
extern "C" bool in_planner()
{
return currentApplicationState == "PlanDive" || currentApplicationState == "EditPlannedDive";
return getAppState() == ApplicationState::PlanDive || getAppState() == ApplicationState::EditPlannedDive;
}
extern "C" enum deco_mode decoMode()