Skip to content

Commit

Permalink
Refactor RideFile out of IntervalItem
Browse files Browse the repository at this point in the history
.. and a few nits to get Routes to compile, but it
   needs to be aligned to the intervalsUpdate() method
   in RideItem.
  • Loading branch information
liversedge committed May 22, 2015
1 parent 63dbaa2 commit 25c5b7f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
5 changes: 4 additions & 1 deletion src/AnalysisSidebar.cpp
Expand Up @@ -537,10 +537,13 @@ AnalysisSidebar::showIntervalMenu(const QPoint &pos)
// ZOOM IN AND OUT FOR ALL
QAction *actZoomOut = new QAction(tr("Zoom Out"), intervalTree);
QAction *actZoomInt = new QAction(tr("Zoom to interval"), intervalTree);
QAction *actRoute = new QAction(tr("Create as a route"), intervalTree);
connect(actZoomOut, SIGNAL(triggered(void)), this, SLOT(zoomOut(void)));
connect(actZoomInt, SIGNAL(triggered(void)), this, SLOT(zoomInterval(void)));
connect(actRoute, SIGNAL(triggered(void)), this, SLOT(createRouteIntervalSelected(void)));
menu.addAction(actZoomOut);
menu.addAction(actZoomInt);
menu.addAction(actRoute);

