diff --git a/inputsource.cpp b/inputsource.cpp index 24d182b..de1bbc5 100644 --- a/inputsource.cpp +++ b/inputsource.cpp @@ -71,6 +71,8 @@ void InputSource::openFile(const char *filename) inputFile = file; fileSize = size; mmapData = data; + + invalidate(); } std::unique_ptr[]> InputSource::getSamples(off_t start, off_t length) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7535212..f2f8f64 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -31,7 +31,7 @@ MainWindow::MainWindow() dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); addDockWidget(Qt::LeftDockWidgetArea, dock); - InputSource *input = new InputSource(); + input = new InputSource(); plots = new PlotView(input); setCentralWidget(plots); @@ -45,5 +45,5 @@ void MainWindow::openFile(QString fileName) { QString title="%1: %2"; this->setWindowTitle(title.arg(QApplication::applicationName(),fileName.section('/',-1,-1))); - // TODO: open a file again + input->openFile(fileName.toUtf8().constData()); } diff --git a/mainwindow.h b/mainwindow.h index 5601386..f29bd99 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -38,4 +38,5 @@ public slots: private: SpectrogramControls *dock; PlotView *plots; + InputSource *input; }; diff --git a/plotview.cpp b/plotview.cpp index a0a0582..7822696 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -36,6 +36,8 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0}) mainSampleSource = input; setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); enableCursors(false); + + mainSampleSource->subscribe(this); } void PlotView::refreshSources() @@ -93,13 +95,8 @@ void PlotView::enableCursors(bool enabled) cursors.hide(); } -void PlotView::inputSourceChanged(AbstractSampleSource *src) +void PlotView::invalidateEvent() { - auto derived = dynamic_cast>*>(src); - if (derived == nullptr) - throw new std::runtime_error("SampleSource doesn't provide correct type for GRSampleBuffer"); - - mainSampleSource = derived; refreshSources(); horizontalScrollBar()->setMinimum(0); diff --git a/plotview.h b/plotview.h index 6f6a6c0..3b204f2 100644 --- a/plotview.h +++ b/plotview.h @@ -27,7 +27,7 @@ #include "plot.h" #include "spectrogramplot.h" -class PlotView : public QAbstractScrollArea +class PlotView : public QAbstractScrollArea, Subscriber { Q_OBJECT @@ -36,7 +36,7 @@ public: public slots: void enableCursors(bool enable); - void inputSourceChanged(AbstractSampleSource *input); + void invalidateEvent(); void selectionChanged(std::pair selectionTime, std::pair selectionFreq); void selectionCleared(); void setFFTSize(int size);