diff --git a/src/IntervalSummaryWindow.cpp b/src/IntervalSummaryWindow.cpp new file mode 100644 index 000000000..d4bcdfa9f --- /dev/null +++ b/src/IntervalSummaryWindow.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2011 Eric Brandt (eric.l.brandt@gmail.com) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "MainWindow.h" +#include "IntervalItem.h" +#include "IntervalSummaryWindow.h" +#include "Settings.h" +#include "TimeUtils.h" + +IntervalSummaryWindow::IntervalSummaryWindow(MainWindow *mainWindow) : mainWindow(mainWindow) { + setWindowTitle(tr("Interval Summary")); + setReadOnly(true); + + connect(mainWindow, SIGNAL(intervalSelected()), this, SLOT(intervalSelected())); +} + +IntervalSummaryWindow::~IntervalSummaryWindow() { +} + +void IntervalSummaryWindow::intervalSelected() +{ + QString html; + if (mainWindow->allIntervalItems() != NULL) { + for (int i=0; iallIntervalItems()->childCount(); i++) { + IntervalItem *current = dynamic_cast(mainWindow->allIntervalItems()->child(i)); + if (current != NULL) { + if (current->isSelected()) { + calcInterval(current, html); + } + } + } + } + if (html.length() == 0) + html = "" + tr("select an interval for summary info") + ""; + + setHtml(html); + return; +} + +void IntervalSummaryWindow::calcInterval(IntervalItem* interval, QString& html) +{ + const RideFile* ride = mainWindow->currentRide(); + + QVariant unit = appsettings->value(this, GC_UNIT); + bool metricUnits = (unit.toString() == "Metric"); + + RideFile f(ride->startTime(), ride->recIntSecs()); + int start = ride->timeIndex(interval->start); + int end = ride->timeIndex(interval->stop); + for (int i = start; i < end; ++i) { + const RideFilePoint *p = ride->dataPoints()[i]; + f.appendPoint(p->secs, p->cad, p->hr, p->km, p->kph, p->nm, + p->watts, p->alt, p->lon, p->lat, p->headwind, 0); + } + if (f.dataPoints().size() == 0) { + // Interval empty, do not compute any metrics + html += "" + tr("empty interval") + ""; + } + + QString s; + if (appsettings->contains(GC_SETTINGS_INTERVAL_METRICS)) + s = appsettings->value(this, GC_SETTINGS_INTERVAL_METRICS).toString(); + else + s = GC_SETTINGS_INTERVAL_METRICS_DEFAULT; + QStringList intervalMetrics = s.split(","); + + QHash metrics = + RideMetric::computeMetrics(mainWindow, &f, mainWindow->zones(), mainWindow->hrZones(), intervalMetrics); + + html += "" + interval->text(0) + ""; + html += "" + m->name() + ""; + + // right column (values) + QString s(""); + if (m->units(metricUnits) == "seconds") + html += s.arg(time_to_string(m->value(metricUnits))); + else + html += s.arg(m->value(metricUnits), 0, 'f', m->precision()); + + html += ""; + + html += ""; + + } + html += "
%1"; + if (m->units(metricUnits) == "seconds") + ; // don't do anything + else if (m->units(metricUnits).size() > 0) + html += m->units(metricUnits); + html += "
"; +} + + diff --git a/src/IntervalSummaryWindow.h b/src/IntervalSummaryWindow.h new file mode 100644 index 000000000..8b628d863 --- /dev/null +++ b/src/IntervalSummaryWindow.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011 Eric Brandt (eric.l.brandt@gmail.com) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef INTERVALSUMMARYWINDOW_H_ +#define INTERVALSUMMARYWINDOW_H_ + +#include + +class MainWindow; +class IntervalItem; + +class IntervalSummaryWindow : public QTextEdit { + Q_OBJECT; + +public: + IntervalSummaryWindow(MainWindow *mainWindow); + virtual ~IntervalSummaryWindow(); + +public slots: + + void intervalSelected(); + +protected: + void calcInterval(IntervalItem* interval, QString& html); + + MainWindow *mainWindow; +}; + +#endif /* INTERVALSUMMARYWINDOW_H_ */ diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7307fd126..6cdc05d79 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -46,6 +46,7 @@ #include "RealtimeWindow.h" #include "RideItem.h" #include "IntervalItem.h" +#include "IntervalSummaryWindow.h" #include "RideEditor.h" #ifdef GC_HAVE_ICAL #include "DiaryWindow.h" @@ -305,7 +306,8 @@ MainWindow::MainWindow(const QDir &home) : treeWidget->expandItem(allRides); treeWidget->setFirstItemColumnSpanned (allRides, true); - intervalWidget = new QTreeWidget(this); + intervalSummaryWindow = new IntervalSummaryWindow(this); + intervalWidget = new QTreeWidget(); intervalWidget->setColumnCount(1); intervalWidget->setIndentation(5); intervalWidget->setSortingEnabled(false); @@ -320,7 +322,10 @@ MainWindow::MainWindow(const QDir &home) : allIntervals->setText(0, tr("Intervals")); intervalWidget->expandItem(allIntervals); - + intervalSplitter = new QSplitter(this); + intervalSplitter->setOrientation(Qt::Vertical); + intervalSplitter->addWidget(intervalWidget); + intervalSplitter->addWidget(intervalSummaryWindow); #ifdef GC_HAVE_ICAL rideCalendar = new ICalendar(this); // my local/remote calendar entries @@ -403,7 +408,7 @@ MainWindow::MainWindow(const QDir &home) : dock->setWidget(toolBox); #endif toolBox->addItem(treeWidget, "Rides"); - toolBox->addItem(intervalWidget, "Intervals"); + toolBox->addItem(intervalSplitter, "Intervals"); toolBox->addItem(masterControls, "Controls"); toolBox->addItem(new AthleteTool(QFileInfo(home.path()).path(), this), "Athletes"); toolBox->addItem(chartTool, "Charts"); diff --git a/src/MainWindow.h b/src/MainWindow.h index 76d8e0919..f5efff66d 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -66,6 +66,7 @@ class HomeWindow; class ICalendar; class CalDAV; class Seasons; +class IntervalSummaryWindow; class MainWindow : public QMainWindow { @@ -268,8 +269,9 @@ class MainWindow : public QMainWindow QSplitter *splitter; QSplitter *metaSplitter; QTreeWidget *treeWidget; - QSplitter *intervalsplitter; + QSplitter *intervalSplitter; QTreeWidget *intervalWidget; + IntervalSummaryWindow *intervalSummaryWindow; QTabWidget *tabWidget; SummaryWindow *summaryWindow; DiaryWindow *diaryWindow; diff --git a/src/src.pro b/src/src.pro index 919312bbd..8abb79c4b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -170,6 +170,7 @@ HEADERS += \ HrPwPlot.h \ HrPwWindow.h \ IntervalItem.h \ + IntervalSummaryWindow.h \ JsonRideFile.h \ LogTimeScaleDraw.h \ LogTimeScaleEngine.h \ @@ -324,6 +325,7 @@ SOURCES += \ HrPwPlot.cpp \ HrPwWindow.cpp \ IntervalItem.cpp \ + IntervalSummaryWindow.cpp \ LogTimeScaleDraw.cpp \ LogTimeScaleEngine.cpp \ LTMCanvasPicker.cpp \