From 522824bb404d4c9321e579205aaeb4eec34d5d00 Mon Sep 17 00:00:00 2001 From: Sean Rhea Date: Sun, 1 Nov 2009 10:56:29 -0500 Subject: [PATCH] switch RideFile::dataPoints to QVector ...so that we can binary search within them. Also, switch a lot of QListIterators to Qt foreach. --- src/AllPlot.cpp | 4 +--- src/BestIntervalDialog.cpp | 4 +--- src/BikeScore.cpp | 9 ++------- src/CpintPlot.cpp | 4 +--- src/PfPvPlot.cpp | 4 +--- src/PowerHist.cpp | 5 +---- src/RideFile.cpp | 4 +--- src/RideFile.h | 10 +++++----- src/RideItem.cpp | 5 +---- src/RideMetric.h | 5 +---- src/SplitRideDialog.cpp | 4 ++-- 11 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/AllPlot.cpp b/src/AllPlot.cpp index aedadbde5..f26333902 100644 --- a/src/AllPlot.cpp +++ b/src/AllPlot.cpp @@ -519,9 +519,7 @@ AllPlot::setData(RideItem *_rideItem) if (!altArray.empty()) altCurve->attach(this); arrayLength = 0; - QListIterator i(ride->dataPoints()); - while (i.hasNext()) { - RideFilePoint *point = i.next(); + foreach (const RideFilePoint *point, ride->dataPoints()) { timeArray[arrayLength] = point->secs; if (!wattsArray.empty()) wattsArray[arrayLength] = max(0, point->watts); diff --git a/src/BestIntervalDialog.cpp b/src/BestIntervalDialog.cpp index c3ea35023..eec34ee6d 100644 --- a/src/BestIntervalDialog.cpp +++ b/src/BestIntervalDialog.cpp @@ -115,9 +115,7 @@ BestIntervalDialog::findClicked() int expectedSamples = (int) floor(windowSizeSecs / secsDelta); double totalWatts = 0.0; - QListIterator i(ride->dataPoints()); - while (i.hasNext()) { - const RideFilePoint *point = i.next(); + foreach (const RideFilePoint *point, ride->dataPoints()) { while (!window.empty() && (point->secs >= window.first()->secs + windowSizeSecs)) { totalWatts -= window.first()->watts; diff --git a/src/BikeScore.cpp b/src/BikeScore.cpp index b950ecc29..2454ccfbf 100644 --- a/src/BikeScore.cpp +++ b/src/BikeScore.cpp @@ -102,11 +102,8 @@ class XPower : public RideMetric { */ - QListIterator i(ride->dataPoints()); - int count = 0; - while (i.hasNext()) { - const RideFilePoint *point = i.next(); + foreach (const RideFilePoint *point, ride->dataPoints()) { // if there are missing data then add in the contribution // from the exponentially decaying smoothed power @@ -205,9 +202,7 @@ class BikeScore : public RideMetric { return; if (ride->deviceType() == QString("Manual CSV")) { // manual entry, use BS from dataPoints - QListIterator i(ride->dataPoints()); - const RideFilePoint *point = i.next(); - score = point->bs; + score = ride->dataPoints().first()->bs; } else { assert(deps.contains("skiba_xpower")); diff --git a/src/CpintPlot.cpp b/src/CpintPlot.cpp index fe563859d..6cad74be9 100644 --- a/src/CpintPlot.cpp +++ b/src/CpintPlot.cpp @@ -120,9 +120,7 @@ update_cpi_file(const cpi_file_info *info, QProgressDialog *progress, return; cpint_data data; data.rec_int_ms = (int) round(rideFile->recIntSecs() * 1000.0); - QListIterator i(rideFile->dataPoints()); - while (i.hasNext()) { - const RideFilePoint *p = i.next(); + foreach (const RideFilePoint *p, rideFile->dataPoints()) { double secs = round(p->secs * 1000.0) / 1000; if (secs > 0) data.points.append(cpint_point(secs, (int) round(p->watts))); diff --git a/src/PfPvPlot.cpp b/src/PfPvPlot.cpp index 943839fcb..578d3a88e 100644 --- a/src/PfPvPlot.cpp +++ b/src/PfPvPlot.cpp @@ -301,9 +301,7 @@ PfPvPlot::setData(RideItem *_rideItem) long tot_cad_points = 0; - QListIterator i(ride->dataPoints()); - while (i.hasNext()) { - const RideFilePoint *p1 = i.next(); + foreach(const RideFilePoint *p1, ride->dataPoints()) { if (p1->watts != 0 && p1->cad != 0) { double aepf = (p1->watts * 60.0) / (p1->cad * cl_ * 2.0 * PI); diff --git a/src/PowerHist.cpp b/src/PowerHist.cpp index 15efa44a7..95e4f1fb2 100644 --- a/src/PowerHist.cpp +++ b/src/PowerHist.cpp @@ -397,14 +397,11 @@ PowerHist::setData(RideItem *_rideItem) kphArray.resize(0); cadArray.resize(0); - QListIterator j(ride->dataPoints()); - // unit conversion factor for imperial units for selected parameters double torque_factor = (useMetricUnits ? 1.0 : 0.73756215); double speed_factor = (useMetricUnits ? 1.0 : 0.62137119); - while (j.hasNext()) { - const RideFilePoint *p1 = j.next(); + foreach(const RideFilePoint *p1, ride->dataPoints()) { int wattsIndex = int(floor(p1->watts / wattsDelta)); if (wattsIndex >= 0 && wattsIndex < maxSize) { diff --git a/src/RideFile.cpp b/src/RideFile.cpp index 1818fc4a7..fe8b40bf2 100644 --- a/src/RideFile.cpp +++ b/src/RideFile.cpp @@ -39,9 +39,7 @@ void RideFile::writeAsCsv(QFile &file, bool bIsMetric) const convertUnit = 1.0; } - QListIterator i(dataPoints()); - while (i.hasNext()) { - RideFilePoint *point = i.next(); + foreach (const RideFilePoint *point, dataPoints()) { if (point->secs == 0.0) continue; out << point->secs/60.0; diff --git a/src/RideFile.h b/src/RideFile.h index 614d0c69c..478475660 100644 --- a/src/RideFile.h +++ b/src/RideFile.h @@ -24,6 +24,7 @@ #include #include #include +#include // This file defines four classes: // @@ -68,7 +69,7 @@ class RideFile QDateTime startTime_; // time of day that the ride started double recIntSecs_; // recording interval in seconds - QList dataPoints_; + QVector dataPoints_; RideFileDataPresent dataPresent; QString deviceType_; @@ -80,14 +81,13 @@ class RideFile deviceType_("unknown") {} virtual ~RideFile() { - QListIterator i(dataPoints_); - while (i.hasNext()) - delete i.next(); + foreach(RideFilePoint *point, dataPoints_) + delete point; } const QDateTime &startTime() const { return startTime_; } double recIntSecs() const { return recIntSecs_; } - const QList dataPoints() const { return dataPoints_; } + const QVector dataPoints() const { return dataPoints_; } inline const RideFileDataPresent *areDataPresent() const { return &dataPresent; } const QString &deviceType() const { return deviceType_; } diff --git a/src/RideItem.cpp b/src/RideItem.cpp index a0cefc043..dd275e8c5 100644 --- a/src/RideItem.cpp +++ b/src/RideItem.cpp @@ -300,10 +300,7 @@ RideItem::htmlSummary() double time_start, time_end, km_start, km_end, int_dur; - QListIterator i(ride->dataPoints()); - while (i.hasNext()) { - RideFilePoint *point = i.next(); - + foreach (const RideFilePoint *point, ride->dataPoints()) { double secs_delta = ride->recIntSecs(); if (point->interval != last_interval) { diff --git a/src/RideMetric.h b/src/RideMetric.h index b12f3884b..335f0f184 100644 --- a/src/RideMetric.h +++ b/src/RideMetric.h @@ -48,11 +48,8 @@ struct RideMetric { struct PointwiseRideMetric : public RideMetric { void compute(const RideFile *ride, const Zones *zones, int zoneRange, const QHash &) { - QListIterator i(ride->dataPoints()); - while (i.hasNext()) { - const RideFilePoint *point = i.next(); + foreach (const RideFilePoint *point, ride->dataPoints()) perPoint(point, ride->recIntSecs(), ride, zones, zoneRange); - } } virtual void perPoint(const RideFilePoint *point, double secsDelta, const RideFile *ride, const Zones *zones, diff --git a/src/SplitRideDialog.cpp b/src/SplitRideDialog.cpp index 3a1390885..44da28eae 100644 --- a/src/SplitRideDialog.cpp +++ b/src/SplitRideDialog.cpp @@ -86,9 +86,8 @@ SplitRideDialog::SplitRideDialog(MainWindow *mainWindow) int nDataPoint = 0; const RideFile *ride = mainWindow->currentRide(); - for (QListIterator i(ride->dataPoints()); i.hasNext(); ++nDataPoint) + foreach (const RideFilePoint *point, ride->dataPoints()) { - const RideFilePoint *point = i.next(); if (dLastSeconds>=0 && ((point->secs-dLastSeconds)>=30 || nLastInterval!=point->interval)) { @@ -110,6 +109,7 @@ SplitRideDialog::SplitRideDialog(MainWindow *mainWindow) dLastSeconds = point->secs; nLastInterval = point->interval; + ++nDataPoint; } }