diff --git a/src/Core/Context.cpp b/src/Core/Context.cpp index 0a428d418..fbf98ba05 100644 --- a/src/Core/Context.cpp +++ b/src/Core/Context.cpp @@ -99,6 +99,7 @@ Context::notifyConfigChanged(qint32 state) void Context::userMetricsConfigChanged() { + // read em in... QString metrics = QString("%1/../usermetrics.xml").arg(athlete->home->root().absolutePath()); if (QFile(metrics).exists()) { @@ -124,7 +125,7 @@ Context::userMetricsConfigChanged() // we'll fix it UserMetricSchemaVersion = changed; - // update metric factory + // update metric factory deleting originals RideMetricFactory::instance().removeUserMetrics(); // now add initial metrics -- what about multiple contexts (?) XXX diff --git a/src/Core/DataFilter.h b/src/Core/DataFilter.h index 486f0cc38..4c0e4bb56 100644 --- a/src/Core/DataFilter.h +++ b/src/Core/DataFilter.h @@ -169,6 +169,8 @@ class DataFilter : public QObject static QStringList builtins(); // return list of functions supported + int refcount; // used by user metrics + public slots: QStringList parseFilter(Context *context, QString query, QStringList *list=0); QStringList check(QString query); diff --git a/src/Metrics/UserMetric.cpp b/src/Metrics/UserMetric.cpp index a252a3a25..2bafdd92b 100644 --- a/src/Metrics/UserMetric.cpp +++ b/src/Metrics/UserMetric.cpp @@ -25,6 +25,7 @@ UserMetric::UserMetric(Context *context, UserMetricSettings settings) { // compile the program - built in a context that can close. program = new DataFilter(NULL, context, settings.program); + program->refcount = 1; root = program->root(); rt = &program->rt; @@ -43,6 +44,7 @@ UserMetric::UserMetric(const UserMetric *from) : RideMetric() { this->settings = from->settings; this->program = from->program; + this->program->refcount++; this->root = from->program->root(); this->finit = from->finit; @@ -64,7 +66,11 @@ UserMetric::UserMetric(const UserMetric *from) : RideMetric() UserMetric::~UserMetric() { - if (!clone_ && program) delete program; + // program is shared, only delete when last is destroyed + if (program) { + program->refcount--; + if (!program->refcount) delete program; + } if (clone_) delete rt; } diff --git a/src/Metrics/UserMetricSettings.h b/src/Metrics/UserMetricSettings.h index 30e9e0d90..6f1c190fa 100644 --- a/src/Metrics/UserMetricSettings.h +++ b/src/Metrics/UserMetricSettings.h @@ -57,6 +57,8 @@ class UserMetricSettings { this->conversionSum != right.conversionSum || this->program != right.program || this->precision != right.precision || + this->istime != right.istime || + this->aggzero != right.aggzero || this->fingerprint != right.fingerprint) return true; else