mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
Danniel Connelly's patch regarding Histogram and the implementation of a Y Axis.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
#include <assert.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_scale_engine.h>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_data.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user