mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
Performance Manager Date Labels
Linker error using different TimeScaleDraw::label but also a memory leak with unneccesary calls to create a new ScaleDraw object. Also applied recent fixes from qwt6 for scale draws. We should look to pick up some of the other recent fixes -- especially QT5 support. Fixes #363.
This commit is contained in:
@@ -184,7 +184,7 @@ void QwtAbstractScaleDraw::draw( QPainter *painter,
|
||||
{
|
||||
const double v = majorTicks[i];
|
||||
if ( d_data->scldiv.contains( v ) )
|
||||
drawLabel( painter, majorTicks[i] );
|
||||
drawLabel( painter, v );
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
|
||||
@@ -46,8 +46,6 @@ public:
|
||||
void QwtPlotScaleItem::PrivateData::updateBorders( const QRectF &canvasRect,
|
||||
const QwtScaleMap &xMap, const QwtScaleMap &yMap )
|
||||
{
|
||||
canvasRectCache = canvasRect;
|
||||
|
||||
QwtInterval interval;
|
||||
if ( scaleDraw->orientation() == Qt::Horizontal )
|
||||
{
|
||||
@@ -350,7 +348,10 @@ void QwtPlotScaleItem::draw( QPainter *painter,
|
||||
if ( d_data->scaleDivFromAxis )
|
||||
{
|
||||
if ( canvasRect != d_data->canvasRectCache )
|
||||
{
|
||||
d_data->updateBorders( canvasRect, xMap, yMap );
|
||||
d_data->canvasRectCache = canvasRect;
|
||||
}
|
||||
}
|
||||
|
||||
QPen pen = painter->pen();
|
||||
@@ -438,6 +439,7 @@ void QwtPlotScaleItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
|
||||
{
|
||||
d_data->updateBorders( plt->canvas()->contentsRect(),
|
||||
plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) );
|
||||
d_data->canvasRectCache = QRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,47 @@
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_grid.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include "RideItem.h"
|
||||
#include "RideFile.h"
|
||||
#include "PerfPlot.h"
|
||||
#include "StressCalculator.h"
|
||||
#include "Colors.h"
|
||||
|
||||
// handle x-axis names
|
||||
class PPTimeScaleDraw: public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
PPTimeScaleDraw(const QDateTime &base):
|
||||
QwtScaleDraw(), baseTime(base) {
|
||||
format = "MMM d";
|
||||
QwtScaleDraw::invalidateCache();
|
||||
}
|
||||
virtual QwtText label(double v) const
|
||||
{
|
||||
QDateTime upTime = baseTime.addDays((int)v);
|
||||
return upTime.toString(format);
|
||||
}
|
||||
void setBase(QDateTime base)
|
||||
{
|
||||
baseTime = base;
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
private:
|
||||
QDateTime baseTime;
|
||||
QString format;
|
||||
|
||||
};
|
||||
|
||||
PerfPlot::PerfPlot() : STScurve(NULL), LTScurve(NULL), SBcurve(NULL), DAYcurve(NULL)
|
||||
{
|
||||
setInstanceName("PM Plot");
|
||||
|
||||
xsd = new PPTimeScaleDraw(QDateTime());
|
||||
xsd->setTickLength(QwtScaleDiv::MajorTick, 3);
|
||||
setAxisScaleDraw(QwtPlot::xBottom, xsd);
|
||||
|
||||
insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
|
||||
setAxisTitle(yLeft, "Exponentially Weighted Average Stress");
|
||||
setAxisTitle(xBottom, "Time (days)");
|
||||
@@ -47,10 +78,6 @@ PerfPlot::PerfPlot() : STScurve(NULL), LTScurve(NULL), SBcurve(NULL), DAYcurve(N
|
||||
|
||||
QwtScaleDraw *sd = new QwtScaleDraw;
|
||||
sd->setTickLength(QwtScaleDiv::MajorTick, 3);
|
||||
setAxisScaleDraw(QwtPlot::xBottom, sd);
|
||||
|
||||
sd = new QwtScaleDraw;
|
||||
sd->setTickLength(QwtScaleDiv::MajorTick, 3);
|
||||
setAxisScaleDraw(QwtPlot::yLeft, sd);
|
||||
|
||||
sd = new QwtScaleDraw;
|
||||
@@ -105,9 +132,11 @@ void PerfPlot::plot() {
|
||||
} else if (num < 364) {
|
||||
tics = 27;
|
||||
}
|
||||
setAxisScale(xBottom, xmin, xmax,tics);
|
||||
//setAxisScale(xBottom, xmin, xmax,tics);
|
||||
//axisWidget(xBottom)->update();
|
||||
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(startDate));
|
||||
// set base
|
||||
xsd->setBase(startDate);
|
||||
|
||||
double width = appsettings->value(this, GC_LINEWIDTH, 20.0).toDouble();
|
||||
|
||||
@@ -172,6 +201,7 @@ void PerfPlot::plot() {
|
||||
SBcurve->setData(_sc->getDays()+xmin,_sc->getSBvalues()+xmin,num);
|
||||
SBcurve->attach(this);
|
||||
|
||||
axisWidget(QwtPlot::xBottom)->update();
|
||||
replot();
|
||||
|
||||
}
|
||||
@@ -205,4 +235,5 @@ PerfPlot::setAxisTitle(int axis, QString label)
|
||||
title.setFont(stGiles);
|
||||
QwtPlot::setAxisFont(axis, stGiles);
|
||||
QwtPlot::setAxisTitle(axis, title);
|
||||
axisWidget(axis)->update();
|
||||
}
|
||||
|
||||
@@ -30,28 +30,7 @@
|
||||
#include "Settings.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// handle x-axis names
|
||||
class TimeScaleDraw: public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
TimeScaleDraw(const QDateTime &base):
|
||||
baseTime(base) {
|
||||
format = "MMM d";
|
||||
}
|
||||
virtual QwtText label(double v) const
|
||||
{
|
||||
QDateTime upTime = baseTime.addDays((int)v);
|
||||
return upTime.toString(format);
|
||||
}
|
||||
private:
|
||||
QDateTime baseTime;
|
||||
QString format;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class PPTimeScaleDraw;
|
||||
class PerfPlot : public QwtPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -64,6 +43,7 @@ class PerfPlot : public QwtPlot
|
||||
int days;
|
||||
QDateTime startDate;
|
||||
StressCalculator *_sc;
|
||||
PPTimeScaleDraw *xsd;
|
||||
int xmin, xmax;
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user