diff --git a/src/AllPlotWindow.cpp b/src/AllPlotWindow.cpp index 10e8b2381..c1d042740 100644 --- a/src/AllPlotWindow.cpp +++ b/src/AllPlotWindow.cpp @@ -25,7 +25,8 @@ #include #include -AllPlotWindow::AllPlotWindow(MainWindow *mainWindow) : QWidget(mainWindow) +AllPlotWindow::AllPlotWindow(MainWindow *mainWindow) : + QWidget(mainWindow), mainWindow(mainWindow) { QVBoxLayout *vlayout = new QVBoxLayout; @@ -130,12 +131,16 @@ AllPlotWindow::AllPlotWindow(MainWindow *mainWindow) : QWidget(mainWindow) this, SLOT(setSmoothingFromSlider())); connect(smoothLineEdit, SIGNAL(editingFinished()), this, SLOT(setSmoothingFromLineEdit())); + connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); } void -AllPlotWindow::setData(RideItem *ride) +AllPlotWindow::rideSelected() { + RideItem *ride = mainWindow->rideItem(); + if (!ride) + return; setAllPlotWidgets(ride); allPlot->setData(ride); allZoomer->setZoomBase(); diff --git a/src/AllPlotWindow.h b/src/AllPlotWindow.h index 092fd08e2..3e69164f0 100644 --- a/src/AllPlotWindow.h +++ b/src/AllPlotWindow.h @@ -34,18 +34,19 @@ class AllPlotWindow : public QWidget public: AllPlotWindow(MainWindow *mainWindow); - void setData(RideItem *ride); public slots: void setSmoothingFromSlider(); void setSmoothingFromLineEdit(); + void rideSelected(); void zonesChanged(); protected: void setAllPlotWidgets(RideItem *rideItem); + MainWindow *mainWindow; AllPlot *allPlot; QwtPlotPanner *allPanner; QwtPlotZoomer *allZoomer; diff --git a/src/CriticalPowerWindow.cpp b/src/CriticalPowerWindow.cpp index 91ad7b393..4dc38d0c0 100644 --- a/src/CriticalPowerWindow.cpp +++ b/src/CriticalPowerWindow.cpp @@ -30,7 +30,7 @@ #include CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) : - QWidget(parent), home(home), mainWindow(parent) + QWidget(parent), home(home), mainWindow(parent), active(false) { QVBoxLayout *vlayout = new QVBoxLayout; @@ -99,6 +99,7 @@ CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) : this, SLOT(seasonSelected(int))); connect(yAxisCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setEnergyMode(int))); + connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected())); } void @@ -115,11 +116,25 @@ CriticalPowerWindow::deleteCpiFile(QString rideFilename) } void -CriticalPowerWindow::setData(RideItem *ride) +CriticalPowerWindow::setActive(bool new_value) { - currentRide = ride; - cpintPlot->calculate(ride); - cpintSetCPButton->setEnabled(cpintPlot->cp > 0); + bool was_active = active; + active = new_value; + if (active && !was_active) { + currentRide = mainWindow->rideItem(); + if (currentRide) + cpintPlot->calculate(currentRide); + } +} + +void +CriticalPowerWindow::rideSelected() +{ + currentRide = mainWindow->rideItem(); + if (active && currentRide) { + cpintPlot->calculate(currentRide); + cpintSetCPButton->setEnabled(cpintPlot->cp > 0); + } } void diff --git a/src/CriticalPowerWindow.h b/src/CriticalPowerWindow.h index c5accaebe..779b65e4b 100644 --- a/src/CriticalPowerWindow.h +++ b/src/CriticalPowerWindow.h @@ -37,12 +37,13 @@ class CriticalPowerWindow : public QWidget void newRideAdded(); void deleteCpiFile(QString filename); - void setData(RideItem *ride); + void setActive(bool value); protected slots: void cpintSetCPButtonClicked(); void pickerMoved(const QPoint &pos); + void rideSelected(); void seasonSelected(int season); void setEnergyMode(int index); @@ -61,6 +62,7 @@ class CriticalPowerWindow : public QWidget void addSeasons(); QList seasons; RideItem *currentRide; + bool active; }; #endif // _GC_CriticalPowerWindow_h diff --git a/src/HistogramWindow.cpp b/src/HistogramWindow.cpp index 61995c324..ab3988ca5 100644 --- a/src/HistogramWindow.cpp +++ b/src/HistogramWindow.cpp @@ -24,7 +24,8 @@ #include #include -HistogramWindow::HistogramWindow(MainWindow *mainWindow) : QWidget(mainWindow) +HistogramWindow::HistogramWindow(MainWindow *mainWindow) : + QWidget(mainWindow), mainWindow(mainWindow) { QVBoxLayout *vlayout = new QVBoxLayout; QHBoxLayout *binWidthLayout = new QHBoxLayout; @@ -72,12 +73,16 @@ HistogramWindow::HistogramWindow(MainWindow *mainWindow) : QWidget(mainWindow) this, SLOT(setWithZerosFromCheckBox())); connect(histParameterCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setHistSelection(int))); + connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); } void -HistogramWindow::setData(RideItem *ride) +HistogramWindow::rideSelected() { + RideItem *ride = mainWindow->rideItem(); + if (!ride) + return; // set the histogram data powerHist->setData(ride); // make sure the histogram has a legal selection diff --git a/src/HistogramWindow.h b/src/HistogramWindow.h index ccc5b62d5..6f64d6234 100644 --- a/src/HistogramWindow.h +++ b/src/HistogramWindow.h @@ -36,10 +36,10 @@ class HistogramWindow : public QWidget public: HistogramWindow(MainWindow *mainWindow); - void setData(RideItem *ride); public slots: + void rideSelected(); void zonesChanged(); protected slots: @@ -56,6 +56,7 @@ class HistogramWindow : public QWidget void setHistTextValidator(); void setHistBinWidthText(); + MainWindow *mainWindow; PowerHist *powerHist; QSlider *binWidthSlider; QLineEdit *binWidthLineEdit; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b459ee1f1..594b8a5e1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -559,40 +559,30 @@ void MainWindow::treeWidgetSelectionChanged() { assert(treeWidget->selectedItems().size() <= 1); - if (treeWidget->selectedItems().isEmpty()) { - rideSummaryWindow->setData(NULL); - return; + if (treeWidget->selectedItems().isEmpty()) + ride = NULL; + else { + QTreeWidgetItem *which = treeWidget->selectedItems().first(); + if (which->type() != RIDE_TYPE) + ride = NULL; + else + ride = (RideItem*) which; } + rideSelected(); - QTreeWidgetItem *which = treeWidget->selectedItems().first(); - if (which->type() != RIDE_TYPE) { - rideSummaryWindow->setData(NULL); - return; - } + if (!ride) + return; - ride = (RideItem*) which; calendar->setSelectedDate(ride->dateTime.date()); - if (ride) { - rideSummaryWindow->setData(ride); - allPlotWindow->setData(ride); - histogramWindow->setData(ride); - pfPvWindow->setData(ride); - - // turn off tabs that don't make sense for manual file entry - if (ride->ride && ride->ride->deviceType() == QString("Manual CSV")) { - tabWidget->setTabEnabled(3,false); // Power Histogram - tabWidget->setTabEnabled(4,false); // PF/PV Plot - } - else { - tabWidget->setTabEnabled(3,true); // Power Histogram - tabWidget->setTabEnabled(4,true); // PF/PV Plot - } + // turn off tabs that don't make sense for manual file entry + if (ride->ride && ride->ride->deviceType() == QString("Manual CSV")) { + tabWidget->setTabEnabled(3,false); // Power Histogram + tabWidget->setTabEnabled(4,false); // PF/PV Plot + } + else { + tabWidget->setTabEnabled(3,true); // Power Histogram + tabWidget->setTabEnabled(4,true); // PF/PV Plot } - if (tabWidget->currentIndex() == 2) - criticalPowerWindow->setData(ride); - - // generate a weekly summary of the week associated with the current ride - weeklySummaryWindow->generateWeeklySummary(ride, allRides, zones()); saveAndOpenNotes(); } @@ -818,17 +808,8 @@ MainWindow::setCriticalPower(int cp) void MainWindow::tabChanged(int index) { - if (index == 2) { - if (treeWidget->selectedItems().size() == 1) { - QTreeWidgetItem *which = treeWidget->selectedItems().first(); - if (which->type() == RIDE_TYPE) { - RideItem *ride = (RideItem*) which; - criticalPowerWindow->setData(ride); - return; - } - } - } - else if (index == 6) { + criticalPowerWindow->setActive(index == 2); + if (index == 6) { // Performance Manager performanceManagerWindow->replot(home,allRides); } diff --git a/src/MainWindow.h b/src/MainWindow.h index f7cbd142c..1ed4dfad7 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -60,6 +60,7 @@ class MainWindow : public QMainWindow RealtimeWindow *realtimeWindow; // public so config dialog can notify it of changes config const Zones *zones() const { return zones_; } + RideItem *rideItem() const { return ride; } protected: @@ -73,6 +74,7 @@ class MainWindow : public QMainWindow signals: + void rideSelected(); void zonesChanged(); private slots: diff --git a/src/PfPvWindow.cpp b/src/PfPvWindow.cpp index 273bd1221..fba4b57f3 100644 --- a/src/PfPvWindow.cpp +++ b/src/PfPvWindow.cpp @@ -22,7 +22,8 @@ #include "RideItem.h" #include -PfPvWindow::PfPvWindow(MainWindow *mainWindow) : QWidget(mainWindow) +PfPvWindow::PfPvWindow(MainWindow *mainWindow) : + QWidget(mainWindow), mainWindow(mainWindow) { QVBoxLayout *vlayout = new QVBoxLayout; QHBoxLayout *qaLayout = new QHBoxLayout; @@ -66,12 +67,16 @@ PfPvWindow::PfPvWindow(MainWindow *mainWindow) : QWidget(mainWindow) this, SLOT(setQaCLFromLineEdit())); connect(shadeZonesPfPvCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setShadeZonesPfPvFromCheckBox())); + connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(mainWindow, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); } void -PfPvWindow::setData(RideItem *ride) +PfPvWindow::rideSelected() { + RideItem *ride = mainWindow->rideItem(); + if (!ride) + return; pfPvPlot->setData(ride); // update the QLabel widget with the CP value set in PfPvPlot::setData() qaCPValue->setText(QString("%1").arg(pfPvPlot->getCP())); diff --git a/src/PfPvWindow.h b/src/PfPvWindow.h index e9c0d75f3..0bd22df9b 100644 --- a/src/PfPvWindow.h +++ b/src/PfPvWindow.h @@ -34,10 +34,10 @@ class PfPvWindow : public QWidget public: PfPvWindow(MainWindow *mainWindow); - void setData(RideItem *item); public slots: + void rideSelected(); void zonesChanged(); protected slots: @@ -49,6 +49,7 @@ class PfPvWindow : public QWidget protected: + MainWindow *mainWindow; PfPvPlot *pfPvPlot; QCheckBox *shadeZonesPfPvCheckBox; QLineEdit *qaCPValue; diff --git a/src/RideSummaryWindow.cpp b/src/RideSummaryWindow.cpp index d2d7d49ca..854863bc3 100644 --- a/src/RideSummaryWindow.cpp +++ b/src/RideSummaryWindow.cpp @@ -31,27 +31,21 @@ #include RideSummaryWindow::RideSummaryWindow(MainWindow *mainWindow) : - QWidget(mainWindow), mainWindow(mainWindow), rideItem(NULL) + QWidget(mainWindow), mainWindow(mainWindow) { QVBoxLayout *vlayout = new QVBoxLayout; rideSummary = new QTextEdit(this); rideSummary->setReadOnly(true); vlayout->addWidget(rideSummary); + connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(refresh())); connect(mainWindow, SIGNAL(zonesChanged()), this, SLOT(refresh())); setLayout(vlayout); } -void -RideSummaryWindow::setData(RideItem *ride) -{ - rideItem = ride; - refresh(); -} - void RideSummaryWindow::refresh() { - if (!rideItem) { + if (!mainWindow->rideItem()) { rideSummary->clear(); return; } @@ -164,6 +158,7 @@ RideSummaryWindow::htmlSummary() const { QString summary; + RideItem *rideItem = mainWindow->rideItem(); QFile file(rideItem->path + "/" + rideItem->fileName); QStringList errors; RideFile *ride = RideFileFactory::instance().openRideFile(file, errors); diff --git a/src/RideSummaryWindow.h b/src/RideSummaryWindow.h index 58964e8dc..14b8ed9d9 100644 --- a/src/RideSummaryWindow.h +++ b/src/RideSummaryWindow.h @@ -22,7 +22,6 @@ #include class MainWindow; -class RideItem; class QTextEdit; class RideSummaryWindow : public QWidget @@ -32,7 +31,6 @@ class RideSummaryWindow : public QWidget public: RideSummaryWindow(MainWindow *parent); - void setData(RideItem *ride); protected slots: @@ -43,7 +41,6 @@ class RideSummaryWindow : public QWidget QString htmlSummary() const; MainWindow *mainWindow; - RideItem *rideItem; QTextEdit *rideSummary; }; diff --git a/src/WeeklySummaryWindow.cpp b/src/WeeklySummaryWindow.cpp index e84b3b06f..c1fb3f706 100644 --- a/src/WeeklySummaryWindow.cpp +++ b/src/WeeklySummaryWindow.cpp @@ -133,24 +133,18 @@ WeeklySummaryWindow::WeeklySummaryWindow(bool useMetricUnits, setLayout(glayout); - connect(mainWindow, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); + connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(refresh())); + connect(mainWindow, SIGNAL(zonesChanged()), this, SLOT(refresh())); } void -WeeklySummaryWindow::zonesChanged() -{ - generateWeeklySummary(mainWindow->currentRideItem(), - mainWindow->allRideItems(), - mainWindow->zones()); -} - -void -WeeklySummaryWindow::generateWeeklySummary(const RideItem *ride, - const QTreeWidgetItem *allRides, - const Zones *zones) +WeeklySummaryWindow::refresh() { + const RideItem *ride = mainWindow->rideItem(); if (!ride) return; + const QTreeWidgetItem *allRides = mainWindow->allRideItems(); + const Zones *zones = mainWindow->zones(); QDate wstart = ride->dateTime.date(); wstart = wstart.addDays(Qt::Monday - wstart.dayOfWeek()); assert(wstart.dayOfWeek() == Qt::Monday); diff --git a/src/WeeklySummaryWindow.h b/src/WeeklySummaryWindow.h index 0ff72c280..c7aa2a37d 100644 --- a/src/WeeklySummaryWindow.h +++ b/src/WeeklySummaryWindow.h @@ -36,13 +36,10 @@ class WeeklySummaryWindow : public QWidget public: WeeklySummaryWindow(bool useMetricUnits, MainWindow *parent); - void generateWeeklySummary(const RideItem *ride, - const QTreeWidgetItem *allRides, - const Zones *zones); public slots: - void zonesChanged(); + void refresh(); protected: