Index: sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp =================================================================== diff -u -r0ced87f43c28bcc9f3402e19284030ad1405e9e8 -r80b727733768477975addc967b3d6b04ed39e598 --- sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 0ced87f43c28bcc9f3402e19284030ad1405e9e8) +++ sources/view/hd/adjustment/common/VCommonAdjustmentVitals.cpp (.../VCommonAdjustmentVitals.cpp) (revision 80b727733768477975addc967b3d6b04ed39e598) @@ -28,8 +28,6 @@ * \details All the class signal/slot connections are defined here. */ void View::VTreatmentVitals::initConnections() { - connect(this, SIGNAL( intervalChanged (const quint8 &)), - this, SLOT(onIntervalChanged ( ))); ACTION_VIEW_CONNECTION( TreatmentVitalsData ); } @@ -47,6 +45,7 @@ .arg(vData.mSystolic ) .arg(vData.mDiastolic) .arg(vData.mHeartRate)); + adjustment ( true ); } /*! @@ -66,7 +65,7 @@ .arg(_diastolic) .arg(_heartRate) ); - timerReset(); + timerStart(); } /*! @@ -75,10 +74,7 @@ */ void View::VTreatmentVitals::doSkip() { - if ( enableDialog() ) { - LOG_APPED_UI(tr("Vital Skipped")); - timerReset(); - } + LOG_APPED_UI(tr("Vital Skipped")); } /*! @@ -89,21 +85,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,68 +155,56 @@ */ 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(); } /*! - * \brief View::VTreatmentVitals::onIntervalChanged - * \details Resets or stops the timer depending on whether an interval - * is currently set. - */ -void View::VTreatmentVitals::onIntervalChanged() -{ - if ( _interval ) timerReset(); - else timerStop (); // Timer stop is resetting timer too. -} - -/*! * \brief View::VTreatmentVitals::start * \details Starts the timer by 1 min interval * \note the vital times are all minutes. */ 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() { + int interval = _interval ? _interval : _defaultInterval; + _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 ) { 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(); + } + + // construct count down string 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 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')) ); } - else { // if _interval == 0, counter should set to 0 too not to -1 - _counter_min = 0; - } - _counter_sec = 0; - _totalCount = 0; } /*! @@ -232,5 +216,4 @@ if ( ! _timerId ) return; // No timer started or failed starting killTimer(_timerId); _timerId = 0; - timerReset(); }