BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
UpdateTimer.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Tool/UpdateTimer.cpp
6 //! @brief Implements class UpdateTimer
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include <QTimer>
17 
18 UpdateTimer::UpdateTimer(int timerInterval, QObject* parent)
19  : QObject(parent)
20  , m_update_request_count(0)
21  , m_timer_interval(timerInterval)
22  , m_is_busy(false)
23  , m_timer(new QTimer(this))
24 {
25  m_timer->setInterval(m_timer_interval);
26  m_timer->setSingleShot(true);
27  connect(m_timer, &QTimer::timeout, this, &UpdateTimer::onTimerTimeout);
28 }
29 
31 {
33  m_timer->stop();
34  m_is_busy = false;
35 }
36 
37 void UpdateTimer::setWallclockTimer(int timerInterval)
38 {
39  m_timer_interval = timerInterval;
40 }
41 
43 {
44  if (m_is_busy)
45  return;
46 
48 
49  if (!m_timer->isActive())
50  m_timer->start(m_timer_interval);
51 }
52 
54 {
55  m_is_busy = true;
56 
57  if (m_update_request_count > 0) {
59  emit timeToUpdate();
60  }
61 
62  m_is_busy = false;
63 }
Defines class UpdateTimer.
UpdateTimer(int timerInterval, QObject *parent=nullptr)
Definition: UpdateTimer.cpp:18
void scheduleUpdate()
Definition: UpdateTimer.cpp:42
QTimer * m_timer
Definition: UpdateTimer.h:49
void timeToUpdate()
void setWallclockTimer(int timerInterval)
Definition: UpdateTimer.cpp:37
bool m_is_busy
Definition: UpdateTimer.h:48
qint64 m_update_request_count
Number of requests accumulated so far.
Definition: UpdateTimer.h:46
int m_timer_interval
Timer in msec.
Definition: UpdateTimer.h:47
void reset()
Definition: UpdateTimer.cpp:30
void onTimerTimeout()
Definition: UpdateTimer.cpp:53