diff --git a/src/CpintPlot.cpp b/src/CpintPlot.cpp index 69e2163ce..85fe3348f 100644 --- a/src/CpintPlot.cpp +++ b/src/CpintPlot.cpp @@ -29,6 +29,7 @@ #include "LogTimeScaleDraw.h" #include "LogTimeScaleEngine.h" #include "RideFile.h" +#include "Season.h" CpintPlot::CpintPlot( QString p @@ -695,6 +696,7 @@ CpintPlot::calculate(RideItem *rideItem) QStringList filters; filters << "*.cpi"; QStringList list = dir.entryList(filters, QDir::Files, QDir::Name); + list = filterForSeason(list, startDate, endDate); progress->setLabelText( existing + tr("Aggregating over all files.")); progress->setRange(0, list.size()); @@ -814,3 +816,39 @@ CpintPlot::showGrid(int state) grid->setVisible(state == Qt::Checked); replot(); } + +QStringList +CpintPlot::filterForSeason(QStringList cpints, QDate startDate, QDate endDate) +{ + QString cpi; + QDate cpiDate; + QStringListIterator cpis(cpints); + QStringList returnList; + + //Check to see if no date was assigned. + QDate nilDate; + if(startDate == nilDate) + return cpints; + + while (cpis.hasNext()) + { + cpi = cpis.next(); + cpiDate = cpi_filename_to_date(cpi); + if(cpiDate > startDate && cpiDate < endDate) + returnList << cpi; + + } + return returnList; +} + +void +CpintPlot::setStartDate(QDate _startDate) +{ + startDate = _startDate; +} + +void +CpintPlot::setEndDate(QDate _endDate) +{ + endDate = _endDate; +} diff --git a/src/CpintPlot.h b/src/CpintPlot.h index 42e7f20a8..b66f1cba3 100644 --- a/src/CpintPlot.h +++ b/src/CpintPlot.h @@ -52,7 +52,8 @@ class CpintPlot : public QwtPlot double cp, tau, t0; // CP model parameters void deriveCPParameters(); // derive the CP model parameters bool deleteCpiFile(QString filename); // delete a CPI file and clean up - + void setStartDate(QDate); + void setEndDate(QDate); public slots: @@ -78,11 +79,13 @@ class CpintPlot : public QwtPlot QList allCurves; QList allZoneLabels; void clear_CP_Curves(); - + QStringList filterForSeason(QStringList cpints, QDate startDate, QDate endDate); QwtPlotGrid *grid; - + QVector bests; QVector bestDates; + QDate startDate; + QDate endDate; Zones **zones; // pointer to power zones added djconnel 24Apr2009 diff --git a/src/CriticalPowerWindow.cpp b/src/CriticalPowerWindow.cpp index 684f5e55c..c73a0b832 100644 --- a/src/CriticalPowerWindow.cpp +++ b/src/CriticalPowerWindow.cpp @@ -23,12 +23,19 @@ #include "TimeUtils.h" #include #include +#include +#include "Season.h" +#include "SeasonParser.h" +#include +#include CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) : QWidget(parent), home(home), mainWindow(parent) { QVBoxLayout *vlayout = new QVBoxLayout; QHBoxLayout *cpintPickerLayout = new QHBoxLayout; + QLabel *cSeasonLabel = new QLabel(tr("Season"), this); + cComboSeason = new QComboBox(this); QLabel *cpintTimeLabel = new QLabel(tr("Interval Duration:"), this); cpintTimeValue = new QLineEdit("0 s"); QLabel *cpintTodayLabel = new QLabel(tr("Today:"), this); @@ -42,6 +49,10 @@ CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) : cpintSetCPButton = new QPushButton(tr("&Save CP value"), this); cpintSetCPButton->setEnabled(false); + addSeasons(); + + cpintPickerLayout->addWidget(cSeasonLabel); + cpintPickerLayout->addWidget(cComboSeason); cpintPickerLayout->addWidget(cpintTimeLabel); cpintPickerLayout->addWidget(cpintTimeValue); cpintPickerLayout->addWidget(cpintTodayLabel); @@ -64,6 +75,9 @@ CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) : SLOT(pickerMoved(const QPoint &))); connect(cpintSetCPButton, SIGNAL(clicked()), this, SLOT(cpintSetCPButtonClicked())); + connect(cComboSeason, SIGNAL(currentIndexChanged(int)), + this, SLOT(seasonSelected(int))); + } void @@ -82,6 +96,7 @@ CriticalPowerWindow::deleteCpiFile(QString rideFilename) void CriticalPowerWindow::setData(RideItem *ride) { + currentRide = ride; cpintPlot->calculate(ride); cpintSetCPButton->setEnabled(cpintPlot->cp > 0); } @@ -158,3 +173,37 @@ CriticalPowerWindow::pickerMoved(const QPoint &pos) } } +void CriticalPowerWindow::addSeasons() +{ + QFile seasonFile(home.absolutePath() + "/seasons.xml"); + QXmlInputSource source( &seasonFile ); + QXmlSimpleReader xmlReader; + SeasonParser( handler ); + xmlReader.setContentHandler(&handler); + xmlReader.setErrorHandler(&handler); + bool ok = xmlReader.parse( source ); + if(!ok) + qWarning("Failed to parse seasons.xml"); + + seasons = handler.getSeasons(); + Season season; + season.setName("All Seasons"); + seasons.insert(0,season); + + for (int i = 0; i < seasons.size(); ++i) + { + season = seasons.at(i); + cComboSeason->addItem(season.getName()); + } +} + +void CriticalPowerWindow::seasonSelected(int iSeason) +{ + Season season = seasons.at(iSeason); + cpintPlot->setStartDate(season.getStart()); + cpintPlot->setEndDate(season.getEnd()); + cpintPlot->needToScanRides = true; + cpintPlot->calculate(currentRide); +} + + diff --git a/src/CriticalPowerWindow.h b/src/CriticalPowerWindow.h index 11586ff58..d6ca917d0 100644 --- a/src/CriticalPowerWindow.h +++ b/src/CriticalPowerWindow.h @@ -20,6 +20,7 @@ #define _GC_CriticalPowerWindow_h 1 #include +#include "Season.h" class CpintPlot; class MainWindow; @@ -42,6 +43,7 @@ class CriticalPowerWindow : public QWidget void cpintSetCPButtonClicked(); void pickerMoved(const QPoint &pos); + void seasonSelected(int season); protected: @@ -51,8 +53,12 @@ class CriticalPowerWindow : public QWidget QLineEdit *cpintTimeValue; QLineEdit *cpintTodayValue; QLineEdit *cpintAllValue; + QComboBox *cComboSeason; QPushButton *cpintSetCPButton; QwtPlotPicker *picker; + void addSeasons(); + QList seasons; + RideItem *currentRide; }; #endif // _GC_CriticalPowerWindow_h