tst_Q*AnimationGroup: use QBasicTimer instead of handling raw timer ids
Change-Id: I1392a62e358e8367c24f3db839d53fc0b072483a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
7595c21be8
commit
52fd8c716e
@ -8,9 +8,12 @@
|
|||||||
#include <QSignalSpy>
|
#include <QSignalSpy>
|
||||||
|
|
||||||
#include <QtCore/qanimationgroup.h>
|
#include <QtCore/qanimationgroup.h>
|
||||||
|
#include <QtCore/qbasictimer.h>
|
||||||
#include <QtCore/qsequentialanimationgroup.h>
|
#include <QtCore/qsequentialanimationgroup.h>
|
||||||
#include <QtCore/qparallelanimationgroup.h>
|
#include <QtCore/qparallelanimationgroup.h>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QAbstractAnimation::State)
|
Q_DECLARE_METATYPE(QAbstractAnimation::State)
|
||||||
|
|
||||||
class tst_QAnimationGroup : public QObject
|
class tst_QAnimationGroup : public QObject
|
||||||
@ -72,7 +75,7 @@ class UncontrolledAnimation : public QPropertyAnimation
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
|
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
|
||||||
: QPropertyAnimation(target, propertyName, parent), id(0)
|
: QPropertyAnimation(target, propertyName, parent)
|
||||||
{
|
{
|
||||||
setDuration(250);
|
setDuration(250);
|
||||||
}
|
}
|
||||||
@ -82,22 +85,21 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent *event) override
|
void timerEvent(QTimerEvent *event) override
|
||||||
{
|
{
|
||||||
if (event->timerId() == id)
|
if (event->id() == timer.id())
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRunning(bool running)
|
void updateRunning(bool running)
|
||||||
{
|
{
|
||||||
if (running) {
|
if (running) {
|
||||||
id = startTimer(500);
|
timer.start(500ms, this);
|
||||||
} else {
|
} else {
|
||||||
killTimer(id);
|
timer.stop();
|
||||||
id = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int id;
|
QBasicTimer timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QAnimationGroup::emptyGroup()
|
void tst_QAnimationGroup::emptyGroup()
|
||||||
|
@ -6,9 +6,12 @@
|
|||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QSignalSpy>
|
#include <QSignalSpy>
|
||||||
|
|
||||||
|
#include <QtCore/qbasictimer.h>
|
||||||
#include <QtCore/qparallelanimationgroup.h>
|
#include <QtCore/qparallelanimationgroup.h>
|
||||||
#include <QtCore/qscopeguard.h>
|
#include <QtCore/qscopeguard.h>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QAbstractAnimation::State)
|
Q_DECLARE_METATYPE(QAbstractAnimation::State)
|
||||||
|
|
||||||
class tst_QParallelAnimationGroup : public QObject
|
class tst_QParallelAnimationGroup : public QObject
|
||||||
@ -107,7 +110,7 @@ class UncontrolledAnimation : public QPropertyAnimation
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
|
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
|
||||||
: QPropertyAnimation(target, propertyName, parent), id(0)
|
: QPropertyAnimation(target, propertyName, parent)
|
||||||
{
|
{
|
||||||
setDuration(250);
|
setDuration(250);
|
||||||
setEndValue(0);
|
setEndValue(0);
|
||||||
@ -118,22 +121,21 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent *event) override
|
void timerEvent(QTimerEvent *event) override
|
||||||
{
|
{
|
||||||
if (event->timerId() == id)
|
if (event->id() == timer.id())
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRunning(bool running)
|
void updateRunning(bool running)
|
||||||
{
|
{
|
||||||
if (running) {
|
if (running) {
|
||||||
id = startTimer(500);
|
timer.start(500ms, this);
|
||||||
} else {
|
} else {
|
||||||
killTimer(id);
|
timer.stop();
|
||||||
id = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int id;
|
QBasicTimer timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QParallelAnimationGroup::setCurrentTime()
|
void tst_QParallelAnimationGroup::setCurrentTime()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user