mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Fix UserMetric calculation error
.. add a reference count for clones and originals, noting that for user metrics the factory gets a clone and the original is always deleted at startup. .. additionally when the clone in the factory is deleted on metric changes we finally delete the program that was created initially. .. note there is also a fix to let the configuration settings spot when aggregate zero and istime change in options as these were not spotted before.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user