Permalink
Browse files

Autocompleter for measure builtin with all the options

To avoid the user the need to RTFM
  • Loading branch information...
amtriathlon committed Nov 5, 2017
1 parent e26a672 commit c7d4f33ce6cfaa517413ae9926b7bb3c977ea564
Showing with 15 additions and 10 deletions.
  1. +4 −4 src/Core/Athlete.cpp
  2. +5 −5 src/Core/Athlete.h
  3. +6 −1 src/Core/DataFilter.cpp
View
@@ -634,29 +634,29 @@ Athlete::getHrvMeasure(QDate date, int field, bool useMetricUnits)
// Common access to Measures
QStringList
Athlete::getMeasureGroupSymbols() const
Athlete::getMeasureGroupSymbols()
{
const QStringList groups = QStringList() << "Body" << "Hrv";
return groups;
}
QStringList
Athlete::getMeasureGroupNames() const
Athlete::getMeasureGroupNames()
{
const QStringList groups = QStringList() << tr("Body") << tr("Hrv");
return groups;
}
QStringList
Athlete::getMeasureFieldSymbols(int group) const
Athlete::getMeasureFieldSymbols(int group)
{
if (group == 0) return BodyMeasure::getFieldSymbols();
else if (group == 1) return HrvMeasure::getFieldSymbols();
else return QStringList();
}
QStringList
Athlete::getMeasureFieldNames(int group) const
Athlete::getMeasureFieldNames(int group)
{
if (group == 0) return BodyMeasure::getFieldNames();
else if (group == 1) return HrvMeasure::getFieldNames();
View
@@ -159,11 +159,11 @@ class Athlete : public QObject
void getHrvMeasure(QDate date, HrvMeasure&);
// Common access to Measures
QStringList getMeasureGroupSymbols() const;
QStringList getMeasureGroupNames() const;
QStringList getMeasureFieldSymbols(int group) const;
QStringList getMeasureFieldNames(int group) const;
QString getMeasureUnits(int group, int field, bool useMetricUnits=true);
static QStringList getMeasureGroupSymbols();
static QStringList getMeasureGroupNames();
static QStringList getMeasureFieldSymbols(int group);
static QStringList getMeasureFieldNames(int group);
static QString getMeasureUnits(int group, int field, bool useMetricUnits=true);
double getMeasureValue(QDate date, int group, int field, bool useMetricUnits=true);
// ride collection
View
@@ -157,7 +157,10 @@ DataFilter::builtins()
} else if (i == 41) {
returning << "XDATA_UNITS(\"xdata\", \"series\")";
} else if (i == 42) {
returning << "measure(date, \"group\", \"field\")";
QStringList groupSymbols = Athlete::getMeasureGroupSymbols();
for (int g=0; g<groupSymbols.count(); g++)
foreach (QString fieldSymbol, Athlete::getMeasureFieldSymbols(g))
returning << QString("measure(Date, \"%1\", \"%2\")").arg(groupSymbols[g]).arg(fieldSymbol);
} else {
function = DataFilterFunctions[i].name + "(";
for(int j=0; j<DataFilterFunctions[i].parameters; j++) {
@@ -2483,10 +2486,12 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, RideItem *m, RideF
QDate date = QDate(1900,01,01).addDays(days.number);
if (!date.isValid()) return Result(0); // invalid date
if (leaf->fparms[1]->type != String) return Result(0);
QString group_symbol = *(leaf->fparms[1]->lvalue.s);
int group = m->context->athlete->getMeasureGroupSymbols().indexOf(group_symbol);
if (group < 0) return Result(0); // unknown group
if (leaf->fparms[2]->type != String) return Result(0);
QString field_symbol = *(leaf->fparms[2]->lvalue.s);
int field = m->context->athlete->getMeasureFieldSymbols(group).indexOf(field_symbol);
if (field < 0) return Result(0); // unknown field

0 comments on commit c7d4f33

Please sign in to comment.