mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 10:22:55 +00:00
replace use of QTime as timer with QElapsedTimer
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
14dedd9435
commit
04f3e6c541
12 changed files with 51 additions and 45 deletions
|
@ -29,6 +29,7 @@
|
|||
#include "qpaintengine.h"
|
||||
#include "qgraphicsproxywidget.h"
|
||||
#include "qthread.h"
|
||||
#include "qelapsedtimer.h"
|
||||
#include "qwidget_p.h"
|
||||
#include "qwindowsurface_p.h"
|
||||
#include "qapplication_p.h"
|
||||
|
@ -53,21 +54,26 @@ static inline void qt_flush(QWidget *widget, const QRegion ®ion, QWindowSurfa
|
|||
//using this FPS when you have > 1 windowsurface can give you inaccurate FPS
|
||||
static const bool fpsDebug = qgetenv("QT_DEBUG_FPS").toInt();
|
||||
if (fpsDebug) {
|
||||
static QTime time = QTime::currentTime();
|
||||
static QElapsedTimer time;
|
||||
static int frames = 0;
|
||||
|
||||
frames++;
|
||||
|
||||
if(time.elapsed() > 5000) {
|
||||
if (!time.isValid()) {
|
||||
time.start();
|
||||
}
|
||||
|
||||
if (time.elapsed() > 5000) {
|
||||
double fps = double(frames * 1000) /time.restart();
|
||||
fprintf(stderr,"FPS: %.1f\n",fps);
|
||||
frames = 0;
|
||||
}
|
||||
}
|
||||
if (widget != tlw)
|
||||
if (widget != tlw) {
|
||||
windowSurface->flush(widget, region, tlwOffset + widget->mapTo(tlw, QPoint()));
|
||||
else
|
||||
} else {
|
||||
windowSurface->flush(widget, region, tlwOffset);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
|
|
|
@ -75,7 +75,7 @@ private slots:
|
|||
void setRepeatAction();
|
||||
|
||||
private:
|
||||
void waitUntilTimeElapsed(const QTime& t, int ms);
|
||||
void waitUntilTimeElapsed(const QElapsedTimer& t, int ms);
|
||||
|
||||
QWidget *topLevel;
|
||||
Slider *slider;
|
||||
|
@ -1161,11 +1161,11 @@ void tst_QAbstractSlider::setValue()
|
|||
QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp);
|
||||
}
|
||||
|
||||
void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms)
|
||||
void tst_QAbstractSlider::waitUntilTimeElapsed(const QElapsedTimer& t, int ms)
|
||||
{
|
||||
const int eps = 80;
|
||||
while (t.elapsed() < ms + eps)
|
||||
QTest::qWait(qMax(ms - t.elapsed() + eps, 25));
|
||||
QTest::qWait(qMax(ms - t.elapsed() + eps, qint64(25)));
|
||||
}
|
||||
|
||||
void tst_QAbstractSlider::setRepeatAction()
|
||||
|
@ -1181,7 +1181,7 @@ void tst_QAbstractSlider::setRepeatAction()
|
|||
QCOMPARE(spy.count(), 0);
|
||||
QCOMPARE(slider->value(), 55);
|
||||
|
||||
QTime t;
|
||||
QElapsedTimer t;
|
||||
t.start();
|
||||
QTest::qWait(300);
|
||||
QCOMPARE(spy.count(), 0);
|
||||
|
|
|
@ -498,7 +498,7 @@ void tst_QAtomicInt::fetchAndAdd()
|
|||
|
||||
void tst_QAtomicInt::testAndSet_loop()
|
||||
{
|
||||
QTime stopWatch;
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
|
||||
int iterations = 10000000;
|
||||
|
|
|
@ -506,7 +506,7 @@ void tst_QCoreApplication::processEventsAlwaysSendsPostedEvents()
|
|||
QCoreApplication app(argc, argv);
|
||||
|
||||
ProcessEventsAlwaysSendsPostedEventsObject object;
|
||||
QTime t;
|
||||
QElapsedTimer t;
|
||||
t.start();
|
||||
int i = 1;
|
||||
do {
|
||||
|
|
|
@ -87,7 +87,7 @@ void tst_QMutex::tryLock()
|
|||
testsTurn.release();
|
||||
|
||||
threadsTurn.acquire();
|
||||
QTime timer;
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
QVERIFY(!normalMutex.tryLock(1000));
|
||||
QVERIFY(timer.elapsed() >= 1000);
|
||||
|
@ -227,7 +227,7 @@ enum { one_minute = 60 * 1000, threadCount = 10 };
|
|||
|
||||
class StressTestThread : public QThread
|
||||
{
|
||||
QTime t;
|
||||
QElapsedTimer t;
|
||||
public:
|
||||
static QAtomicInt lockCount;
|
||||
static QAtomicInt sentinel;
|
||||
|
@ -279,7 +279,7 @@ public:
|
|||
|
||||
void run()
|
||||
{
|
||||
QTime t;
|
||||
QElapsedTimer t;
|
||||
t.start();
|
||||
do {
|
||||
if (mutex.tryLock())
|
||||
|
|
|
@ -385,7 +385,7 @@ void tst_QProcess::echoTest()
|
|||
msgStartProcessFailed(binary, process->errorString()).constData());
|
||||
process->write(input);
|
||||
|
||||
QTime stopWatch;
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
do {
|
||||
QVERIFY(process->isOpen());
|
||||
|
@ -440,7 +440,7 @@ void tst_QProcess::echoTest2()
|
|||
QSignalSpy spy1(process, SIGNAL(readyReadStandardOutput()));
|
||||
QSignalSpy spy2(process, SIGNAL(readyReadStandardError()));
|
||||
|
||||
QTime stopWatch;
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
forever {
|
||||
QTestEventLoop::instance().enterLoop(1);
|
||||
|
@ -486,7 +486,7 @@ void tst_QProcess::echoTest_performance()
|
|||
|
||||
QVERIFY(process.waitForStarted());
|
||||
|
||||
QTime stopWatch;
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
|
||||
qint64 totalBytes = 0;
|
||||
|
@ -1785,7 +1785,7 @@ void tst_QProcess::fileWriterProcess()
|
|||
for (int i = 0; i < 5000; ++i)
|
||||
stdinStr += QString::fromLatin1("%1 -- testing testing 1 2 3\n").arg(i);
|
||||
|
||||
QTime stopWatch;
|
||||
QElapsedTimer stopWatch;
|
||||
stopWatch.start();
|
||||
do {
|
||||
QFile::remove("fileWriterProcess.txt");
|
||||
|
|
|
@ -223,14 +223,14 @@ public:
|
|||
SleepType sleepType;
|
||||
int interval;
|
||||
|
||||
int elapsed; // result, in *MILLISECONDS*
|
||||
qint64 elapsed; // result, in *MILLISECONDS*
|
||||
|
||||
void run()
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
elapsed = 0;
|
||||
QTime time;
|
||||
QElapsedTimer time;
|
||||
time.start();
|
||||
switch (sleepType) {
|
||||
case Second:
|
||||
|
@ -938,7 +938,7 @@ void tst_QThread::adoptThreadExitWithActiveTimer()
|
|||
|
||||
void tst_QThread::stressTest()
|
||||
{
|
||||
QTime t;
|
||||
QElapsedTimer t;
|
||||
t.start();
|
||||
while (t.elapsed() < one_minute) {
|
||||
Current_Thread t;
|
||||
|
|
|
@ -826,7 +826,7 @@ void tst_QThreadPool::tryStartCount()
|
|||
|
||||
void tst_QThreadPool::waitForDone()
|
||||
{
|
||||
QTime total, pass;
|
||||
QElapsedTimer total, pass;
|
||||
total.start();
|
||||
|
||||
QThreadPool threadPool;
|
||||
|
@ -881,7 +881,7 @@ void tst_QThreadPool::waitForDoneTimeout()
|
|||
|
||||
void tst_QThreadPool::destroyingWaitsForTasksToFinish()
|
||||
{
|
||||
QTime total, pass;
|
||||
QElapsedTimer total, pass;
|
||||
total.start();
|
||||
|
||||
while (total.elapsed() < 10000) {
|
||||
|
@ -935,7 +935,7 @@ void tst_QThreadPool::stressTest()
|
|||
}
|
||||
};
|
||||
|
||||
QTime total;
|
||||
QElapsedTimer total;
|
||||
total.start();
|
||||
while (total.elapsed() < 30000) {
|
||||
Task t;
|
||||
|
|
|
@ -390,7 +390,7 @@ public:
|
|||
QBasicTimer m_timer;
|
||||
|
||||
int m_interval;
|
||||
QTime m_startedTime;
|
||||
QElapsedTimer m_startedTime;
|
||||
QEventLoop eventLoop;
|
||||
|
||||
inline RestartedTimerFiresTooSoonObject()
|
||||
|
@ -416,7 +416,7 @@ public:
|
|||
|
||||
m_timer.stop();
|
||||
|
||||
int elapsed = m_startedTime.elapsed();
|
||||
qint64 elapsed = m_startedTime.elapsed();
|
||||
|
||||
if (elapsed < m_interval / 2) {
|
||||
// severely too early!
|
||||
|
@ -455,7 +455,7 @@ public slots:
|
|||
void longLastingSlot()
|
||||
{
|
||||
// Don't use timers for this, because we are testing them.
|
||||
QTime time;
|
||||
QElapsedTimer time;
|
||||
time.start();
|
||||
while (time.elapsed() < 200) {
|
||||
for (int c = 0; c < 100000; c++) {} // Mindless looping.
|
||||
|
|
|
@ -63,26 +63,26 @@ void ChipTester::paintEvent(QPaintEvent *event)
|
|||
{
|
||||
QGraphicsView::paintEvent(event);
|
||||
if (++npaints == 50)
|
||||
eventLoop.quit();
|
||||
eventLoop.quit();
|
||||
}
|
||||
|
||||
void ChipTester::timerEvent(QTimerEvent *)
|
||||
{
|
||||
switch (operation) {
|
||||
case Rotate360:
|
||||
rotate(1);
|
||||
break;
|
||||
case ZoomInOut: {
|
||||
qreal s = 0.05 + (npaints / 20.0);
|
||||
setTransform(QTransform().scale(s, s));
|
||||
break;
|
||||
}
|
||||
case Translate: {
|
||||
int offset = horizontalScrollBar()->minimum()
|
||||
+ (npaints % (horizontalScrollBar()->maximum() - horizontalScrollBar()->minimum()));
|
||||
horizontalScrollBar()->setValue(offset);
|
||||
break;
|
||||
}
|
||||
case Rotate360:
|
||||
rotate(1);
|
||||
break;
|
||||
case ZoomInOut: {
|
||||
qreal s = 0.05 + (npaints / 20.0);
|
||||
setTransform(QTransform().scale(s, s));
|
||||
break;
|
||||
}
|
||||
case Translate: {
|
||||
int offset = horizontalScrollBar()->minimum()
|
||||
+ (npaints % (horizontalScrollBar()->maximum() - horizontalScrollBar()->minimum()));
|
||||
horizontalScrollBar()->setValue(offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QEventLoop>
|
||||
#include <QTime>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
class ChipTester : public QGraphicsView
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ private:
|
|||
int npaints;
|
||||
int timerId;
|
||||
QEventLoop eventLoop;
|
||||
QTime stopWatch;
|
||||
QElapsedTimer stopWatch;
|
||||
Operation operation;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
qreal result() const { return m_result; }
|
||||
|
||||
public:
|
||||
QTime timer;
|
||||
QElapsedTimer timer;
|
||||
|
||||
Benchmark *m_benchmark;
|
||||
|
||||
|
@ -70,7 +70,7 @@ void BenchWidget::paintEvent(QPaintEvent *)
|
|||
|
||||
++m_iteration;
|
||||
|
||||
uint currentElapsed = timer.isNull() ? 0 : timer.elapsed();
|
||||
uint currentElapsed = !timer.isValid() ? 0 : timer.elapsed();
|
||||
timer.restart();
|
||||
|
||||
m_total += currentElapsed;
|
||||
|
|
Loading…
Add table
Reference in a new issue