pgLab/stopwatch.cpp

39 lines
821 B
C++
Raw Normal View History

#include "stopwatch.h"
#include "util.h"
StopWatch::StopWatch()
: m_elapsed(std::make_unique<QElapsedTimer>())
{}
void StopWatch::start()
{
m_elapsed->start();
m_timer = std::make_unique<QTimer>(nullptr);
connect(m_timer.get(), SIGNAL(timeout()), this, SLOT(updateTimer()));
m_timer->start(18);
}
void StopWatch::updateTimer()
{
// auto nu = std::chrono::steady_clock::now();
// std::chrono::duration<float, std::milli> diff = nu - m_startTime;
// elapsedTime = diff;
// m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count()));
qint64 ms = m_elapsed->elapsed();
msfloatToHumanReadableString(ms);
if (m_timer) {
int interval = 18;
if (ms >= 10000) {
int rem = ms % 1000;
interval = 1000 - rem;
}
else if (ms >= 1000) {
interval = 100;
}
m_timer->start(interval);
}
}