fix tabs and eol spaces -- no functional change

This commit is contained in:
Sean Rhea
2009-11-01 07:36:31 -05:00
parent 8595f2cfc5
commit 68832ff6c0
4 changed files with 275 additions and 274 deletions

View File

@@ -1,16 +1,16 @@
/*
/*
* Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -44,9 +44,9 @@ class AllPlotBackground: public QwtPlotItem
public:
AllPlotBackground(AllPlot *_parent)
{
setZ(0.0);
parent = _parent;
}
setZ(0.0);
parent = _parent;
}
virtual int rtti() const
{
@@ -54,38 +54,38 @@ class AllPlotBackground: public QwtPlotItem
}
virtual void draw(QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &yMap,
const QRect &rect) const
const QwtScaleMap &, const QwtScaleMap &yMap,
const QRect &rect) const
{
RideItem *rideItem = parent->rideItem;
RideItem *rideItem = parent->rideItem;
if (! rideItem)
return;
if (! rideItem)
return;
Zones **zones = rideItem->zones;
int zone_range = rideItem->zoneRange();
Zones **zones = rideItem->zones;
int zone_range = rideItem->zoneRange();
if (parent->shadeZones() && zones && *zones && (zone_range >= 0)) {
QList <int> zone_lows = (*zones)->getZoneLows(zone_range);
int num_zones = zone_lows.size();
if (num_zones > 0) {
for (int z = 0; z < num_zones; z ++) {
QRect r = rect;
if (parent->shadeZones() && zones && *zones && (zone_range >= 0)) {
QList <int> zone_lows = (*zones)->getZoneLows(zone_range);
int num_zones = zone_lows.size();
if (num_zones > 0) {
for (int z = 0; z < num_zones; z ++) {
QRect r = rect;
QColor shading_color = zoneColor(z, num_zones);
shading_color.setHsv(
shading_color.hue(),
shading_color.saturation() / 4,
shading_color.value()
);
r.setBottom(yMap.transform(zone_lows[z]));
if (z + 1 < num_zones)
r.setTop(yMap.transform(zone_lows[z + 1]));
if (r.top() <= r.bottom())
painter->fillRect(r, shading_color);
}
}
}
QColor shading_color = zoneColor(z, num_zones);
shading_color.setHsv(
shading_color.hue(),
shading_color.saturation() / 4,
shading_color.value()
);
r.setBottom(yMap.transform(zone_lows[z]));
if (z + 1 < num_zones)
r.setTop(yMap.transform(zone_lows[z + 1]));
if (r.top() <= r.bottom())
painter->fillRect(r, shading_color);
}
}
}
}
};
@@ -102,66 +102,66 @@ class AllPlotZoneLabel: public QwtPlotItem
public:
AllPlotZoneLabel(AllPlot *_parent, int _zone_number)
{
parent = _parent;
zone_number = _zone_number;
parent = _parent;
zone_number = _zone_number;
RideItem *rideItem = parent->rideItem;
RideItem *rideItem = parent->rideItem;
if (! rideItem)
return;
if (! rideItem)
return;
Zones **zones = rideItem->zones;
int zone_range = rideItem->zoneRange();
// create new zone labels if we're shading
if (parent->shadeZones() && zones && *zones && (zone_range >= 0)) {
QList <int> zone_lows = (*zones)->getZoneLows(zone_range);
QList <QString> zone_names = (*zones)->getZoneNames(zone_range);
int num_zones = zone_lows.size();
assert(zone_names.size() == num_zones);
if (zone_number < num_zones) {
watts =
(
(zone_number + 1 < num_zones) ?
0.5 * (zone_lows[zone_number] + zone_lows[zone_number + 1]) :
(
(zone_number > 0) ?
(1.5 * zone_lows[zone_number] - 0.5 * zone_lows[zone_number - 1]) :
2.0 * zone_lows[zone_number]
)
);
Zones **zones = rideItem->zones;
int zone_range = rideItem->zoneRange();
text = QwtText(zone_names[zone_number]);
text.setFont(QFont("Helvetica",24, QFont::Bold));
QColor text_color = zoneColor(zone_number, num_zones);
text_color.setAlpha(64);
text.setColor(text_color);
}
}
// create new zone labels if we're shading
if (parent->shadeZones() && zones && *zones && (zone_range >= 0)) {
QList <int> zone_lows = (*zones)->getZoneLows(zone_range);
QList <QString> zone_names = (*zones)->getZoneNames(zone_range);
int num_zones = zone_lows.size();
assert(zone_names.size() == num_zones);
if (zone_number < num_zones) {
watts =
(
(zone_number + 1 < num_zones) ?
0.5 * (zone_lows[zone_number] + zone_lows[zone_number + 1]) :
(
(zone_number > 0) ?
(1.5 * zone_lows[zone_number] - 0.5 * zone_lows[zone_number - 1]) :
2.0 * zone_lows[zone_number]
)
);
setZ(1.0 + zone_number / 100.0);
}
virtual int rtti() const
{
return QwtPlotItem::Rtti_PlotUserItem;
}
text = QwtText(zone_names[zone_number]);
text.setFont(QFont("Helvetica",24, QFont::Bold));
QColor text_color = zoneColor(zone_number, num_zones);
text_color.setAlpha(64);
text.setColor(text_color);
}
}
void draw(QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &yMap,
const QRect &rect) const
{
if (parent->shadeZones()) {
int x = (rect.left() + rect.right()) / 2;
int y = yMap.transform(watts);
setZ(1.0 + zone_number / 100.0);
}
virtual int rtti() const
{
return QwtPlotItem::Rtti_PlotUserItem;
}
// the following code based on source for QwtPlotMarker::draw()
QRect tr(QPoint(0, 0), text.textSize(painter->font()));
tr.moveCenter(QPoint(x, y));
text.draw(painter, tr);
}
}
void draw(QPainter *painter,
const QwtScaleMap &, const QwtScaleMap &yMap,
const QRect &rect) const
{
if (parent->shadeZones()) {
int x = (rect.left() + rect.right()) / 2;
int y = yMap.transform(watts);
// the following code based on source for QwtPlotMarker::draw()
QRect tr(QPoint(0, 0), text.textSize(painter->font()));
tr.moveCenter(QPoint(x, y));
text.draw(painter, tr);
}
}
};
@@ -176,9 +176,9 @@ AllPlot::AllPlot(QWidget *parent):
smooth(30), bydist(false),
shade_zones(false)
{
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
unit = settings->value(GC_UNIT);
useMetricUnits = (unit.toString() == "Metric");
// create a background object for shading
@@ -236,7 +236,7 @@ AllPlot::AllPlot(QWidget *parent):
struct DataPoint {
double time, hr, watts, speed, cad, alt;
int inter;
DataPoint(double t, double h, double w, double s, double c, double a, int i) :
DataPoint(double t, double h, double w, double s, double c, double a, int i) :
time(t), hr(h), watts(w), speed(s), cad(c), alt(a), inter(i) {}
};
@@ -254,18 +254,18 @@ void AllPlot::refreshZoneLabels()
zoneLabels.clear();
if (rideItem) {
int zone_range = rideItem->zoneRange();
Zones **zones = rideItem->zones;
int zone_range = rideItem->zoneRange();
Zones **zones = rideItem->zones;
// generate labels for existing zones
if (zones && *zones && (zone_range >= 0)) {
int num_zones = (*zones)->numZones(zone_range);
for (int z = 0; z < num_zones; z ++) {
AllPlotZoneLabel *label = new AllPlotZoneLabel(this, z);
label->attach(this);
zoneLabels.append(label);
}
}
// generate labels for existing zones
if (zones && *zones && (zone_range >= 0)) {
int num_zones = (*zones)->numZones(zone_range);
for (int z = 0; z < num_zones; z ++) {
AllPlotZoneLabel *label = new AllPlotZoneLabel(this, z);
label->attach(this);
zoneLabels.append(label);
}
}
}
}
@@ -278,16 +278,16 @@ AllPlot::recalc()
int rideTimeSecs = (int) ceil(timeArray[arrayLength - 1]);
if (rideTimeSecs > 7*24*60*60) {
QwtArray<double> data;
if (!wattsArray.empty())
wattsCurve->setData(data, data);
if (!hrArray.empty())
hrCurve->setData(data, data);
if (!speedArray.empty())
speedCurve->setData(data, data);
if (!cadArray.empty())
cadCurve->setData(data, data);
if (!altArray.empty())
altCurve->setData(data, data);
if (!wattsArray.empty())
wattsCurve->setData(data, data);
if (!hrArray.empty())
hrCurve->setData(data, data);
if (!speedArray.empty())
speedCurve->setData(data, data);
if (!cadArray.empty())
cadCurve->setData(data, data);
if (!altArray.empty())
altCurve->setData(data, data);
return;
}
double totalWatts = 0.0;
@@ -313,7 +313,7 @@ AllPlot::recalc()
int lastInterval = 0; //Detect if we hit a new interval
for (int secs = 0; ((secs < smooth)
for (int secs = 0; ((secs < smooth)
&& (secs < rideTimeSecs)); ++secs) {
smoothWatts[secs] = 0.0;
smoothHr[secs] = 0.0;
@@ -328,22 +328,22 @@ AllPlot::recalc()
for (int secs = smooth; secs <= rideTimeSecs; ++secs) {
while ((i < arrayLength) && (timeArray[i] <= secs)) {
DataPoint dp(timeArray[i],
(!hrArray.empty() ? hrArray[i] : 0),
(!wattsArray.empty() ? wattsArray[i] : 0),
(!hrArray.empty() ? hrArray[i] : 0),
(!wattsArray.empty() ? wattsArray[i] : 0),
(!speedArray.empty() ? speedArray[i] : 0),
(!cadArray.empty() ? cadArray[i] : 0),
(!altArray.empty() ? altArray[i] : 0),
interArray[i]);
(!cadArray.empty() ? cadArray[i] : 0),
(!altArray.empty() ? altArray[i] : 0),
interArray[i]);
if (!wattsArray.empty())
totalWatts += wattsArray[i];
if (!hrArray.empty())
totalHr += hrArray[i];
if (!speedArray.empty())
totalSpeed += speedArray[i];
if (!cadArray.empty())
totalCad += cadArray[i];
if (!altArray.empty())
totalAlt += altArray[i];
if (!hrArray.empty())
totalHr += hrArray[i];
if (!speedArray.empty())
totalSpeed += speedArray[i];
if (!cadArray.empty())
totalCad += cadArray[i];
if (!altArray.empty())
totalAlt += altArray[i];
totalDist = distanceArray[i];
list.append(dp);
//Figure out when and if we have a new interval..
@@ -376,7 +376,7 @@ AllPlot::recalc()
smoothHr[secs] = totalHr / list.size();
smoothSpeed[secs] = totalSpeed / list.size();
smoothCad[secs] = totalCad / list.size();
smoothAltitude[secs] = totalAlt / list.size();
smoothAltitude[secs] = totalAlt / list.size();
}
smoothDistance[secs] = totalDist;
smoothTime[secs] = secs / 60.0;
@@ -387,9 +387,9 @@ AllPlot::recalc()
int totalPoints = rideTimeSecs + 1 - startingIndex;
// set curves
if (!wattsArray.empty())
wattsCurve->setData(xaxis.data() + startingIndex, smoothWatts.data() + startingIndex, totalPoints);
wattsCurve->setData(xaxis.data() + startingIndex, smoothWatts.data() + startingIndex, totalPoints);
if (!hrArray.empty())
hrCurve->setData(xaxis.data() + startingIndex, smoothHr.data() + startingIndex, totalPoints);
hrCurve->setData(xaxis.data() + startingIndex, smoothHr.data() + startingIndex, totalPoints);
if (!speedArray.empty())
speedCurve->setData(xaxis.data() + startingIndex, smoothSpeed.data() + startingIndex, totalPoints);
if (!cadArray.empty())
@@ -434,8 +434,8 @@ AllPlot::setYMax()
if (wattsCurve->isVisible()) {
setAxisTitle(yLeft, "Watts");
setAxisScale(yLeft, 0.0, 1.05 * wattsCurve->maxYValue());
setAxisLabelRotation(yLeft,270);
setAxisLabelAlignment(yLeft,Qt::AlignVCenter);
setAxisLabelRotation(yLeft,270);
setAxisLabelAlignment(yLeft,Qt::AlignVCenter);
}
if (hrCurve->isVisible() || cadCurve->isVisible()) {
double ymax = 0;
@@ -450,22 +450,22 @@ AllPlot::setYMax()
}
setAxisTitle(yLeft2, labels.join(" / "));
setAxisScale(yLeft2, 0.0, 1.05 * ymax);
setAxisLabelRotation(yLeft2,270);
setAxisLabelAlignment(yLeft2,Qt::AlignVCenter);
setAxisLabelRotation(yLeft2,270);
setAxisLabelAlignment(yLeft2,Qt::AlignVCenter);
}
if (speedCurve->isVisible()) {
setAxisTitle(yRight, (useMetricUnits ? "KPH" : "MPH"));
setAxisScale(yRight, 0.0, 1.05 * speedCurve->maxYValue());
setAxisLabelRotation(yRight,90);
setAxisLabelAlignment(yRight,Qt::AlignVCenter);
setAxisLabelRotation(yRight,90);
setAxisLabelAlignment(yRight,Qt::AlignVCenter);
}
if (altCurve->isVisible()) {
setAxisTitle(yRight2, useMetricUnits ? "Meters" : "Feet");
double ymin = altCurve->minYValue();
double ymax = qMax(ymin + 100, 1.05 * altCurve->maxYValue());
setAxisScale(yRight2, ymin, ymax);
setAxisLabelRotation(yRight2,90);
setAxisLabelAlignment(yRight2,Qt::AlignVCenter);
setAxisLabelRotation(yRight2,90);
setAxisLabelAlignment(yRight2,Qt::AlignVCenter);
altCurve->setBaseline(ymin);
}
@@ -493,73 +493,73 @@ AllPlot::setData(RideItem *_rideItem)
RideFile *ride = rideItem->ride;
if (ride) {
setTitle(ride->startTime().toString(GC_DATETIME_FORMAT));
setTitle(ride->startTime().toString(GC_DATETIME_FORMAT));
const RideFileDataPresent *dataPresent = ride->areDataPresent();
int npoints = ride->dataPoints().size();
wattsArray.resize(dataPresent->watts ? npoints : 0);
hrArray.resize(dataPresent->hr ? npoints : 0);
speedArray.resize(dataPresent->kph ? npoints : 0);
cadArray.resize(dataPresent->cad ? npoints : 0);
altArray.resize(dataPresent->alt ? npoints : 0);
timeArray.resize(npoints);
interArray.resize(npoints);
distanceArray.resize(npoints);
const RideFileDataPresent *dataPresent = ride->areDataPresent();
int npoints = ride->dataPoints().size();
wattsArray.resize(dataPresent->watts ? npoints : 0);
hrArray.resize(dataPresent->hr ? npoints : 0);
speedArray.resize(dataPresent->kph ? npoints : 0);
cadArray.resize(dataPresent->cad ? npoints : 0);
altArray.resize(dataPresent->alt ? npoints : 0);
timeArray.resize(npoints);
interArray.resize(npoints);
distanceArray.resize(npoints);
// attach appropriate curves
wattsCurve->detach();
hrCurve->detach();
speedCurve->detach();
cadCurve->detach();
altCurve->detach();
if (!wattsArray.empty()) wattsCurve->attach(this);
if (!hrArray.empty()) hrCurve->attach(this);
if (!speedArray.empty()) speedCurve->attach(this);
if (!cadArray.empty()) cadCurve->attach(this);
if (!altArray.empty()) altCurve->attach(this);
// attach appropriate curves
wattsCurve->detach();
hrCurve->detach();
speedCurve->detach();
cadCurve->detach();
altCurve->detach();
if (!wattsArray.empty()) wattsCurve->attach(this);
if (!hrArray.empty()) hrCurve->attach(this);
if (!speedArray.empty()) speedCurve->attach(this);
if (!cadArray.empty()) cadCurve->attach(this);
if (!altArray.empty()) altCurve->attach(this);
arrayLength = 0;
QListIterator<RideFilePoint*> i(ride->dataPoints());
while (i.hasNext()) {
RideFilePoint *point = i.next();
timeArray[arrayLength] = point->secs;
if (!wattsArray.empty())
wattsArray[arrayLength] = max(0, point->watts);
if (!hrArray.empty())
hrArray[arrayLength] = max(0, point->hr);
if (!speedArray.empty())
speedArray[arrayLength] = max(0,
(useMetricUnits
? point->kph
: point->kph * MILES_PER_KM));
if (!cadArray.empty())
cadArray[arrayLength] = max(0, point->cad);
arrayLength = 0;
QListIterator<RideFilePoint*> i(ride->dataPoints());
while (i.hasNext()) {
RideFilePoint *point = i.next();
timeArray[arrayLength] = point->secs;
if (!wattsArray.empty())
wattsArray[arrayLength] = max(0, point->watts);
if (!hrArray.empty())
hrArray[arrayLength] = max(0, point->hr);
if (!speedArray.empty())
speedArray[arrayLength] = max(0,
(useMetricUnits
? point->kph
: point->kph * MILES_PER_KM));
if (!cadArray.empty())
cadArray[arrayLength] = max(0, point->cad);
if (!altArray.empty())
altArray[arrayLength] = (useMetricUnits
? point->alt
: point->alt * FEET_PER_METER);
interArray[arrayLength] = point->interval;
distanceArray[arrayLength] = max(0,
(useMetricUnits
? point->km
: point->km * MILES_PER_KM));
++arrayLength;
}
interArray[arrayLength] = point->interval;
distanceArray[arrayLength] = max(0,
(useMetricUnits
? point->km
: point->km * MILES_PER_KM));
++arrayLength;
}
recalc();
recalc();
}
else {
setTitle("no data");
wattsCurve->detach();
hrCurve->detach();
speedCurve->detach();
cadCurve->detach();
altCurve->detach();
setTitle("no data");
wattsCurve->detach();
hrCurve->detach();
speedCurve->detach();
cadCurve->detach();
altCurve->detach();
}
}
void
AllPlot::showPower(int id)
AllPlot::showPower(int id)
{
wattsCurve->setVisible(id < 2);
shade_zones = (id == 0);
@@ -568,7 +568,7 @@ AllPlot::showPower(int id)
}
void
AllPlot::showHr(int state)
AllPlot::showHr(int state)
{
assert(state != Qt::PartiallyChecked);
hrCurve->setVisible(state == Qt::Checked);
@@ -577,7 +577,7 @@ AllPlot::showHr(int state)
}
void
AllPlot::showSpeed(int state)
AllPlot::showSpeed(int state)
{
assert(state != Qt::PartiallyChecked);
speedCurve->setVisible(state == Qt::Checked);
@@ -586,7 +586,7 @@ AllPlot::showSpeed(int state)
}
void
AllPlot::showCad(int state)
AllPlot::showCad(int state)
{
assert(state != Qt::PartiallyChecked);
cadCurve->setVisible(state == Qt::Checked);
@@ -595,7 +595,7 @@ AllPlot::showCad(int state)
}
void
AllPlot::showAlt(int state)
AllPlot::showAlt(int state)
{
assert(state != Qt::PartiallyChecked);
altCurve->setVisible(state == Qt::Checked);
@@ -604,7 +604,7 @@ AllPlot::showAlt(int state)
}
void
AllPlot::showGrid(int state)
AllPlot::showGrid(int state)
{
assert(state != Qt::PartiallyChecked);
grid->setVisible(state == Qt::Checked);

View File

@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2007 Sean C. Rhea (srhea@srhea.net)
* 2009 Justin F. Knotzke (jknotzke@shampoo.ca)
*
@@ -6,12 +6,12 @@
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -62,10 +62,10 @@ void RideFile::writeAsCsv(QFile &file, bool bIsMetric) const
out << ",";
out << point->alt;
if (point->bs > 0.0) {
out << ",";
out << point->bs;
}
out << "\n";
out << ",";
out << point->bs;
}
out << "\n";
}
file.close();
@@ -73,16 +73,16 @@ void RideFile::writeAsCsv(QFile &file, bool bIsMetric) const
RideFileFactory *RideFileFactory::instance_;
RideFileFactory &RideFileFactory::instance()
{
if (!instance_)
RideFileFactory &RideFileFactory::instance()
{
if (!instance_)
instance_ = new RideFileFactory();
return *instance_;
}
int RideFileFactory::registerReader(const QString &suffix,
const QString &description,
RideFileReader *reader)
RideFileReader *reader)
{
assert(!readFuncs_.contains(suffix));
readFuncs_.insert(suffix, reader);
@@ -103,8 +103,8 @@ RideFileFactory::rideFileRegExp() const
return QRegExp(s.arg(suffixList.join("|")));
}
RideFile *RideFileFactory::openRideFile(QFile &file,
QStringList &errors) const
RideFile *RideFileFactory::openRideFile(QFile &file,
QStringList &errors) const
{
QString suffix = file.fileName();
int dot = suffix.lastIndexOf(".");
@@ -115,7 +115,7 @@ RideFile *RideFileFactory::openRideFile(QFile &file,
return reader->openRideFile(file, errors);
}
QStringList RideFileFactory::listRideFiles(const QDir &dir) const
QStringList RideFileFactory::listRideFiles(const QDir &dir) const
{
QStringList filters;
QMapIterator<QString,RideFileReader*> i(readFuncs_);
@@ -133,12 +133,12 @@ QStringList RideFileFactory::listRideFiles(const QDir &dir) const
return dir.entryList(filters, QDir::Files, QDir::Name|QDir::Reversed);
}
void RideFile::appendPoint(double secs, double cad, double hr, double km,
double kph, double nm, double watts, double alt,
void RideFile::appendPoint(double secs, double cad, double hr, double km,
double kph, double nm, double watts, double alt,
int interval, double bs)
{
dataPoints_.append(new RideFilePoint(secs, cad, hr, km, kph,
nm, watts, alt, interval,bs));
dataPoints_.append(new RideFilePoint(secs, cad, hr, km, kph,
nm, watts, alt, interval,bs));
dataPresent.secs |= (secs != 0);
dataPresent.cad |= (cad != 0);
dataPresent.hr |= (hr != 0);

View File

@@ -1,16 +1,16 @@
/*
/*
* Copyright (c) 2007 Sean C. Rhea (srhea@srhea.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -29,7 +29,7 @@
//
// RideFile, as the name suggests, represents the data stored in a ride file,
// regardless of what type of file it is (.raw, .srm, .csv).
//
//
// RideFilePoint represents the data for a single sample in a RideFile.
//
// RideFileReader is an abstract base class for function-objects that take a
@@ -40,16 +40,16 @@
// suffixes to the RideFileReader objects capable of converting those files
// into RideFile objects.
struct RideFilePoint
struct RideFilePoint
{
double secs, cad, hr, km, kph, nm, watts, alt;
int interval;
double bs; // to init in order
RideFilePoint() : secs(0.0), cad(0.0), hr(0.0), km(0.0), kph(0.0),
RideFilePoint() : secs(0.0), cad(0.0), hr(0.0), km(0.0), kph(0.0),
nm(0.0), watts(0.0), alt(0.0), interval(0), bs(0.0) {}
RideFilePoint(double secs, double cad, double hr, double km, double kph,
RideFilePoint(double secs, double cad, double hr, double km, double kph,
double nm, double watts, double alt, int interval, double bs) :
secs(secs), cad(cad), hr(hr), km(km), kph(kph), nm(nm),
secs(secs), cad(cad), hr(hr), km(km), kph(kph), nm(nm),
watts(watts), alt(alt), interval(interval), bs(bs) {}
};
@@ -59,17 +59,17 @@ struct RideFileDataPresent
// whether non-zero data of each field is present
RideFileDataPresent():
secs(false), cad(false), hr(false), km(false),
kph(false), nm(false), watts(false), alt(false), interval(false) {}
kph(false), nm(false), watts(false), alt(false), interval(false) {}
};
class RideFile
class RideFile
{
private:
QDateTime startTime_; // time of day that the ride started
double recIntSecs_; // recording interval in seconds
QList<RideFilePoint*> dataPoints_;
RideFileDataPresent dataPresent;
RideFileDataPresent dataPresent;
QString deviceType_;
public:
@@ -77,11 +77,11 @@ class RideFile
RideFile() : recIntSecs_(0.0), deviceType_("unknown") {}
RideFile(const QDateTime &startTime, double recIntSecs) :
startTime_(startTime), recIntSecs_(recIntSecs),
deviceType_("unknown") {}
deviceType_("unknown") {}
virtual ~RideFile() {
QListIterator<RideFilePoint*> i(dataPoints_);
while (i.hasNext())
while (i.hasNext())
delete i.next();
}
@@ -94,13 +94,14 @@ class RideFile
void setStartTime(const QDateTime &value) { startTime_ = value; }
void setRecIntSecs(double value) { recIntSecs_ = value; }
void setDeviceType(const QString &value) { deviceType_ = value; }
void appendPoint(double secs, double cad, double hr, double km,
double kph, double nm, double watts, double alt, int interval, double bs=0.0);
void appendPoint(double secs, double cad, double hr, double km,
double kph, double nm, double watts, double alt,
int interval, double bs=0.0);
void writeAsCsv(QFile &file, bool bIsMetric) const;
void resetDataPresent();
void resetDataPresent();
};
struct RideFileReader {

View File

@@ -1,16 +1,16 @@
/*
/*
* Copyright (c) 2006 Sean C. Rhea (srhea@srhea.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -28,9 +28,9 @@
#include <QtXml/QtXml>
RideItem::RideItem(int type,
QString path, QString fileName, const QDateTime &dateTime,
Zones **zones, QString notesFileName) :
QTreeWidgetItem(type), path(path), fileName(fileName),
QString path, QString fileName, const QDateTime &dateTime,
Zones **zones, QString notesFileName) :
QTreeWidgetItem(type), path(path), fileName(fileName),
dateTime(dateTime), ride(NULL), zones(zones), notesFileName(notesFileName)
{
setText(0, dateTime.toString("ddd"));
@@ -59,7 +59,7 @@ static void summarize(QString &intervals,
double &int_kph_sum,
double &int_secs_hr,
double &int_max_power,
double int_dur)
double int_dur)
{
double dur = int_dur;
double mile_len = (km_end - km_start) * MILES_PER_KM;
@@ -110,26 +110,26 @@ static void summarize(QString &intervals,
int_hrs.clear();
}
int RideItem::zoneRange()
int RideItem::zoneRange()
{
return (
(zones && *zones) ?
(*zones)->whichRange(dateTime.date()) :
-1
);
(zones && *zones) ?
(*zones)->whichRange(dateTime.date()) :
-1
);
}
int RideItem::numZones()
int RideItem::numZones()
{
if (zones && *zones) {
int zone_range = zoneRange();
return ((zone_range >= 0) ?
(*zones)->numZones(zone_range) :
0
);
int zone_range = zoneRange();
return ((zone_range >= 0) ?
(*zones)->numZones(zone_range) :
0
);
}
else
return 0;
return 0;
}
double RideItem::timeInZone(int zone)
@@ -141,15 +141,15 @@ double RideItem::timeInZone(int zone)
return time_in_zone[zone];
}
static const char *metricsXml =
static const char *metricsXml =
"<metrics>\n"
" <metric_group name=\"Totals\">\n"
" <metric name=\"workout_time\" display_name=\"Workout time\"\n"
" precision=\"0\"/>\n"
" precision=\"0\"/>\n"
" <metric name=\"time_riding\" display_name=\"Time riding\"\n"
" precision=\"0\"/>\n"
" precision=\"0\"/>\n"
" <metric name=\"total_distance\" display_name=\"Distance\"\n"
" precision=\"1\"/>\n"
" precision=\"1\"/>\n"
" <metric name=\"total_work\" display_name=\"Work\"\n"
" precision=\"0\"/>\n"
" <metric name=\"elevation_gain\" display_name=\"Elevation Gain\"\n"
@@ -192,7 +192,7 @@ RideItem::computeMetrics()
{
const QDateTime nilTime;
if ((computeMetricsTime != nilTime) &&
(!zones || !*zones || (computeMetricsTime >= (*zones)->modificationTime))) {
(!zones || !*zones || (computeMetricsTime >= (*zones)->modificationTime))) {
return;
}
@@ -245,14 +245,14 @@ RideItem::computeMetrics()
}
}
QString
QString
RideItem::htmlSummary()
{
if (summary.isEmpty() ||
(zones && *zones && (summaryGenerationTime < (*zones)->modificationTime))) {
// set defaults for zone range and number of zones
int zone_range = -1;
int num_zones = 0;
(zones && *zones && (summaryGenerationTime < (*zones)->modificationTime))) {
// set defaults for zone range and number of zones
int zone_range = -1;
int num_zones = 0;
summaryGenerationTime = QDateTime::currentDateTime();
@@ -266,27 +266,27 @@ RideItem::htmlSummary()
summary += "<br>" + i.next();
return summary;
}
summary = ("<p><center><h2>"
+ dateTime.toString("dddd MMMM d, yyyy, h:mm AP")
summary = ("<p><center><h2>"
+ dateTime.toString("dddd MMMM d, yyyy, h:mm AP")
+ "</h2><h3>Device Type: " + ride->deviceType() + "</h3>");
computeMetrics();
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
QVariant unit = settings->value(GC_UNIT);
if (zones &&
*zones &&
((zone_range = (*zones)->whichRange(dateTime.date())) >= 0) &&
((num_zones = (*zones)->numZones(zone_range)) > 0)
)
{
time_in_zone.clear();
time_in_zone.resize(num_zones);
}
*zones &&
((zone_range = (*zones)->whichRange(dateTime.date())) >= 0) &&
((num_zones = (*zones)->numZones(zone_range)) > 0)
)
{
time_in_zone.clear();
time_in_zone.resize(num_zones);
}
double secs_watts = 0.0;
QString intervals = "";
int interval_count = 0;
int last_interval = INT_MAX;
@@ -310,7 +310,7 @@ RideItem::htmlSummary()
if (last_interval != INT_MAX) {
summarize(intervals, last_interval,
km_start, km_end, int_watts_sum,
km_start, km_end, int_watts_sum,
int_hr_sum, int_hrs, int_cad_sum, int_kph_sum,
int_secs_hr, int_max_power, int_dur);
}
@@ -330,7 +330,7 @@ RideItem::htmlSummary()
int_watts_sum += point->watts * secs_delta;
if (point->watts > int_max_power)
int_max_power = point->watts;
if (num_zones > 0) {
if (num_zones > 0) {
int zone = (*zones)->whichZone(zone_range, point->watts);
if (zone >= 0)
time_in_zone[zone] += secs_delta;
@@ -351,7 +351,7 @@ RideItem::htmlSummary()
time_end = point->secs + secs_delta;
}
summarize(intervals, last_interval,
km_start, km_end, int_watts_sum,
km_start, km_end, int_watts_sum,
int_hr_sum, int_hrs, int_cad_sum, int_kph_sum,
int_secs_hr, int_max_power, int_dur);
@@ -427,7 +427,7 @@ RideItem::htmlSummary()
|| (groupNum == groups.size() - 1))
summary += "</tr></table>";
}
if (num_zones > 0) {
summary += "<h2>Power Zones</h2>";
summary += (*zones)->summarize(zone_range, time_in_zone);
@@ -438,7 +438,7 @@ RideItem::htmlSummary()
// and an integer < 30 when in an interval.
// We'll need to create a counter for the intervals
// rather than relying on the final data point's interval number.
if (interval_count > 1) {
if (interval_count > 1) {
summary += "<p><h2>Intervals</h2>\n<p>\n";
summary += "<table align=\"center\" width=\"90%\" ";
summary += "cellspacing=0 border=0><tr>";
@@ -475,7 +475,7 @@ RideItem::htmlSummary()
if (!errors.empty()) {
summary += "<p><h2>Errors reading file:</h2><ul>";
QStringListIterator i(errors);
QStringListIterator i(errors);
while(i.hasNext())
summary += " <li>" + i.next();
summary += "</ul>";