summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-06-12 19:30:44 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-06-13 08:32:51 +0200
commitb367ddfed778ac2f3ce28e39ba83bbe3c1e1437c (patch)
treed6fe2b6f9fca94df39995fe124366c824408b334
parent14fa4591eb34a35cf3d485fd901e3f1e2caa7770 (diff)
downloadqtsvg-b367ddfed778ac2f3ce28e39ba83bbe3c1e1437c.tar.gz
Convert uses of QTime as a timer to QElapsedTimer
One was an easy replacement, the other changes its reference time, which isn't supported by QElapsedTimer. However, it was easy enough to reimplement in terms of QDateTime::currentMSecsSinceEpoch(); and, as it was previously using QTime as timer, this is presumably good enough (although a proper monotonic timer would be better). Change-Id: I90f8e08635e7d2bc364755efd93fce008b6a62c0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r--examples/svg/embedded/fluidlauncher/pictureflow.cpp6
-rw-r--r--src/svg/qsvgtinydocument.cpp19
-rw-r--r--src/svg/qsvgtinydocument_p.h4
3 files changed, 14 insertions, 15 deletions
diff --git a/examples/svg/embedded/fluidlauncher/pictureflow.cpp b/examples/svg/embedded/fluidlauncher/pictureflow.cpp
index 191ff2e..b0657a2 100644
--- a/examples/svg/embedded/fluidlauncher/pictureflow.cpp
+++ b/examples/svg/embedded/fluidlauncher/pictureflow.cpp
@@ -85,7 +85,7 @@
#include <QTimer>
#include <QVector>
#include <QWidget>
-#include <QTime>
+#include <QElapsedTimer>
#include <QDebug>
@@ -376,7 +376,7 @@ public:
int singlePressThreshold;
QPoint firstPress;
QPoint previousPos;
- QTime previousPosTimestamp;
+ QElapsedTimer previousPosTimestamp;
int pixelDistanceMoved;
int pixelsToMovePerSlide;
@@ -1397,7 +1397,7 @@ void PictureFlow::timerEvent(QTimerEvent* event)
{
if(event->timerId() == d->animateTimer.timerId())
{
-// QTime now = QTime::currentTime();
+// QElapsedTimer now; now.start();
d->updateAnimation();
// d->animateTimer.start(qMax(0, 30-now.elapsed() ), this);
}
diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp
index 77aafb4..3143ad2 100644
--- a/src/svg/qsvgtinydocument.cpp
+++ b/src/svg/qsvgtinydocument.cpp
@@ -60,6 +60,7 @@ QSvgTinyDocument::QSvgTinyDocument()
: QSvgStructureNode(0)
, m_widthPercent(false)
, m_heightPercent(false)
+ , m_time(0)
, m_animated(false)
, m_animationDuration(0)
, m_fps(30)
@@ -230,9 +231,8 @@ QSvgTinyDocument * QSvgTinyDocument::load(QXmlStreamReader *contents)
void QSvgTinyDocument::draw(QPainter *p, const QRectF &bounds)
{
- if (m_time.isNull()) {
- m_time.start();
- }
+ if (m_time == 0)
+ m_time = QDateTime::currentMSecsSinceEpoch();
if (displayMode() == QSvgNode::NoneMode)
return;
@@ -269,9 +269,8 @@ void QSvgTinyDocument::draw(QPainter *p, const QString &id,
qCDebug(lcSvgHandler, "Couldn't find node %s. Skipping rendering.", qPrintable(id));
return;
}
- if (m_time.isNull()) {
- m_time.start();
- }
+ if (m_time == 0)
+ m_time = QDateTime::currentMSecsSinceEpoch();
if (node->displayMode() == QSvgNode::NoneMode)
return;
@@ -377,7 +376,7 @@ QSvgFillStyleProperty *QSvgTinyDocument::namedStyle(const QString &id) const
void QSvgTinyDocument::restartAnimation()
{
- m_time.restart();
+ m_time = QDateTime::currentMSecsSinceEpoch();
}
bool QSvgTinyDocument::animated() const
@@ -491,7 +490,7 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const
int QSvgTinyDocument::currentFrame() const
{
- double runningPercentage = qMin(m_time.elapsed()/double(m_animationDuration), 1.);
+ double runningPercentage = qMin(currentElapsed() / double(m_animationDuration), 1.);
int totalFrames = m_fps * m_animationDuration;
@@ -504,8 +503,8 @@ void QSvgTinyDocument::setCurrentFrame(int frame)
double framePercentage = frame/double(totalFrames);
double timeForFrame = m_animationDuration * framePercentage; //in S
timeForFrame *= 1000; //in ms
- int timeToAdd = int(timeForFrame - m_time.elapsed());
- m_time = m_time.addMSecs(timeToAdd);
+ int timeToAdd = int(timeForFrame - currentElapsed());
+ m_time += timeToAdd;
}
void QSvgTinyDocument::setFramesPerSecond(int num)
diff --git a/src/svg/qsvgtinydocument_p.h b/src/svg/qsvgtinydocument_p.h
index 5f5d06b..404587d 100644
--- a/src/svg/qsvgtinydocument_p.h
+++ b/src/svg/qsvgtinydocument_p.h
@@ -132,7 +132,7 @@ private:
QHash<QString, QSvgNode *> m_namedNodes;
QHash<QString, QSvgRefCounter<QSvgFillStyleProperty> > m_namedStyles;
- QTime m_time;
+ qint64 m_time;
bool m_animated;
int m_animationDuration;
int m_fps;
@@ -189,7 +189,7 @@ inline bool QSvgTinyDocument::preserveAspectRatio() const
inline int QSvgTinyDocument::currentElapsed() const
{
- return m_time.elapsed();
+ return QDateTime::currentMSecsSinceEpoch() - m_time;
}
inline int QSvgTinyDocument::animationDuration() const