FotoBox
FotoBox::Countdown Class Reference

The Countdown class. More...

#include <countdown.h>

+ Inheritance diagram for FotoBox::Countdown:
+ Collaboration diagram for FotoBox::Countdown:

Signals

void update (unsigned int)
 Update countdown. More...
 
void elapsed ()
 Countdown elapsed. More...
 

Public Member Functions

 Countdown (QObject *parent=nullptr, unsigned int i_seconds=0)
 Countdown constructor. More...
 
 ~Countdown () override=default
 Countdown default destructor. More...
 
 Countdown (const Countdown &other)=delete
 Countdown default copy constructor. More...
 
Countdownoperator= (const Countdown &other)=delete
 Countdown default copy assignment. More...
 
 Countdown (Countdown &&other)=delete
 Countdown default move constructor. More...
 
Countdownoperator= (Countdown &&other)=delete
 Countdown default move assignment. More...
 
void setStartTime (unsigned int i_seconds)
 Set the countdown start time. More...
 
auto isActive () const -> bool
 Show countdown status. More...
 
auto start () -> bool
 Start countdown. More...
 
auto stop () -> bool
 Stop countdown and check. More...
 
auto reset () -> bool
 Reset countdown (reset. More...
 

Private Member Functions

void updateTimeLeft ()
 Start the timer until there is no time left, means. More...
 

Private Attributes

QTimer m_timer
 
unsigned int m_startTime
 
unsigned int m_timeLeft
 
bool m_isActive {false}
 

Static Private Attributes

static constexpr int ONE_SECOND = 1000
 

Detailed Description

The Countdown class.

Provides a countdown which operates on the base of seconds

Definition at line 20 of file countdown.h.

Constructor & Destructor Documentation

◆ Countdown() [1/3]

FotoBox::Countdown::Countdown ( QObject *  parent = nullptr,
unsigned int  i_seconds = 0 
)
explicit

Countdown constructor.

Parameters
parentQObject
i_secondsset the start time
See also
m_startTime

Definition at line 12 of file countdown.cpp.

13  : QObject(parent)
14  , m_timer(this)
15  , m_startTime(i_seconds)
16  , m_timeLeft(i_seconds)
17 {
18  //set update intervall to one second
19  m_timer.setInterval(ONE_SECOND);
20 
21  //Every second it is checked if the countdown is elapsed
22  connect(&m_timer, &QTimer::timeout, this, &Countdown::updateTimeLeft);
23 }
static constexpr int ONE_SECOND
Definition: countdown.h:121
unsigned int m_startTime
Definition: countdown.h:112
void updateTimeLeft()
Start the timer until there is no time left, means.
Definition: countdown.cpp:25
unsigned int m_timeLeft
Definition: countdown.h:115

References m_timer, ONE_SECOND, and updateTimeLeft().

+ Here is the call graph for this function:

◆ ~Countdown()

FotoBox::Countdown::~Countdown ( )
overridedefault

Countdown default destructor.

◆ Countdown() [2/3]

FotoBox::Countdown::Countdown ( const Countdown other)
delete

Countdown default copy constructor.

◆ Countdown() [3/3]

FotoBox::Countdown::Countdown ( Countdown &&  other)
delete

Countdown default move constructor.

Member Function Documentation

◆ elapsed

void FotoBox::Countdown::elapsed ( )
signal

Countdown elapsed.

See also
m_timeLeft reached zero

Referenced by FotoBox::FotoBox::countdown(), FotoBox::Preferences::Preferences(), and updateTimeLeft().

+ Here is the caller graph for this function:

◆ isActive()

auto FotoBox::Countdown::isActive ( ) const -> bool

Show countdown status.

Returns
bool getter
See also
m_isActive true: is active / false: not active

Definition at line 52 of file countdown.cpp.

53 {
54  return m_isActive;
55 }

References m_isActive.

◆ operator=() [1/2]

Countdown& FotoBox::Countdown::operator= ( const Countdown other)
delete

Countdown default copy assignment.

◆ operator=() [2/2]

Countdown& FotoBox::Countdown::operator= ( Countdown &&  other)
delete

Countdown default move assignment.

◆ reset()

auto FotoBox::Countdown::reset ( ) -> bool

Reset countdown (reset.

See also
m_timeLeft value with
m_startTime)

Will also

See also
stop() current countdown
Returns
bool true: is reseted / false: not reseted

Definition at line 88 of file countdown.cpp.

89 {
90  //stop countdown
91  if (stop()) {
92  //reset it
94  return true;
95  }
96 
97  return false;
98 }
auto stop() -> bool
Stop countdown and check.
Definition: countdown.cpp:78

Referenced by setStartTime().

+ Here is the caller graph for this function:

◆ setStartTime()

void FotoBox::Countdown::setStartTime ( unsigned int  i_seconds)

Set the countdown start time.

Parameters
i_secondssetter
See also
m_startTime

Definition at line 46 of file countdown.cpp.

47 {
48  m_startTime = i_seconds;
49  reset();
50 }
auto reset() -> bool
Reset countdown (reset.
Definition: countdown.cpp:88

References m_startTime, and reset().

+ Here is the call graph for this function:

◆ start()

auto FotoBox::Countdown::start ( ) -> bool

Start countdown.

only start if not running

See also
m_isActive and start value
m_startValue is set
Returns
bool true: running / false: not running

Definition at line 57 of file countdown.cpp.

58 {
59  //not running and start time set
60  if (!m_isActive && m_startTime > 0) {
61  //start countdown
62  m_timer.start();
63 
64  //check if really running
65  if (m_timer.isActive()) {
66  //countdown active
67  m_isActive = true;
68 
69  //inform whith current value
70  Q_EMIT update(m_timeLeft);
71  return true;
72  }
73  }
74 
75  return false;
76 }
void update(unsigned int)
Update countdown.

Referenced by FotoBox::FotoBox::countdown(), and FotoBox::Preferences::Preferences().

+ Here is the caller graph for this function:

◆ stop()

auto FotoBox::Countdown::stop ( ) -> bool

Stop countdown and check.

See also
m_timer has really stopped
Returns
bool true: is stopped / false: not stopped

Definition at line 78 of file countdown.cpp.

79 {
80  //stop timer
81  m_timer.stop();
82  m_isActive = m_timer.isActive();
83 
84  //if isn't active it's stopped so negate bool
85  return !m_isActive;
86 }

Referenced by updateTimeLeft().

+ Here is the caller graph for this function:

◆ update

void FotoBox::Countdown::update ( unsigned int  )
signal

Update countdown.

Referenced by FotoBox::FotoBox::countdown(), FotoBox::Preferences::Preferences(), and updateTimeLeft().

+ Here is the caller graph for this function:

◆ updateTimeLeft()

void FotoBox::Countdown::updateTimeLeft ( )
private

Start the timer until there is no time left, means.

See also
m_timeLeft reaches zero

Attention: this function always deals with the already expired second.

Definition at line 25 of file countdown.cpp.

26 {
27  //this function always deals with the already expired second
28  //check if countdown isn't elapsed
29  if (m_timeLeft > 1) {
30  //reduce counter before sending the signal
31  --m_timeLeft;
32 
33  //send the signal that one second has passed
34  Q_EMIT update(m_timeLeft);
35 
36  //Because it isn't a single shot time we don't need to start it again
37  return;
38  }
39 
40  //countdown finished/elapsed
41  stop();
42  m_timeLeft = 0;
43  Q_EMIT elapsed();
44 }
void elapsed()
Countdown elapsed.

References elapsed(), m_timeLeft, stop(), and update().

Referenced by Countdown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_isActive

bool FotoBox::Countdown::m_isActive {false}
private

status of the countdown

Definition at line 118 of file countdown.h.

Referenced by isActive().

◆ m_startTime

unsigned int FotoBox::Countdown::m_startTime
private

countdown start time (seconds)

Definition at line 112 of file countdown.h.

Referenced by setStartTime().

◆ m_timeLeft

unsigned int FotoBox::Countdown::m_timeLeft
private

time left (seconds)

Definition at line 115 of file countdown.h.

Referenced by updateTimeLeft().

◆ m_timer

QTimer FotoBox::Countdown::m_timer
private

timer intervall (one second)

Definition at line 109 of file countdown.h.

Referenced by Countdown().

◆ ONE_SECOND

constexpr int FotoBox::Countdown::ONE_SECOND = 1000
staticconstexprprivate

one second = 1000 ms

Definition at line 121 of file countdown.h.

Referenced by Countdown().


The documentation for this class was generated from the following files: