QCommonStyle: simplify removeAnimation

Simplify removeAnimation by directly passing the pointer to remove to
the function instead trying to figure them out later on and relying on
QObject::sender().

Change-Id: I9de3a138c60b0da8dd1ab23fe8521798b7f4c13c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-10-20 12:45:05 +02:00
parent 4d9d66d7a8
commit 01eb95acf0
2 changed files with 8 additions and 11 deletions

View File

@ -1275,11 +1275,11 @@ QStyleAnimation * QCommonStylePrivate::animation(const QObject *target) const
void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) const void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) const
{ {
Q_Q(const QCommonStyle); Q_Q(const QCommonStyle);
stopAnimation(animation->target()); const auto target = animation->target();
QObjectPrivate::connect(animation, &QStyleAnimation::destroyed, stopAnimation(target);
this, &QCommonStylePrivate::removeAnimation, QObject::connect(animation, &QStyleAnimation::destroyed,
Qt::UniqueConnection); q, [this, target]() { removeAnimation(target); });
animations.insert(animation->target(), animation); animations.insert(target, animation);
animation->start(); animation->start();
} }
@ -1294,12 +1294,9 @@ void QCommonStylePrivate::stopAnimation(const QObject *target) const
} }
/*! \internal */ /*! \internal */
void QCommonStylePrivate::removeAnimation() void QCommonStylePrivate::removeAnimation(const QObject *target) const
{ {
Q_Q(QCommonStyle); animations.remove(target);
QObject *animation = q->sender();
if (animation)
animations.remove(animation->parent());
} }
#endif #endif

View File

@ -95,7 +95,7 @@ public:
QStyleAnimation* animation(const QObject *target) const; QStyleAnimation* animation(const QObject *target) const;
void startAnimation(QStyleAnimation *animation) const; void startAnimation(QStyleAnimation *animation) const;
void stopAnimation(const QObject *target) const; void stopAnimation(const QObject *target) const;
void removeAnimation(); void removeAnimation(const QObject *target) const;
private: private:
mutable QHash<const QObject*, QStyleAnimation*> animations; mutable QHash<const QObject*, QStyleAnimation*> animations;