From 065e337ef236f66cd490a28eab2089b110a58397 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Wed, 17 Dec 2014 11:25:35 +0000 Subject: [PATCH] Migrate TreeMap to use RideCache .. and therefore also using the Specification approach. --- src/TreeMapPlot.cpp | 14 ++++++-------- src/TreeMapPlot.h | 1 - src/TreeMapWindow.cpp | 31 +++++++++++++++++-------------- src/TreeMapWindow.h | 5 ++--- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/TreeMapPlot.cpp b/src/TreeMapPlot.cpp index ed9c61673..faff749fe 100644 --- a/src/TreeMapPlot.cpp +++ b/src/TreeMapPlot.cpp @@ -20,8 +20,7 @@ #include "TreeMapPlot.h" #include "LTMTool.h" #include "TreeMapWindow.h" -#include "MetricAggregator.h" -#include "SummaryMetrics.h" +#include "RideCache.h" #include "RideMetric.h" #include "Settings.h" #include "Colors.h" @@ -65,15 +64,14 @@ TreeMapPlot::setData(TMSettings *settings) { root->clear(); - foreach (SummaryMetrics rideMetrics, *(settings->data)) { + foreach (RideItem *item, context->athlete->rideCache->rides()) { // don't plot if filtered - if (context->isfiltered && !context->filters.contains(rideMetrics.getFileName())) continue; - if (context->ishomefiltered && !context->homeFilters.contains(rideMetrics.getFileName())) continue; + if (!settings->specification.pass(item)) continue; - double value = rideMetrics.getForSymbol(settings->symbol); - QString text1 = rideMetrics.getText(settings->field1, tr("(unknown)")); - QString text2 = rideMetrics.getText(settings->field2, tr("(unknown)")); + double value = item->getForSymbol(settings->symbol); + QString text1 = item->getText(settings->field1, tr("(unknown)")); + QString text2 = item->getText(settings->field2, tr("(unknown)")); if (text1 == "") text1 = tr("(unknown)"); if (text2 == "") text2 = tr("(unknown)"); diff --git a/src/TreeMapPlot.h b/src/TreeMapPlot.h index e0bdb28e4..7f0de6fbc 100644 --- a/src/TreeMapPlot.h +++ b/src/TreeMapPlot.h @@ -22,7 +22,6 @@ #include -#include "MetricAggregator.h" #include "TreeMapWindow.h" #include "Context.h" diff --git a/src/TreeMapWindow.cpp b/src/TreeMapWindow.cpp index dca807449..4cc34f872 100644 --- a/src/TreeMapWindow.cpp +++ b/src/TreeMapWindow.cpp @@ -21,9 +21,7 @@ #include "TreeMapPlot.h" #include "LTMSettings.h" #include "Context.h" -#include "Context.h" #include "Athlete.h" -#include "SummaryMetrics.h" #include "Settings.h" #include "math.h" #include "Units.h" // for MILES_PER_KM @@ -220,26 +218,31 @@ TreeMapWindow::refresh() } } + DateRange dr; + if (useCustom) { - settings.from = custom.from; - settings.to = custom.to; + dr.from = custom.from; + dr.to = custom.to; } else if (useToToday) { QDate today = QDate::currentDate(); - settings.from = myDateRange.from; - settings.to = myDateRange.to > today ? today : myDateRange.to; + dr.from = myDateRange.from; + dr.to = myDateRange.to > today ? today : myDateRange.to; } else { - settings.from = myDateRange.from; - settings.to = myDateRange.to; + dr.from = myDateRange.from; + dr.to = myDateRange.to; } + + // set the specification + FilterSet fs; + fs.addFilter(context->isfiltered, context->filters); + fs.addFilter(context->ishomefiltered, context->homeFilters); + settings.specification.setFilterSet(fs); + settings.specification.setDateRange(dr); + + // and the fields to use SpecialFields sp; settings.field1 = sp.internalName(field1->currentText()); settings.field2 = sp.internalName(field2->currentText()); - settings.data = &results; - - // get the data - results.clear(); // clear any old data - results = context->athlete->metricDB->getAllMetricsFor(QDateTime(settings.from, QTime(0,0,0)), - QDateTime(settings.to, QTime(0,0,0))); refreshPlot(); } diff --git a/src/TreeMapWindow.h b/src/TreeMapWindow.h index eb61e1f19..31eeec628 100644 --- a/src/TreeMapWindow.h +++ b/src/TreeMapWindow.h @@ -23,12 +23,12 @@ #include #include #include "Context.h" -#include "MetricAggregator.h" #include "RideMetadata.h" #include "Season.h" #include "LTMPopup.h" #include "GcPane.h" #include "SpecialFields.h" +#include "Specification.h" #include @@ -40,8 +40,7 @@ class TMSettings public: QString symbol; QString field1, field2; - QDate from, to; - QList *data; + Specification specification; }; class TreeMapPlot;