mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
@@ -31,7 +31,7 @@
|
||||
#include <QXmlSimpleReader>
|
||||
|
||||
CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) :
|
||||
GcWindow(parent), home(home), mainWindow(parent), currentRide(NULL)
|
||||
GcWindow(parent), _dateRange("{00000000-0000-0000-0000-000000000001}"), home(home), mainWindow(parent), currentRide(NULL)
|
||||
{
|
||||
setInstanceName("Critical Power Window");
|
||||
|
||||
@@ -76,7 +76,8 @@ CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) :
|
||||
seriesCombo = new QComboBox(this);
|
||||
addSeries();
|
||||
cComboSeason = new QComboBox(this);
|
||||
addSeasons();
|
||||
seasons = parent->seasons;
|
||||
resetSeasons();
|
||||
cpintSetCPButton = new QPushButton(tr("&Save CP value"), this);
|
||||
cpintSetCPButton->setEnabled(false);
|
||||
cl->addWidget(cpintSetCPButton);
|
||||
@@ -103,6 +104,7 @@ CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) :
|
||||
connect(mainWindow, SIGNAL(configChanged()), this, SLOT(rideSelected()));
|
||||
connect(mainWindow, SIGNAL(rideAdded(RideItem*)), this, SLOT(newRideAdded(RideItem*)));
|
||||
connect(mainWindow, SIGNAL(rideDeleted(RideItem*)), this, SLOT(newRideAdded(RideItem*)));
|
||||
connect(seasons, SIGNAL(seasonsChanged()), this, SLOT(resetSeasons()));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -111,7 +113,7 @@ CriticalPowerWindow::newRideAdded(RideItem *here)
|
||||
// mine just got Zapped, a new rideitem would not be my current item
|
||||
if (here == currentRide) currentRide = NULL;
|
||||
|
||||
Season season = seasons.at(cComboSeason->currentIndex());
|
||||
Season season = seasons->seasons.at(cComboSeason->currentIndex());
|
||||
|
||||
// Refresh global curve if a ride is added during those dates
|
||||
if ((here->dateTime.date() >= season.getStart() || season.getStart() == QDate())
|
||||
@@ -302,33 +304,53 @@ void CriticalPowerWindow::addSeries()
|
||||
}
|
||||
}
|
||||
|
||||
void CriticalPowerWindow::addSeasons()
|
||||
{
|
||||
QFile seasonFile(home.absolutePath() + "/seasons.xml");
|
||||
QXmlInputSource source( &seasonFile );
|
||||
QXmlSimpleReader xmlReader;
|
||||
SeasonParser( handler );
|
||||
xmlReader.setContentHandler(&handler);
|
||||
xmlReader.setErrorHandler(&handler);
|
||||
xmlReader.parse( source );
|
||||
seasons = handler.getSeasons();
|
||||
Season season;
|
||||
season.setName(tr("All Seasons"));
|
||||
seasons.insert(0,season);
|
||||
/*----------------------------------------------------------------------
|
||||
* Seasons stuff
|
||||
*--------------------------------------------------------------------*/
|
||||
|
||||
foreach (Season season, seasons)
|
||||
|
||||
void
|
||||
CriticalPowerWindow::resetSeasons()
|
||||
{
|
||||
// remove seasons
|
||||
cComboSeason->clear();
|
||||
|
||||
//Store current selection
|
||||
QString previousDateRange = _dateRange;
|
||||
// insert seasons
|
||||
for (int i=0; i <seasons->seasons.count(); i++) {
|
||||
Season season = seasons->seasons.at(i);
|
||||
cComboSeason->addItem(season.getName());
|
||||
if (!seasons.empty()) {
|
||||
cComboSeason->setCurrentIndex(cComboSeason->count() - 1);
|
||||
Season season = seasons.last();
|
||||
cpintPlot->changeSeason(season.getStart(), season.getEnd());
|
||||
}
|
||||
// restore previous selection
|
||||
setDateRange(previousDateRange);
|
||||
}
|
||||
|
||||
QString
|
||||
CriticalPowerWindow::dateRange() const
|
||||
{
|
||||
return seasons->seasons[cComboSeason->currentIndex()].id();
|
||||
}
|
||||
|
||||
void
|
||||
CriticalPowerWindow::setDateRange(QString s)
|
||||
{
|
||||
QUuid find(s);
|
||||
|
||||
for(int i=0; i<seasons->seasons.count(); i++) {
|
||||
if (seasons->seasons[i].id() == find) {
|
||||
cComboSeason->setCurrentIndex(i);
|
||||
seasonSelected(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CriticalPowerWindow::seasonSelected(int iSeason)
|
||||
{
|
||||
if (iSeason >= seasons.count() || iSeason < 0) return;
|
||||
Season season = seasons.at(iSeason);
|
||||
if (iSeason >= seasons->seasons.count() || iSeason < 0) return;
|
||||
Season season = seasons->seasons.at(iSeason);
|
||||
_dateRange = season.id();
|
||||
cpintPlot->changeSeason(season.getStart(), season.getEnd());
|
||||
cpintPlot->calculate(currentRide);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,13 @@ class CriticalPowerWindow : public GcWindow
|
||||
G_OBJECT
|
||||
|
||||
// properties can be saved/restored/set by the layout manager
|
||||
Q_PROPERTY(int season READ season WRITE setSeason USER true)
|
||||
|
||||
Q_PROPERTY(QString dateRange READ dateRange WRITE setDateRange USER true)
|
||||
Q_PROPERTY(int mode READ mode WRITE setMode USER true)
|
||||
|
||||
// for retro compatibility
|
||||
Q_PROPERTY(int season READ season WRITE setSeason USER false)
|
||||
|
||||
public:
|
||||
|
||||
CriticalPowerWindow(const QDir &home, MainWindow *parent);
|
||||
@@ -44,11 +48,18 @@ class CriticalPowerWindow : public GcWindow
|
||||
void deleteCpiFile(QString filename);
|
||||
|
||||
// set/get properties
|
||||
int season() const { return cComboSeason->currentIndex(); }
|
||||
void setSeason(int x) { cComboSeason->setCurrentIndex(x); }
|
||||
// ---------------------------------------------------
|
||||
int mode() const { return seriesCombo->currentIndex(); }
|
||||
void setMode(int x) { seriesCombo->setCurrentIndex(x); }
|
||||
|
||||
// date ranges set/get the string from the treeWidget
|
||||
QString dateRange() const;
|
||||
void setDateRange(QString x);
|
||||
|
||||
// for retro compatibility
|
||||
int season() const { return cComboSeason->currentIndex(); }
|
||||
void setSeason(int x) { cComboSeason->setCurrentIndex(x); }
|
||||
|
||||
RideFile::SeriesType series() {
|
||||
return static_cast<RideFile::SeriesType>
|
||||
(seriesCombo->itemData(seriesCombo->currentIndex()).toInt());
|
||||
@@ -62,10 +73,13 @@ class CriticalPowerWindow : public GcWindow
|
||||
void rideSelected();
|
||||
void seasonSelected(int season);
|
||||
void setSeries(int index);
|
||||
void resetSeasons();
|
||||
|
||||
private:
|
||||
void updateCpint(double minutes);
|
||||
|
||||
QString _dateRange;
|
||||
|
||||
protected:
|
||||
|
||||
QDir home;
|
||||
@@ -79,9 +93,9 @@ class CriticalPowerWindow : public GcWindow
|
||||
QComboBox *cComboSeason;
|
||||
QPushButton *cpintSetCPButton;
|
||||
QwtPlotPicker *picker;
|
||||
void addSeasons();
|
||||
void addSeries();
|
||||
QList<Season> seasons;
|
||||
Seasons *seasons;
|
||||
QList<Season> seasonsList;
|
||||
RideItem *currentRide;
|
||||
QList<RideFile::SeriesType> seriesList;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user