Data Filter (Part 1 of 3)

Part 1 of Data filtering, this patch adds the ability
to enter and parse filter statements in the search box
(by clicking on the magnifying glass it becomes a filter
box).

The statements can reference metrics and metadata fields
allowing the user to define boolean expressions to filter
data. An example of the syntax;

    Average_Power > 200 and Duration > 3600

This references the metric Average_Power and ride Duration. But
will also support operations on metadata fields, for example;

    Workout_Code endsWith "SST"

The operators are;
    = <> > >= < <= matches contains endswith beginswith
    ( ) && and || or

Filters are syntactically and semantically validated. But at
this point the resulting tree is not evaluated, i.e. we can
parse the filters, but do not execute them.

Two further updates are pending (once written and tested):
- Part 2 of 3 : Execute filters and apply to the ride list
- Part 3 of 3 : Allow named filters and apply to LTM charts

Further updates will support a visual editor and allowing filters
to be applied to CP and Histogram charts and affect the PMC stress
calculators.
This commit is contained in:
Mark Liversedge
2012-10-28 20:05:12 +00:00
parent 299b8f6fa9
commit 7e4786bc5a
9 changed files with 542 additions and 7 deletions

View File

@@ -35,7 +35,7 @@ SearchBox::SearchBox(QWidget *parent)
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
clearButton->hide();
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(clearButton, SIGNAL(clicked()), this, SIGNAL(clearQuery()));
connect(clearButton, SIGNAL(clicked()), this, SLOT(clearClicked()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
// search button
@@ -92,6 +92,7 @@ void SearchBox::resizeEvent(QResizeEvent *)
void SearchBox::toggleMode()
{
clear(); // clear whatever is there first
if (mode == Search) setMode(Filter);
else setMode(Search);
}
@@ -124,20 +125,25 @@ void SearchBox::setMode(SearchBoxMode mode)
void SearchBox::updateCloseButton(const QString& text)
{
if (clearButton->isVisible() && text.isEmpty()) clearQuery();
if (clearButton->isVisible() && text.isEmpty()) mode == Search ? clearQuery() : clearFilter();
clearButton->setVisible(!text.isEmpty());
if (mode == Search) searchSubmit();
if (mode == Search) searchSubmit(); // only do search as you type in search mode
}
void SearchBox::searchSubmit()
{
// return hit / key pressed
if (text() != "") {
submitQuery(text());
mode == Search ? submitQuery(text()) : submitFilter(text());
}
}
void SearchBox::clearClicked()
{
mode == Search ? clearQuery() : clearFilter();
}
// Drag and drop columns from the chooser...
void
SearchBox::dragEnterEvent(QDragEnterEvent *event)
@@ -157,5 +163,5 @@ SearchBox::dropEvent(QDropEvent *event)
// we do very little to the name, just space to _ and lower case it for now...
name.replace(' ', '_');
insert(name + ":\"\"");
insert(name + (mode == Search ? ":\"\"" : ""));
}