// EDIT / DELETE USER ONLY
if (isUser) {
Expand Down Expand Up @@ -854,7 +857,7 @@ AnalysisSidebar::zoomInterval()
void
AnalysisSidebar::createRouteIntervalSelected()
{
#if 0
#if 0 //WAIT FOR REFACTOR!!!!!!
// create a new route for this interval
context->athlete->routes->createRouteFromInterval(activeInterval);
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/IntervalItem.cpp
Expand Up @@ -21,22 +21,21 @@
#include "Context.h"
#include "Athlete.h"

IntervalItem::IntervalItem(const RideFile *ride, QString name, double start, double stop,
IntervalItem::IntervalItem(const RideItem *ride, QString name, double start, double stop,
double startKM, double stopKM, int displaySequence, QColor color,
RideFileInterval::IntervalType type)
{
this->name = name;
this->ride = ride;
this->start = start;
this->stop = stop;
this->startKM = startKM;
this->stopKM = stopKM;
this->displaySequence = displaySequence;
this->rideItem_ = NULL;
this->type = type;
this->color = color;
this->selected = false;
this->rideInterval = NULL;
this->rideItem_ = const_cast<RideItem*>(ride);
metrics_.fill(0, RideMetricFactory::instance().metricCount());
}

Expand Down
5 changes: 1 addition & 4 deletions src/IntervalItem.h
Expand Up @@ -26,15 +26,13 @@
#include <QLabel>
#include <QLineEdit>

class RideFile;

class IntervalItem
{

public:

// constructors and accessors
IntervalItem(const RideFile *, QString, double, double, double, double, int, QColor, RideFileInterval::IntervalType);
IntervalItem(const RideItem *, QString, double, double, double, double, int, QColor, RideFileInterval::IntervalType);
IntervalItem();

// ride item we are in
Expand Down Expand Up @@ -74,7 +72,6 @@ class IntervalItem
QVector<double> &metrics() { return metrics_; }

// extracted sample data
const RideFile *ride;
RideFileInterval *rideInterval;

// used by qSort()
Expand Down
29 changes: 10 additions & 19 deletions src/RideItem.cpp
Expand Up @@ -268,11 +268,9 @@ IntervalItem *
RideItem::newInterval(QString name, double start, double stop, double startKM, double stopKM)
{
// add a new interval to the end of the list
IntervalItem *add = new IntervalItem(ride(), name, start, stop, startKM, stopKM, 1,
IntervalItem *add = new IntervalItem(this, name, start, stop, startKM, stopKM, 1,
standardColor(intervals(RideFileInterval::USER).count()),
RideFileInterval::USER);
add->rideItem_ = this;

// add to RideFile
add->rideInterval = ride()->newInterval(name, start, stop);

Expand Down Expand Up @@ -666,7 +664,7 @@ RideItem::updateIntervals()
RideFilePoint *end = f->dataPoints().last();

// add entire ride using ride metrics
IntervalItem *entire = new IntervalItem(f, tr("Entire Activity"),
IntervalItem *entire = new IntervalItem(this, tr("Entire Activity"),
begin->secs, end->secs,
f->timeToDistance(begin->secs),
f->timeToDistance(end->secs),
Expand All @@ -676,11 +674,10 @@ RideItem::updateIntervals()

// same as the whole ride, not need to compute
entire->metrics() = metrics();
entire->rideItem_ = this;
entire->rideInterval = NULL;
intervals_ << entire;

int count = 1;
int count = 0;
foreach(RideFileInterval *interval, f->intervals()) {

// skip peaks, they're autodiscovered now
Expand All @@ -701,14 +698,13 @@ RideItem::updateIntervals()
if (interval->start >= interval->stop) continue;

// create a new interval item
IntervalItem *intervalItem = new IntervalItem(f, interval->name,
IntervalItem *intervalItem = new IntervalItem(this, interval->name,
interval->start, interval->stop,
f->timeToDistance(interval->start),
f->timeToDistance(interval->stop),
count,
standardColor(count++),
RideFileInterval::USER);
intervalItem->rideItem_ = this; // XXX will go when we refactor and be passed instead of ridefile
intervalItem->rideInterval = interval;
intervalItem->refresh(); // XXX will get called in constructore when refactor
intervals_ << intervalItem;
Expand Down Expand Up @@ -736,14 +732,13 @@ RideItem::updateIntervals()
// did we get one ?
if (results.count() > 0 && results[0].avg > 0 && results[0].stop > 0) {
// qDebug()<<"found"<<names[i]<<"peak power"<<results[0].start<<"-"<<results[0].stop<<"of"<<results[0].avg<<"watts";
IntervalItem *intervalItem = new IntervalItem(f, QString(tr("%1 (%2 watts)")).arg(names[i]).arg(int(results[0].avg)),
IntervalItem *intervalItem = new IntervalItem(this, QString(tr("%1 (%2 watts)")).arg(names[i]).arg(int(results[0].avg)),
results[0].start, results[0].stop,
f->timeToDistance(results[0].start),
f->timeToDistance(results[0].stop),
count++,
QColor(Qt::gray),
RideFileInterval::PEAKPOWER);
intervalItem->rideItem_ = this; // XXX will go when we refactor and be passed instead of ridefile
intervalItem->rideInterval = NULL;
intervalItem->refresh(); // XXX will get called in constructore when refactor
intervals_ << intervalItem;
Expand Down Expand Up @@ -1004,20 +999,19 @@ RideItem::updateIntervals()

IntervalItem *intervalItem=NULL;
if (x.quality >= 1.0f) {
intervalItem = new IntervalItem(f,
intervalItem = new IntervalItem(this,
QString(tr("TTE of %1 (%2 watts)")).arg(time_to_string(x.duration)).arg(x.joules/x.duration),
x.start, x.start+x.duration,
f->timeToDistance(x.start), f->timeToDistance(x.start+x.duration),
count++, QColor(Qt::red), RideFileInterval::TTE);
} else {
intervalItem = new IntervalItem(f,
intervalItem = new IntervalItem(this,
QString(tr("%3% EFFORT of %1 (%2 watts)")).arg(time_to_string(x.duration)).arg(x.joules/x.duration).arg(int(x.quality*100)),
x.start, x.start+x.duration,
f->timeToDistance(x.start), f->timeToDistance(x.start+x.duration),
count++, QColor(Qt::red), RideFileInterval::EFFORT);
}

intervalItem->rideItem_ = this; // XXX will go when we refactor
intervalItem->rideInterval = NULL;
intervalItem->refresh(); // XXX will get called in constructore when refactor
intervals_ << intervalItem;
Expand All @@ -1030,14 +1024,13 @@ RideItem::updateIntervals()

IntervalItem *intervalItem=NULL;

intervalItem = new IntervalItem(f,
intervalItem = new IntervalItem(this,
QString(tr("SPRINT of %1 secs (%2 watts)")).arg(x.duration).arg(x.joules/x.duration),
x.start, x.start+x.duration,
f->timeToDistance(x.start), f->timeToDistance(x.start+x.duration),
count++, QColor(Qt::red), RideFileInterval::SPRINT);


intervalItem->rideItem_ = this; // XXX will go when we refactor
intervalItem->rideInterval = NULL;
intervalItem->refresh(); // XXX will get called in constructore when refactor
intervals_ << intervalItem;
Expand Down Expand Up @@ -1137,14 +1130,13 @@ RideItem::updateIntervals()


// create a new interval item
IntervalItem *intervalItem = new IntervalItem(f, QString("Climb %1").arg(++hills),
IntervalItem *intervalItem = new IntervalItem(this, QString("Climb %1").arg(++hills),
pstart->secs, pstop->secs,
pstart->km,
pstop->km,
count++,
QColor(Qt::green),
RideFileInterval::CLIMB);
intervalItem->rideItem_ = this; // XXX will go when we refactor and be passed instead of ridefile
intervalItem->rideInterval = NULL;
intervalItem->refresh(); // XXX will get called in constructore when refactor
intervals_ << intervalItem;
Expand Down Expand Up @@ -1181,14 +1173,13 @@ RideItem::updateIntervals()
//qDebug() << "find ride "<< fileName <<" for " <<rideSegmentName;

// create a new interval item
IntervalItem *intervalItem = new IntervalItem(f, route->getName(),
IntervalItem *intervalItem = new IntervalItem(this, route->getName(),
_ride.start, _ride.stop,
f->timeToDistance(_ride.start),
f->timeToDistance(_ride.stop),
count++, // sequence defaults to count
QColor(Qt::gray),
RideFileInterval::ROUTE);
intervalItem->rideItem_ = this; // XXX will go when we refactor and be passed instead of ridefile
intervalItem->rideInterval = NULL;
intervalItem->refresh(); // XXX will get called in constructore when refactor
intervals_ << intervalItem;
Expand Down
2 changes: 1 addition & 1 deletion src/Route.cpp
Expand Up @@ -509,7 +509,7 @@ Routes::createRouteFromInterval(IntervalItem *activeInterval) {
// Construct the route with interval gps data
double dist = 0, lastLat = 0, lastLon = 0;

foreach (RideFilePoint *point, activeInterval->ride->dataPoints()) {
foreach (RideFilePoint *point, activeInterval->rideItem()->ride()->dataPoints()) {
if (point->secs >= activeInterval->start && point->secs < activeInterval->stop) {
if (lastLat != 0 && lastLon != 0 &&
point->lat != 0 && point->lon != 0 &&
Expand Down

0 comments on commit 25c5b7f

Please sign in to comment.