mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Applied JTC's P10, changing DatePickerDialog and RideFile objects to use boost::scoped_ptr to ensure that the objects are deleted. He recommends that we extend this technique to replace other raw pointer / delete methods.
Also, changed PfPvPlot so it will look for the CP from the power.zones file and use that rather than a hard coded value.
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <qwt_plot_picker.h>
|
||||
#include <qwt_plot_zoomer.h>
|
||||
#include <qwt_data.h>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include "DatePickerDialog.h"
|
||||
#include "ToolsDialog.h"
|
||||
@@ -353,11 +354,11 @@ MainWindow::MainWindow(const QDir &home) :
|
||||
this, SLOT(setBinWidthFromSlider()));
|
||||
connect(binWidthLineEdit, SIGNAL(editingFinished()),
|
||||
this, SLOT(setBinWidthFromLineEdit()));
|
||||
connect(qaCPValue, SIGNAL(returnPressed()),
|
||||
connect(qaCPValue, SIGNAL(editingFinished()),
|
||||
this, SLOT(setQaCPFromLineEdit()));
|
||||
connect(qaCadValue, SIGNAL(returnPressed()),
|
||||
connect(qaCadValue, SIGNAL(editingFinished()),
|
||||
this, SLOT(setQaCADFromLineEdit()));
|
||||
connect(qaClValue, SIGNAL(returnPressed()),
|
||||
connect(qaClValue, SIGNAL(editingFinished()),
|
||||
this, SLOT(setQaCLFromLineEdit()));
|
||||
connect(tabWidget, SIGNAL(currentChanged(int)),
|
||||
this, SLOT(tabChanged(int)));
|
||||
@@ -577,7 +578,8 @@ MainWindow::exportCSV()
|
||||
void MainWindow::importCSV()
|
||||
{
|
||||
// Prompt the user for the ride date
|
||||
DatePickerDialog *dpd = new DatePickerDialog(this);
|
||||
boost::scoped_ptr<DatePickerDialog> dpd(new DatePickerDialog(this));
|
||||
|
||||
dpd->exec();
|
||||
|
||||
if(dpd->canceled == true)
|
||||
@@ -585,8 +587,8 @@ void MainWindow::importCSV()
|
||||
|
||||
QFile file ( dpd->fileName );
|
||||
QStringList errors;
|
||||
RideFile *ride =
|
||||
RideFileFactory::instance().openRideFile(file, errors);
|
||||
boost::scoped_ptr<RideFile> ride(
|
||||
RideFileFactory::instance().openRideFile(file, errors));
|
||||
|
||||
if (!ride || !errors.empty())
|
||||
{
|
||||
@@ -624,8 +626,6 @@ void MainWindow::importCSV()
|
||||
return;
|
||||
}
|
||||
|
||||
delete ride;
|
||||
delete dpd;
|
||||
addRide ( name );
|
||||
}
|
||||
|
||||
@@ -648,8 +648,10 @@ MainWindow::importSRM()
|
||||
QString fileName = i.next();
|
||||
QFile file(fileName);
|
||||
QStringList errors;
|
||||
RideFile *ride =
|
||||
RideFileFactory::instance().openRideFile(file, errors);
|
||||
|
||||
boost::scoped_ptr<RideFile> ride(
|
||||
RideFileFactory::instance().openRideFile(file, errors));
|
||||
|
||||
if (!ride || !errors.empty()) {
|
||||
QString all = (ride
|
||||
? tr("Non-fatal problem(s) opening %1:")
|
||||
@@ -680,7 +682,6 @@ MainWindow::importSRM()
|
||||
return;
|
||||
}
|
||||
|
||||
delete ride;
|
||||
addRide(name);
|
||||
}
|
||||
}
|
||||
@@ -704,8 +705,10 @@ MainWindow::importTCX()
|
||||
QString fileName = i.next();
|
||||
QFile file(fileName);
|
||||
QStringList errors;
|
||||
RideFile *ride =
|
||||
RideFileFactory::instance().openRideFile(file, errors);
|
||||
|
||||
boost::scoped_ptr<RideFile> ride(
|
||||
RideFileFactory::instance().openRideFile(file, errors));
|
||||
|
||||
if (!ride || !errors.empty()) {
|
||||
QString all = (ride
|
||||
? tr("Non-fatal problem(s) opening %1:")
|
||||
@@ -736,7 +739,6 @@ MainWindow::importTCX()
|
||||
return;
|
||||
}
|
||||
|
||||
delete ride;
|
||||
addRide(name);
|
||||
}
|
||||
}
|
||||
@@ -771,8 +773,12 @@ MainWindow::rideSelected()
|
||||
cpintPlot->calculate(ride->fileName, ride->dateTime);
|
||||
if (ride->ride)
|
||||
powerHist->setData(ride->ride);
|
||||
if (ride->ride)
|
||||
pfPvPlot->setData(ride->ride);
|
||||
if (ride){
|
||||
// using a RideItem rather than RideFile to provide access to zones information
|
||||
pfPvPlot->setData(ride);
|
||||
// update the QLabel widget with the CP value set in PfPvPlot::setData()
|
||||
qaCPValue->setText(QString("%1").arg(pfPvPlot->getCP()));
|
||||
}
|
||||
|
||||
QDate wstart = ride->dateTime.date();
|
||||
wstart = wstart.addDays(Qt::Monday - wstart.dayOfWeek());
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
#include "PfPvPlot.h"
|
||||
#include "RideFile.h"
|
||||
#include "RideItem.h"
|
||||
#include "Settings.h"
|
||||
#include "Zones.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <qwt_data.h>
|
||||
@@ -63,10 +65,11 @@ PfPvPlot::PfPvPlot()
|
||||
}
|
||||
|
||||
void
|
||||
PfPvPlot::setData(RideFile *ride)
|
||||
PfPvPlot::setData(RideItem *rideItem)
|
||||
{
|
||||
RideFile *ride = rideItem->ride;
|
||||
setTitle(ride->startTime().toString(GC_DATETIME_FORMAT));
|
||||
|
||||
|
||||
// due to the discrete power and cadence values returned by the
|
||||
// power meter, there will very likely be many duplicate values.
|
||||
// Rather than pass them all to the curve, use a set to strip
|
||||
@@ -98,6 +101,14 @@ PfPvPlot::setData(RideFile *ride)
|
||||
++j;
|
||||
}
|
||||
|
||||
// get the current zone's CP if available:
|
||||
if(rideItem->zones){
|
||||
int zone_range = rideItem->zones->whichRange(rideItem->dateTime.date());
|
||||
if (zone_range >= 0) {
|
||||
setCP(rideItem->zones->getCP(rideItem->zones->whichRange(rideItem->dateTime.date())));
|
||||
}
|
||||
}
|
||||
|
||||
curve->setData(cpvArray, aepfArray);
|
||||
replot();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
// forward references
|
||||
class RideFile;
|
||||
class RideItem;
|
||||
class QwtPlotCurve;
|
||||
class QwtPlotMarker;
|
||||
|
||||
@@ -34,7 +35,7 @@ class PfPvPlot : public QwtPlot
|
||||
public:
|
||||
|
||||
PfPvPlot();
|
||||
void setData(RideFile *ride);
|
||||
void setData(RideItem *rideItem);
|
||||
|
||||
int getCP();
|
||||
void setCP(int cp);
|
||||
|
||||
@@ -146,6 +146,8 @@ int Zones::whichRange(const QDate &date) const
|
||||
|
||||
int Zones::numZones(int rnum) const
|
||||
{
|
||||
// TODO: Fix an array index out of range error when a gap in the zones ranges
|
||||
// is causing rnum to be -1, but the program still thinks that zones info is available
|
||||
assert(rnum < ranges.size());
|
||||
return ranges[rnum]->zones.size();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user