From 268afe536c924961244dfd1e2519f9c1a52099ff Mon Sep 17 00:00:00 2001 From: Greg Lonnon Date: Fri, 26 Feb 2010 18:22:44 -0700 Subject: [PATCH] untabify the GoogleMapsControl files --- src/GoogleMapControl.cpp | 488 +++++++++++++++++++-------------------- src/GoogleMapControl.h | 38 +-- 2 files changed, 263 insertions(+), 263 deletions(-) diff --git a/src/GoogleMapControl.cpp b/src/GoogleMapControl.cpp index 10c1d6d1a..05e5da865 100644 --- a/src/GoogleMapControl.cpp +++ b/src/GoogleMapControl.cpp @@ -38,63 +38,63 @@ namespace gm // but more of a pipeline... // it makes the math somewhat easier to do and understand... - class RideFilePointAlgorithm - { - protected: - RideFilePoint prevRfp; - bool first; - RideFilePointAlgorithm() { first = false; } - }; + class RideFilePointAlgorithm + { + protected: + RideFilePoint prevRfp; + bool first; + RideFilePointAlgorithm() { first = false; } + }; - class AltGained : private RideFilePointAlgorithm - { - protected: - RideFilePoint prevRfp; - double gained; - public: - AltGained() { gained = 0; } + class AltGained : private RideFilePointAlgorithm + { + protected: + RideFilePoint prevRfp; + double gained; + public: + AltGained() { gained = 0; } - void operator()(RideFilePoint rfp) - { - if(rfp.alt > prevRfp.alt) - { - gained += rfp.alt - prevRfp.alt; - } - prevRfp = rfp; - } - int TotalGained() { return gained; } - operator int() { return TotalGained(); } - }; + void operator()(RideFilePoint rfp) + { + if(rfp.alt > prevRfp.alt) + { + gained += rfp.alt - prevRfp.alt; + } + prevRfp = rfp; + } + int TotalGained() { return gained; } + operator int() { return TotalGained(); } + }; - class AvgHR - { - int samples; - int totalHR; - public: - AvgHR() : samples(0),totalHR(0.0) {} - void operator()(RideFilePoint rfp) - { - totalHR += rfp.hr; - samples++; - } - int HR() { return totalHR / samples; } - operator int() { return HR(); } - }; + class AvgHR + { + int samples; + int totalHR; + public: + AvgHR() : samples(0),totalHR(0.0) {} + void operator()(RideFilePoint rfp) + { + totalHR += rfp.hr; + samples++; + } + int HR() { return totalHR / samples; } + operator int() { return HR(); } + }; - class AvgPower - { - int samples; - double totalPower; - public: - AvgPower() : samples(0), totalPower(0.0) { } - void operator()(RideFilePoint rfp) - { - totalPower += rfp.watts; - samples++; - } - int Power() { return (int) (totalPower / samples); } - operator int() { return Power(); } - }; + class AvgPower + { + int samples; + double totalPower; + public: + AvgPower() : samples(0), totalPower(0.0) { } + void operator()(RideFilePoint rfp) + { + totalPower += rfp.watts; + samples++; + } + int Power() { return (int) (totalPower / samples); } + operator int() { return Power(); } + }; } using namespace gm; @@ -103,15 +103,15 @@ using namespace gm; GoogleMapControl::GoogleMapControl(MainWindow *mw, QTabWidget *tw) { - parent = mw; - tabWidget = tw; - view = new QWebView(); - layout = new QVBoxLayout(); - layout->addWidget(view); - setLayout(layout); - connect(parent, SIGNAL(rideSelected()), this, SLOT(rideSelected())); - view->load(QUrl("http://google.com")); - tabIndex = -1; + parent = mw; + tabWidget = tw; + view = new QWebView(); + layout = new QVBoxLayout(); + layout->addWidget(view); + setLayout(layout); + connect(parent, SIGNAL(rideSelected()), this, SLOT(rideSelected())); + view->load(QUrl("http://google.com")); + tabIndex = -1; } void @@ -120,248 +120,248 @@ GoogleMapControl::rideSelected() { ride = parent->rideItem(); if (!ride) - return; + return; int currentTab = tabWidget->currentIndex(); // Does the ride have GPS data if(ride->ride()->dataPoints().front()->lat == 0.0) { - if(tabIndex > -1) - { - tabWidget->removeTab(tabIndex); + if(tabIndex > -1) + { + tabWidget->removeTab(tabIndex); if (currentTab == tabIndex) tabWidget->setCurrentIndex(0); - } - tabIndex = -1; + } + tabIndex = -1; } else { - if (tabIndex == -1) tabIndex = tabWidget->addTab(this, tr("Map")); + if (tabIndex == -1) tabIndex = tabWidget->addTab(this, tr("Map")); if (currentTab != tabIndex) tabWidget->setCurrentIndex(currentTab); - createHtml(); + createHtml(); } } void GoogleMapControl::resizeEvent(QResizeEvent * ) { - // createHtml will handle resize the widget correct - createHtml(); + // createHtml will handle resize the widget correct + createHtml(); } void GoogleMapControl::createHtml() { - if(ride == NULL) return; + if(ride == NULL) return; - double minLat, minLon, maxLat, maxLon; - minLat = minLon = 1000; - maxLat = maxLon = -1000; // larger than 360 + double minLat, minLon, maxLat, maxLon; + minLat = minLon = 1000; + maxLat = maxLon = -1000; // larger than 360 - foreach(RideFilePoint *rfp, ride->ride()->dataPoints()) - { - minLat = std::min(minLat,rfp->lat); - maxLat = std::max(maxLat,rfp->lat); - minLon = std::min(minLon,rfp->lon); - maxLon = std::max(maxLon,rfp->lon); - } - /// seems to be the magic number... to stop the scrollbars - int width = view->width() -16; - int height = view->height() -16; + foreach(RideFilePoint *rfp, ride->ride()->dataPoints()) + { + minLat = std::min(minLat,rfp->lat); + maxLat = std::max(maxLat,rfp->lat); + minLon = std::min(minLon,rfp->lon); + maxLon = std::max(maxLon,rfp->lon); + } + /// seems to be the magic number... to stop the scrollbars + int width = view->width() -16; + int height = view->height() -16; - std::ostringstream oss; - oss.precision(6); - oss.setf(ios::fixed,ios::floatfield); + std::ostringstream oss; + oss.precision(6); + oss.setf(ios::fixed,ios::floatfield); - oss << "" << endl - << "" << endl - << "" << endl - << "" << endl - << "GoldenCheetah" << endl - << "" << endl - << "" << endl - << "" << endl - << "" << endl - << "
" << endl - << "
" << endl - << "
" << endl - << "" << endl - << "" << endl; + oss << "" << endl + << "" << endl + << "" << endl + << "" << endl + << "GoldenCheetah" << endl + << "" << endl + << "" << endl + << "" << endl + << "" << endl + << "
" << endl + << "
" << endl + << "
" << endl + << "" << endl + << "" << endl; #define DEBUG_GMAPS 1 #if DEBUG_GMAPS - QString htmlFile(QDir::tempPath()); - htmlFile.append("/maps.html"); - QFile file(htmlFile); - file.remove(); - file.open(QIODevice::ReadWrite); - file.write(oss.str().c_str(),oss.str().length()); - file.flush(); - file.close(); - QString filename("file:///"); - filename.append(htmlFile); - QUrl url(filename); - view->load(url); + QString htmlFile(QDir::tempPath()); + htmlFile.append("/maps.html"); + QFile file(htmlFile); + file.remove(); + file.open(QIODevice::ReadWrite); + file.write(oss.str().c_str(),oss.str().length()); + file.flush(); + file.close(); + QString filename("file:///"); + filename.append(htmlFile); + QUrl url(filename); + view->load(url); #endif - view->setHtml(QString(oss.str().c_str())); + view->setHtml(QString(oss.str().c_str())); } QColor GoogleMapControl::GetColor(int cp, int watts) { - double effort = watts/ (double) cp /1.25; + double effort = watts/ (double) cp /1.25; - if(effort < 0.25) - { - effort = 0; - } - if(effort > 1.0) - { - effort = 1; - } + if(effort < 0.25) + { + effort = 0; + } + if(effort > 1.0) + { + effort = 1; + } QColor color; - color.setHsv(int(360 - (360 * effort)), 255, 255); - return color; + color.setHsv(int(360 - (360 * effort)), 255, 255); + return color; } /// create the ride line string GoogleMapControl::CreatePolyLine(RideItem *ride) { - std::vector intervalPoints; - ostringstream oss; + std::vector intervalPoints; + ostringstream oss; - int cp; - int intervalTime = 30; // 30 seconds - int zone =ride->zoneRange(); - if(zone >= 0) - { - cp = 300; // default cp to 300 watts - } - else - { - cp = ride->zones->getCP(zone); - } + int cp; + int intervalTime = 30; // 30 seconds + int zone =ride->zoneRange(); + if(zone >= 0) + { + cp = 300; // default cp to 300 watts + } + else + { + cp = ride->zones->getCP(zone); + } - foreach(RideFilePoint* rfp, ride->ride()->dataPoints()) - { - intervalPoints.push_back(*rfp); - if((intervalPoints.back().secs - intervalPoints.front().secs) > intervalTime) - { - // find the avg power and color code it and create a polyline... - AvgPower avgPower = for_each(intervalPoints.begin(), - intervalPoints.end(), - AvgPower()); - // find the color - QColor color = GetColor(cp,avgPower); - // create the polyline - CreateSubPolyLine(intervalPoints,oss,color); - intervalPoints.clear(); - intervalPoints.push_back(*rfp); - } + foreach(RideFilePoint* rfp, ride->ride()->dataPoints()) + { + intervalPoints.push_back(*rfp); + if((intervalPoints.back().secs - intervalPoints.front().secs) > intervalTime) + { + // find the avg power and color code it and create a polyline... + AvgPower avgPower = for_each(intervalPoints.begin(), + intervalPoints.end(), + AvgPower()); + // find the color + QColor color = GetColor(cp,avgPower); + // create the polyline + CreateSubPolyLine(intervalPoints,oss,color); + intervalPoints.clear(); + intervalPoints.push_back(*rfp); + } - } - return oss.str(); + } + return oss.str(); } void GoogleMapControl::CreateSubPolyLine(const std::vector &points, - std::ostringstream &oss, - QColor color) + std::ostringstream &oss, + QColor color) { - oss.precision(6); - QString colorstr = color.name(); - oss.setf(ios::fixed,ios::floatfield); - oss << "map.addOverlay (new GPolyline(["; + oss.precision(6); + QString colorstr = color.name(); + oss.setf(ios::fixed,ios::floatfield); + oss << "map.addOverlay (new GPolyline(["; - BOOST_FOREACH(RideFilePoint rfp, points) - { + BOOST_FOREACH(RideFilePoint rfp, points) + { if (ceil(rfp.lat) != 180 && ceil(rfp.lon) != 180) - { - oss << "new GLatLng(" << rfp.lat << "," << rfp.lon << ")," << endl; - } - } + { + oss << "new GLatLng(" << rfp.lat << "," << rfp.lon << ")," << endl; + } + } - oss << "],\"" << colorstr.toStdString() << "\",5));"; + oss << "],\"" << colorstr.toStdString() << "\",5));"; } string GoogleMapControl::CreateIntervalMarkers(RideItem *ride) { - ostringstream oss; - oss.precision(6); - oss.setf(ios::fixed,ios::floatfield); + ostringstream oss; + oss.precision(6); + oss.setf(ios::fixed,ios::floatfield); - oss << "var marker;" << endl; - int currentInterval = 0; - std::vector intervalPoints; - foreach(RideFilePoint* rfp, ride->ride()->dataPoints()) - { - intervalPoints.push_back(*rfp); - if(currentInterval < rfp->interval) - { - // want to see avg power, avg speed, alt changes, avg hr - double distance = intervalPoints.back().km - - intervalPoints.front().km ; - int secs = intervalPoints.back().secs - - intervalPoints.front().secs; + oss << "var marker;" << endl; + int currentInterval = 0; + std::vector intervalPoints; + foreach(RideFilePoint* rfp, ride->ride()->dataPoints()) + { + intervalPoints.push_back(*rfp); + if(currentInterval < rfp->interval) + { + // want to see avg power, avg speed, alt changes, avg hr + double distance = intervalPoints.back().km - + intervalPoints.front().km ; + int secs = intervalPoints.back().secs - + intervalPoints.front().secs; - double avgSpeed = (distance/((double)secs)) * 3600; - QTime time; - time = time.addSecs(secs); + double avgSpeed = (distance/((double)secs)) * 3600; + QTime time; + time = time.addSecs(secs); - AvgHR avgHr = for_each(intervalPoints.begin(), - intervalPoints.end(), - AvgHR()); - AvgPower avgPower = for_each(intervalPoints.begin(), - intervalPoints.end(), - AvgPower()); + AvgHR avgHr = for_each(intervalPoints.begin(), + intervalPoints.end(), + AvgHR()); + AvgPower avgPower = for_each(intervalPoints.begin(), + intervalPoints.end(), + AvgPower()); - AltGained altGained =for_each(intervalPoints.begin(), - intervalPoints.end(), - AltGained()); - oss << "marker = new GMarker(new GLatLng( "; - oss<< rfp->lat << "," << rfp->lon << "));" << endl; - oss << "marker.bindInfoWindowHtml(" <

Lap: " << currentInterval << "

" ; - oss << "

Distance: " << distance << "

" ; - oss << "

Time: " << time.toString().toStdString() << "

"; - oss << "

Avg Speed: " << avgSpeed << "

"; - if(avgHr != 0) { - oss << "

Avg HR: " << avgHr << "

"; - } - if(avgPower != 0) - { - oss << "

Avg Power: " << avgPower << "

"; - } - oss << "

Alt Gained: " << altGained << "

"; - oss << "\");" << endl; - oss << "map.addOverlay(marker);" << endl; + AltGained altGained =for_each(intervalPoints.begin(), + intervalPoints.end(), + AltGained()); + oss << "marker = new GMarker(new GLatLng( "; + oss<< rfp->lat << "," << rfp->lon << "));" << endl; + oss << "marker.bindInfoWindowHtml(" <

Lap: " << currentInterval << "

" ; + oss << "

Distance: " << distance << "

" ; + oss << "

Time: " << time.toString().toStdString() << "

"; + oss << "

Avg Speed: " << avgSpeed << "

"; + if(avgHr != 0) { + oss << "

Avg HR: " << avgHr << "

"; + } + if(avgPower != 0) + { + oss << "

Avg Power: " << avgPower << "

"; + } + oss << "

Alt Gained: " << altGained << "

