Index: sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp =================================================================== diff -u -r0ced87f43c28bcc9f3402e19284030ad1405e9e8 -r83d2e1a9625c2035214bf6604d1603736877dab8 --- sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 0ced87f43c28bcc9f3402e19284030ad1405e9e8) +++ sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 83d2e1a9625c2035214bf6604d1603736877dab8) @@ -47,6 +47,7 @@ .arg(vData.mSystolic ) .arg(vData.mDiastolic) .arg(vData.mHeartRate)); + emit didTrigger(); } /*! @@ -66,7 +67,7 @@ .arg(_diastolic) .arg(_heartRate) ); - timerReset(); + timerStart(); } /*! @@ -75,10 +76,7 @@ */ void View::VTreatmentVitals::doSkip() { - if ( enableDialog() ) { - LOG_APPED_UI(tr("Vital Skipped")); - timerReset(); - } + LOG_APPED_UI(tr("Vital Skipped")); } /*! @@ -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,10 @@ */ 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 ( ! _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(); } /*! @@ -189,8 +170,6 @@ */ void View::VTreatmentVitals::onIntervalChanged() { - if ( _interval ) timerReset(); - else timerStop (); // Timer stop is resetting timer too. } /*! @@ -201,26 +180,42 @@ void View::VTreatmentVitals::timerStart() { 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) } /*! - * \brief View::VTreatmentVitals::timerReset - * \details Resets the timer counters based on the current interval. + * \brief View::VTreatmentVitals::updateTimer + * \details Update timer from current time with set interval and update UI data */ -void View::VTreatmentVitals::timerReset() +void View::VTreatmentVitals::updateTimer() { - 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; + int interval = _interval && _enableBPCuff ? _interval : 15; + _now = QDateTime::currentDateTime(); + + // minutes past last interval mark + int past = _now.time().minute() % interval; + int currentCount = past * 60 + _now.time().second(); + + // Seconds since the last interval mark + if ( _interval && _enableBPCuff ) { totalCount( currentCount ); } + + // Seconds until the next interval mark + int totalSecLeft = interval * 60 - currentCount; + + // trigger timeout when timer countdown is done + if (totalSecLeft <= 1 ) { + timerStop(); + emit didTimeout(); } - else { // if _interval == 0, counter should set to 0 too not to -1 - _counter_min = 0; + + // construct count down string + if ( _interval && _enableBPCuff ) { + int counter_min = totalSecLeft / 60; + int counter_sec = totalSecLeft % 60; + countdown( QStringLiteral("%1:%2") .arg(counter_min,2,10,QChar('0')) + .arg(counter_sec,2,10,QChar('0')) ); } - _counter_sec = 0; - _totalCount = 0; } /*! @@ -232,5 +227,4 @@ if ( ! _timerId ) return; // No timer started or failed starting killTimer(_timerId); _timerId = 0; - timerReset(); }