allow the user to hide tabs

...and remember their tab hiding preferences across restarts.
This commit is contained in:
Sean Rhea
2010-03-09 12:43:38 -05:00
parent e47847c19e
commit f523fd5d3c
5 changed files with 74 additions and 27 deletions

View File

@@ -139,7 +139,7 @@ using namespace gm;
#define GOOGLE_KEY "ABQIAAAAS9Z2oFR8vUfLGYSzz40VwRQ69UCJw2HkJgivzGoninIyL8-QPBTtnR-6pM84ljHLEk3PDql0e2nJmg"
GoogleMapControl::GoogleMapControl(MainWindow *mw, QTabWidget *tw)
GoogleMapControl::GoogleMapControl(MainWindow *mw)
{
parent = mw;
view = new QWebView();
@@ -151,8 +151,6 @@ GoogleMapControl::GoogleMapControl(MainWindow *mw, QTabWidget *tw)
connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
loadingPage = false;
newRideToLoad = false;
tw->addTab(this, tr("Map"));
}
void

View File

@@ -77,7 +77,7 @@ Q_OBJECT
void resizeEvent(QResizeEvent *);
public:
GoogleMapControl(MainWindow *,QTabWidget *);
GoogleMapControl(MainWindow *);
virtual ~GoogleMapControl() { }
};

View File

