From f471462a84202f12968ff4d4b6f2944aaca588f4 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 1 Apr 2022 22:30:00 +0200 Subject: [PATCH] AnalyzerBase: Refactor code --- src/analyzer/analyzerbase.cpp | 35 +++++++++++++++++++++--------- src/analyzer/analyzerbase.h | 20 +++++------------ src/analyzer/analyzercontainer.cpp | 4 ++-- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/analyzer/analyzerbase.cpp b/src/analyzer/analyzerbase.cpp index 18192926f..55f3469ba 100644 --- a/src/analyzer/analyzerbase.cpp +++ b/src/analyzer/analyzerbase.cpp @@ -32,10 +32,11 @@ #include #include #include +#include +#include +#include #include -#include -#include "core/logging.h" #include "engine/enginebase.h" // INSTRUCTIONS Base2D @@ -51,16 +52,34 @@ Analyzer::Base::Base(QWidget *parent, const uint scopeSize) : QWidget(parent), - timeout_(40), fht_(new FHT(scopeSize)), engine_(nullptr), lastscope_(512), new_frame_(false), - is_playing_(false) {} + is_playing_(false), + timeout_(40) {} -void Analyzer::Base::hideEvent(QHideEvent*) { timer_.stop(); } +Analyzer::Base::~Base() { + delete fht_; +} -void Analyzer::Base::showEvent(QShowEvent*) { timer_.start(timeout(), this); } +void Analyzer::Base::showEvent(QShowEvent*) { + timer_.start(timeout(), this); +} + +void Analyzer::Base::hideEvent(QHideEvent*) { + timer_.stop(); +} + +void Analyzer::Base::ChangeTimeout(const int timeout) { + + timeout_ = timeout; + if (timer_.isActive()) { + timer_.stop(); + timer_.start(timeout_, this); + } + +} void Analyzer::Base::transform(Scope &scope) { @@ -186,10 +205,6 @@ void Analyzer::Base::demo(QPainter &p) { } -void Analyzer::Base::polishEvent() { - init(); -} - void Analyzer::interpolate(const Scope &inVec, Scope &outVec) { double pos = 0.0; diff --git a/src/analyzer/analyzerbase.h b/src/analyzer/analyzerbase.h index 5ee6a144b..ebea39b62 100644 --- a/src/analyzer/analyzerbase.h +++ b/src/analyzer/analyzerbase.h @@ -44,8 +44,8 @@ class QHideEvent; class QShowEvent; -class QTimerEvent; class QPaintEvent; +class QTimerEvent; namespace Analyzer { @@ -55,19 +55,13 @@ class Base : public QWidget { Q_OBJECT public: - ~Base() override { delete fht_; } + ~Base() override; int timeout() const { return timeout_; } void set_engine(EngineBase *engine) { engine_ = engine; } - void changeTimeout(int newTimeout) { - timeout_ = newTimeout; - if (timer_.isActive()) { - timer_.stop(); - timer_.start(timeout_, this); - } - } + void ChangeTimeout(const int timeout); virtual void framerateChanged() {} @@ -76,10 +70,8 @@ class Base : public QWidget { void hideEvent(QHideEvent*) override; void showEvent(QShowEvent*) override; - void paintEvent(QPaintEvent*) override; - void timerEvent(QTimerEvent*) override; - - void polishEvent(); + void paintEvent(QPaintEvent *e) override; + void timerEvent(QTimerEvent *e) override; int resizeExponent(int); int resizeForBands(const int); @@ -90,13 +82,13 @@ class Base : public QWidget { protected: QBasicTimer timer_; - int timeout_; FHT *fht_; EngineBase *engine_; Scope lastscope_; bool new_frame_; bool is_playing_; + int timeout_; }; void interpolate(const Scope&, Scope&); diff --git a/src/analyzer/analyzercontainer.cpp b/src/analyzer/analyzercontainer.cpp index f288e7316..2c095a8ea 100644 --- a/src/analyzer/analyzercontainer.cpp +++ b/src/analyzer/analyzercontainer.cpp @@ -153,7 +153,7 @@ void AnalyzerContainer::ChangeAnalyzer(const int id) { current_analyzer_->set_engine(engine_); // Even if it is not supposed to happen, I don't want to get a dbz error current_framerate_ = current_framerate_ == 0 ? kMediumFramerate : current_framerate_; - current_analyzer_->changeTimeout(1000 / current_framerate_); + current_analyzer_->ChangeTimeout(1000 / current_framerate_); layout()->addWidget(current_analyzer_); @@ -166,7 +166,7 @@ void AnalyzerContainer::ChangeFramerate(int new_framerate) { if (current_analyzer_) { // Even if it is not supposed to happen, I don't want to get a dbz error new_framerate = new_framerate == 0 ? kMediumFramerate : new_framerate; - current_analyzer_->changeTimeout(1000 / new_framerate); + current_analyzer_->ChangeTimeout(1000 / new_framerate); // notify the current analyzer that the framerate has changed current_analyzer_->framerateChanged();