diff --git a/plot.cpp b/plot.cpp index b89d419..9124ae4 100644 --- a/plot.cpp +++ b/plot.cpp @@ -20,6 +20,16 @@ #include "plot.h" Plot::Plot(std::shared_ptr src) : sampleSource(src) +{ + sampleSource->subscribe(this); +} + +Plot::~Plot() +{ + sampleSource->unsubscribe(this); +} + +void Plot::invalidateEvent() { } diff --git a/plot.h b/plot.h index 87da417..a8bc0c0 100644 --- a/plot.h +++ b/plot.h @@ -25,12 +25,14 @@ #include "abstractsamplesource.h" #include "util.h" -class Plot : public QObject +class Plot : public QObject, public Subscriber { - Q_OBJECT + Q_OBJECT public: Plot(std::shared_ptr src); + ~Plot(); + void invalidateEvent() override; virtual bool mouseEvent(QEvent::Type type, QMouseEvent event); virtual std::shared_ptr output(); virtual void paintBack(QPainter &painter, QRect &rect, range_t sampleRange); diff --git a/spectrogramplot.cpp b/spectrogramplot.cpp index 5f50c20..31487b6 100644 --- a/spectrogramplot.cpp +++ b/spectrogramplot.cpp @@ -47,7 +47,6 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr(src); connect(&tuner, &Tuner::tunerMoved, this, &SpectrogramPlot::tunerMoved); - src->subscribe(this); } void SpectrogramPlot::invalidateEvent() diff --git a/spectrogramplot.h b/spectrogramplot.h index 51e2bcc..7c496ef 100644 --- a/spectrogramplot.h +++ b/spectrogramplot.h @@ -33,7 +33,7 @@ class TileCacheKey; -class SpectrogramPlot : public Plot, public Subscriber +class SpectrogramPlot : public Plot { Q_OBJECT