@@ -245,11 +245,11 @@ MainWindow::MainWindow(const QDir &home) :
summarySizes.append(200);
summarySplitter->setSizes(summarySizes);
tabWidget->addTab(summarySplitter, tr("Ride Summary"));
tabs.append(TabInfo(summarySplitter, tr("Ride Summary")));
/////////////////////////// Ride Plot Tab ///////////////////////////
allPlotWindow = new AllPlotWindow(this);
tabWidget->addTab(allPlotWindow, tr("Ride Plot"));
tabs.append(TabInfo(allPlotWindow, tr("Ride Plot")));
splitter->addWidget(tabWidget);
splitter->setCollapsible(1, true);
@@ -266,52 +266,53 @@ MainWindow::MainWindow(const QDir &home) :
////////////////////// Critical Power Plot Tab //////////////////////
criticalPowerWindow = new CriticalPowerWindow(home, this);
tabWidget->addTab(criticalPowerWindow, tr("Critical Power"));
tabs.append(TabInfo(criticalPowerWindow, tr("Critical Power")));
//////////////////////// Power Histogram Tab ////////////////////////
histogramWindow = new HistogramWindow(this);
tabWidget->addTab(histogramWindow, tr("Histograms"));
tabs.append(TabInfo(histogramWindow, tr("Histograms")));
//////////////////////// Pedal Force/Velocity Plot ////////////////////////
pfPvWindow = new PfPvWindow(this);
tabWidget->addTab(pfPvWindow, tr("PF/PV"));
tabs.append(TabInfo(pfPvWindow, tr("PF/PV")));
//////////////////////// 3d Model Window ////////////////////////////
#ifdef GC_HAVE_QWTPLOT3D
modelWindow = new ModelWindow(this, home);
tabWidget->addTab(modelWindow, tr("3D"));
tabs.append(TabInfo(modelWindow, tr("3D")));
#endif
//////////////////////// Weekly Summary ////////////////////////
// add daily distance / duration graph:
weeklySummaryWindow = new WeeklySummaryWindow(useMetricUnits, this);
tabWidget->addTab(weeklySummaryWindow, tr("Weekly Summary"));
tabs.append(TabInfo(weeklySummaryWindow, tr("Weekly Summary")));
//////////////////////// LTM ////////////////////////
// long term metrics window
metricDB = new MetricAggregator(this, home, zones()); // just to catch config updates!
ltmWindow = new LTMWindow(this, useMetricUnits, home);
tabWidget->addTab(ltmWindow, tr("Metrics"));
tabs.append(TabInfo(ltmWindow, tr("Metrics")));
//////////////////////// Performance Manager ////////////////////////
performanceManagerWindow = new PerformanceManagerWindow(this);
tabWidget->addTab(performanceManagerWindow, tr("PM"));
tabs.append(TabInfo(performanceManagerWindow, tr("PM")));
///////////////////////////// Aerolab //////////////////////////////////
aerolabWindow = new AerolabWindow(this);
tabWidget->addTab(aerolabWindow, tr("Aerolab"));
tabs.append(TabInfo(aerolabWindow, tr("Aerolab")));
///////////////////////////// GoogleMapsb //////////////////////////////////
googleMap = new GoogleMapControl(this,tabWidget);
googleMap = new GoogleMapControl(this);
tabs.append(TabInfo(googleMap, tr("Map")));
////////////////////////////// Signals //////////////////////////////
@@ -381,6 +382,21 @@ MainWindow::MainWindow(const QDir &home) :
//optionsMenu->addAction(tr("&Update Metrics..."), this,
// SLOT(scanForMissing()()), tr("Ctrl+U"));
QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
QStringList tabsToHide = settings->value(GC_TABS_TO_HIDE, "").toString().split(",");
for (int i = 0; i < tabs.size(); ++i) {
TabInfo &tab = tabs[i]; // QListIterator only returns const references.
bool hide = tabsToHide.contains(tab.name);
if (!hide)
tabWidget->addTab(tab.contents, tab.name);
if (tab.contents == summarySplitter)
continue; // Always show the ride summary.
tab.action = new QAction(tab.name, this);
tab.action->setCheckable(true);
tab.action->setChecked(!hide);
connect(tab.action, SIGNAL(triggered(bool)), this, SLOT(tabViewTriggered(bool)));
viewMenu->addAction(tab.action);
}
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("&About GoldenCheetah"), this, SLOT(aboutDialog()));
@@ -402,6 +418,29 @@ MainWindow::MainWindow(const QDir &home) :
setAttribute(Qt::WA_DeleteOnClose);
}
void
MainWindow::tabViewTriggered(bool)
{
disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
QWidget *currentWidget = tabWidget->currentWidget();
int currentIndex = tabWidget->currentIndex();
tabWidget->clear();
QStringList tabsToHide;
foreach (const TabInfo &tab, tabs) {
if (!tab.action || tab.action->isChecked())
tabWidget->addTab(tab.contents, tab.name);
else
tabsToHide << tab.name;
}
if (tabWidget->indexOf(currentWidget) >= 0)
tabWidget->setCurrentWidget(currentWidget);
else if (currentIndex < tabWidget->count())
tabWidget->setCurrentIndex(currentIndex);
tabChanged(tabWidget->currentIndex());
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
settings->setValue(GC_TABS_TO_HIDE, tabsToHide.join(","));
}
void
MainWindow::selectView(int view)
{
@@ -470,7 +509,7 @@ MainWindow::addRide(QString name, bool bSelect /*=true*/)
criticalPowerWindow->newRideAdded();
if (bSelect)
{
tabWidget->setCurrentIndex(0);
tabWidget->setCurrentWidget(summarySplitter);
treeWidget->setCurrentItem(last);
}
rideAdded(last);
@@ -769,14 +808,13 @@ MainWindow::rideTreeWidgetSelectionChanged()
}
// 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
}
int histIndex = tabWidget->indexOf(histogramWindow);
int pfpvIndex = tabWidget->indexOf(pfPvWindow);
bool enabled = !ride->ride() || ride->ride()->deviceType() != QString("Manual CSV");
if (histIndex >= 0)
tabWidget->setTabEnabled(histIndex, enabled);
if (pfpvIndex >= 0)
tabWidget->setTabEnabled(pfpvIndex, enabled);
saveAndOpenNotes();
}
void
@@ -838,11 +876,11 @@ MainWindow::showContextMenuPopup(const QPoint &pos)
connect(actFrontInt, SIGNAL(triggered(void)), this, SLOT(frontInterval(void)));
connect(actBackInt, SIGNAL(triggered(void)), this, SLOT(backInterval(void)));
if (tabWidget->currentIndex() == 1) // on ride plot
if (tabWidget->currentWidget() == allPlotWindow)
menu.addAction(actZoomInt);
menu.addAction(actRenameInt);
menu.addAction(actDeleteInt);
if (tabWidget->currentIndex() == 4 && activeInterval->isSelected()) { // on PfPv plot
if (tabWidget->currentWidget() == pfPvWindow && activeInterval->isSelected()) {
menu.addAction(actFrontInt);
menu.addAction(actBackInt);
}
@@ -1167,7 +1205,7 @@ MainWindow::setCriticalPower(int cp)
void
MainWindow::tabChanged(int index)
{
criticalPowerWindow->setActive(index == 2);
criticalPowerWindow->setActive(tabWidget->widget(index) == criticalPowerWindow);
performanceManagerWindow->setActive(tabWidget->widget(index) == performanceManagerWindow);
ltmWindow->setActive(tabWidget->widget(index) == ltmWindow);
#ifdef GC_HAVE_QWTPLOT3D

View File

@@ -101,6 +101,7 @@ class MainWindow : public QMainWindow
void rideDeleted(RideItem *);
private slots:
void tabViewTriggered(bool);
void rideTreeWidgetSelectionChanged();
void intervalTreeWidgetSelectionChanged();
void leftLayoutMoved();
@@ -145,6 +146,15 @@ class MainWindow : public QMainWindow
private:
bool parseRideFileName(const QString &name, QString *notesFileName, QDateTime *dt);
struct TabInfo {
QWidget *contents;
QString name;
QAction *action;
TabInfo(QWidget *contents, QString name) :
contents(contents), name(name), action(NULL) {}
};
QList<TabInfo> tabs;
boost::shared_ptr<QSettings> settings;
IntervalItem *activeInterval; // currently active for context menu popup
RideItem *activeRide; // currently active for context menu popup

View File

@@ -29,6 +29,7 @@
#define GC_SETTINGS_MAIN_GEOM "mainwindow/geometry"
#define GC_SETTINGS_SPLITTER_SIZES "mainwindow/splitterSizes"
#define GC_SETTINGS_CALENDAR_SIZES "mainwindow/calendarSizes"
#define GC_TABS_TO_HIDE "mainwindow/tabsToHide"
#define GC_SETTINGS_INTERVAL_METRICS "rideSummaryWindow/intervalMetrics"
#define GC_RIDE_PLOT_SMOOTHING "ridePlot/Smoothing"
#define GC_PERF_MAN_METRIC "performanceManager/metric"