From fdc07dba67181ff6b94ff2bdc8449662dfb572dd Mon Sep 17 00:00:00 2001 From: Rexbas Date: Sun, 22 Oct 2023 14:23:14 +0200 Subject: [PATCH] Gui: Split stopAnimation() into onStop() and inherited stop() --- src/Gui/NavigationAnimation.cpp | 9 +++------ src/Gui/NavigationAnimation.h | 4 ++-- src/Gui/NavigationAnimator.cpp | 36 +++++++++++---------------------- src/Gui/NavigationAnimator.h | 3 --- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/Gui/NavigationAnimation.cpp b/src/Gui/NavigationAnimation.cpp index 3025c549f0..e6f898d374 100644 --- a/src/Gui/NavigationAnimation.cpp +++ b/src/Gui/NavigationAnimation.cpp @@ -39,10 +39,8 @@ void NavigationAnimation::updateCurrentValue(const QVariant& value) update(value); } -void NavigationAnimation::stopAnimation() -{ - QAbstractAnimation::stop(); -} +void NavigationAnimation::onStop(bool finished) +{} FixedTimeAnimation::FixedTimeAnimation(NavigationStyle* navigation, const SbRotation& orientation, const SbVec3f& rotationCenter, const SbVec3f& translation, @@ -139,9 +137,8 @@ void SpinningAnimation::update(const QVariant& value) prevAngle = value.toFloat(); } -void SpinningAnimation::stopAnimation() +void SpinningAnimation::onStop(bool finished) { - NavigationAnimation::stopAnimation(); if (navigation->getViewingMode() != NavigationStyle::SPINNING) { return; } diff --git a/src/Gui/NavigationAnimation.h b/src/Gui/NavigationAnimation.h index f93d213ee7..b60da2e4b2 100644 --- a/src/Gui/NavigationAnimation.h +++ b/src/Gui/NavigationAnimation.h @@ -42,7 +42,7 @@ protected: virtual void initialize() = 0; virtual void update(const QVariant& value) = 0; - virtual void stopAnimation(); + virtual void onStop(bool finished); private: void updateCurrentValue(const QVariant& value) override; @@ -85,7 +85,7 @@ private: void initialize() override; void update(const QVariant& value) override; - void stopAnimation() override; + void onStop(bool finished) override; }; } // namespace Gui diff --git a/src/Gui/NavigationAnimator.cpp b/src/Gui/NavigationAnimator.cpp index 21ed00a10f..68b6c59b18 100644 --- a/src/Gui/NavigationAnimator.cpp +++ b/src/Gui/NavigationAnimator.cpp @@ -48,7 +48,11 @@ void NavigationAnimator::start(const std::shared_ptr& anima activeAnimation = animation; activeAnimation->initialize(); - connect(activeAnimation.get(), &NavigationAnimation::finished, this, &NavigationAnimator::reset); + connect(activeAnimation.get(), &NavigationAnimation::finished, this, [this]() { + activeAnimation->onStop(true); + activeAnimation.reset(); + }); + activeAnimation->start(); } @@ -63,37 +67,21 @@ bool NavigationAnimator::startAndWait(const std::shared_ptr stop(); bool finished = true; QEventLoop loop; - loop.connect(animation.get(), &NavigationAnimation::finished, - [&loop, &finished, &animation]() { // clazy:exclude=lambda-in-connect - if (animation->state() == QAbstractAnimation::State::Running) { - finished = false; - } - - loop.quit(); - }); + connect(animation.get(), &NavigationAnimation::finished, &loop, &QEventLoop::quit); start(animation); loop.exec(); return finished; } /** - * @brief Stops an active animation + * @brief Stops an active animation and releases shared ownership of the animation */ void NavigationAnimator::stop() { - if (activeAnimation != nullptr && activeAnimation->state() != QAbstractAnimation::State::Stopped) { - Q_EMIT activeAnimation->finished(); + if (activeAnimation && activeAnimation->state() != QAbstractAnimation::State::Stopped) { + disconnect(activeAnimation.get(), &NavigationAnimation::finished, 0, 0); + activeAnimation->stop(); + activeAnimation->onStop(false); + activeAnimation.reset(); } } - -/** - * @brief Stops the animation and releases ownership of the animation - * - * Is called when the animation finished() signal is received which is triggered when the animation - * is finished or when the animation is interrupted by NavigationAnimator::stop() - */ -void NavigationAnimator::reset() { - disconnect(activeAnimation.get(), &NavigationAnimation::finished, 0, 0); - activeAnimation->stopAnimation(); - activeAnimation.reset(); -} diff --git a/src/Gui/NavigationAnimator.h b/src/Gui/NavigationAnimator.h index d3d654560f..e2f7290a1e 100644 --- a/src/Gui/NavigationAnimator.h +++ b/src/Gui/NavigationAnimator.h @@ -43,9 +43,6 @@ public: bool startAndWait(const std::shared_ptr& animation); void stop(); -private Q_SLOTS: - void reset(); - private: std::shared_ptr activeAnimation; };