mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 00:28:42 +00:00
Data Filter - Internal Field Names + Multiple tr()
... allow/use only internal field names (delivered by Column Chooser) in Data Filter expressions ... multipe tr() (cherry picked from commit bc4164adab74dd82c0a0307d7d0fbb736f95ef0d)
This commit is contained in:
@@ -205,11 +205,11 @@ CriticalPowerWindow::CriticalPowerWindow(const QDir &home, Context *context, boo
|
||||
// model config
|
||||
// 2 or 3 point model ?
|
||||
modelCombo= new QComboBox(this);
|
||||
modelCombo->addItem("None");
|
||||
modelCombo->addItem("2 parameter");
|
||||
modelCombo->addItem("3 parameter");
|
||||
modelCombo->addItem("Extended CP");
|
||||
modelCombo->addItem("Multicomponent");
|
||||
modelCombo->addItem(tr("None"));
|
||||
modelCombo->addItem(tr("2 parameter"));
|
||||
modelCombo->addItem(tr("3 parameter"));
|
||||
modelCombo->addItem(tr("Extended CP"));
|
||||
modelCombo->addItem(tr("Multicomponent"));
|
||||
modelCombo->setCurrentIndex(1);
|
||||
|
||||
mcl->addRow(new QLabel(tr("CP Model")), modelCombo);
|
||||
|
||||
@@ -137,7 +137,7 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf)
|
||||
// a lookup at execution time
|
||||
QString lookup = df->lookupMap.value(*(leaf->lvalue.n), "");
|
||||
if (lookup == "") {
|
||||
DataFiltererrors << QString("%1 is unknown").arg(*(leaf->lvalue.n));
|
||||
DataFiltererrors << QString(QObject::tr("%1 is unknown")).arg(*(leaf->lvalue.n));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -150,10 +150,10 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf)
|
||||
QString symbol = *(leaf->series->lvalue.n);
|
||||
|
||||
if (leaf->function == "best" && !bestValidSymbols.exactMatch(symbol))
|
||||
DataFiltererrors << QString("invalid data series for best(): %1").arg(symbol);
|
||||
DataFiltererrors << QString(QObject::tr("invalid data series for best(): %1")).arg(symbol);
|
||||
|
||||
if (leaf->function == "tiz" && !tizValidSymbols.exactMatch(symbol))
|
||||
DataFiltererrors << QString("invalid data series for tiz(): %1").arg(symbol);
|
||||
DataFiltererrors << QString(QObject::tr("invalid data series for tiz(): %1")).arg(symbol);
|
||||
|
||||
// now set the series type
|
||||
leaf->seriesType = nameToSeries(symbol);
|
||||
@@ -167,13 +167,13 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf)
|
||||
bool lhsType = Leaf::isNumber(df, leaf->lvalue.l);
|
||||
bool rhsType = Leaf::isNumber(df, leaf->rvalue.l);
|
||||
if (lhsType != rhsType) {
|
||||
DataFiltererrors << QString("comparing strings with numbers");
|
||||
DataFiltererrors << QString(QObject::tr("comparing strings with numbers"));
|
||||
}
|
||||
|
||||
// what about using string operations on a lhs/rhs that
|
||||
// are numeric?
|
||||
if ((lhsType || rhsType) && leaf->op >= MATCHES && leaf->op <= CONTAINS) {
|
||||
DataFiltererrors << "using a string operations with a number";
|
||||
DataFiltererrors << QObject::tr("using a string operations with a number");
|
||||
}
|
||||
|
||||
validateFilter(df, leaf->lvalue.l);
|
||||
@@ -222,7 +222,7 @@ QStringList DataFilter::parseFilter(QString query, QStringList *list)
|
||||
if (!treeRoot || DataFiltererrors.count() > 0) { // nope
|
||||
|
||||
// no errors just failed to finish
|
||||
if (!treeRoot) DataFiltererrors << "malformed expression.";
|
||||
if (!treeRoot) DataFiltererrors << tr("malformed expression.");
|
||||
|
||||
// Bzzzt, malformed
|
||||
emit parseBad(DataFiltererrors);
|
||||
@@ -269,12 +269,16 @@ void DataFilter::configUpdate()
|
||||
lookupMap.clear();
|
||||
lookupType.clear();
|
||||
|
||||
// create lookup map from 'friendly name' to name used in smmaryMetrics
|
||||
// create lookup map from 'friendly name' to INTERNAL-name used in summaryMetrics
|
||||
// to enable a quick lookup && the lookup for the field type (number, text)
|
||||
const RideMetricFactory &factory = RideMetricFactory::instance();
|
||||
for (int i=0; i<factory.metricCount(); i++) {
|
||||
QString symbol = factory.metricName(i);
|
||||
QString name = factory.rideMetric(symbol)->name();
|
||||
QString name = context->specialFields.internalName(factory.rideMetric(symbol)->name());
|
||||
|
||||
//special Treatment for BikeScore
|
||||
if (name.startsWith("BikeScore")) name = "BikeScore™";
|
||||
|
||||
lookupMap.insert(name.replace(" ","_"), symbol);
|
||||
lookupType.insert(name.replace(" ","_"), true);
|
||||
}
|
||||
@@ -283,10 +287,16 @@ void DataFilter::configUpdate()
|
||||
foreach(FieldDefinition field, context->athlete->rideMetadata()->getFields()) {
|
||||
QString underscored = field.name;
|
||||
if (!context->specialFields.isMetric(underscored)) {
|
||||
|
||||
// translate to internal name if name has non Latin1 characters
|
||||
underscored = context->specialFields.internalName(underscored);
|
||||
field.name = context->specialFields.internalName((field.name));
|
||||
|
||||
lookupMap.insert(underscored.replace(" ","_"), field.name);
|
||||
lookupType.insert(underscored.replace(" ","_"), (field.type > 2)); // true if is number
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double Leaf::eval(DataFilter *df, Leaf *leaf, SummaryMetrics m, QString f)
|
||||
|
||||
@@ -61,7 +61,11 @@
|
||||
|
||||
"TRIMP(100)_Points" return SYMBOL; /* special case */
|
||||
"Left/Right_Balance" return SYMBOL; /* special case */
|
||||
"Minimum_W'_bal" return SYMBOL; /* special case */
|
||||
"Minimum_W'bal" return SYMBOL; /* special case */
|
||||
"Maximum_W'bal_Match" return SYMBOL; /* special case */
|
||||
"Max_W'_Expended" return SYMBOL; /* special case */
|
||||
"W'_Work" return SYMBOL; /* special case */
|
||||
"W'bal_TAU" return SYMBOL; /* special case */
|
||||
[a-zA-Z0-9][a-zA-Z0-9_%™]+ return SYMBOL; /* symbols can start with 0-9 */
|
||||
|
||||
|
||||
|
||||
@@ -907,9 +907,6 @@ void
|
||||
RideNavigator::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QString name = event->mimeData()->data("application/x-columnchooser");
|
||||
// fugly, but it works for BikeScore with the (TM) in it...
|
||||
// when MIME object is UTF-8 and not Latin-1 - this seems not to be required any more
|
||||
// if (name == "BikeScore?") name = QTextEdit("BikeScore™").toPlainText();
|
||||
tableView->setColumnHidden(logicalHeadings.indexOf(name), false);
|
||||
tableView->setColumnWidth(logicalHeadings.indexOf(name), 50);
|
||||
tableView->header()->moveSection(tableView->header()->visualIndex(logicalHeadings.indexOf(name)), 1);
|
||||
@@ -1182,8 +1179,8 @@ ColumnChooser::buttonClicked(QString name)
|
||||
// setup the drag data
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
QByteArray empty;
|
||||
// mimeData->setData("application/x-columnchooser", name.toLatin1());
|
||||
// Use UTF-8 in Mime Date to cover also special characters
|
||||
// Use UTF-8 in Mime Date to cover also special characters,
|
||||
// but the Receiver of the mimeData has to be able to handle Utf8() or translate
|
||||
mimeData->setData("application/x-columnchooser", name.toUtf8());
|
||||
|
||||
// create a drag event
|
||||
|
||||
@@ -231,7 +231,7 @@ void SearchBox::setBad(QStringList errors)
|
||||
pal.setColor(QPalette::Text, Qt::red);
|
||||
setPalette(pal);
|
||||
|
||||
setToolTip(errors.join(" and "));
|
||||
setToolTip(errors.join(tr(" and ")));
|
||||
}
|
||||
|
||||
void SearchBox::setGood()
|
||||
@@ -259,8 +259,13 @@ void
|
||||
SearchBox::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QString name = event->mimeData()->data("application/x-columnchooser");
|
||||
// fugly, but it works for BikeScore with the (TM) in it...
|
||||
if (name == "BikeScore?") name = QString("BikeScore™").replace("™", QChar(0x2122));
|
||||
// fugly, but it works for BikeScore with the (TM) in it... so...
|
||||
// independent of Latin1 or UTF-8 coming from "Column Chooser" the "TM" is not recognized by the parser,
|
||||
// when stripping it of, all works fine (Parser add's it internally to find the right metrics)
|
||||
if (name.startsWith("BikeScore")) name = QString("BikeScore");
|
||||
// Always use the "internalNames" in Filter expressions
|
||||
SpecialFields sp;
|
||||
name = sp.internalName(name);
|
||||
|
||||
// we do very little to the name, just space to _ and lower case it for now...
|
||||
name.replace(' ', '_');
|
||||
|
||||
Reference in New Issue
Block a user