Add data models to setup timers
This commit is contained in:
@@ -47,3 +47,24 @@ QString DataHelpers::getElementName(const QString & prefix, const unsigned int i
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString DataHelpers::timeToString(const int value, const unsigned int mask)
|
||||
{
|
||||
bool negative = value < 0 ? true : false;
|
||||
int val = abs(value);
|
||||
|
||||
QString result = QString("%1").arg(negative ? "-" : ((mask & TIMESTR_MASK_PADSIGN) ? " " : ""));
|
||||
|
||||
if (mask & TIMESTR_MASK_HRSMINS) {
|
||||
int hours = val / 3600;
|
||||
if (hours > 0 || (mask & TIMESTR_MASK_ZEROHRS)) {
|
||||
val -= hours * 3600;
|
||||
result.append(QString("%1:").arg(hours, 2, 10, QLatin1Char('0')));
|
||||
}
|
||||
}
|
||||
|
||||
int minutes = val / 60;
|
||||
int seconds = val % 60;
|
||||
result.append(QString("%1:%2").arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0')));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,11 @@ class FieldRange
|
||||
QString unit;
|
||||
};
|
||||
|
||||
|
||||
constexpr unsigned int TIMESTR_MASK_HRSMINS { 1 << 1 };
|
||||
constexpr unsigned int TIMESTR_MASK_ZEROHRS { 1 << 2 };
|
||||
constexpr unsigned int TIMESTR_MASK_PADSIGN { 1 << 3 };
|
||||
|
||||
namespace DataHelpers
|
||||
{
|
||||
enum BoolFormat {
|
||||
@@ -59,5 +64,6 @@ namespace DataHelpers
|
||||
|
||||
QString boolToString(const bool value, const BoolFormat format);
|
||||
QString getElementName(const QString & prefix, const unsigned int index, const char * name = 0, const bool padding = false);
|
||||
QString timeToString(const int value, const unsigned int mask);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "timerdata.h"
|
||||
#include "radiodataconversionstate.h"
|
||||
#include "compounditemmodels.h"
|
||||
|
||||
void TimerData::convert(RadioDataConversionState & cstate)
|
||||
{
|
||||
@@ -36,7 +37,7 @@ void TimerData::clear()
|
||||
|
||||
bool TimerData::isEmpty()
|
||||
{
|
||||
return (mode == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0) && name[0] == '\0' && minuteBeep == 0 && countdownBeep == COUNTDOWN_SILENT && val == 0 && persistent == 0 /*&& pvalue == 0*/);
|
||||
return (mode == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0) && name[0] == '\0' && minuteBeep == 0 && countdownBeep == COUNTDOWNBEEP_SILENT && val == 0 && persistent == 0 /*&& pvalue == 0*/);
|
||||
}
|
||||
|
||||
bool TimerData::isModeOff()
|
||||
@@ -59,9 +60,14 @@ QString TimerData::countdownStartToString() const
|
||||
return countdownStartToString(countdownStart);
|
||||
}
|
||||
|
||||
QString TimerData::persistentToString() const
|
||||
QString TimerData::persistentToString(const bool verbose) const
|
||||
{
|
||||
return persistentToString(persistent);
|
||||
return persistentToString(persistent, verbose);
|
||||
}
|
||||
|
||||
QString TimerData::pvalueToString() const
|
||||
{
|
||||
return pvalueToString(pvalue);
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -99,25 +105,31 @@ QString TimerData::countdownStartToString(const int value)
|
||||
}
|
||||
|
||||
// static
|
||||
QString TimerData::persistentToString(const int value)
|
||||
QString TimerData::persistentToString(const int value, const bool verbose)
|
||||
{
|
||||
switch(value) {
|
||||
case PERSISTENT_NOT:
|
||||
return tr("Not persistent");
|
||||
return verbose ? tr("Not persistent") : tr("NOT");
|
||||
case PERSISTENT_FLIGHT:
|
||||
return tr("Persistent (flight)");
|
||||
return verbose ? tr("Persistent (flight)") : tr("Flight");
|
||||
case PERSISTENT_MANUALRESET:
|
||||
return tr("Persistent (manual reset)");
|
||||
return verbose ? tr("Persistent (manual reset)") : tr("Manual reset");
|
||||
default:
|
||||
return CPN_STR_UNKNOWN_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
QString TimerData::pvalueToString(const int value)
|
||||
{
|
||||
return DataHelpers::timeToString(value, TIMESTR_MASK_HRSMINS);
|
||||
}
|
||||
|
||||
// static
|
||||
AbstractStaticItemModel * TimerData::countdownBeepItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("timerdata.countdownBeep");
|
||||
mdl->setName(AIM_TIMER_COUNTDOWNBEEP);
|
||||
|
||||
for (int i = 0; i < COUNTDOWNBEEP_COUNT; i++) {
|
||||
QString str = countdownBeepToString(i);
|
||||
@@ -131,7 +143,7 @@ AbstractStaticItemModel * TimerData::countdownBeepItemModel()
|
||||
AbstractStaticItemModel * TimerData::countdownStartItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("timerdata.countdownStart");
|
||||
mdl->setName(AIM_TIMER_COUNTDOWNSTART);
|
||||
|
||||
for (int i = COUNTDOWNSTART_LAST - 1; i >= COUNTDOWNSTART_FIRST; i--) {
|
||||
QString str = countdownStartToString(i);
|
||||
@@ -145,7 +157,7 @@ AbstractStaticItemModel * TimerData::countdownStartItemModel()
|
||||
AbstractStaticItemModel * TimerData::persistentItemModel()
|
||||
{
|
||||
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
|
||||
mdl->setName("timerdata.persistent");
|
||||
mdl->setName(AIM_TIMER_PERSISTENT);
|
||||
|
||||
for (int i = 0; i < PERSISTENT_COUNT; i++) {
|
||||
QString str = persistentToString(i);
|
||||
|
||||
@@ -26,8 +26,13 @@
|
||||
#include <QtCore>
|
||||
|
||||
class RadioDataConversionState;
|
||||
class AbstractStaticItemModel;
|
||||
|
||||
#define TIMER_NAME_LEN 8
|
||||
constexpr char AIM_TIMER_COUNTDOWNBEEP[] {"timerdata.countdownBeep"};
|
||||
constexpr char AIM_TIMER_COUNTDOWNSTART[] {"timerdata.countdownStart"};
|
||||
constexpr char AIM_TIMER_PERSISTENT[] {"timerdata.persistent"};
|
||||
|
||||
constexpr int TIMER_NAME_LEN {8};
|
||||
|
||||
class TimerData {
|
||||
Q_DECLARE_TR_FUNCTIONS(TimerData)
|
||||
@@ -74,13 +79,15 @@ class TimerData {
|
||||
bool isEmpty();
|
||||
bool isModeOff();
|
||||
QString nameToString(int index) const;
|
||||
QString countdownBeepToString();
|
||||
QString countdownStartToString();
|
||||
QString persistentToString();
|
||||
QString countdownBeepToString() const;
|
||||
QString countdownStartToString() const;
|
||||
QString persistentToString(const bool verbose = true) const;
|
||||
QString pvalueToString() const;
|
||||
|
||||
static QString countdownBeepToString(const int value);
|
||||
static QString countdownStartToString(const int value);
|
||||
static QString persistentToString(const int value);
|
||||
static QString persistentToString(const int value, const bool verbose = true);
|
||||
static QString pvalueToString(const int value);
|
||||
static AbstractStaticItemModel * countdownBeepItemModel();
|
||||
static AbstractStaticItemModel * countdownStartItemModel();
|
||||
static AbstractStaticItemModel * persistentItemModel();
|
||||
|
||||
Reference in New Issue
Block a user