diff --git a/qwt/src/qwt_abstract_scale_draw.cpp b/qwt/src/qwt_abstract_scale_draw.cpp index 72f664c03..c29e226a0 100644 --- a/qwt/src/qwt_abstract_scale_draw.cpp +++ b/qwt/src/qwt_abstract_scale_draw.cpp @@ -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(); diff --git a/qwt/src/qwt_plot_scaleitem.cpp b/qwt/src/qwt_plot_scaleitem.cpp index b5b27ee1e..212f5bee4 100644 --- a/qwt/src/qwt_plot_scaleitem.cpp +++ b/qwt/src/qwt_plot_scaleitem.cpp @@ -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(); } } } diff --git a/src/PerfPlot.cpp b/src/PerfPlot.cpp index 906a81786..435ba5303 100644 --- a/src/PerfPlot.cpp +++ b/src/PerfPlot.cpp @@ -24,16 +24,47 @@ #include #include #include +#include #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(); } diff --git a/src/PerfPlot.h b/src/PerfPlot.h index 211f92628..6185ccaa5 100644 --- a/src/PerfPlot.h +++ b/src/PerfPlot.h @@ -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: