gXAxis UTC correction hack

This commit is contained in:
Mark Watkins 2011-09-03 11:24:11 +10:00
parent 4dab8e5c63
commit 8504db82e2
4 changed files with 22 additions and 12 deletions

View File

@ -57,6 +57,7 @@ void gBarChart::SetDay(Day * day)
for (QMap<QDate,QVector<Day *> >::iterator d=m_profile->daylist.begin();d!=m_profile->daylist.end();d++) {
tt=QDateTime(d.key(),QTime(0,0,0),Qt::UTC).toTime_t();
//tt=QDateTime(d.key(),QTime(12,0,0)).toTime_t();
dn=tt/86400;
tt*=1000L;
if (!m_minx || tt<m_minx) m_minx=tt;
@ -91,7 +92,9 @@ void gBarChart::SetDay(Day * day)
//m_minx-=86400000L;
// m_minx=qint64(QDateTime(m_profile->FirstDay(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
//m_maxx=qint64(QDateTime(m_profile->LastDay().addDays(1),QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
m_maxx=qint64(QDateTime(m_profile->LastDay().addDays(1),QTime(0,0,0),Qt::UTC).toTime_t())*1000L;
//m_maxx=qint64(QDateTime(m_profile->LastDay().addDays(1),QTime(12,0,0)).toTime_t())*1000L;
int i=0;
//set miny & maxy here.. how?
@ -128,9 +131,11 @@ void gBarChart::paint(gGraph & w,int left, int top, int width, int height)
int daynum=0;
float h,tmp;
qint64 offs=minx% 86400000L;
qint64 offs=(minx) % 86400000L;
//zz*=86400000L;
float offset=offs/86400000.0;
float offset=(offs)/86400000.0;
//offset+=float(utcoff)/86400000.0;
offset*=barw;
px=left-offset;

View File

@ -22,6 +22,7 @@ gXAxis::gXAxis(QColor col,bool fadeout)
m_show_minor_lines=false;
m_show_minor_ticks=true;
m_show_major_ticks=true;
m_utcfix=false;
m_fadeout=fadeout;
QDateTime d=QDateTime::currentDateTime();
QTime t1=d.time();
@ -66,14 +67,14 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
//fitmode=-1;
fd="MMM dd";
} else */
if (xx>86400000L) { // Day
if (xx>=86400000L) { // Day
fd="MMM 00";
dividx=0;
divmax=15;
divmax=7;
fitmode=0;
} else if (xx>600000) { // Minutes
fd="00:00";
dividx=6;
dividx=7;
divmax=24;
fitmode=1;
} else if (xx>5000) { // Seconds
@ -140,6 +141,7 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
if (py<start_px) continue;
lines->add(py,top,py,top+4,linecol);
}
int utcoff=m_utcfix ? QDateTime(QDate(1970,1,1),QTime(0,0,0)).secsTo(QDateTime(QDate(1970,1,1),QTime(0,0,0),Qt::UTC))/3600 : 0;
for (qint64 i=aligned_start;i<maxx;i+=step) {
px=double(i-minx)*xmult;
@ -148,7 +150,7 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height)
qint64 j=i+tz_offset;
int ms=j % 1000;
int m=(j/60000L) % 60L;
int h=(j/3600000L) % 24L;
int h=((j/3600000L)-utcoff) % 24L;
int s=(j/1000L) % 60L;
if (fitmode==0) {

View File

@ -23,7 +23,7 @@ class gXAxis:public Layer
void SetShowMajorTicks(bool b) { m_show_major_ticks=b; }
bool ShowMinorTicks() { return m_show_minor_ticks; }
bool ShowMajorTicks() { return m_show_major_ticks; }
void setUtcFix(bool b) { m_utcfix=b; }
protected:
// virtual const wxString & Format(double v) { static wxString t; wxDateTime d; d.Set(v); t=d.Format(wxT("%H:%M")); return t; };
bool m_show_major_lines;
@ -31,6 +31,7 @@ class gXAxis:public Layer
bool m_show_minor_ticks;
bool m_show_major_ticks;
bool m_utcfix;
QColor m_line_color;
QColor m_text_color;

View File

@ -111,7 +111,9 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw)
bc->addSlice(CPAP_Obstructive,QColor("#40c0ff"));
bc->addSlice(CPAP_ClearAirway,QColor("purple"));
BC->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin);
BC->AddLayer(new gXAxis(),LayerBottom,0,gXAxis::Margin);
gXAxis *gx=new gXAxis();
gx->setUtcFix(true);
BC->AddLayer(gx,LayerBottom,0,gXAxis::Margin);
BC->AddLayer(bc);
BC->AddLayer(new gXGrid());
@ -1101,9 +1103,9 @@ Session * Daily::CreateJournalSession(QDate date)
profile->AddMachine(m);
}
Session *sess=new Session(m,0);
QDateTime dt;
dt.setDate(date);
dt.setTime(QTime(17,0)); //5pm to make sure it goes in the right day
QDateTime dt(date,QTime(17,0));
//dt.setDate(date);
//dt.setTime(QTime(17,0)); //5pm to make sure it goes in the right day
sess->set_first(qint64(dt.toTime_t())*1000L);
dt=dt.addSecs(3600);
sess->set_last(qint64(dt.toTime_t())*1000L);