diff --git a/Graphs/gYAxis.cpp b/Graphs/gYAxis.cpp index 1530ef04..f01afb94 100644 --- a/Graphs/gYAxis.cpp +++ b/Graphs/gYAxis.cpp @@ -248,15 +248,6 @@ bool gYAxis::mouseMoveEvent(QMouseEvent * event) return false; } -gYAxisTime::gYAxisTime(QColor col): - gYAxis(col) -{ - show_12hr=true; -} - -gYAxisTime::~gYAxisTime() -{ -} const QString gYAxisTime::Format(EventDataType v, int dp) { @@ -277,3 +268,15 @@ const QString gYAxisTime::Format(EventDataType v, int dp) if (dp>2) return QString().sprintf("%02i:%02i:%02i%s",h,m,s,pm); return QString().sprintf("%i:%02i%s",h,m,pm); } + +const QString gYAxisWeight::Format(EventDataType v, int dp) +{ + if (m_unitsystem==US_Metric) { + return QString("%1kg").arg(v,0,'f',2); + } else if (m_unitsystem==US_Archiac) { + int oz=v / (float)ounce_convert; + int lb=oz / 16; + oz = oz % 16; + return QString("%1lb %2oz").arg(lb).arg(oz); + } +} diff --git a/Graphs/gYAxis.h b/Graphs/gYAxis.h index 201a378e..d7c72954 100644 --- a/Graphs/gYAxis.h +++ b/Graphs/gYAxis.h @@ -121,8 +121,8 @@ class gYAxisTime:public gYAxis { public: //! \brief Construct a gYAxisTime object, with QColor col for tickers & times - gYAxisTime(QColor col=Qt::black); - virtual ~gYAxisTime(); + gYAxisTime(bool hr12=true, QColor col=Qt::black) : gYAxis(col), show_12hr(hr12) {} + virtual ~gYAxisTime() {} protected: //! \brief Overrides gYAxis Format to display Time format virtual const QString Format(EventDataType v, int dp); @@ -131,4 +131,27 @@ protected: bool show_12hr; }; + +/*! \class gYAxisWeight + \brief Draws the YAxis tick markers, and labels in weight format + */ +class gYAxisWeight:public gYAxis +{ +public: + //! \brief Construct a gYAxisWeight object, with QColor col for tickers & weight values + gYAxisWeight(UnitSystem us=US_Metric, QColor col=Qt::black) :gYAxis(col), m_unitsystem(us) {} + virtual ~gYAxisWeight() {} + + //! \brief Returns the current UnitSystem displayed (eg, US_Metric (the rest of the world), US_Archiac (American) ) + UnitSystem unitSystem() { return m_unitsystem; } + + //! \brief Set the unit system displayed by this YTicker + void setUnitSystem(UnitSystem us) { m_unitsystem=us; } +protected: + //! \brief Overrides gYAxis Format to display Time format + virtual const QString Format(EventDataType v, int dp); + UnitSystem m_unitsystem; +}; + + #endif // GYAXIS_H diff --git a/SleepLib/loader_plugins/resmed_loader.cpp b/SleepLib/loader_plugins/resmed_loader.cpp index 1367dbd7..94720a61 100644 --- a/SleepLib/loader_plugins/resmed_loader.cpp +++ b/SleepLib/loader_plugins/resmed_loader.cpp @@ -472,6 +472,7 @@ int ResmedLoader::Open(QString & path,Profile *profile) } } + if (m) { m->Save(); } diff --git a/SleepLib/machine_common.h b/SleepLib/machine_common.h index 88f53f37..cfca16fd 100644 --- a/SleepLib/machine_common.h +++ b/SleepLib/machine_common.h @@ -43,6 +43,10 @@ enum SummaryType { ST_CNT, ST_SUM, ST_AVG, ST_WAVG, ST_90P, ST_MIN, ST_MAX, ST_C enum MachineType { MT_UNKNOWN=0,MT_CPAP,MT_OXIMETER,MT_SLEEPSTAGE,MT_JOURNAL }; //void InitMapsWithoutAwesomeInitializerLists(); +enum UnitSystem { US_Metric, US_Archiac }; +const float ounce_convert=28.3495231; +const float pound_convert=ounce_convert*16; + /*! \enum CPAPMode \brief CPAP Machines mode of operation diff --git a/daily.cpp b/daily.cpp index 4554ad20..37461bbe 100644 --- a/daily.cpp +++ b/daily.cpp @@ -38,8 +38,6 @@ extern MainWindow * mainwin; const int min_height=150; -const float ounce_convert=28.3495231; -const float pound_convert=ounce_convert*16; Daily::Daily(QWidget *parent,gGraphView * shared) :QWidget(parent), ui(new Ui::Daily) diff --git a/overview.cpp b/overview.cpp index 0d11d876..88b7890c 100644 --- a/overview.cpp +++ b/overview.cpp @@ -93,14 +93,8 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : AHI=createGraph("AHI","Apnea\nHypopnea\nIndex"); UC=createGraph("Usage","Usage\n(hours)"); - int default_height=PROFILE["GraphHeight"].toInt(); - US=new gGraph(GraphView,"Session Times","Session Times\n(hours)",default_height,0); - US->AddLayer(new gYAxisTime(),LayerLeft,gYAxis::Margin); - gXAxis *x=new gXAxis(); - x->setUtcFix(true); - US->AddLayer(x,LayerBottom,0,gXAxis::Margin); - US->AddLayer(new gXGrid()); + US=createGraph(tr("Session Times"),tr("Session Times\n(hours)"),YT_Time); PR=createGraph(tr("Pressure"),tr("Pressure\n(cmH2O)")); SET=createGraph(tr("Settings"),("Settings")); LK=createGraph(tr("Leaks"),tr("Leak Rate\n(L/min)")); @@ -113,7 +107,7 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : SES=createGraph(tr("Sessions"),tr("Sessions\n(count)")); PULSE=createGraph(tr("Pulse Rate"),tr("Pulse Rate\n(bpm)")); SPO2=createGraph(tr("SpO2"),tr("Oxygen Saturation\n(%)")); - WEIGHT=createGraph(tr("Weight"),tr("Weight\n(kg)")); + WEIGHT=createGraph(tr("Weight"),tr("Weight\n(kg)"),YT_Weight); BMI=createGraph(tr("BMI"),tr("Body\nMass\nIndex")); ZOMBIE=createGraph(tr("Zombie"),tr("How you felt\n(0-10)")); @@ -237,11 +231,25 @@ Overview::~Overview() disconnect(this,SLOT(dateEnd_currentPageChanged(int,int))); delete ui; } -gGraph * Overview::createGraph(QString name,QString units) +gGraph * Overview::createGraph(QString name,QString units, YTickerType yttype) { int default_height=PROFILE["GraphHeight"].toInt(); gGraph *g=new gGraph(GraphView,name,units,default_height,0); - g->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); + + gYAxis *yt; + switch (yttype) { + case YT_Time: + yt=new gYAxisTime(true); // Time scale + break; + case YT_Weight: + yt=new gYAxisWeight(US_Archiac); // Weight scale, which adjusts for UnitSystem + break; + default: + yt=new gYAxis(); // Plain numeric scale + break; + } + + g->AddLayer(yt,LayerLeft,gYAxis::Margin); gXAxis *x=new gXAxis(); x->setUtcFix(true); g->AddLayer(x,LayerBottom,0,gXAxis::Margin); diff --git a/overview.h b/overview.h index c215b4ab..9b1c899f 100644 --- a/overview.h +++ b/overview.h @@ -21,6 +21,8 @@ namespace Ui { class Report; +enum YTickerType { YT_Number, YT_Time, YT_Weight }; + /*! \class Overview \author Mark Watkins \brief Overview tab, showing overall summary data @@ -48,7 +50,7 @@ public: /*! \brief Create an overview graph, adding it to the overview gGraphView object \param QString name The title of the graph \param QString units The units of measurements to show in the popup */ - gGraph * createGraph(QString name,QString units=""); + gGraph * createGraph(QString name,QString units="",YTickerType yttype=YT_Number); gGraph *AHI, *AHIHR, *UC, *US, *PR,*LK,*NPB,*SET,*SES,*RR,*MV,*TV,*PTB,*PULSE,*SPO2,*WEIGHT,*ZOMBIE, *BMI; SummaryChart *bc,*uc, *us, *pr,*lk,*npb,*set,*ses,*rr,*mv,*tv,*ptb,*pulse,*spo2,*weight,*zombie, *bmi, *ahihr;