diff --git a/src/Athlete.cpp b/src/Athlete.cpp index 823b796af..118d83c11 100644 --- a/src/Athlete.cpp +++ b/src/Athlete.cpp @@ -457,3 +457,41 @@ Athlete::translateDefaultCharts(QList&charts) charts[i].name = chartNameMap.value(charts[i].name, charts[i].name); } } + +void +Athlete::configChanged() +{ + // re-read Zones in case it changed + QFile zonesFile(home.absolutePath() + "/power.zones"); + if (zonesFile.exists()) { + if (!zones_->read(zonesFile)) { + QMessageBox::critical(context->mainWindow, tr("Zones File Error"), + zones_->errorString()); + } + else if (! zones_->warningString().isEmpty()) + QMessageBox::warning(context->mainWindow, tr("Reading Zones File"), zones_->warningString()); + } + + // reread HR zones + QFile hrzonesFile(home.absolutePath() + "/hr.zones"); + if (hrzonesFile.exists()) { + if (!hrzones_->read(hrzonesFile)) { + QMessageBox::critical(context->mainWindow, tr("HR Zones File Error"), + hrzones_->errorString()); + } + else if (! hrzones_->warningString().isEmpty()) + QMessageBox::warning(context->mainWindow, tr("Reading HR Zones File"), hrzones_->warningString()); + } + + QVariant unit = appsettings->cvalue(cyclist, GC_UNIT); + useMetricUnits = (unit.toString() == GC_UNIT_METRIC); + + // forget all the cached weight values in case weight changed + for (int i=0; ichildCount(); i++) { + RideItem *rideItem = static_cast(allRides->child(i)); + if (rideItem->ride(false)) { + rideItem->ride(false)->setWeight(0); + rideItem->ride(false)->getWeight(); + } + } +} diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a19e67cf8..27abc9c1f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1887,36 +1887,6 @@ Context::notifyConfigChanged() configChanged(); } -void -Athlete::configChanged() -{ - // re-read Zones in case it changed - QFile zonesFile(home.absolutePath() + "/power.zones"); - if (zonesFile.exists()) { - if (!zones_->read(zonesFile)) { - QMessageBox::critical(context->mainWindow, tr("Zones File Error"), - zones_->errorString()); - } - else if (! zones_->warningString().isEmpty()) - QMessageBox::warning(context->mainWindow, tr("Reading Zones File"), zones_->warningString()); - } - - // reread HR zones - QFile hrzonesFile(home.absolutePath() + "/hr.zones"); - if (hrzonesFile.exists()) { - if (!hrzones_->read(hrzonesFile)) { - QMessageBox::critical(context->mainWindow, tr("HR Zones File Error"), - hrzones_->errorString()); - } - else if (! hrzones_->warningString().isEmpty()) - QMessageBox::warning(context->mainWindow, tr("Reading HR Zones File"), hrzones_->warningString()); - } - - QVariant unit = appsettings->cvalue(cyclist, GC_UNIT); - useMetricUnits = (unit.toString() == GC_UNIT_METRIC); - -} - /*---------------------------------------------------------------------- * Measures *--------------------------------------------------------------------*/ diff --git a/src/MetricAggregator.cpp b/src/MetricAggregator.cpp index 45c1f20b5..94da019dc 100644 --- a/src/MetricAggregator.cpp +++ b/src/MetricAggregator.cpp @@ -127,7 +127,7 @@ void MetricAggregator::refreshMetrics(QDateTime forceAfterThisDate) } } - unsigned long zoneFingerPrint = static_cast(context->athlete->zones()->getFingerprint()) + unsigned long zoneFingerPrint = static_cast(context->athlete->zones()->getFingerprint(context)) + static_cast(context->athlete->hrZones()->getFingerprint()); // checksum of *all* zone data (HR and Power) // update statistics for ride files which are out of date @@ -276,7 +276,7 @@ void MetricAggregator::refreshMetrics(QDateTime forceAfterThisDate) void MetricAggregator::addRide(RideItem*ride) { if (ride && ride->ride()) { - importRide(context->athlete->home, ride->ride(), ride->fileName, context->athlete->zones()->getFingerprint(), true); + importRide(context->athlete->home, ride->ride(), ride->fileName, context->athlete->zones()->getFingerprint(context), true); RideFileCache updater(context, context->athlete->home.absolutePath() + "/" + ride->fileName, ride->ride(), true); // update cpx etc dataChanged(); // notify models/views } diff --git a/src/RideFile.cpp b/src/RideFile.cpp index 9cd2df363..028d8a85e 100644 --- a/src/RideFile.cpp +++ b/src/RideFile.cpp @@ -1075,6 +1075,12 @@ RideFile::emitModified() emit modified(); } +void +RideFile::setWeight(double x) +{ + weight_ = x; +} + double RideFile::getWeight() { diff --git a/src/RideFile.h b/src/RideFile.h index 0afcc1421..97129f5db 100644 --- a/src/RideFile.h +++ b/src/RideFile.h @@ -216,6 +216,7 @@ class RideFile : public QObject // QObject to emit signals Context *context; double getWeight(); + void setWeight(double x); WPrime *wprimeData(); // return wprime, init/refresh if needed diff --git a/src/RideItem.cpp b/src/RideItem.cpp index 1d9f53c62..eae5c75ff 100644 --- a/src/RideItem.cpp +++ b/src/RideItem.cpp @@ -33,9 +33,9 @@ RideItem::RideItem(int type, dateTime(dateTime), zones(zones), hrZones(hrZones) { } -RideFile *RideItem::ride() +RideFile *RideItem::ride(bool open) { - if (ride_) return ride_; + if (!open || ride_) return ride_; // open the ride file QFile file(path + "/" + fileName); diff --git a/src/RideItem.h b/src/RideItem.h index 8f39c652e..f0bed5d4c 100644 --- a/src/RideItem.h +++ b/src/RideItem.h @@ -70,7 +70,10 @@ class RideItem : public QObject, public QTreeWidgetItem //<< for signals/slots QString path; QString fileName; QDateTime dateTime; - RideFile *ride(); + // ride() will open the ride if it isn't already when open=true + // if we pass false then it will just return ride_ so we can + // traverse currently open rides when config changes + RideFile *ride(bool open=true); const QStringList errors() { return errors_; } const Zones *zones; const HrZones *hrZones; diff --git a/src/Zones.cpp b/src/Zones.cpp index 2894a3d09..04d8e9f7c 100644 --- a/src/Zones.cpp +++ b/src/Zones.cpp @@ -913,7 +913,7 @@ int Zones::deleteRange(int rnum) { } quint16 -Zones::getFingerprint() const +Zones::getFingerprint(Context *context) const { quint64 x = 0; for (int i=0; ivalue(this, GC_ELEVATION_HYSTERESIS).toDouble()*10); + + // if default athlete weight changes everything needs to change ! + double weight = appsettings->cvalue(context->athlete->cyclist, GC_WEIGHT, "0.0").toDouble(); + return qChecksum(ba, ba.length()) + weight + (appsettings->value(this, GC_ELEVATION_HYSTERESIS).toDouble()*10); } diff --git a/src/Zones.h b/src/Zones.h index 8a7840988..644c5e194 100644 --- a/src/Zones.h +++ b/src/Zones.h @@ -19,6 +19,8 @@ #ifndef _Zones_h #define _Zones_h #include "GoldenCheetah.h" +#include "Context.h" +#include "Athlete.h" #include @@ -192,7 +194,7 @@ class Zones : public QObject // calculate a CRC for the zones data - used to see if zones // data is changed since last referenced in Metric code // could also be used in Configuration pages (later) - quint16 getFingerprint() const; + quint16 getFingerprint(Context *context) const; }; QColor zoneColor(int zone, int num_zones);