From 2c3600ab0955797ab2cc00d584538b6c7bf8af70 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sun, 17 Jul 2011 17:03:26 +1000 Subject: [PATCH] Minor Zoom Cleverizement --- Graphs/graphdata_custom.cpp | 14 +++++++------- Graphs/graphdata_custom.h | 36 +++++++++++++++++------------------ Graphs/graphwindow.cpp | 18 ++++++++++++++---- SleepLib/profiles.cpp | 6 ++++-- daily.cpp | 4 ++-- overview.cpp | 38 ++++++++++++++++++++----------------- overview.h | 9 ++------- 7 files changed, 68 insertions(+), 57 deletions(-) diff --git a/Graphs/graphdata_custom.cpp b/Graphs/graphdata_custom.cpp index 0ff2ae6a..d17626b5 100644 --- a/Graphs/graphdata_custom.cpp +++ b/Graphs/graphdata_custom.cpp @@ -344,9 +344,9 @@ void FlagData::Reload(Day *day) //////////////////////////////////////////////////////////////////////////////////////////// SessionTimes::SessionTimes(Profile * _profile) - :gPointData(2048),profile(_profile) +:HistoryData(_profile,2048) { - AddSegment(max_points); + /*AddSegment(max_points); if (profile->LastDay().isValid()) { QDateTime tmp; tmp.setDate(profile->FirstDay()); @@ -354,12 +354,12 @@ SessionTimes::SessionTimes(Profile * _profile) tmp.setDate(profile->LastDay()); real_max_x=(tmp.toMSecsSinceEpoch()/86400000.0)+1; } - real_min_y=real_max_y=0; + real_min_y=real_max_y=0; */ } SessionTimes::~SessionTimes() { } -void SessionTimes::ResetDateRange() +/*void SessionTimes::ResetDateRange() { if (profile->LastDay().isValid()) { QDateTime tmp; @@ -395,7 +395,7 @@ void SessionTimes::SetDateRange(QDate start,QDate end) (*i)->DataChanged(this); } // Do nothing else.. Callers responsibility to Refresh window. } - +*/ void SessionTimes::Reload(Day *day) { @@ -454,8 +454,8 @@ void SessionTimes::Reload(Day *day) // HistoryData Implementation //////////////////////////////////////////////////////////////////////////////////////////// -HistoryData::HistoryData(Profile * _profile) -:gPointData(1024),profile(_profile) +HistoryData::HistoryData(Profile * _profile,int mpts) +:gPointData(mpts),profile(_profile) { AddSegment(max_points); if (profile->LastDay().isValid()) { diff --git a/Graphs/graphdata_custom.h b/Graphs/graphdata_custom.h index 72ec5fa0..32520c6f 100644 --- a/Graphs/graphdata_custom.h +++ b/Graphs/graphdata_custom.h @@ -70,27 +70,10 @@ public: virtual void Reload(Day *day=NULL); }; -class SessionTimes:public gPointData -{ -public: - SessionTimes(Profile * _profile); - virtual ~SessionTimes(); - - void SetProfile(Profile *_profile) { profile=_profile; Reload(); } - Profile * GetProfile() { return profile; } - double GetAverage(); // length?? - virtual void Reload(Day *day=NULL); - virtual void ResetDateRange(); - virtual void SetDateRange(QDate start,QDate end); - -protected: - Profile * profile; -}; - class HistoryData:public gPointData { public: - HistoryData(Profile * _profile); + HistoryData(Profile * _profile,int mpts=2048); virtual ~HistoryData(); void SetProfile(Profile *_profile) { profile=_profile; Reload(); } @@ -106,6 +89,23 @@ protected: Profile * profile; }; +class SessionTimes:public HistoryData +{ +public: + SessionTimes(Profile * _profile); + virtual ~SessionTimes(); + + //void SetProfile(Profile *_profile) { profile=_profile; Reload(); } + //Profile * GetProfile() { return profile; } + //virtual double GetAverage(); // length?? + virtual void Reload(Day *day=NULL); + //virtual void ResetDateRange(); + //virtual void SetDateRange(QDate start,QDate end); + +protected: + // Profile * profile; +}; + class HistoryCodeData:public HistoryData { public: diff --git a/Graphs/graphwindow.cpp b/Graphs/graphwindow.cpp index 65e96d0f..2827209e 100644 --- a/Graphs/graphwindow.cpp +++ b/Graphs/graphwindow.cpp @@ -211,18 +211,28 @@ void gGraphWindow::ZoomX(double mult,int origin_px) if (origin_px<0) origin_px=0; if (origin_px>Width()) origin_px=Width(); + + // Okay, I want it to zoom in centered on the mouse click area.. + // Find X graph position of mouse click + // find current zoom width + // apply zoom + // center on point found in step 1. + double min=min_x; double max=max_x; double hardspan=rmax_x-rmin_x; double span=max-min; - double origin=double(origin_px) / Width() * span; + double ww=double(origin_px) / double(Width()); + double origin=ww * span; + //double center=0.5*span; + //double dist=(origin-center); double q=span*mult; if (q>hardspan) q=hardspan; if (qmodifiers() & Qt::ControlModifier) zoom_fact=5; //if (!m_block_zoom) { - ZoomX(zoom_fact,0); + ZoomX(zoom_fact,x); did_draw=true; //} m_foobar_moved=0; @@ -540,7 +550,7 @@ void gGraphWindow::OnMouseRightRelease(QMouseEvent * event) //(*g)->ZoomX(zoom_fact,0); //} //if (!m_block_zoom) { - ZoomX(zoom_fact,0); //event.GetX()); // adds origin to zoom out.. Doesn't look that cool. + ZoomX(zoom_fact,x); //event.GetX()); // adds origin to zoom out.. Doesn't look that cool. if (pref["LinkGraphMovement"].toBool()) { double min=MinX(); diff --git a/SleepLib/profiles.cpp b/SleepLib/profiles.cpp index f06cebdf..a93d4ce2 100644 --- a/SleepLib/profiles.cpp +++ b/SleepLib/profiles.cpp @@ -350,15 +350,17 @@ void Scan() QFileInfoList list=dir.entryInfoList(); QString username=getUserName(); - if (list.size()==0) { + if (list.size()==0) { // No profiles.. Create one. Create(username,username,""); return; } + + // Iterate through subdirectories and load profiles.. for (int i=0;iOpen(); + prof->Open(); // Read it's XML file.. profiles[fi.fileName()]=prof; } diff --git a/daily.cpp b/daily.cpp index d8014a1e..e772664b 100644 --- a/daily.cpp +++ b/daily.cpp @@ -262,7 +262,7 @@ Daily::Daily(QWidget *parent,QGLContext *context) : G_AHI->SetGradientBackground(false); //G_AHI->setMaximumSize(2000,30); //TAP->setMaximumSize(2000,30); - NoData=new QLabel(tr("No CPAP Data"),gSplitter); + NoData=new QLabel(tr("No data"),gSplitter); NoData->setAlignment(Qt::AlignCenter); QFont font("FreeSans",20); //NoData->font(); //font.setBold(true); @@ -665,7 +665,7 @@ void Daily::Load(QDate date) //SPO2->hide(); } if (!cpap && !oxi) { - NoData->setText(tr("No CPAP Data for ")+date.toString(Qt::SystemLocaleLongDate)); + NoData->setText(tr("No data for ")+date.toString(Qt::SystemLocaleLongDate)); NoData->show(); } else NoData->hide(); diff --git a/overview.cpp b/overview.cpp index ec0c57af..20cbc98f 100644 --- a/overview.cpp +++ b/overview.cpp @@ -28,22 +28,19 @@ Overview::Overview(QWidget *parent,QGLContext *context) : AddData(pressure=new HistoryCodeData(profile,CPAP_PressureAverage)); AddData(pressure_min=new HistoryCodeData(profile,CPAP_PressureMin)); AddData(pressure_max=new HistoryCodeData(profile,CPAP_PressureMax)); - AddData(pressure_eap=new HistoryCodeData(profile,BIPAP_EAPAverage)); AddData(pressure_iap=new HistoryCodeData(profile,BIPAP_IAPAverage)); - - session_times=new SessionTimes(profile); - - // pressure->ForceMinY(3); - // pressure->ForceMaxY(12); AddData(leak=new HistoryCodeData(profile,CPAP_LeakMedian)); AddData(usage=new UsageHistoryData(profile,UHD_Hours)); AddData(waketime=new UsageHistoryData(profile,UHD_Waketime)); AddData(bedtime=new UsageHistoryData(profile,UHD_Bedtime)); + AddData(session_times=new SessionTimes(profile)); + + // pressure->ForceMinY(3); + // pressure->ForceMaxY(12); gSplitter=new QSplitter(Qt::Vertical,ui->SummaryGraphWindow); gSplitter->setStyleSheet("QSplitter::handle { background-color: 'dark grey'; }"); - gSplitter->setChildrenCollapsible(true); gSplitter->setHandleWidth(3); ui->graphLayout->addWidget(gSplitter); @@ -70,8 +67,6 @@ Overview::Overview(QWidget *parent,QGLContext *context) : PRESSURE->setMinimumHeight(170); AddGraph(LEAK=new gGraphWindow(ui->SummaryGraphWindow,tr("Leak"),AHI)); - //LEAK->SetMargins(10,15,65,80); - //LEAK->AddLayer(new gBarChart(leak,wxYELLOW)); LEAK->AddLayer(new gXAxis()); LEAK->AddLayer(new gYAxis()); LEAK->AddLayer(new gFooBar(7)); @@ -80,11 +75,10 @@ Overview::Overview(QWidget *parent,QGLContext *context) : LEAK->setMinimumHeight(170); AddGraph(USAGE=new gGraphWindow(ui->SummaryGraphWindow,tr("Usage (Hours)"),AHI)); - //USAGE->SetMargins(10,15,65,80); USAGE->AddLayer(new gFooBar(7)); USAGE->AddLayer(new gYAxis()); USAGE->AddLayer(new gBarChart(usage,QColor("green"))); - USAGE->SetBottomMargin(USAGE->GetBottomMargin()+gXAxis::Margin+15); + USAGE->SetBottomMargin(USAGE->GetBottomMargin()+gXAxis::Margin+25); //USAGE->AddLayer(new gXAxis()); //USAGE->AddLayer(new gLineChart(usage,QColor("green"))); USAGE->setMinimumHeight(170); @@ -98,6 +92,13 @@ Overview::Overview(QWidget *parent,QGLContext *context) : //SESSTIMES->AddLayer(new gXAxis()); SESSTIMES->setMinimumHeight(270); + NoData=new QLabel(tr("No data"),gSplitter); + NoData->setAlignment(Qt::AlignCenter); + QFont font("FreeSans",20); //NoData->font(); + //font.setBold(true); + NoData->setFont(font); + NoData->hide(); + gGraphWindow * graphs[]={AHI,PRESSURE,LEAK,USAGE,SESSTIMES}; int ss=sizeof(graphs)/sizeof(gGraphWindow *); @@ -132,13 +133,16 @@ void Overview::RedrawGraphs() void Overview::ReloadGraphs() { for (list::iterator h=Data.begin();h!=Data.end();h++) { - (*h)->SetProfile(profile); - (*h)->ResetDateRange(); - (*h)->Reload(NULL); + if (HistoryData *hd=dynamic_cast(*h)){ + hd->SetProfile(profile); + hd->ResetDateRange(); + hd->Reload(NULL); + } + } - session_times->SetProfile(profile); - session_times->ResetDateRange(); - session_times->Reload(NULL); +// session_times->SetProfile(profile); + // session_times->ResetDateRange(); + // session_times->Reload(NULL); on_rbLastWeek_clicked(); } diff --git a/overview.h b/overview.h index fee35ae7..8dd6574b 100644 --- a/overview.h +++ b/overview.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -31,19 +32,12 @@ public: private slots: - void on_drStart_dateChanged(const QDate &date); - void on_drEnd_dateChanged(const QDate &date); - void on_rbDateRange_toggled(bool checked); - void on_rbLastWeek_clicked(); - void on_rbLastMonth_clicked(); - void on_rbEverything_clicked(); - void on_rbDateRange_clicked(); private: @@ -66,6 +60,7 @@ private: list Graphs; Day *dummyday; QSplitter *gSplitter; + QLabel *NoData; }; #endif // OVERVIEW_H