Qwt x-axis should indicate hh:mm:ss
-
I have found a solution for finding better fitting tick labels.
I have introduced following class:
@
class SecondsLinearScaleEngine : public QwtLinearScaleEngine
{
public:
virtual void autoScale( int maxSteps,
double &x1, double &x2, double &stepSize ) const;protected:
double divideInterval( double interval, int numSteps ) const;
double ceil60 ( double v ) const;
};
@
You need to copy autoScale from its base class, since divideInterval is not virtual.
@
double SecondsLinearScaleEngine::divideInterval(
double intervalSize, int numSteps ) const
{
if ( numSteps <= 0 )
return 0.0;double v = QwtScaleArithmetic::divideEps( intervalSize, numSteps ); if ( v < 1.0 ) return QwtScaleArithmetic::ceil125( v ); return ceil60( v );
}
@
This is basically the same as of the base class. Only the return line has been substituted with the three last lines.
ceil60 does return multiples of 1,2,3,5 up to 30 seconds, minutes.The equivalent of cpuplot requires two additional statements.
@
setAxisScaleDraw ( QwtPlot::xBottom, new TimeScaleDraw ( QTime() ) );
setAxisScaleEngine ( QwtPlot::xBottom, new SecondsLinearScaleEngine );
@Thanks to Scylla for playing the sparing partner.
-
Thanks for feedback.
at Scylla: Yes, it is a very nice lib. Even so, I grumbled a bit to myself about the documentation in the beginning, it was not so hard to extend. ;-)
at Andre: No. This is a good suggestion. However, at the time being it is a bit too much "hand-knitten". After some clean-up I will contact them. -
Welcome to devnet
I am not sure right away, but IIRC it is part of the old style in Qwt lib and had something to do with the rounding process.
You should change to Qwt 6.1.0 which has a date-time engine already as part of the library. Checkout "QwtDateScaleEngine":http://qwt.sourceforge.net/class_qwt_date_scale_engine.html
With Qt5.1 I had to change to this recent version 6.1.0 of Qwt and I abandoned my solution too. -
My code contains now following part
@
#if QWT_VERSION < 0x060100
setAxisScaleDraw ( QwtPlot::xBottom, new TimeScaleDraw ( QTime() ) );
setAxisScaleEngine ( QwtPlot::xBottom, new SecondsLinearScaleEngine );
#endif
#if QWT_VERSION >= 0x060100
setAxisScaleDraw ( QwtPlot::xBottom, new QwtDateScaleDraw ( Qt::UTC ) );
setAxisScaleEngine ( QwtPlot::xBottom, new QwtDateScaleEngine ( Qt::UTC ) );
#endif
@The first part would be for my old-style as described above. However, it has a couple of deficiencies. For the use of Qt 5.1 I had to change to newer Qwt 6.1 lib. Qwt 6.1 did not work with my solution. I believe I ran into the same problem as you did. However, the second part of code above did solve it for me.