"; + oss << "\");" << endl; + oss << "map.addOverlay(marker);" << endl; - currentInterval = rfp->interval; - intervalPoints.clear(); - } - } - return oss.str(); + currentInterval = rfp->interval; + intervalPoints.clear(); + } + } + return oss.str(); } diff --git a/src/GoogleMapControl.h b/src/GoogleMapControl.h index 53a3defd3..d0459d66a 100644 --- a/src/GoogleMapControl.h +++ b/src/GoogleMapControl.h @@ -39,31 +39,31 @@ class GoogleMapControl : public QWidget Q_OBJECT private: - QVBoxLayout *layout; - QWebView *view; - RideItem *ride; - MainWindow *parent; - std::string CreatePolyLine(RideItem *); - void CreateSubPolyLine(const std::vector &points, - std::ostringstream &oss, - QColor color); - std::string CreateIntervalMarkers(RideItem *); - GoogleMapControl(); - QColor GetColor(int cp, int watts); - // tabIndex tracks the index of the Maps tab, -1 means it's not showing - int tabIndex; - QTabWidget *tabWidget; + QVBoxLayout *layout; + QWebView *view; + RideItem *ride; + MainWindow *parent; + std::string CreatePolyLine(RideItem *); + void CreateSubPolyLine(const std::vector &points, + std::ostringstream &oss, + QColor color); + std::string CreateIntervalMarkers(RideItem *); + GoogleMapControl(); + QColor GetColor(int cp, int watts); + // tabIndex tracks the index of the Maps tab, -1 means it's not showing + int tabIndex; + QTabWidget *tabWidget; public slots: - void rideSelected(); + void rideSelected(); protected: - void createHtml(); - void resizeEvent(QResizeEvent *); + void createHtml(); + void resizeEvent(QResizeEvent *); public: - GoogleMapControl(MainWindow *,QTabWidget *); - virtual ~GoogleMapControl() { } + GoogleMapControl(MainWindow *,QTabWidget *); + virtual ~GoogleMapControl() { } }; #endif