The querytab now shows the elapsed time of the query using the new stopwatch class.

The old elapsedtime code from the mainwindow has been removed.
This commit is contained in:
Eelke Klein 2017-01-22 08:50:41 +01:00
parent 7f379f3b80
commit 6e852f466f
7 changed files with 232 additions and 163 deletions

View file

@ -1,16 +1,24 @@
#include "stopwatch.h"
#include "util.h"
#include <QLabel>
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);
m_elapsed.start();
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateTimer()));
m_timer.start(18);
}
void StopWatch::stop()
{
m_timeTaken = m_elapsed.elapsed();
m_timer.stop();
updateTimer();
m_elapsed.invalidate();
}
void StopWatch::updateTimer()
@ -19,20 +27,40 @@ void StopWatch::updateTimer()
// std::chrono::duration<float, std::milli> diff = nu - m_startTime;
// elapsedTime = diff;
// m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count()));
if (m_elapsed.isValid()) {
qint64 ms = m_elapsed.elapsed();
m_output->setText(msfloatToHumanReadableString(ms));
qint64 ms = m_elapsed->elapsed();
msfloatToHumanReadableString(ms);
if (m_timer) {
int interval = 18;
if (ms >= 10000) {
int rem = ms % 1000;
interval = 1000 - rem;
if (m_timer.isActive()) {
int interval;
if (ms >= 10000) {
int rem = ms % 1000;
interval = 1000 - rem;
}
else if (ms >= 1000)
interval = 100;
else
interval = 18;
if (interval != m_timer.interval())
m_timer.setInterval(interval);
}
else if (ms >= 1000) {
interval = 100;
}
m_timer->start(interval);
}
}
void StopWatch::setOutputLabel(QLabel *label)
{
m_output = label;
}
qint64 StopWatch::elapsed()
{
qint64 result;
if (m_elapsed.isValid())
result = m_elapsed.elapsed();
else
result = m_timeTaken;
return result;
}