diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index aad6cb6a9..2fb9c4e73 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -299,11 +299,16 @@ MainWindow::MainWindow(const QDir &home) : binWidthLineEdit)); binWidthLayout->addWidget(binWidthSlider); + lnYHistCheckBox = new QCheckBox; + lnYHistCheckBox->setText("Log y"); + binWidthLayout->addWidget(lnYHistCheckBox); + withZerosCheckBox = new QCheckBox; withZerosCheckBox->setText("With zeros"); binWidthLayout->addWidget(withZerosCheckBox); powerHist = new PowerHist(); + lnYHistCheckBox->setChecked(powerHist->islnY()); withZerosCheckBox->setChecked(powerHist->withZeros()); binWidthSlider->setValue(powerHist->binWidth()); binWidthLineEdit->setText(QString("%1").arg(powerHist->binWidth())); @@ -378,6 +383,8 @@ MainWindow::MainWindow(const QDir &home) : this, SLOT(setBinWidthFromSlider())); connect(binWidthLineEdit, SIGNAL(editingFinished()), this, SLOT(setBinWidthFromLineEdit())); + connect(lnYHistCheckBox, SIGNAL(stateChanged(int)), + this, SLOT(setlnYHistFromCheckBox())); connect(withZerosCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setWithZerosFromCheckBox())); connect(qaCPValue, SIGNAL(editingFinished()), @@ -1100,6 +1107,13 @@ MainWindow::setBinWidthFromSlider() } } +void +MainWindow::setlnYHistFromCheckBox() +{ + if (powerHist->islnY() != lnYHistCheckBox->isChecked()) + powerHist->setlnY(! powerHist->islnY()); +} + void MainWindow::setWithZerosFromCheckBox() { diff --git a/src/MainWindow.h b/src/MainWindow.h index e33f08575..c171a0fac 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -65,6 +65,7 @@ class MainWindow : public QMainWindow void setSmoothingFromLineEdit(); void setBinWidthFromSlider(); void setBinWidthFromLineEdit(); + void setlnYHistFromCheckBox(); void setWithZerosFromCheckBox(); void setQaCPFromLineEdit(); void setQaCADFromLineEdit(); @@ -104,6 +105,7 @@ class MainWindow : public QMainWindow QLineEdit *smoothLineEdit; QSlider *binWidthSlider; QLineEdit *binWidthLineEdit; + QCheckBox *lnYHistCheckBox; QCheckBox *withZerosCheckBox; QTreeWidgetItem *allRides; PowerHist *powerHist; diff --git a/src/PowerHist.cpp b/src/PowerHist.cpp index e9613e945..66c68c005 100644 --- a/src/PowerHist.cpp +++ b/src/PowerHist.cpp @@ -23,11 +23,12 @@ #include #include #include +#include #include #include PowerHist::PowerHist() : - array(NULL), binw(20), withz(true) + array(NULL), binw(20), withz(true), lny(false) { setCanvasBackground(Qt::white); @@ -48,6 +49,11 @@ PowerHist::PowerHist() : grid->attach(this); } +PowerHist::~PowerHist() { + delete curve; + delete grid; +} + void PowerHist::recalc() { @@ -63,11 +69,11 @@ PowerHist::recalc() if (low==0 && !withz) low++; smoothWatts[i] = low; - smoothTime[i] = 0.0; + smoothTime[i] = 1e-9; // non-zero for log axis while (low < high) smoothTime[i] += array[low++] / 60.0; } - smoothTime[i] = 0.0; + smoothTime[i] = 1e-9; smoothWatts[i] = i * binw; curve->setData(smoothWatts.data(), smoothTime.data(), count+1); setAxisScale(xBottom, 0.0, smoothWatts[count]); @@ -78,7 +84,7 @@ PowerHist::recalc() void PowerHist::setYMax() { - setAxisScale(yLeft, 0.0, curve->maxYValue() * 1.1); + setAxisScale(yLeft, (lny ? 0.1 : 0.0), curve->maxYValue() * 1.1); } void @@ -123,3 +129,27 @@ PowerHist::setWithZeros(bool value) recalc(); } +void +PowerHist::setlnY(bool value) +{ + // note: setAxisScaleEngine deletes the old ScaleEngine, so specifying + // "new" in the argument list is not a leak + + if (lny = value) { + setAxisScaleEngine( + yLeft, + new QwtLog10ScaleEngine + ); + curve->setBaseline(1e-6); + } + else { + setAxisScaleEngine( + yLeft, + new QwtLinearScaleEngine + ); + curve->setBaseline(0); + } + setYMax(); + replot(); +} + diff --git a/src/PowerHist.h b/src/PowerHist.h index c93741e22..a00d9db2c 100644 --- a/src/PowerHist.h +++ b/src/PowerHist.h @@ -34,15 +34,18 @@ class PowerHist : public QwtPlot QwtPlotCurve *curve; PowerHist(); + ~PowerHist(); int binWidth() const { return binw; } - bool withZeros() const { return withz; } + inline bool withZeros() const { return withz; } + inline bool islnY() const { return lny; } void setData(RideFile *ride); public slots: + void setlnY(bool value); void setWithZeros(bool value); void setBinWidth(int value); @@ -54,7 +57,8 @@ class PowerHist : public QwtPlot double *array; int arrayLength; - bool withz; + bool withz; // whether P=0 are omitted from hisogram + bool lny; // whether y-axis is a log scale int binw;