mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Add XData UNITS support Part 2 of 2
.. added to DataFilter XDATA_UNITS("..", "...") returns the units as
a string.
.. added to the various dialogs in RideEditor, to enable units and
series name to be set and edited by the user.
This commit is contained in:
@@ -3275,8 +3275,8 @@ XDataEditor::isColumnSelected()
|
||||
void
|
||||
XDataEditor::insCol()
|
||||
{
|
||||
QString name;
|
||||
XDataSeriesSettingsDialog *dialog = new XDataSeriesSettingsDialog(this, name);
|
||||
QString name, unit;
|
||||
XDataSeriesSettingsDialog *dialog = new XDataSeriesSettingsDialog(this, name, unit);
|
||||
int ret = dialog->exec();
|
||||
|
||||
if (ret == QDialog::Accepted && name != "") {
|
||||
|
||||
@@ -112,6 +112,8 @@ static struct {
|
||||
{ "postprocess", 2 }, // postprocess(processor, filter) to run processor
|
||||
|
||||
// add new ones above this line
|
||||
{ "XDATA_UNITS", 2 }, // e.g. xdata("WEATHER", "HUMIDITY") returns "Relative Humidity"
|
||||
|
||||
{ "", -1 }
|
||||
};
|
||||
|
||||
@@ -148,6 +150,8 @@ DataFilter::builtins()
|
||||
returning <<"set(field, value, expr)";
|
||||
} else if (i == 37) {
|
||||
returning << "XDATA(\"xdata\", \"series\", sparse|repeat|interpolate|resample)";
|
||||
} else if (i == 41) {
|
||||
returning << "XDATA_UNITS(\"xdata\", \"series\")";
|
||||
} else {
|
||||
function = DataFilterFunctions[i].name + "(";
|
||||
for(int j=0; j<DataFilterFunctions[i].parameters; j++) {
|
||||
@@ -1187,6 +1191,25 @@ void Leaf::validateFilter(Context *context, DataFilterRuntime *df, Leaf *leaf)
|
||||
}
|
||||
}
|
||||
|
||||
} else if (leaf->function == "XDATA_UNITS") {
|
||||
|
||||
leaf->dynamic = false;
|
||||
|
||||
if (leaf->fparms.count() != 2) {
|
||||
leaf->inerror = true;
|
||||
DataFiltererrors << QString(tr("XDATA_UNITS needs 2 parameters."));
|
||||
} else {
|
||||
|
||||
// are the first two strings ?
|
||||
Leaf *first=leaf->fparms[0];
|
||||
Leaf *second=leaf->fparms[1];
|
||||
if (first->type != Leaf::String || second->type != Leaf::String) {
|
||||
DataFiltererrors << QString(tr("XDATA_UNITS expects a string for first two parameters"));
|
||||
leaf->inerror = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if (leaf->function == "isset" || leaf->function == "set" || leaf->function == "unset") {
|
||||
|
||||
// don't run it everytime a ride is selected!
|
||||
@@ -2412,6 +2435,28 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, RideItem *m, RideF
|
||||
}
|
||||
break;
|
||||
|
||||
case 41 :
|
||||
{ // XDATA_UNITS ("XDATA", "XDATASERIES")
|
||||
|
||||
if (p) { // only valid when iterating
|
||||
// processing ride item (e.g. filter, formula)
|
||||
// we return true or false if the xdata series exists for the ride in question
|
||||
QString xdata = *(leaf->fparms[0]->lvalue.s);
|
||||
QString series = *(leaf->fparms[1]->lvalue.s);
|
||||
XDataSeries *xs = m->ride()->xdata(xdata);
|
||||
|
||||
if (xs && m->xdata().value(xdata,QStringList()).contains(series)) {
|
||||
int idx = m->xdata().value(xdata,QStringList()).indexOf(series);
|
||||
QString units;
|
||||
int count = m->ride()->xdata(xdata)->unitname.count();
|
||||
if (idx >= 0 && idx < xs->unitname.count())
|
||||
units = xs->unitname[idx];
|
||||
return Result(units);
|
||||
}
|
||||
|
||||
} else return Result(""); // not for filtering
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return Result(0);
|
||||
}
|
||||
|
||||
@@ -137,9 +137,9 @@ RideFileCommand::addXData(XDataSeries *series)
|
||||
}
|
||||
|
||||
void
|
||||
RideFileCommand::addXDataSeries(QString xdata, QString name)
|
||||
RideFileCommand::addXDataSeries(QString xdata, QString name, QString unit)
|
||||
{
|
||||
AddXDataSeriesCommand *cmd = new AddXDataSeriesCommand(ride, xdata, name);
|
||||
AddXDataSeriesCommand *cmd = new AddXDataSeriesCommand(ride, xdata, name, unit);
|
||||
doCommand(cmd);
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ RemoveXDataSeriesCommand::undoCommand()
|
||||
}
|
||||
|
||||
|
||||
AddXDataSeriesCommand::AddXDataSeriesCommand(RideFile *ride, QString xdata, QString name) : RideCommand(ride), xdata(xdata), name(name) {
|
||||
AddXDataSeriesCommand::AddXDataSeriesCommand(RideFile *ride, QString xdata, QString name, QString unit) : RideCommand(ride), xdata(xdata), name(name), unit(unit) {
|
||||
type = RideCommand::AddXDataSeries;
|
||||
description = tr("Add XData Series");
|
||||
}
|
||||
@@ -597,6 +597,7 @@ AddXDataSeriesCommand::doCommand()
|
||||
if (series == NULL) return false;
|
||||
|
||||
series->valuename.append(name);
|
||||
series->unitname.append(unit);
|
||||
|
||||
int index = series->valuename.indexOf(name);
|
||||
if (index == -1) return false;
|
||||
|
||||
@@ -59,7 +59,7 @@ class RideFileCommand : public QObject
|
||||
void removeXData(QString name);
|
||||
void addXData(XDataSeries *series);
|
||||
void removeXDataSeries(QString xdata, QString name);
|
||||
void addXDataSeries(QString xdata, QString name);
|
||||
void addXDataSeries(QString xdata, QString name, QString unit);
|
||||
void setXDataPointValue(QString xdata, int row, int column, double value);
|
||||
void deleteXDataPoints(QString xdata, int index, int count);
|
||||
void insertXDataPoint(QString xdata, int index, XDataPoint *point);
|
||||
@@ -186,12 +186,12 @@ class AddXDataSeriesCommand : public RideCommand
|
||||
Q_DECLARE_TR_FUNCTIONS(AddXDataSeriesCommand)
|
||||
|
||||
public:
|
||||
AddXDataSeriesCommand(RideFile *ride, QString xdata, QString name);
|
||||
AddXDataSeriesCommand(RideFile *ride, QString xdata, QString name, QString unit);
|
||||
bool doCommand();
|
||||
bool undoCommand();
|
||||
|
||||
// state
|
||||
QString xdata, name;
|
||||
QString xdata, name, unit;
|
||||
};
|
||||
|
||||
class SetPointValueCommand : public RideCommand
|
||||
|
||||
@@ -232,12 +232,12 @@ XDataDialog::addXDataSeriesClicked()
|
||||
const XDataSeries *series = item->ride()->xdata(xdata);
|
||||
if (series == NULL) return;
|
||||
|
||||
QString name;
|
||||
XDataSeriesSettingsDialog *dialog = new XDataSeriesSettingsDialog(this, name);
|
||||
QString name, unit;
|
||||
XDataSeriesSettingsDialog *dialog = new XDataSeriesSettingsDialog(this, name, unit);
|
||||
int ret = dialog->exec();
|
||||
|
||||
if (ret == QDialog::Accepted) {
|
||||
item->ride()->command->addXDataSeries(xdata, name);
|
||||
item->ride()->command->addXDataSeries(xdata, name, unit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,23 +251,27 @@ XDataSettingsDialog::XDataSettingsDialog(QWidget *parent, XDataSeries &series) :
|
||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::Tool);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
QFormLayout *form = new QFormLayout();
|
||||
mainLayout->addLayout(form);
|
||||
QGridLayout *grid = new QGridLayout();
|
||||
mainLayout->addLayout(grid);
|
||||
|
||||
|
||||
QLabel *xdataLabel = new QLabel(tr("xData"), this);
|
||||
xdataName = new QLineEdit(this);
|
||||
|
||||
form->addRow(xdataLabel, xdataName);
|
||||
form->addRow(new QLabel("",this), new QLabel("", this));
|
||||
grid->addWidget(xdataLabel, 0, 0);
|
||||
grid->addWidget(xdataName, 0, 1);
|
||||
grid->addWidget(new QLabel("",this), 1, 0);
|
||||
|
||||
form->addRow(new QLabel(tr("Data Series"),this));
|
||||
grid->addWidget(new QLabel(tr("Data Series"), this), 2, 0);
|
||||
grid->addWidget(new QLabel(tr("Units"), this), 2, 1);
|
||||
for (int i=0; i<8; i++) {
|
||||
xdataSeriesName[i] = new QLineEdit(this);
|
||||
form->addRow(new QLabel(QString(tr("Series %1")).arg(i+1)), xdataSeriesName[i]);
|
||||
xdataUnitName[i] = new QLineEdit(this);
|
||||
grid->addWidget(new QLabel(QString(tr("Series %1")).arg(i+1)), 3+i, 0);
|
||||
grid->addWidget(xdataSeriesName[i], 3+i, 1);
|
||||
grid->addWidget(xdataUnitName[i], 3+i, 2);
|
||||
}
|
||||
|
||||
form->addRow(new QLabel("",this), new QLabel("", this));
|
||||
grid->addWidget(new QLabel("",this), 11, 0);
|
||||
mainLayout->addStretch();
|
||||
|
||||
cancelButton = new QPushButton(tr("Cancel"), this);
|
||||
@@ -296,6 +300,7 @@ void XDataSettingsDialog::okClicked()
|
||||
for(int i=0; i<8; i++) {
|
||||
if (xdataSeriesName[i]->text() != "")
|
||||
series.valuename << xdataSeriesName[i]->text();
|
||||
series.unitname << xdataUnitName[i]->text();
|
||||
}
|
||||
|
||||
if (series.valuename.count() >0) accept();
|
||||
@@ -309,7 +314,7 @@ void XDataSettingsDialog::okClicked()
|
||||
///
|
||||
/// XDataSeriesSettingsDialog
|
||||
///
|
||||
XDataSeriesSettingsDialog::XDataSeriesSettingsDialog(QWidget *parent, QString &name) : QDialog(parent), name(name)
|
||||
XDataSeriesSettingsDialog::XDataSeriesSettingsDialog(QWidget *parent, QString &name, QString &unit) : QDialog(parent), name(name), unit(unit)
|
||||
{
|
||||
setWindowTitle("XData Series Name");
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
@@ -323,8 +328,13 @@ XDataSeriesSettingsDialog::XDataSeriesSettingsDialog(QWidget *parent, QString &n
|
||||
QLabel *nameLabel = new QLabel(tr("Name"), this);
|
||||
nameEdit = new QLineEdit(this);
|
||||
nameEdit->setText(name);
|
||||
|
||||
form->addRow(nameLabel, nameEdit);
|
||||
|
||||
QLabel *unitLabel = new QLabel(tr("Units"), this);
|
||||
unitEdit = new QLineEdit(this);
|
||||
unitEdit->setText(unit);
|
||||
form->addRow(unitLabel, unitEdit);
|
||||
|
||||
form->addRow(new QLabel("",this), new QLabel("", this));
|
||||
mainLayout->addStretch();
|
||||
|
||||
@@ -348,6 +358,7 @@ void XDataSeriesSettingsDialog::okClicked()
|
||||
return;
|
||||
} else {
|
||||
name = nameEdit->text();
|
||||
unit = unitEdit->text();
|
||||
}
|
||||
|
||||
accept();
|
||||
|
||||
@@ -79,6 +79,7 @@ class XDataSettingsDialog : public QDialog
|
||||
|
||||
QLineEdit *xdataName;
|
||||
QLineEdit *xdataSeriesName[8];
|
||||
QLineEdit *xdataUnitName[8];
|
||||
|
||||
QPushButton *cancelButton, *okButton;
|
||||
|
||||
@@ -89,14 +90,15 @@ class XDataSeriesSettingsDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
XDataSeriesSettingsDialog(QWidget *parent, QString &name);
|
||||
XDataSeriesSettingsDialog(QWidget *parent, QString &name, QString &unit);
|
||||
|
||||
private slots:
|
||||
void okClicked();
|
||||
|
||||
private:
|
||||
QString &name;
|
||||
QString &name, &unit;
|
||||
QLineEdit *nameEdit;
|
||||
QLineEdit *unitEdit;
|
||||
|
||||
QPushButton *cancelButton, *okButton;
|
||||
};
|
||||
|
||||
@@ -185,7 +185,7 @@ XDataTableModel::removeRows(int row, int count, const QModelIndex &)
|
||||
bool
|
||||
XDataTableModel::insertColumn(QString name)
|
||||
{
|
||||
ride->command->addXDataSeries(xdata, name);
|
||||
ride->command->addXDataSeries(xdata, name, "");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user