Index: sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp =================================================================== diff -u -r0ced87f43c28bcc9f3402e19284030ad1405e9e8 -r9bd436782039b50ac45eb38f561a36706517271b --- sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 0ced87f43c28bcc9f3402e19284030ad1405e9e8) +++ sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 9bd436782039b50ac45eb38f561a36706517271b) @@ -66,7 +66,7 @@ .arg(_diastolic) .arg(_heartRate) ); - timerReset(); + timerStart(); } /*! @@ -75,10 +75,8 @@ */ void View::VTreatmentVitals::doSkip() { - if ( enableDialog() ) { - LOG_APPED_UI(tr("Vital Skipped")); - timerReset(); - } + LOG_APPED_UI(tr("Vital Skipped")); + timerReset(); } /*! @@ -89,21 +87,21 @@ */ void View::VTreatmentVitals::doReset() { - epoch ( 0 ); - lastRead ( ""); - systolic ( 0 ); - diastolic ( 0 ); - heartRate ( 0 ); + epoch ( 0 ); + lastRead ( ""); + systolic ( 0 ); + diastolic ( 0 ); + heartRate ( 0 ); + countdown ( ""); + totalCount ( 0 ); + canStartInterval ( 0 ); - enableDialog ( 0 ); - // force notify the Gui emit epochChanged ( 0 ); emit lastReadChanged ( ""); emit systolicChanged ( 0 ); emit diastolicChanged ( 0 ); emit heartRateChanged ( 0 ); - emit totalCountChanged ( 0 ); } /*! @@ -159,27 +157,11 @@ */ void View::VTreatmentVitals::timerEvent(QTimerEvent *) { - if ( ! _timerId ) return; // No timer started or failed starting - if ( ! _interval ) return; // if interval is 0/OFF return + if ( ! _timerId ) return; // No timer started or failed starting + if ( ! _interval ) return; // if interval is 0/OFF return + if ( ! _canStartInterval ) return; // parameters have not been confirmed yet - _counter_sec++; - emit totalCountChanged(++_totalCount); - - min_left(_counter_min ); - sec_left(60 - _counter_sec); - - countdown(QStringLiteral("%1:%2").arg(_min_left,2,10,QChar('0')).arg(_sec_left,2,10,QChar('0'))); - - if ( _counter_sec % 60 ) return; // only check every minute - - if ( ! _counter_min ) { - timerStop(); - emit didTrigger(); - } - else { - _counter_min--; - _counter_sec = 0; - } + updateTimer(); } /*! @@ -202,25 +184,53 @@ { if ( _timerId ) killTimer(_timerId); // this typically should not happen. if ( ! _interval ) return; // if interval is 0/OFF return + timerReset(); _timerId = startTimer(1000); // 1 sec interval which will used as 1 min in timerEvent (easier to debug) } +void View::VTreatmentVitals::updateTimer() +{ + _now = QDateTime::currentDateTime(); + + // minutes past last interval mark + int past = _now.time().minute() % _interval; + + // Seconds since the last interval mark + totalCount( past * 60 + _now.time().second()); + + // Seconds until the next interval mark + total_sec_left (_interval * 60 - _totalCount); + + // when exactly on mark, show full interval + if (_total_sec_left <= 1 ) { + timerStop(); + emit didTrigger(); + _total_sec_left = _interval * 60; + } + + // construct count down string + _counter_min = _total_sec_left / 60; + _counter_sec = _total_sec_left % 60; + countdown( QStringLiteral("%1:%2") .arg(_counter_min,2,10,QChar('0')) + .arg(_counter_sec,2,10,QChar('0')) ); +} + /*! * \brief View::VTreatmentVitals::timerReset * \details Resets the timer counters based on the current interval. */ void View::VTreatmentVitals::timerReset() -{ - if ( _interval ) { - // ( -1 ) :the interval is 0 based but if as an example we set the counter to 5 then 5 itself gets a minute to pass which makes it 6 min. - _counter_min = _interval - 1; +{ + if ( _interval && _canStartInterval && _timerId ) { // get time past interval + updateTimer(); } - else { // if _interval == 0, counter should set to 0 too not to -1 - _counter_min = 0; + else { // if _interval == 0, clear counters + _counter_sec = 0; + _counter_min = 0; + _totalCount = 0; + _total_sec_left = 0; } - _counter_sec = 0; - _totalCount = 0; } /*!