introduce MainWindow rideSelected signal

...and use it to update the various tabs when a ride is selected.
This commit is contained in:
Sean Rhea
2009-12-10 12:13:47 -08:00
parent 4c7311e152
commit 2db45dc0c5
14 changed files with 84 additions and 83 deletions

View File

@@ -25,7 +25,8 @@
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>
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();

View File

@@ -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;

View File

@@ -30,7 +30,7 @@
#include <QXmlSimpleReader>
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

View File

@@ -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<Season> seasons;
RideItem *currentRide;
bool active;
};
#endif // _GC_CriticalPowerWindow_h

View File

@@ -24,7 +24,8 @@
#include <QtGui>
#include <assert.h>
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

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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:

View File

@@ -22,7 +22,8 @@
#include "RideItem.h"
#include <QtGui>
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()));

View File

@@ -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;

View File

@@ -31,27 +31,21 @@
#include <math.h>
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);

View File

@@ -22,7 +22,6 @@
#include <QWidget>
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;
};

View File

@@ -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);

View File

@@ -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: