Hello,

I've read a few questions on the forum and googled for it, yet I can't figure out how to properly set the date range.

I have a CSV file I load into memory, and use boost::gregorian_date, which I then convert into QDate like so:
Qt Code:
  1. auto first = csvdata.Rows().front().date;
  2. auto last = csvdata.Rows().back().date;
  3.  
  4. QDateTime start ( QDate( first.year(), first.month(), first.day() ), QTime( 0, 0, 0 ) );
  5. QDateTime end ( QDate( last.year(), last.month(), last.day() ), QTime( 0, 0, 0 ) );
  6.  
  7. auto * scaleDraw = new QwtDateScaleDraw( Qt::UTC );
  8. scaleDraw->setDateFormat( QwtDate::Day, QString("dd-mm-yyyy") );
  9.  
  10. auto * scaleEngine = new QwtDateScaleEngine( Qt::UTC );
  11.  
  12. plot.setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );
  13. plot.setAxisScale( QwtPlot::xBottom, start.toTime_t(), end.toTime_t() , 24 * 3600 * 30 );
  14. plot.setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
  15.  
  16. plot.setAxisLabelRotation( QwtPlot::xBottom, -90.0 );
  17. plot.setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
To copy to clipboard, switch view to plain text mode 

I then plot a simple moving average curve, which is essentialy an
Qt Code:
  1. std::pair<double, boost::gregorian_date> sma;
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QwtPlotCurve * sma_curve = new QwtPlotCurve();
  2. QPolygonF points;
  3. for ( int i = 0; i < sma.size()-1; i++ )
  4. {
  5. static boost::posix_time::ptime epoch ( boost::gregorian::date( 1970, 1, 1 ) );
  6. auto secs = ( boost::posix_time::ptime ( sma[i].second, boost::posix_time::seconds(0) ) - epoch ).total_seconds();
  7. points << QPointF( secs, sma[i].first );
  8. }
  9.  
  10. sma_curve->setSamples( points );
To copy to clipboard, switch view to plain text mode 

Yet, the date range on the bottom is always starting from the unix time (Jan 1970).
I'm obviously doing something wrong.
Also, the date label for the axis, is not set to dd-mm-yyyyy, but rather to hh:mm DD dd MM yyyy

Yet the plotted data is correct, just misaligned to the actual dates (which in this case should be 2012-Feb-01 to 2014-Nov-12).


plot_error.jpg


Can someone please help?

PS: I'm using qwt 6.1.1 from the svn repository.