From 9777ecd2ab15d5de1f6aeb439ba2eba2c33e52e9 Mon Sep 17 00:00:00 2001 From: LoudSnorer <Just4Me.1947@gmail.com> Date: Sun, 21 Mar 2021 16:21:48 -0400 Subject: [PATCH] This allows the Overview Custon range to be saved and resurvive a reloaded of OSCAR. a New feature has been been added but can not be activated until a UI file is changed - another submission. This new feature will utilize the current displayed range as the custom range. Other wise the Overview custom range uses the values from the calendar. This changes does not require and data or translations. --- oscar/SleepLib/profiles.h | 6 ++++ oscar/overview.cpp | 72 +++++++++++++++++++++++++-------------- oscar/overview.h | 5 +-- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/oscar/SleepLib/profiles.h b/oscar/SleepLib/profiles.h index 4c218082..6acf9b6a 100644 --- a/oscar/SleepLib/profiles.h +++ b/oscar/SleepLib/profiles.h @@ -369,6 +369,8 @@ const QString STR_US_PrefCalcMax = "PrefCalcMax"; const QString STR_US_ShowUnknownFlags = "ShowUnknownFlags"; const QString STR_US_StatReportMode = "StatReportMode"; const QString STR_US_LastOverviewRange = "LastOverviewRange"; +const QString STR_US_CustomOverviewRangeStart = "CustomOverviewRangeStart"; +const QString STR_US_CustomOverviewRangeEnd = "CustomOverviewRangeEnd"; // Values for StatReportMode const int STAT_MODE_STANDARD = 0; @@ -742,6 +744,8 @@ class UserSettings : public PrefSettings int statReportMode() const { return getPref(STR_US_StatReportMode).toInt(); } inline bool showUnknownFlags() const { return m_showUnownFlags; } int lastOverviewRange() const { return getPref(STR_US_LastOverviewRange).toInt(); } + QDate customOverviewRangeStart () const { return getPref(STR_US_CustomOverviewRangeStart).toDate(); } + QDate customOverviewRangeEnd () const { return getPref(STR_US_CustomOverviewRangeEnd).toDate(); } void setUnitSystem(UnitSystem us) { setPref(STR_US_UnitSystem, (int)us); } void setEventWindowSize(double size) { setPref(STR_US_EventWindowSize, size); } @@ -754,6 +758,8 @@ class UserSettings : public PrefSettings void setStatReportMode(int i) { setPref(STR_US_StatReportMode, i); } void setShowUnknownFlags(bool b) { setPref(STR_US_ShowUnknownFlags, m_showUnownFlags=b); } void setLastOverviewRange(int i) { setPref(STR_US_LastOverviewRange, i); } + void setCustomOverviewRangeStart(QDate i) { setPref(STR_US_CustomOverviewRangeStart, i); } + void setCustomOverviewRangeEnd(QDate i) { setPref(STR_US_CustomOverviewRangeEnd, i); } bool m_calculateRDI, m_showUnownFlags, m_skipEmptyDays; int m_prefCalcMiddle, m_prefCalcMax; diff --git a/oscar/overview.cpp b/oscar/overview.cpp index de2b930b..755f4b05 100644 --- a/oscar/overview.cpp +++ b/oscar/overview.cpp @@ -151,11 +151,6 @@ Overview::~Overview() disconnect(ui->dateEnd->calendarWidget(), SIGNAL(currentPageChanged(int, int)), this, SLOT(dateEnd_currentPageChanged(int, int))); disconnect(ui->dateStart->calendarWidget(), SIGNAL(currentPageChanged(int, int)), this, SLOT(dateStart_currentPageChanged(int, int))); - // Don't save custom date range. Default to last 3 months - if (p_profile->general->lastOverviewRange() == 8) { - p_profile->general->setLastOverviewRange(4); - } - // Save graph orders and pin status, etc... GraphView->SaveSettings("Overview");//no trans @@ -325,9 +320,6 @@ void Overview::updateGraphCombo() { ui->graphCombo->clear(); gGraph *g; - // ui->graphCombo->addItem("Show All Graphs"); - // ui->graphCombo->addItem("Hide All Graphs"); - // ui->graphCombo->addItem("---------------"); for (int i = 0; i < GraphView->size(); i++) { g = (*GraphView)[i]; @@ -345,6 +337,7 @@ void Overview::updateGraphCombo() updateCube(); } +#if 0 void Overview::ResetGraphs() { QDate start = ui->dateStart->date(); @@ -366,6 +359,7 @@ void Overview::ResetGraph(QString name) g->setDay(nullptr); GraphView->redraw(); } +#endif void Overview::RedrawGraphs() { @@ -430,6 +424,9 @@ void Overview::on_dateEnd_dateChanged(const QDate &date) qint64 d2 = qint64(QDateTime(date, QTime(23, 0, 0)/*, Qt::UTC*/).toTime_t()) * 1000L; GraphView->SetXBounds(d1, d2); ui->dateStart->setMaximumDate(date); + if (customMode) { + p_profile->general->setCustomOverviewRangeEnd(date); + } } void Overview::on_dateStart_dateChanged(const QDate &date) @@ -438,6 +435,10 @@ void Overview::on_dateStart_dateChanged(const QDate &date) qint64 d2 = qint64(QDateTime(ui->dateEnd->date(), QTime(23, 0, 0)/*, Qt::UTC*/).toTime_t()) * 1000L; GraphView->SetXBounds(d1, d2); ui->dateEnd->setMinimumDate(date); + if (customMode) { + p_profile->general->setCustomOverviewRangeStart(date); + } + } // Zoom to 100% button clicked or called back from 100% zoom in popup menu @@ -463,7 +464,6 @@ void Overview::ResetGraphOrder(int type) // Process new range selection from combo button void Overview::on_rangeCombo_activated(int index) { - p_profile->general->setLastOverviewRange(index); // type of range in last use ui->dateStart->setMinimumDate(p_profile->FirstDay()); // first and last dates for ANY machine type ui->dateEnd->setMaximumDate(p_profile->LastDay()); @@ -474,22 +474,6 @@ void Overview::on_rangeCombo_activated(int index) end = max(end, p_profile->LastDay(MT_SLEEPSTAGE)); QDate start; - if (index == 8) { // Custom - ui->dateStartLabel->setEnabled(true); - ui->dateEndLabel->setEnabled(true); - ui->dateEnd->setEnabled(true); - ui->dateStart->setEnabled(true); - - ui->dateStart->setMaximumDate(ui->dateEnd->date()); - ui->dateEnd->setMinimumDate(ui->dateStart->date()); - p_profile->general->setLastOverviewRange(8); - return; - } - - ui->dateEnd->setEnabled(false); - ui->dateStart->setEnabled(false); - ui->dateStartLabel->setEnabled(false); - ui->dateEndLabel->setEnabled(false); if (index == 0) { start = end.addDays(-6); @@ -507,10 +491,48 @@ void Overview::on_rangeCombo_activated(int index) start = end.addYears(-1).addDays(1); } else if (index == 7) { // Everything start = p_profile->FirstDay(); + } else if (index == 8 || index == 9) { // Custom + // Validate save Overview Custom Range for first access. + if (!p_profile->general->customOverviewRangeStart().isValid() + || (!p_profile->general->customOverviewRangeEnd().isValid() ) + || (index==9 /* New Coustom mode - to reset custom range to displayed date range*/) + ) { + // Reset Custom Range to current range displayed + // on first initialization of this version of OSCAR + // or on new custom Mode to reset range. + qint64 istart,iend; + GraphView->GetXBounds(istart , iend); + start = QDateTime::fromMSecsSinceEpoch( istart ).date(); + end = QDateTime::fromMSecsSinceEpoch( iend ).date(); + p_profile->general->setCustomOverviewRangeStart(start); + p_profile->general->setCustomOverviewRangeEnd(end); + index=8; + ui->rangeCombo->setCurrentIndex(index); + } else if (customMode) { // last mode was custom. + // Reset Custom Range to current range in calendar widget + // Custom mode MUST be initialized to false when the Custom Instance is created. + start = ui->dateStart->date(); + end = ui->dateEnd->date(); + p_profile->general->setCustomOverviewRangeStart(start); + p_profile->general->setCustomOverviewRangeEnd(end); + } else { + // have a change in RangeCombo selection. Use last saved values. + start = p_profile->general->customOverviewRangeStart() ; + end = p_profile->general->customOverviewRangeEnd() ; + } } if (start < p_profile->FirstDay()) { start = p_profile->FirstDay(); } + customMode = (index == 8) ; + ui->dateStartLabel->setEnabled(customMode); + ui->dateEndLabel->setEnabled(customMode); + ui->dateEnd->setEnabled(customMode); + ui->dateStart->setEnabled(customMode); + + + p_profile->general->setLastOverviewRange(index); // type of range in last use + // Ensure that all summary files are available and update version numbers if required int size = start.daysTo(end); qDebug() << "Overview range combo from" << start << "to" << end << "with" << size << "days"; diff --git a/oscar/overview.h b/oscar/overview.h index 5a434b18..5513c329 100644 --- a/oscar/overview.h +++ b/oscar/overview.h @@ -50,7 +50,7 @@ class Overview : public QWidget void ResetFont(); //! \brief Recalculates Overview chart info, but keeps the date set - void ResetGraphs(); + //void ResetGraphs(); //! \brief Reset graphs to uniform heights void ResetGraphLayout(); @@ -80,7 +80,7 @@ class Overview : public QWidget //! \brief List of SummaryCharts shown on the overview page QVector<SummaryChart *> OverviewCharts; - void ResetGraph(QString name); + //void ResetGraph(QString name); void RebuildGraphs(bool reset = true); @@ -128,6 +128,7 @@ class Overview : public QWidget QIcon *icon_on; QIcon *icon_off; MyLabel *dateLabel; + bool customMode=false; //! \brief Updates the calendar highlighting for the calendar object for this date. void UpdateCalendarDay(QDateEdit *calendar, QDate date);