combine setActive and rideSelected

And pay attention to MainWindow::activeTab, such that only the active
tab redraws itself when changing rides.  This change really increases
GC's responsiveness when scrolling through the ride list.
This commit is contained in:
Sean Rhea
2010-03-11 09:24:02 -05:00
parent 92725db36a
commit cd4fe5fe2e
17 changed files with 54 additions and 45 deletions

View File

@@ -200,6 +200,9 @@ AerolabWindow::AerolabWindow(MainWindow *mainWindow) :
void
AerolabWindow::rideSelected() {
if (mainWindow->activeTab() != this)
return;
RideItem *ride = mainWindow->rideItem();
if (!ride)

View File

@@ -228,6 +228,8 @@ AllPlotWindow::AllPlotWindow(MainWindow *mainWindow) :
void
AllPlotWindow::rideSelected()
{
if (mainWindow->activeTab() != this)
return;
RideItem *ride = mainWindow->rideItem();
if (!ride)
return;
@@ -245,6 +247,8 @@ AllPlotWindow::rideSelected()
void
AllPlotWindow::zonesChanged()
{
if (mainWindow->activeTab() != this)
return;
allPlot->refreshZoneLabels();
allPlot->replot();
}
@@ -252,6 +256,8 @@ AllPlotWindow::zonesChanged()
void
AllPlotWindow::intervalsChanged()
{
if (mainWindow->activeTab() != this)
return;
allPlot->refreshIntervalMarkers();
allPlot->replot();
foreach (AllPlot *plot, allPlots) {
@@ -263,6 +269,8 @@ AllPlotWindow::intervalsChanged()
void
AllPlotWindow::intervalSelected()
{
if (mainWindow->activeTab() != this)
return;
hideSelection();
}

View File

@@ -30,7 +30,7 @@
#include <QXmlSimpleReader>
CriticalPowerWindow::CriticalPowerWindow(const QDir &home, MainWindow *parent) :
QWidget(parent), home(home), mainWindow(parent), active(false)
QWidget(parent), home(home), mainWindow(parent), currentRide(NULL)
{
QVBoxLayout *vlayout = new QVBoxLayout;
@@ -115,25 +115,13 @@ CriticalPowerWindow::deleteCpiFile(QString rideFilename)
ride_filename_to_cpi_filename(rideFilename));
}
void
CriticalPowerWindow::setActive(bool new_value)
{
bool was_active = active;
active = new_value;
if (active && !was_active) {
currentRide = mainWindow->rideItem();
if (currentRide) {
cpintPlot->calculate(currentRide);
cpintSetCPButton->setEnabled(cpintPlot->cp > 0);
}
}
}
void
CriticalPowerWindow::rideSelected()
{
if (mainWindow->activeTab() != this)
return;
currentRide = mainWindow->rideItem();
if (active && currentRide) {
if (currentRide) {
cpintPlot->calculate(currentRide);
cpintSetCPButton->setEnabled(cpintPlot->cp > 0);
}

View File

@@ -37,7 +37,6 @@ class CriticalPowerWindow : public QWidget
void newRideAdded();
void deleteCpiFile(QString filename);
void setActive(bool value);
protected slots:
@@ -62,7 +61,6 @@ class CriticalPowerWindow : public QWidget
void addSeasons();
QList<Season> seasons;
RideItem *currentRide;
bool active;
};
#endif // _GC_CriticalPowerWindow_h

View File

@@ -156,6 +156,8 @@ GoogleMapControl::GoogleMapControl(MainWindow *mw)
void
GoogleMapControl::rideSelected()
{
if (parent->activeTab() != this)
return;
RideItem * ride = parent->rideItem();
if (!ride)

View File

@@ -81,6 +81,8 @@ HistogramWindow::HistogramWindow(MainWindow *mainWindow) :
void
HistogramWindow::rideSelected()
{
if (mainWindow->activeTab() != this)
return;
RideItem *ride = mainWindow->rideItem();
if (!ride)
return;
@@ -95,6 +97,8 @@ HistogramWindow::rideSelected()
void
HistogramWindow::intervalSelected()
{
if (mainWindow->activeTab() != this)
return;
RideItem *ride = mainWindow->rideItem();
if (!ride) return;
@@ -105,6 +109,8 @@ HistogramWindow::intervalSelected()
void
HistogramWindow::zonesChanged()
{
if (mainWindow->activeTab() != this)
return;
powerHist->refreshZoneLabels();
powerHist->replot();
}

View File

@@ -149,6 +149,7 @@ LTMWindow::LTMWindow(MainWindow *parent, bool useMetricUnits, const QDir &home)
connect(picker, SIGNAL(appended(const QPoint &)), ltmPlot, SLOT(pickerAppended(const QPoint &)));
// config changes or ride file activities cause a redraw/refresh (but only if active)
connect(main, SIGNAL(rideSelected()), this, SLOT(rideSelected(void)));
connect(main, SIGNAL(rideAdded(RideItem*)), this, SLOT(refresh(void)));
connect(main, SIGNAL(rideDeleted(RideItem*)), this, SLOT(refresh(void)));
connect(main, SIGNAL(configChanged()), this, SLOT(refresh()));
@@ -160,9 +161,9 @@ LTMWindow::~LTMWindow()
}
void
LTMWindow::setActive(bool me)
LTMWindow::rideSelected()
{
active = me;
active = (main->activeTab() == this);
if (active == true && metricDB == NULL) {
metricDB = new MetricAggregator(main, home, main->zones());
@@ -189,12 +190,12 @@ LTMWindow::refreshPlot()
void
LTMWindow::refresh()
{
// if config has changed get new useMetricUnits
boost::shared_ptr<QSettings> appsettings = GetApplicationSettings();
useMetricUnits = appsettings->value(GC_UNIT).toString() == "Metric";
// refresh for changes to ridefiles / zones
if (active == true && metricDB != NULL) {
// if config has changed get new useMetricUnits
boost::shared_ptr<QSettings> appsettings = GetApplicationSettings();
useMetricUnits = appsettings->value(GC_UNIT).toString() == "Metric";
results.clear(); // clear any old data
results = metricDB->getAllMetricsFor(settings.start, settings.end);
refreshPlot();

View File

@@ -74,10 +74,10 @@ class LTMWindow : public QWidget
MainWindow *main; // used by zones shader
LTMWindow(MainWindow *, bool, const QDir &);
~LTMWindow();
void setActive(bool);
LTMToolTip *toolTip() { return picker; }
public slots:
void rideSelected();
void refreshPlot();
void splitterMoved();
void dateRangeSelected(const Season *);

View File

@@ -1203,14 +1203,9 @@ MainWindow::setCriticalPower(int cp)
}
void
MainWindow::tabChanged(int index)
MainWindow::tabChanged(int)
{
criticalPowerWindow->setActive(tabWidget->widget(index) == criticalPowerWindow);
performanceManagerWindow->setActive(tabWidget->widget(index) == performanceManagerWindow);
ltmWindow->setActive(tabWidget->widget(index) == ltmWindow);
#ifdef GC_HAVE_QWTPLOT3D
modelWindow->setActive(tabWidget->widget(index) == modelWindow);
#endif
rideSelected();
}
void

View File

@@ -73,6 +73,7 @@ class MainWindow : public QMainWindow
void saveSilent(RideItem *);
bool saveRideSingleDialog(RideItem *);
RideItem *rideItem() const { return ride; }
const QWidget *activeTab() const { return tabWidget->currentWidget(); }
void notifyConfigChanged(); // used by ConfigDialog to notify MainWindow
// when config has changed - and to get a

View File

@@ -46,7 +46,7 @@ ModelWindow::addStandardChannels(QComboBox *box)
}
ModelWindow::ModelWindow(MainWindow *parent, const QDir &home) :
QWidget(parent), home(home), main(parent), active(false), ride(NULL)
QWidget(parent), home(home), main(parent), ride(NULL)
{
// Layouts
QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -165,7 +165,7 @@ ModelWindow::ModelWindow(MainWindow *parent, const QDir &home) :
// now connect up the widgets
connect(main, SIGNAL(rideSelected()), this, SLOT(rideSelected()));
connect(main, SIGNAL(intervalSelected()), this, SLOT(rideSelected()));
connect(main, SIGNAL(intervalSelected()), this, SLOT(intervalSelected()));
connect(presetValues, SIGNAL(currentIndexChanged(int)), this, SLOT(applyPreset(int)));
connect(xSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(setDirty()));
connect(ySelector, SIGNAL(currentIndexChanged(int)), this, SLOT(setDirty()));
@@ -182,17 +182,13 @@ ModelWindow::ModelWindow(MainWindow *parent, const QDir &home) :
connect(zpane, SIGNAL(valueChanged(int)), this, SLOT(setZPane(int)));
}
void
ModelWindow::setActive(bool active)
{
this->active = active;
if (active) setData(true);
}
void
ModelWindow::rideSelected()
{
if (main->activeTab() != this)
return;
ride = main->rideItem();
if (active) setData(true);
setData(true);
}
void
@@ -227,6 +223,8 @@ ModelWindow::setZPane(int z)
void
ModelWindow::intervalSelected()
{
if (main->activeTab() != this)
return;
setData(false);
}

View File

@@ -52,7 +52,6 @@ class ModelWindow : public QWidget
public:
ModelWindow(MainWindow *, const QDir &);
void setActive(bool);
public slots:
void rideSelected();

View File

@@ -101,6 +101,7 @@ PerformanceManagerWindow::PerformanceManagerWindow(MainWindow *mainWindow) :
connect(metricCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(metricChanged()));
connect(mainWindow, SIGNAL(configChanged()), this, SLOT(configChanged()));
connect(mainWindow, SIGNAL(rideSelected()), this, SLOT(rideSelected()));
}
PerformanceManagerWindow::~PerformanceManagerWindow()
@@ -125,9 +126,12 @@ void PerformanceManagerWindow::metricChanged()
replot();
}
void PerformanceManagerWindow::setActive(bool value)
void PerformanceManagerWindow::rideSelected()
{
if (active=value) replot();
bool wasActive = active;
active = (mainWindow->activeTab() == this);
if (!wasActive && active)
replot();
}
void PerformanceManagerWindow::replot()

View File

@@ -45,7 +45,6 @@ class PerformanceManagerWindow : public QWidget
PerformanceManagerWindow (MainWindow *mainWindow);
~PerformanceManagerWindow (void);
void setActive(bool value);
public slots:
@@ -54,6 +53,7 @@ class PerformanceManagerWindow : public QWidget
void replot();
void configChanged();
void metricChanged();
void rideSelected();
protected:

View File

@@ -88,6 +88,8 @@ PfPvWindow::PfPvWindow(MainWindow *mainWindow) :
void
PfPvWindow::rideSelected()
{
if (mainWindow->activeTab() != this)
return;
RideItem *ride = mainWindow->rideItem();
if (!ride)
return;

View File

@@ -47,6 +47,8 @@ RideSummaryWindow::RideSummaryWindow(MainWindow *mainWindow) :
void
RideSummaryWindow::refresh()
{
// XXX: activeTab is never equaly to RideSummaryWindow right now because
// it's wrapped in the summarySplitter in MainWindow.
if (!mainWindow->rideItem()) {
rideSummary->clear();
return;

View File

@@ -140,6 +140,8 @@ WeeklySummaryWindow::WeeklySummaryWindow(bool useMetricUnits,
void
WeeklySummaryWindow::refresh()
{
if (mainWindow->activeTab() != this)
return;
const RideItem *ride = mainWindow->rideItem();
if (!ride)
return;